2 // Copyright 2013 Christian Henning
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
8 //#define BOOST_TEST_MODULE pnm_read_test_module
10 #include <boost/gil/extension/io/pnm.hpp>
12 #include <boost/test/unit_test.hpp>
15 #include "scanline_read_test.hpp"
18 using namespace boost::gil;
20 using tag_t = pnm_tag;
22 BOOST_AUTO_TEST_SUITE( gil_io_pnm_tests )
24 #ifdef BOOST_GIL_IO_USE_PNM_TEST_SUITE_IMAGES
26 template< typename Image >
27 void write( Image& img
28 , const string& file_name
31 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
32 write_view( pnm_out + file_name
36 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
39 template< typename Image >
40 void test_pnm_scanline_reader( string filename )
42 test_scanline_reader<Image, pnm_tag>( string( pnm_in + filename ).c_str() );
45 BOOST_AUTO_TEST_CASE( read_header_test )
48 using backend_t = get_reader_backend<std::string const, tag_t>::type;
50 backend_t backend = read_image_info( pnm_filename
54 BOOST_CHECK_EQUAL( backend._info._type , pnm_image_type::color_asc_t::value );
55 BOOST_CHECK_EQUAL( backend._info._width , 256u );
56 BOOST_CHECK_EQUAL( backend._info._height , 256u );
57 BOOST_CHECK_EQUAL( backend._info._max_value, 255u );
61 BOOST_AUTO_TEST_CASE( read_reference_images_test )
67 read_image( pnm_in + "p1.pnm", img, tag_t() );
68 BOOST_CHECK_EQUAL( view( img ).width() , 200u );
69 BOOST_CHECK_EQUAL( view( img ).height(), 200u );
71 write( img, "p1.pnm" );
73 test_pnm_scanline_reader< gray8_image_t >( "p1.pnm" );
80 read_image( pnm_in + "p2.pnm", img, tag_t() );
81 BOOST_CHECK_EQUAL( view( img ).width() , 200u );
82 BOOST_CHECK_EQUAL( view( img ).height(), 200u );
84 write( img, "p2.pnm" );
86 test_pnm_scanline_reader< gray8_image_t >( "p2.pnm" );
93 read_image( pnm_in + "p3.pnm", img, tag_t() );
94 BOOST_CHECK_EQUAL( view( img ).width() , 256u );
95 BOOST_CHECK_EQUAL( view( img ).height(), 256u );
97 write( img, "p3.pnm" );
99 test_pnm_scanline_reader< rgb8_image_t >( "p3.pnm" );
106 read_image( pnm_in + "p4.pnm", img, tag_t() );
107 BOOST_CHECK_EQUAL( view( img ).width() , 200u );
108 BOOST_CHECK_EQUAL( view( img ).height(), 200u );
110 write( img, "p4.pnm" );
112 test_pnm_scanline_reader< gray1_image_t >( "p4.pnm" );
119 read_image( pnm_in + "p5.pnm", img, tag_t() );
120 BOOST_CHECK_EQUAL( view( img ).width() , 200u );
121 BOOST_CHECK_EQUAL( view( img ).height(), 200u );
123 write( img, "p5.pnm" );
125 test_pnm_scanline_reader< gray8_image_t >( "p5.pnm" );
132 read_image( pnm_in + "p6.pnm", img, tag_t() );
133 BOOST_CHECK_EQUAL( view( img ).width() , 256u );
134 BOOST_CHECK_EQUAL( view( img ).height(), 256u );
136 write( img, "p6.pnm" );
138 test_pnm_scanline_reader< rgb8_image_t >( "p6.pnm" );
142 #endif // BOOST_GIL_IO_USE_PNM_TEST_SUITE_IMAGES
144 BOOST_AUTO_TEST_SUITE_END()