tiff_tiled_write_macros.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // Copyright 2013 Christian Henning
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #ifndef BOOST_GIL_TIFF_TILED_WRITE_MACROS_HPP
  9. #define BOOST_GIL_TIFF_TILED_WRITE_MACROS_HPP
  10. #include <boost/gil.hpp>
  11. #include <boost/gil/extension/io/tiff.hpp>
  12. #include <boost/preprocessor/cat.hpp>
  13. #include <boost/preprocessor/stringize.hpp>
  14. #include <boost/preprocessor/tuple/elem.hpp>
  15. #include <boost/preprocessor/comparison/less.hpp>
  16. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  17. #include "paths.hpp"
  18. using tag_t = boost::gil::tiff_tag;
  19. // TODO: Rename the macros to BOOST_GIL_*
  20. #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
  21. #define GENERATE_WRITE_TILE_BIT_ALIGNED_RGB(z, n, data)\
  22. BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_rgb_tile_and_compare_with_,data),_strip_),n), bit_bit_aligned) )\
  23. { \
  24. using namespace std; \
  25. using namespace boost; \
  26. using namespace gil; \
  27. string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-contig-" ); \
  28. string path( tiff_in_GM ); \
  29. string padding(""); \
  30. if(BOOST_PP_LESS(n, 10)==1) \
  31. padding = "0"; \
  32. filename += padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
  33. path += filename; \
  34. bit_aligned_image3_type< n, n, n, rgb_layout_t >::type img_strip, img_saved; \
  35. read_image( path, img_strip, tag_t() ); \
  36. image_write_info<tag_t> info; \
  37. info._is_tiled = true; \
  38. info._tile_width = info._tile_length = 16; \
  39. write_view( tiff_out + filename, view(img_strip), info ); \
  40. read_image( tiff_out + filename, img_saved, tag_t() ); \
  41. BOOST_CHECK_EQUAL( equal_pixels( const_view(img_strip), const_view(img_saved) ), true); \
  42. } \
  43. // Special case for minisblack images
  44. #define GENERATE_WRITE_TILE_BIT_ALIGNED_MINISBLACK(z, n, data)\
  45. BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_minisblack_tile_and_compare_with_,data),_strip_),n), bit_bit_aligned) )\
  46. { \
  47. using namespace std; \
  48. using namespace boost; \
  49. using namespace gil; \
  50. string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
  51. string path( tiff_in_GM ); \
  52. string padding(""); \
  53. if(BOOST_PP_LESS(n, 10)==1) \
  54. padding = "0"; \
  55. filename = filename + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
  56. path += filename; \
  57. bit_aligned_image1_type< n, gray_layout_t >::type img_strip, img_saved; \
  58. read_image( path, img_strip, tag_t() ); \
  59. image_write_info<tag_t> info; \
  60. info._is_tiled = true; \
  61. info._tile_width = info._tile_length = 16; \
  62. write_view( tiff_out + filename, view(img_strip), info ); \
  63. read_image( tiff_out + filename, img_saved, tag_t() ); \
  64. BOOST_CHECK_EQUAL( equal_pixels( const_view(img_strip), const_view(img_saved) ), true); \
  65. } \
  66. // Special case for palette images
  67. #define GENERATE_WRITE_TILE_BIT_ALIGNED_PALETTE(z, n, data)\
  68. BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_palette_tile_and_compare_with_,data),_strip_),n), bit) )\
  69. { \
  70. using namespace std; \
  71. using namespace boost; \
  72. using namespace gil; \
  73. string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
  74. string path( tiff_in_GM ); \
  75. string padding(""); \
  76. if(BOOST_PP_LESS(n, 10)==1) \
  77. padding = "0"; \
  78. filename = filename + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
  79. path += filename; \
  80. rgb16_image_t img_strip, img_saved; \
  81. read_image( path, img_strip, tag_t() ); \
  82. image_write_info<tag_t> info; \
  83. info._is_tiled = true; \
  84. info._tile_width = info._tile_length = 16; \
  85. write_view( tiff_out + filename, view(img_strip), info ); \
  86. read_image( tiff_out + filename, img_saved, tag_t() ); \
  87. BOOST_CHECK_EQUAL( equal_pixels( const_view(img_strip), const_view(img_saved) ), true); \
  88. } \
  89. #else
  90. #define GENERATE_WRITE_TILE_BIT_ALIGNED_RGB(z, n, data)\
  91. BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_rgb_tile_and_compare_with_,data),_strip_),n), bit_bit_aligned) )\
  92. { \
  93. using namespace std; \
  94. using namespace boost; \
  95. using namespace gil; \
  96. string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-contig-" ); \
  97. string path( tiff_in_GM ); \
  98. string padding(""); \
  99. if(BOOST_PP_LESS(n, 10)==1) \
  100. padding = "0"; \
  101. filename += padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
  102. path += filename; \
  103. bit_aligned_image3_type< n, n, n, rgb_layout_t >::type img_strip, img_saved; \
  104. read_image( path, img_strip, tag_t() ); \
  105. image_write_info<tag_t> info; \
  106. info._is_tiled = true; \
  107. info._tile_width = info._tile_length = 16; \
  108. } \
  109. // Special case for minisblack images
  110. #define GENERATE_WRITE_TILE_BIT_ALIGNED_MINISBLACK(z, n, data)\
  111. BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_minisblack_tile_and_compare_with_,data),_strip_),n), bit_bit_aligned) )\
  112. { \
  113. using namespace std; \
  114. using namespace boost; \
  115. using namespace gil; \
  116. string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
  117. string path( tiff_in_GM ); \
  118. string padding(""); \
  119. if(BOOST_PP_LESS(n, 10)==1) \
  120. padding = "0"; \
  121. filename = filename + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
  122. path += filename; \
  123. bit_aligned_image1_type< n, gray_layout_t >::type img_strip, img_saved; \
  124. read_image( path, img_strip, tag_t() ); \
  125. image_write_info<tag_t> info; \
  126. info._is_tiled = true; \
  127. info._tile_width = info._tile_length = 16; \
  128. } \
  129. // Special case for palette images
  130. #define GENERATE_WRITE_TILE_BIT_ALIGNED_PALETTE(z, n, data)\
  131. BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(write_palette_tile_and_compare_with_,data),_strip_),n), bit) )\
  132. { \
  133. using namespace std; \
  134. using namespace boost; \
  135. using namespace gil; \
  136. string filename( string( "tiger-" ) + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
  137. string path( tiff_in_GM ); \
  138. string padding(""); \
  139. if(BOOST_PP_LESS(n, 10)==1) \
  140. padding = "0"; \
  141. filename = filename + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
  142. path += filename; \
  143. rgb16_image_t img_strip, img_saved; \
  144. read_image( path, img_strip, tag_t() ); \
  145. image_write_info<tag_t> info; \
  146. info._is_tiled = true; \
  147. info._tile_width = info._tile_length = 16; \
  148. } \
  149. #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
  150. #endif // BOOST_GIL_TIFF_TILED_READ_MACROS_HPP