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 png_read_test_module
9 #define BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
10 #define BOOST_GIL_IO_ENABLE_GRAY_ALPHA
11 #define BOOST_FILESYSTEM_VERSION 3
13 #include <boost/gil/extension/io/png.hpp>
15 #include <boost/test/unit_test.hpp>
21 #include "scanline_read_test.hpp"
24 using namespace boost;
26 using namespace boost::gil::detail;
27 namespace fs = boost::filesystem;
29 using tag_t = png_tag;
31 BOOST_AUTO_TEST_SUITE( gil_io_png_tests )
33 using gray_alpha8_pixel_t = pixel<uint8_t, gray_alpha_layout_t>;
34 using gray_alpha8_image_t= image<gray_alpha8_pixel_t, false>;
36 using gray_alpha16_pixel_t = pixel<uint16_t, gray_alpha_layout_t>;
37 using gray_alpha16_image_t = image<gray_alpha16_pixel_t, false>;
39 template< typename Image >
40 void test_file( string filename )
44 image_read_settings< png_tag > settings;
45 settings._read_file_gamma = true;
46 settings._read_transparency_data = true;
49 using backend_t = get_reader_backend<std::string const, tag_t>::type;
51 backend_t backend = read_image_info( png_in + filename
55 read_image( png_in + filename
61 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
62 image_write_info< png_tag > write_info;
63 write_info._file_gamma = backend._info._file_gamma;
65 write_view( png_out + filename
70 read_image( png_out + filename
76 BOOST_CHECK( equal_pixels( const_view( src )
80 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
83 template< typename Image >
84 void test_png_scanline_reader( string filename )
86 test_scanline_reader<Image, png_tag>( string( png_in + filename ).c_str() );
89 BOOST_AUTO_TEST_CASE( read_header_test )
91 using backend_t = get_reader_backend<std::string const, tag_t>::type;
93 backend_t backend = read_image_info( png_filename
97 BOOST_CHECK_EQUAL( backend._info._width , 1000u );
98 BOOST_CHECK_EQUAL( backend._info._height, 600u );
100 BOOST_CHECK_EQUAL( backend._info._num_channels, 4 );
101 BOOST_CHECK_EQUAL( backend._info._bit_depth , 8 );
102 BOOST_CHECK_EQUAL( backend._info._color_type , PNG_COLOR_TYPE_RGBA );
104 BOOST_CHECK_EQUAL( backend._info._interlace_method , PNG_INTERLACE_NONE );
105 BOOST_CHECK_EQUAL( backend._info._compression_method, PNG_COMPRESSION_TYPE_BASE );
106 BOOST_CHECK_EQUAL( backend._info._filter_method , PNG_FILTER_TYPE_BASE );
109 BOOST_CHECK_EQUAL( backend._info._file_gamma, 1 );
112 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
114 BOOST_AUTO_TEST_CASE( read_pixel_per_meter )
116 image_read_settings< png_tag > settings;
117 settings.set_read_members_true();
119 using backend_t = get_reader_backend<std::string const, tag_t>::type;
121 backend_t backend = read_image_info( png_base_in + "EddDawson/36dpi.png"
125 BOOST_CHECK_EQUAL( backend._info._pixels_per_meter, png_uint_32( 1417 ));
128 #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
130 #ifdef BOOST_GIL_IO_USE_PNG_TEST_SUITE_IMAGES
132 BOOST_AUTO_TEST_CASE( BASIc_format_test )
134 // Basic format test files (non-interlaced)
136 // BASN0g01 - black & white
137 test_file< gray1_image_t >( "BASN0G01.PNG" );
138 test_png_scanline_reader< gray1_image_t >( "BASN0G01.PNG" );
140 // BASN0g02 - 2 bit (4 level) grayscale
141 test_file< gray2_image_t >( "BASN0G02.PNG" );
142 test_png_scanline_reader< gray2_image_t >( "BASN0G02.PNG" );
144 // BASN0g04 - 4 bit (16 level) grayscale
145 test_file< gray4_image_t >( "BASN0G04.PNG" );
146 test_png_scanline_reader< gray4_image_t >( "BASN0G04.PNG" );
148 // BASN0g08 - 8 bit (256 level) grayscale
149 test_file< gray8_image_t >( "BASN0G08.PNG" );
150 test_png_scanline_reader< gray8_image_t >( "BASN0G08.PNG" );
152 // BASN0g16 - 16 bit (64k level) grayscale
153 test_file< gray16_image_t >( "BASN0G16.PNG" );
154 test_png_scanline_reader< gray16_image_t >( "BASN0G16.PNG" );
156 // BASN2c08 - 3x8 bits rgb color
157 test_file< rgb8_image_t >( "BASN2C08.PNG" );
158 test_png_scanline_reader< rgb8_image_t >( "BASN2C08.PNG" );
160 // BASN2c16 - 3x16 bits rgb color
161 test_file< rgb16_image_t >( "BASN2C16.PNG" );
162 test_png_scanline_reader< rgb16_image_t >( "BASN2C16.PNG" );
164 // BASN3p01 - 1 bit (2 color) paletted
165 test_file< rgb8_image_t >( "BASN3P01.PNG" );
166 test_png_scanline_reader< rgb8_image_t >( "BASN3P01.PNG" );
168 // BASN3p02 - 2 bit (4 color) paletted
169 test_file< rgb8_image_t >( "BASN3P02.PNG" );
170 test_png_scanline_reader< rgb8_image_t >( "BASN3P02.PNG" );
172 // BASN3p04 - 4 bit (16 color) paletted
173 test_file< rgb8_image_t >( "BASN3P04.PNG" );
174 test_png_scanline_reader< rgb8_image_t >( "BASN3P04.PNG" );
176 // BASN3p08 - 8 bit (256 color) paletted
177 test_file< rgb8_image_t >( "BASN3P08.PNG" );
178 test_png_scanline_reader< rgb8_image_t >( "BASN3P08.PNG" );
180 // BASN4a08 - 8 bit grayscale + 8 bit alpha-channel
181 test_file< gray_alpha8_image_t >( "BASN4A08.PNG" );
182 test_png_scanline_reader< gray_alpha8_image_t >( "BASN4A08.PNG" );
184 // BASN4a16 - 16 bit grayscale + 16 bit alpha-channel
185 test_file< gray_alpha16_image_t >( "BASN4A16.PNG" );
186 test_png_scanline_reader< gray_alpha16_image_t >( "BASN4A16.PNG" );
188 // BASN6a08 - 3x8 bits rgb color + 8 bit alpha-channel
189 test_file< rgba8_image_t >( "BASN6A08.PNG" );
190 test_png_scanline_reader< rgba8_image_t >( "BASN6A08.PNG" );
192 // BASN6a16 - 3x16 bits rgb color + 16 bit alpha-channel
193 test_file< rgba16_image_t >( "BASN6A16.PNG" );
194 test_png_scanline_reader< rgba16_image_t >( "BASN6A16.PNG" );
197 BOOST_AUTO_TEST_CASE( BASIc_format_interlaced_test )
199 // Basic format test files (Adam-7 interlaced)
201 // BASI0g01 - black & white
202 test_file< gray1_image_t >( "BASI0G01.PNG" );
204 // BASI0g02 - 2 bit (4 level) grayscale
205 test_file< gray2_image_t >( "BASI0G02.PNG" );
207 // BASI0g04 - 4 bit (16 level) grayscale
208 test_file< gray4_image_t >( "BASI0G04.PNG" );
210 // BASI0g08 - 8 bit (256 level) grayscale
211 test_file< gray8_image_t >( "BASI0G08.PNG" );
213 // BASI0g16 - 16 bit (64k level) grayscale
214 test_file< gray16_image_t >( "BASI0G16.PNG" );
216 // BASI2c08 - 3x8 bits rgb color
217 test_file< rgb8_image_t >( "BASI2C08.PNG" );
219 // BASI2c16 - 3x16 bits rgb color
220 test_file< rgb16_image_t >( "BASI2C16.PNG" );
222 // BASI3p01 - 1 bit (2 color) paletted
223 test_file< rgb8_image_t >( "BASI3P01.PNG" );
225 // BASI3p02 - 2 bit (4 color) paletted
226 test_file< rgb8_image_t >( "BASI3P02.PNG" );
228 // BASI3p04 - 4 bit (16 color) paletted
229 test_file< rgb8_image_t >( "BASI3P04.PNG" );
231 // BASI3p08 - 8 bit (256 color) paletted
232 test_file< rgb8_image_t >( "BASI3P08.PNG" );
234 // BASI4a08 - 8 bit grayscale + 8 bit alpha-channel
235 test_file< gray_alpha8_image_t >( "BASI4A08.PNG" );
237 // BASI4a16 - 16 bit grayscale + 16 bit alpha-channel
238 test_file< gray_alpha16_image_t >( "BASI4A16.PNG" );
240 // BASI6a08 - 3x8 bits rgb color + 8 bit alpha-channel
241 test_file< rgba8_image_t >( "BASI6A08.PNG" );
243 // BASI6a16 - 3x16 bits rgb color + 16 bit alpha-channel
244 test_file< rgba16_image_t >( "BASI6A16.PNG" );
247 BOOST_AUTO_TEST_CASE( odd_sizes_test )
249 // S01I3P01 - 1x1 paletted file, interlaced
250 test_file< rgb8_image_t >( "S01I3P01.PNG" );
252 // S01N3P01 - 1x1 paletted file, no interlacing
253 test_file< rgb8_image_t >( "S01N3P01.PNG" );
254 test_png_scanline_reader< rgb8_image_t >( "S01N3P01.PNG" );
256 // S02I3P01 - 2x2 paletted file, interlaced
257 test_file< rgb8_image_t >( "S02I3P01.PNG" );
259 // S02N3P01 - 2x2 paletted file, no interlacing
260 test_file< rgb8_image_t >( "S02N3P01.PNG" );
261 test_png_scanline_reader< rgb8_image_t >( "S02N3P01.PNG" );
263 // S03I3P01 - 3x3 paletted file, interlaced
264 test_file< rgb8_image_t >( "S03I3P01.PNG" );
266 // S03N3P01 - 3x3 paletted file, no interlacing
267 test_file< rgb8_image_t >( "S03N3P01.PNG" );
268 test_png_scanline_reader< rgb8_image_t >( "S03N3P01.PNG" );
270 // S04I3P01 - 4x4 paletted file, interlaced
271 test_file< rgb8_image_t >( "S04I3P01.PNG" );
273 // S04N3P01 - 4x4 paletted file, no interlacing
274 test_file< rgb8_image_t >( "S04N3P01.PNG" );
275 test_png_scanline_reader< rgb8_image_t >( "S04N3P01.PNG" );
277 // S05I3P02 - 5x5 paletted file, interlaced
278 test_file< rgb8_image_t >( "S05I3P02.PNG" );
280 // S05N3P02 - 5x5 paletted file, no interlacing
281 test_file< rgb8_image_t >( "S05N3P02.PNG" );
282 test_png_scanline_reader< rgb8_image_t >( "S05N3P02.PNG" );
284 // S06I3P02 - 6x6 paletted file, interlaced
285 test_file< rgb8_image_t >( "S06I3P02.PNG" );
287 // S06N3P02 - 6x6 paletted file, no interlacing
288 test_file< rgb8_image_t >( "S06N3P02.PNG" );
289 test_png_scanline_reader< rgb8_image_t >( "S06N3P02.PNG" );
291 // S07I3P02 - 7x7 paletted file, interlaced
292 test_file< rgb8_image_t >( "S07I3P02.PNG" );
294 // S07N3P02 - 7x7 paletted file, no interlacing
295 test_file< rgb8_image_t >( "S07N3P02.PNG" );
296 test_png_scanline_reader< rgb8_image_t >( "S07N3P02.PNG" );
298 // S08I3P02 - 8x8 paletted file, interlaced
299 test_file< rgb8_image_t >( "S08I3P02.PNG" );
301 // S08N3P02 - 8x8 paletted file, no interlacing
302 test_file< rgb8_image_t >( "S08N3P02.PNG" );
303 test_png_scanline_reader< rgb8_image_t >( "S08N3P02.PNG" );
305 // S09I3P02 - 9x9 paletted file, interlaced
306 test_file< rgb8_image_t >( "S09I3P02.PNG" );
308 // S09N3P02 - 9x9 paletted file, no interlacing
309 test_file< rgb8_image_t >( "S09N3P02.PNG" );
310 test_png_scanline_reader< rgb8_image_t >( "S09N3P02.PNG" );
312 // S32I3P04 - 32x32 paletted file, interlaced
313 test_file< rgb8_image_t >( "S32I3P04.PNG" );
315 // S32N3P04 - 32x32 paletted file, no interlacing
316 test_file< rgb8_image_t >( "S32N3P04.PNG" );
317 test_png_scanline_reader< rgb8_image_t >( "S32N3P04.PNG" );
319 // S33I3P04 - 33x33 paletted file, interlaced
320 test_file< rgb8_image_t >( "S33I3P04.PNG" );
322 // S33N3P04 - 33x33 paletted file, no interlacing
323 test_file< rgb8_image_t >( "S33N3P04.PNG" );
324 test_png_scanline_reader< rgb8_image_t >( "S33N3P04.PNG" );
326 // S34I3P04 - 34x34 paletted file, interlaced
327 test_file< rgb8_image_t >( "S34I3P04.PNG" );
329 // S34N3P04 - 34x34 paletted file, no interlacing
330 test_file< rgb8_image_t >( "S34N3P04.PNG" );
331 test_png_scanline_reader< rgb8_image_t >( "S34N3P04.PNG" );
333 // S35I3P04 - 35x35 paletted file, interlaced
334 test_file< rgb8_image_t >( "S35I3P04.PNG" );
336 // S35N3P04 - 35x35 paletted file, no interlacing
337 test_file< rgb8_image_t >( "S35N3P04.PNG" );
338 test_png_scanline_reader< rgb8_image_t >( "S35N3P04.PNG" );
340 // S36I3P04 - 36x36 paletted file, interlaced
341 test_file< rgb8_image_t >( "S36I3P04.PNG" );
343 // S36N3P04 - 36x36 paletted file, no interlacing
344 test_file< rgb8_image_t >( "S36N3P04.PNG" );
345 test_png_scanline_reader< rgb8_image_t >( "S36N3P04.PNG" );
347 // S37I3P04 - 37x37 paletted file, interlaced
348 test_file< rgb8_image_t >( "S37I3P04.PNG" );
350 // S37N3P04 - 37x37 paletted file, no interlacing
351 test_file< rgb8_image_t >( "S37N3P04.PNG" );
352 test_png_scanline_reader< rgb8_image_t >( "S37N3P04.PNG" );
354 // S38I3P04 - 38x38 paletted file, interlaced
355 test_file< rgb8_image_t >( "S38I3P04.PNG" );
357 // S38N3P04 - 38x38 paletted file, no interlacing
358 test_file< rgb8_image_t >( "S38N3P04.PNG" );
359 test_png_scanline_reader< rgb8_image_t >( "S38N3P04.PNG" );
361 // S39I3P04 - 39x39 paletted file, interlaced
362 test_file< rgb8_image_t >( "S39I3P04.PNG" );
364 // S39N3P04 - 39x39 paletted file, no interlacing
365 test_file< rgb8_image_t >( "S39N3P04.PNG" );
366 test_png_scanline_reader< rgb8_image_t >( "S39N3P04.PNG" );
368 // S40I3P04 - 40x40 paletted file, interlaced
369 test_file< rgb8_image_t >( "S40I3P04.PNG" );
371 // S40N3P04 - 40x40 paletted file, no interlacing
372 test_file< rgb8_image_t >( "S40N3P04.PNG" );
373 test_png_scanline_reader< rgb8_image_t >( "S40N3P04.PNG" );
376 BOOST_AUTO_TEST_CASE( background_test )
378 // BGAI4A08 - 8 bit grayscale, alpha, no background chunk, interlaced
379 test_file< gray_alpha8_image_t >( "BGAI4A08.PNG" );
381 // BGAI4A16 - 16 bit grayscale, alpha, no background chunk, interlaced
382 test_file< gray_alpha16_image_t >( "BGAI4A16.PNG" );
384 // BGAN6A08 - 3x8 bits rgb color, alpha, no background chunk
385 test_file< rgba8_image_t >( "BGAN6A08.PNG" );
387 // BGAN6A16 - 3x16 bits rgb color, alpha, no background chunk
388 test_file< rgba16_image_t >( "BGAN6A16.PNG" );
390 // BGBN4A08 - 8 bit grayscale, alpha, black background chunk
391 test_file< gray_alpha8_image_t >( "BGBN4A08.PNG" );
393 // BGGN4A16 - 16 bit grayscale, alpha, gray background chunk
394 test_file< gray_alpha16_image_t >( "BGGN4A16.PNG" );
396 // BGWN6A08 - 3x8 bits rgb color, alpha, white background chunk
397 test_file< rgba8_image_t >( "BGWN6A08.PNG" );
399 // BGYN6A16 - 3x16 bits rgb color, alpha, yellow background chunk
400 test_file< rgba16_image_t >( "BGYN6A16.PNG" );
403 BOOST_AUTO_TEST_CASE( transparency_test )
405 // TBBN1G04 - transparent, black background chunk
407 //test_file< gray_alpha8_image_t >( "TBBN1G04.PNG" );
409 // TBBN2C16 - transparent, blue background chunk
410 test_file< rgba16_image_t >( "TBBN2C16.PNG" );
412 // TBBN3P08 - transparent, black background chunk
413 test_file< rgba8_image_t >( "TBBN3P08.PNG" );
415 // TBGN2C16 - transparent, green background chunk
416 test_file< rgba16_image_t >( "TBGN2C16.PNG" );
418 // TBGN3P08 - transparent, light-gray background chunk
419 test_file< rgba8_image_t >( "TBGN3P08.PNG" );
421 // TBRN2C08 - transparent, red background chunk
422 test_file< rgba8_image_t >( "TBRN2C08.PNG" );
424 // TBWN1G16 - transparent, white background chunk
425 test_file< gray_alpha16_image_t >( "TBWN0G16.PNG" );
427 // TBWN3P08 - transparent, white background chunk
428 test_file< rgba8_image_t >( "TBWN3P08.PNG" );
430 // TBYN3P08 - transparent, yellow background chunk
431 test_file< rgba8_image_t >( "TBYN3P08.PNG" );
433 // TP0N1G08 - not transparent for reference (logo on gray)
434 test_file< gray8_image_t >( "TP0N0G08.PNG" );
436 // TP0N2C08 - not transparent for reference (logo on gray)
437 test_file< rgb8_image_t >( "TP0N2C08.PNG" );
439 // TP0N3P08 - not transparent for reference (logo on gray)
440 test_file< rgb8_image_t >( "TP0N3P08.PNG" );
442 // TP1N3P08 - transparent, but no background chunk
443 test_file< rgba8_image_t >( "TP1N3P08.PNG" );
446 BOOST_AUTO_TEST_CASE( gamma_test )
448 // G03N0G16 - grayscale, file-gamma = 0.35
449 test_file< gray16_image_t >( "G03N0G16.PNG" );
451 // G03N2C08 - color, file-gamma = 0.35
452 test_file< rgb8_image_t >( "G03N2C08.PNG" );
454 // G03N3P04 - paletted, file-gamma = 0.35
455 test_file< rgb8_image_t >( "G03N3P04.PNG" );
457 // G04N0G16 - grayscale, file-gamma = 0.45
458 test_file< gray16_image_t >( "G04N0G16.PNG" );
460 // G04N2C08 - color, file-gamma = 0.45
461 test_file< rgb8_image_t >( "G04N2C08.PNG" );
463 // G04N3P04 - paletted, file-gamma = 0.45
464 test_file< rgb8_image_t >( "G04N3P04.PNG" );
466 // G05N0G16 - grayscale, file-gamma = 0.55
467 test_file< gray16_image_t >( "G05N0G16.PNG" );
469 // G05N2C08 - color, file-gamma = 0.55
470 test_file< rgb8_image_t >( "G05N2C08.PNG" );
472 // G05N3P04 - paletted, file-gamma = 0.55
473 test_file< rgb8_image_t >( "G05N3P04.PNG" );
475 // G07N0G16 - grayscale, file-gamma = 0.70
476 test_file< gray16_image_t >( "G07N0G16.PNG" );
478 // G07N2C08 - color, file-gamma = 0.70
479 test_file< rgb8_image_t >( "G07N2C08.PNG" );
481 // G07N3P04 - paletted, file-gamma = 0.70
482 test_file< rgb8_image_t >( "G07N3P04.PNG" );
484 // G10N0G16 - grayscale, file-gamma = 1.00
485 test_file< gray16_image_t >( "G10N0G16.PNG" );
487 // G10N2C08 - color, file-gamma = 1.00
488 test_file< rgb8_image_t >( "G10N2C08.PNG" );
490 // G10N3P04 - paletted, file-gamma = 1.00
491 test_file< rgb8_image_t >( "G10N3P04.PNG" );
493 // G25N0G16 - grayscale, file-gamma = 2.50
494 test_file< gray16_image_t >( "G25N0G16.PNG" );
496 // G25N2C08 - color, file-gamma = 2.50
497 test_file< rgb8_image_t >( "G25N2C08.PNG" );
499 // G25N3P04 - paletted, file-gamma = 2.50
500 test_file< rgb8_image_t >( "G25N3P04.PNG" );
503 #endif // BOOST_GIL_IO_USE_PNG_TEST_SUITE_IMAGES
505 BOOST_AUTO_TEST_SUITE_END()