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
10 #include <boost/gil/extension/io/pnm.hpp>
11
12 #include <boost/test/unit_test.hpp>
13
14 #include "paths.hpp"
15 #include "scanline_read_test.hpp"
16
17 using namespace std;
18 using namespace boost::gil;
19
20 using tag_t = pnm_tag;
21
BOOST_AUTO_TEST_SUITE(gil_io_pnm_tests)22 BOOST_AUTO_TEST_SUITE( gil_io_pnm_tests )
23
24 #ifdef BOOST_GIL_IO_USE_PNM_TEST_SUITE_IMAGES
25
26 template< typename Image >
27 void write( Image& img
28 , const string& file_name
29 )
30 {
31 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
32 write_view( pnm_out + file_name
33 , view( img )
34 , tag_t()
35 );
36 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
37 }
38
39 template< typename Image >
test_pnm_scanline_reader(string filename)40 void test_pnm_scanline_reader( string filename )
41 {
42 test_scanline_reader<Image, pnm_tag>( string( pnm_in + filename ).c_str() );
43 }
44
BOOST_AUTO_TEST_CASE(read_header_test)45 BOOST_AUTO_TEST_CASE( read_header_test )
46 {
47 {
48 using backend_t = get_reader_backend<std::string const, tag_t>::type;
49
50 backend_t backend = read_image_info( pnm_filename
51 , tag_t()
52 );
53
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 );
58 }
59 }
60
BOOST_AUTO_TEST_CASE(read_reference_images_test)61 BOOST_AUTO_TEST_CASE( read_reference_images_test )
62 {
63 // p1.pnm
64 {
65 gray8_image_t img;
66
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 );
70
71 write( img, "p1.pnm" );
72
73 test_pnm_scanline_reader< gray8_image_t >( "p1.pnm" );
74 }
75
76 // p2.pnm
77 {
78 gray8_image_t img;
79
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 );
83
84 write( img, "p2.pnm" );
85
86 test_pnm_scanline_reader< gray8_image_t >( "p2.pnm" );
87 }
88
89 // p3.pnm
90 {
91 rgb8_image_t img;
92
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 );
96
97 write( img, "p3.pnm" );
98
99 test_pnm_scanline_reader< rgb8_image_t >( "p3.pnm" );
100 }
101
102 // p4.pnm
103 {
104 gray1_image_t img;
105
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 );
109
110 write( img, "p4.pnm" );
111
112 test_pnm_scanline_reader< gray1_image_t >( "p4.pnm" );
113 }
114
115 // p5.pnm
116 {
117 gray8_image_t img;
118
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 );
122
123 write( img, "p5.pnm" );
124
125 test_pnm_scanline_reader< gray8_image_t >( "p5.pnm" );
126 }
127
128 // p6.pnm
129 {
130 rgb8_image_t img;
131
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 );
135
136 write( img, "p6.pnm" );
137
138 test_pnm_scanline_reader< rgb8_image_t >( "p6.pnm" );
139 }
140 }
141
142 #endif // BOOST_GIL_IO_USE_PNM_TEST_SUITE_IMAGES
143
144 BOOST_AUTO_TEST_SUITE_END()
145