pnm_read_test.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 pnm_read_test_module
  9. #include <boost/gil/extension/io/pnm.hpp>
  10. #include <boost/test/unit_test.hpp>
  11. #include "paths.hpp"
  12. #include "scanline_read_test.hpp"
  13. using namespace std;
  14. using namespace boost::gil;
  15. using tag_t = pnm_tag;
  16. BOOST_AUTO_TEST_SUITE( gil_io_pnm_tests )
  17. #ifdef BOOST_GIL_IO_USE_PNM_TEST_SUITE_IMAGES
  18. template< typename Image >
  19. void write( Image& img
  20. , const string& file_name
  21. )
  22. {
  23. #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
  24. write_view( pnm_out + file_name
  25. , view( img )
  26. , tag_t()
  27. );
  28. #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
  29. }
  30. template< typename Image >
  31. void test_pnm_scanline_reader( string filename )
  32. {
  33. test_scanline_reader<Image, pnm_tag>( string( pnm_in + filename ).c_str() );
  34. }
  35. BOOST_AUTO_TEST_CASE( read_header_test )
  36. {
  37. {
  38. using backend_t = get_reader_backend<std::string const, tag_t>::type;
  39. backend_t backend = read_image_info( pnm_filename
  40. , tag_t()
  41. );
  42. BOOST_CHECK_EQUAL( backend._info._type , pnm_image_type::color_asc_t::value );
  43. BOOST_CHECK_EQUAL( backend._info._width , 256u );
  44. BOOST_CHECK_EQUAL( backend._info._height , 256u );
  45. BOOST_CHECK_EQUAL( backend._info._max_value, 255u );
  46. }
  47. }
  48. BOOST_AUTO_TEST_CASE( read_reference_images_test )
  49. {
  50. // p1.pnm
  51. {
  52. gray8_image_t img;
  53. read_image( pnm_in + "p1.pnm", img, tag_t() );
  54. BOOST_CHECK_EQUAL( view( img ).width() , 200u );
  55. BOOST_CHECK_EQUAL( view( img ).height(), 200u );
  56. write( img, "p1.pnm" );
  57. test_pnm_scanline_reader< gray8_image_t >( "p1.pnm" );
  58. }
  59. // p2.pnm
  60. {
  61. gray8_image_t img;
  62. read_image( pnm_in + "p2.pnm", img, tag_t() );
  63. BOOST_CHECK_EQUAL( view( img ).width() , 200u );
  64. BOOST_CHECK_EQUAL( view( img ).height(), 200u );
  65. write( img, "p2.pnm" );
  66. test_pnm_scanline_reader< gray8_image_t >( "p2.pnm" );
  67. }
  68. // p3.pnm
  69. {
  70. rgb8_image_t img;
  71. read_image( pnm_in + "p3.pnm", img, tag_t() );
  72. BOOST_CHECK_EQUAL( view( img ).width() , 256u );
  73. BOOST_CHECK_EQUAL( view( img ).height(), 256u );
  74. write( img, "p3.pnm" );
  75. test_pnm_scanline_reader< rgb8_image_t >( "p3.pnm" );
  76. }
  77. // p4.pnm
  78. {
  79. gray1_image_t img;
  80. read_image( pnm_in + "p4.pnm", img, tag_t() );
  81. BOOST_CHECK_EQUAL( view( img ).width() , 200u );
  82. BOOST_CHECK_EQUAL( view( img ).height(), 200u );
  83. write( img, "p4.pnm" );
  84. test_pnm_scanline_reader< gray1_image_t >( "p4.pnm" );
  85. }
  86. // p5.pnm
  87. {
  88. gray8_image_t img;
  89. read_image( pnm_in + "p5.pnm", img, tag_t() );
  90. BOOST_CHECK_EQUAL( view( img ).width() , 200u );
  91. BOOST_CHECK_EQUAL( view( img ).height(), 200u );
  92. write( img, "p5.pnm" );
  93. test_pnm_scanline_reader< gray8_image_t >( "p5.pnm" );
  94. }
  95. // p6.pnm
  96. {
  97. rgb8_image_t img;
  98. read_image( pnm_in + "p6.pnm", img, tag_t() );
  99. BOOST_CHECK_EQUAL( view( img ).width() , 256u );
  100. BOOST_CHECK_EQUAL( view( img ).height(), 256u );
  101. write( img, "p6.pnm" );
  102. test_pnm_scanline_reader< rgb8_image_t >( "p6.pnm" );
  103. }
  104. }
  105. #endif // BOOST_GIL_IO_USE_PNM_TEST_SUITE_IMAGES
  106. BOOST_AUTO_TEST_SUITE_END()