tiff_subimage_test.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. //#define BOOST_TEST_MODULE tiff_subimage_test_module
  9. #include <boost/gil/extension/io/tiff.hpp>
  10. #include <boost/test/unit_test.hpp>
  11. #include <fstream>
  12. #include <sstream>
  13. #include "mandel_view.hpp"
  14. #include "paths.hpp"
  15. #include "subimage_test.hpp"
  16. using namespace std;
  17. using namespace boost;
  18. using namespace gil;
  19. using tag_t = tiff_tag;
  20. #include <boost/preprocessor/cat.hpp>
  21. #include <boost/preprocessor/stringize.hpp>
  22. #include <boost/preprocessor/tuple/elem.hpp>
  23. #include <boost/preprocessor/comparison/less.hpp>
  24. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  25. #define GENERATE_SUBIMAGE_TEST(z, n, data)\
  26. BOOST_AUTO_TEST_CASE( BOOST_PP_CAT(BOOST_PP_CAT(BOOST_PP_CAT(subimage_test,data),n), bit_bit_aligned) )\
  27. { \
  28. using namespace std; \
  29. using namespace boost; \
  30. using namespace gil; \
  31. string filename_strip( tiff_in_GM + "tiger-" + BOOST_PP_STRINGIZE(data) + "-strip-" ); \
  32. string filename_tile ( tiff_in_GM + "tiger-" + BOOST_PP_STRINGIZE(data) + "-tile-" ); \
  33. string padding(""); \
  34. if(BOOST_PP_LESS(n, 10)==1) \
  35. padding = "0"; \
  36. filename_strip = filename_strip + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
  37. filename_tile = filename_tile + padding + BOOST_PP_STRINGIZE(n) + ".tif"; \
  38. bit_aligned_image1_type< n, gray_layout_t >::type img1, img2, img3; \
  39. point_t top_left( 10, 10 ); \
  40. point_t dim( 32, 32 ); \
  41. image_read_settings< tag_t > settings( top_left, dim ); \
  42. read_image( filename_strip, img1, settings ); \
  43. read_image( filename_tile, img2 , settings ); \
  44. read_image( filename_strip, img3, tag_t() ); \
  45. BOOST_CHECK( equal_pixels( const_view( img1 ), const_view( img2 ))); \
  46. BOOST_CHECK( equal_pixels( const_view( img1 ), subimage_view( view( img3 ), top_left, dim ))); \
  47. } \
  48. BOOST_AUTO_TEST_SUITE( gil_io_tiff_tests )
  49. #ifdef BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
  50. BOOST_PP_REPEAT_FROM_TO( 1, 8, GENERATE_SUBIMAGE_TEST, minisblack )
  51. BOOST_PP_REPEAT_FROM_TO( 9, 16, GENERATE_SUBIMAGE_TEST, minisblack )
  52. BOOST_PP_REPEAT_FROM_TO( 17, 27, GENERATE_SUBIMAGE_TEST, minisblack )
  53. // @todo: there is a bug somewhere when the number of bits is 27 up to 31.
  54. BOOST_AUTO_TEST_CASE( subimage_test_8 )
  55. {
  56. gray8_image_t img1, img2, img3;
  57. point_t top_left( 10, 10 );
  58. point_t dim( 32, 32 );
  59. image_read_settings< tag_t > settings( top_left, dim );
  60. read_image( tiff_in_GM + "tiger-minisblack-strip-08.tif", img1, settings );
  61. read_image( tiff_in_GM + "tiger-minisblack-tile-08.tif" , img2, settings );
  62. read_image( tiff_in_GM + "tiger-minisblack-strip-08.tif", img3, tag_t() );
  63. BOOST_CHECK( equal_pixels( const_view( img1 ), const_view( img2 )));
  64. BOOST_CHECK( equal_pixels( const_view( img1 ), subimage_view( view( img3 ), top_left, dim )));
  65. }
  66. BOOST_AUTO_TEST_CASE( subimage_test_16 )
  67. {
  68. gray16_image_t img1, img2, img3;
  69. point_t top_left( 10, 10 );
  70. point_t dim( 32, 32 );
  71. image_read_settings< tag_t > settings( top_left, dim );
  72. read_image( tiff_in_GM + "tiger-minisblack-strip-16.tif", img1, settings );
  73. read_image( tiff_in_GM + "tiger-minisblack-tile-16.tif" , img2, settings );
  74. read_image( tiff_in_GM + "tiger-minisblack-strip-16.tif", img3, tag_t() );
  75. BOOST_CHECK( equal_pixels( const_view( img1 ), const_view( img2 )));
  76. BOOST_CHECK( equal_pixels( const_view( img1 ), subimage_view( view( img3 ), top_left, dim )));
  77. }
  78. BOOST_AUTO_TEST_CASE( subimage_test_32 )
  79. {
  80. using gray32_pixel_t = pixel<unsigned int, gray_layout_t>;
  81. image< gray32_pixel_t, false > img1, img2, img3;
  82. point_t top_left( 10, 10 );
  83. point_t dim( 32, 32 );
  84. image_read_settings< tag_t > settings( top_left, dim );
  85. read_image( tiff_in_GM + "tiger-minisblack-strip-32.tif", img1, settings );
  86. read_image( tiff_in_GM + "tiger-minisblack-tile-32.tif" , img2, settings );
  87. read_image( tiff_in_GM + "tiger-minisblack-strip-32.tif", img3, tag_t() );
  88. BOOST_CHECK( equal_pixels( const_view( img1 ), const_view( img2 )));
  89. BOOST_CHECK( equal_pixels( const_view( img1 ), subimage_view( view( img3 ), top_left, dim )));
  90. }
  91. #endif // BOOST_GIL_IO_USE_TIFF_GRAPHICSMAGICK_TEST_SUITE_IMAGES
  92. BOOST_AUTO_TEST_SUITE_END()