png_read_test.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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 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
  12. #include <boost/gil/extension/io/png.hpp>
  13. #include <boost/test/unit_test.hpp>
  14. #include <cstdint>
  15. #include <iostream>
  16. #include "paths.hpp"
  17. #include "scanline_read_test.hpp"
  18. #include "unit_test_utility.hpp"
  19. using namespace std;
  20. using namespace boost;
  21. using namespace gil;
  22. using namespace boost::gil::detail;
  23. namespace fs = boost::filesystem;
  24. using tag_t = png_tag;
  25. BOOST_AUTO_TEST_SUITE( gil_io_png_tests )
  26. using gray_alpha8_pixel_t = pixel<uint8_t, gray_alpha_layout_t>;
  27. using gray_alpha8_image_t= image<gray_alpha8_pixel_t, false>;
  28. using gray_alpha16_pixel_t = pixel<uint16_t, gray_alpha_layout_t>;
  29. using gray_alpha16_image_t = image<gray_alpha16_pixel_t, false>;
  30. template< typename Image >
  31. void test_file( string filename )
  32. {
  33. Image src, dst;
  34. image_read_settings< png_tag > settings;
  35. settings._read_file_gamma = true;
  36. settings._read_transparency_data = true;
  37. using backend_t = get_reader_backend<std::string const, tag_t>::type;
  38. backend_t backend = read_image_info( png_in + filename
  39. , settings
  40. );
  41. read_image( png_in + filename
  42. , src
  43. , settings
  44. );
  45. #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
  46. image_write_info< png_tag > write_info;
  47. write_info._file_gamma = backend._info._file_gamma;
  48. write_view( png_out + filename
  49. , view( src )
  50. , write_info
  51. );
  52. read_image( png_out + filename
  53. , dst
  54. , settings
  55. );
  56. BOOST_CHECK( equal_pixels( const_view( src )
  57. , const_view( dst )
  58. )
  59. );
  60. #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
  61. }
  62. template< typename Image >
  63. void test_png_scanline_reader( string filename )
  64. {
  65. test_scanline_reader<Image, png_tag>( string( png_in + filename ).c_str() );
  66. }
  67. BOOST_AUTO_TEST_CASE( read_header_test )
  68. {
  69. using backend_t = get_reader_backend<std::string const, tag_t>::type;
  70. backend_t backend = read_image_info( png_filename
  71. , tag_t()
  72. );
  73. BOOST_CHECK_EQUAL( backend._info._width , 1000u );
  74. BOOST_CHECK_EQUAL( backend._info._height, 600u );
  75. BOOST_CHECK_EQUAL( backend._info._num_channels, 4 );
  76. BOOST_CHECK_EQUAL( backend._info._bit_depth , 8 );
  77. BOOST_CHECK_EQUAL( backend._info._color_type , PNG_COLOR_TYPE_RGBA );
  78. BOOST_CHECK_EQUAL( backend._info._interlace_method , PNG_INTERLACE_NONE );
  79. BOOST_CHECK_EQUAL( backend._info._compression_method, PNG_COMPRESSION_TYPE_BASE );
  80. BOOST_CHECK_EQUAL( backend._info._filter_method , PNG_FILTER_TYPE_BASE );
  81. BOOST_CHECK_EQUAL( backend._info._file_gamma, 1 );
  82. }
  83. #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
  84. BOOST_AUTO_TEST_CASE( read_pixel_per_meter )
  85. {
  86. image_read_settings< png_tag > settings;
  87. settings.set_read_members_true();
  88. using backend_t = get_reader_backend<std::string const, tag_t>::type;
  89. backend_t backend = read_image_info( png_base_in + "EddDawson/36dpi.png"
  90. , settings
  91. );
  92. BOOST_CHECK_EQUAL( backend._info._pixels_per_meter, png_uint_32( 1417 ));
  93. }
  94. BOOST_AUTO_TEST_CASE(read_with_trns_chunk_color_type_0)
  95. {
  96. // PNG 1.2: For color type 0 (grayscale), the tRNS chunk contains a single gray level value,
  97. // stored in the format:
  98. //
  99. // Gray: 2 bytes, range 0 .. (2^bitdepth)-1
  100. {
  101. auto const png_path = png_in + "tbbn0g04.png";
  102. image_read_settings<png_tag> settings;
  103. settings.set_read_members_true();
  104. auto backend = read_image_info(png_path, settings);
  105. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  106. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  107. BOOST_CHECK_EQUAL(backend._info._bit_depth, 4);
  108. BOOST_CHECK_EQUAL(backend._info._num_channels, 1u);
  109. BOOST_CHECK_EQUAL(backend._info._color_type, PNG_COLOR_TYPE_GRAY);
  110. gray_alpha8_image_t img;
  111. read_image(png_path, img, settings);
  112. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  113. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  114. BOOST_TEST(const_view(img).front() == gray_alpha8c_pixel_t(255, 0));
  115. BOOST_TEST(const_view(img)[78] == gray_alpha8c_pixel_t(221, 255));
  116. BOOST_TEST(const_view(img)[79] == gray_alpha8c_pixel_t(204, 255));
  117. BOOST_TEST(const_view(img)[975] == gray_alpha8c_pixel_t(238, 255));
  118. BOOST_TEST(const_view(img)[976] == gray_alpha8c_pixel_t(221, 255));
  119. BOOST_TEST(const_view(img).back() == gray_alpha8c_pixel_t(255, 0));
  120. }
  121. {
  122. auto const png_path = png_in + "tbwn0g16.png";
  123. image_read_settings<png_tag> settings;
  124. settings.set_read_members_true();
  125. auto backend = read_image_info(png_path, settings);
  126. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  127. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  128. BOOST_CHECK_EQUAL(backend._info._bit_depth, 16);
  129. BOOST_CHECK_EQUAL(backend._info._num_channels, 1u);
  130. BOOST_CHECK_EQUAL(backend._info._color_type, PNG_COLOR_TYPE_GRAY);
  131. gray_alpha16_image_t img;
  132. read_image(png_path, img, settings);
  133. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  134. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  135. BOOST_TEST(const_view(img).front() == gray_alpha16c_pixel_t(65535, 0));
  136. BOOST_TEST(const_view(img)[78] == gray_alpha16c_pixel_t(58339, 65535));
  137. BOOST_TEST(const_view(img)[79] == gray_alpha16c_pixel_t(51657, 65535));
  138. BOOST_TEST(const_view(img)[975] == gray_alpha16c_pixel_t(62965, 65535));
  139. BOOST_TEST(const_view(img)[976] == gray_alpha16c_pixel_t(58339, 65535));
  140. BOOST_TEST(const_view(img).back() == gray_alpha16c_pixel_t(65535, 0));
  141. }
  142. }
  143. BOOST_AUTO_TEST_CASE(read_with_trns_chunk_color_type_2)
  144. {
  145. // PNG 1.2: For color type 2 (truecolor), the tRNS chunk contains a single RGB color value,
  146. // stored in the format:
  147. //
  148. // Red: 2 bytes, range 0 .. (2^bitdepth)-1
  149. // Green: 2 bytes, range 0 .. (2^bitdepth)-1
  150. // Blue: 2 bytes, range 0 .. (2^bitdepth)-1
  151. {
  152. auto const png_path = png_in + "tbbn2c16.png";
  153. image_read_settings<png_tag> settings;
  154. settings.set_read_members_true();
  155. auto backend = read_image_info(png_path, settings);
  156. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  157. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  158. BOOST_CHECK_EQUAL(backend._info._bit_depth, 16);
  159. BOOST_CHECK_EQUAL(backend._info._num_channels, 3u);
  160. BOOST_CHECK_EQUAL(backend._info._color_type, PNG_COLOR_TYPE_RGB);
  161. rgba16_image_t img;
  162. read_image(png_path, img, settings);
  163. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  164. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  165. BOOST_TEST(const_view(img).front() == rgba16c_pixel_t(65535, 65535, 65535, 0));
  166. BOOST_TEST(const_view(img)[78] == rgba16c_pixel_t(58339, 58339, 58339, 65535));
  167. BOOST_TEST(const_view(img)[79] == rgba16c_pixel_t(51657, 51657, 51657, 65535));
  168. BOOST_TEST(const_view(img)[975] == rgba16c_pixel_t(62965, 62965, 62965, 65535));
  169. BOOST_TEST(const_view(img)[976] == rgba16c_pixel_t(58339, 58339, 58339, 65535));
  170. BOOST_TEST(const_view(img).back() == rgba16c_pixel_t(65535, 65535, 65535, 0));
  171. }
  172. {
  173. auto const png_path = png_in + "tbgn2c16.png";
  174. image_read_settings<png_tag> settings;
  175. settings.set_read_members_true();
  176. auto backend = read_image_info(png_path, settings);
  177. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  178. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  179. BOOST_CHECK_EQUAL(backend._info._bit_depth, 16);
  180. BOOST_CHECK_EQUAL(backend._info._num_channels, 3u);
  181. BOOST_CHECK_EQUAL(backend._info._color_type, PNG_COLOR_TYPE_RGB);
  182. rgba16_image_t img;
  183. read_image(png_path, img, settings);
  184. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  185. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  186. BOOST_TEST(const_view(img).front() == rgba16c_pixel_t(65535, 65535, 65535, 0));
  187. BOOST_TEST(const_view(img)[78] == rgba16c_pixel_t(58339, 58339, 58339, 65535));
  188. BOOST_TEST(const_view(img)[79] == rgba16c_pixel_t(51657, 51657, 51657, 65535));
  189. BOOST_TEST(const_view(img)[975] == rgba16c_pixel_t(62965, 62965, 62965, 65535));
  190. BOOST_TEST(const_view(img)[976] == rgba16c_pixel_t(58339, 58339, 58339, 65535));
  191. BOOST_TEST(const_view(img).back() == rgba16c_pixel_t(65535, 65535, 65535, 0));
  192. }
  193. {
  194. auto const png_path = png_in + "tbrn2c08.png";
  195. image_read_settings<png_tag> settings;
  196. settings.set_read_members_true();
  197. auto backend = read_image_info(png_path, settings);
  198. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  199. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  200. BOOST_CHECK_EQUAL(backend._info._bit_depth, 8);
  201. BOOST_CHECK_EQUAL(backend._info._num_channels, 3u);
  202. BOOST_CHECK_EQUAL(backend._info._color_type, PNG_COLOR_TYPE_RGB);
  203. rgba8_image_t img;
  204. read_image(png_path, img, settings);
  205. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  206. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  207. BOOST_TEST(const_view(img).front() == rgba8c_pixel_t(255, 255, 255, 0));
  208. BOOST_TEST(const_view(img)[78] == rgba8c_pixel_t(227, 227, 227, 255));
  209. BOOST_TEST(const_view(img)[79] == rgba8c_pixel_t(201, 201, 201, 255));
  210. BOOST_TEST(const_view(img)[975] == rgba8c_pixel_t(245, 245, 245, 255));
  211. BOOST_TEST(const_view(img)[976] == rgba8c_pixel_t(227, 227, 227, 255));
  212. BOOST_TEST(const_view(img).back() == rgba8c_pixel_t(255, 255, 255, 0));
  213. }
  214. }
  215. BOOST_AUTO_TEST_CASE(read_with_trns_chunk_color_type_3)
  216. {
  217. // PNG 1.2: For color type 3 (indexed color), the tRNS chunk contains a series of one-byte
  218. // alpha values, corresponding to entries in the PLTE chunk:
  219. //
  220. // Alpha for palette index 0: 1 byte
  221. // Alpha for palette index 1: 1 byte
  222. // ...etc...
  223. {
  224. auto const png_path = png_in + "tbbn3p08.png";
  225. image_read_settings<png_tag> settings;
  226. settings.set_read_members_true();
  227. auto backend = read_image_info(png_path, settings);
  228. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  229. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  230. BOOST_CHECK_EQUAL(backend._info._bit_depth, 8);
  231. BOOST_CHECK_EQUAL(backend._info._num_channels, 1u);
  232. BOOST_CHECK_EQUAL(backend._info._color_type, PNG_COLOR_TYPE_PALETTE);
  233. rgba8_image_t img;
  234. read_image(png_path, img, settings);
  235. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  236. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  237. BOOST_TEST(const_view(img).front() == rgba8c_pixel_t(255, 255, 255, 0));
  238. BOOST_TEST(const_view(img)[78] == rgba8c_pixel_t(227, 227, 227, 255));
  239. BOOST_TEST(const_view(img)[79] == rgba8c_pixel_t(201, 201, 201, 255));
  240. BOOST_TEST(const_view(img)[975] == rgba8c_pixel_t(246, 246, 246, 255));
  241. BOOST_TEST(const_view(img)[976] == rgba8c_pixel_t(227, 227, 227, 255));
  242. BOOST_TEST(const_view(img).back() == rgba8c_pixel_t(255, 255, 255, 0));
  243. }
  244. {
  245. auto const png_path = png_in + "tbgn3p08.png";
  246. image_read_settings<png_tag> settings;
  247. settings.set_read_members_true();
  248. auto backend = read_image_info(png_path, settings);
  249. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  250. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  251. BOOST_CHECK_EQUAL(backend._info._bit_depth, 8);
  252. BOOST_CHECK_EQUAL(backend._info._num_channels, 1u);
  253. BOOST_CHECK_EQUAL(backend._info._color_type, PNG_COLOR_TYPE_PALETTE);
  254. rgba8_image_t img;
  255. read_image(png_path, img, settings);
  256. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  257. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  258. BOOST_TEST(const_view(img).front() == rgba8c_pixel_t(255, 255, 255, 0));
  259. BOOST_TEST(const_view(img)[78] == rgba8c_pixel_t(227, 227, 227, 255));
  260. BOOST_TEST(const_view(img)[79] == rgba8c_pixel_t(201, 201, 201, 255));
  261. BOOST_TEST(const_view(img)[975] == rgba8c_pixel_t(246, 246, 246, 255));
  262. BOOST_TEST(const_view(img)[976] == rgba8c_pixel_t(227, 227, 227, 255));
  263. BOOST_TEST(const_view(img).back() == rgba8c_pixel_t(255, 255, 255, 0));
  264. }
  265. {
  266. auto const png_path = png_in + "tp1n3p08.png";
  267. image_read_settings<png_tag> settings;
  268. settings.set_read_members_true();
  269. auto backend = read_image_info(png_path, settings);
  270. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  271. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  272. BOOST_CHECK_EQUAL(backend._info._bit_depth, 8);
  273. BOOST_CHECK_EQUAL(backend._info._num_channels, 1u);
  274. BOOST_CHECK_EQUAL(backend._info._color_type, PNG_COLOR_TYPE_PALETTE);
  275. rgba8_image_t img;
  276. read_image(png_path, img, settings);
  277. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  278. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  279. BOOST_TEST(const_view(img).front() == rgba8c_pixel_t(255, 255, 255, 0));
  280. BOOST_TEST(const_view(img)[78] == rgba8c_pixel_t(227, 227, 227, 255));
  281. BOOST_TEST(const_view(img)[79] == rgba8c_pixel_t(201, 201, 201, 255));
  282. BOOST_TEST(const_view(img)[975] == rgba8c_pixel_t(246, 246, 246, 255));
  283. BOOST_TEST(const_view(img)[976] == rgba8c_pixel_t(227, 227, 227, 255));
  284. BOOST_TEST(const_view(img).back() == rgba8c_pixel_t(255, 255, 255, 0));
  285. }
  286. {
  287. auto const png_path = png_in + "tm3n3p02.png";
  288. image_read_settings<png_tag> settings;
  289. settings.set_read_members_true();
  290. auto backend = read_image_info(png_path, settings);
  291. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  292. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  293. BOOST_CHECK_EQUAL(backend._info._bit_depth, 2);
  294. BOOST_CHECK_EQUAL(backend._info._num_channels, 1u);
  295. BOOST_CHECK_EQUAL(backend._info._color_type, PNG_COLOR_TYPE_PALETTE);
  296. rgba8_image_t img;
  297. read_image(png_path, img, settings);
  298. BOOST_CHECK_EQUAL(backend._info._width, 32u);
  299. BOOST_CHECK_EQUAL(backend._info._height, 32u);
  300. BOOST_TEST(const_view(img).front() == rgba8c_pixel_t(0, 0, 255, 0));
  301. BOOST_TEST(const_view(img)[16] == rgba8c_pixel_t(0, 0, 255, 85));
  302. BOOST_TEST(const_view(img)[511] == rgba8c_pixel_t(0, 0, 255, 85));
  303. BOOST_TEST(const_view(img)[1007] == rgba8c_pixel_t(0, 0, 255, 170));
  304. BOOST_TEST(const_view(img).back() == rgba8c_pixel_t(0, 0, 255, 255));
  305. }
  306. }
  307. #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
  308. #ifdef BOOST_GIL_IO_USE_PNG_TEST_SUITE_IMAGES
  309. BOOST_AUTO_TEST_CASE( BASIc_format_test )
  310. {
  311. // Basic format test files (non-interlaced)
  312. // BASN0g01 - black & white
  313. test_file< gray1_image_t >( "BASN0G01.PNG" );
  314. test_png_scanline_reader< gray1_image_t >( "BASN0G01.PNG" );
  315. // BASN0g02 - 2 bit (4 level) grayscale
  316. test_file< gray2_image_t >( "BASN0G02.PNG" );
  317. test_png_scanline_reader< gray2_image_t >( "BASN0G02.PNG" );
  318. // BASN0g04 - 4 bit (16 level) grayscale
  319. test_file< gray4_image_t >( "BASN0G04.PNG" );
  320. test_png_scanline_reader< gray4_image_t >( "BASN0G04.PNG" );
  321. // BASN0g08 - 8 bit (256 level) grayscale
  322. test_file< gray8_image_t >( "BASN0G08.PNG" );
  323. test_png_scanline_reader< gray8_image_t >( "BASN0G08.PNG" );
  324. // BASN0g16 - 16 bit (64k level) grayscale
  325. test_file< gray16_image_t >( "BASN0G16.PNG" );
  326. test_png_scanline_reader< gray16_image_t >( "BASN0G16.PNG" );
  327. // BASN2c08 - 3x8 bits rgb color
  328. test_file< rgb8_image_t >( "BASN2C08.PNG" );
  329. test_png_scanline_reader< rgb8_image_t >( "BASN2C08.PNG" );
  330. // BASN2c16 - 3x16 bits rgb color
  331. test_file< rgb16_image_t >( "BASN2C16.PNG" );
  332. test_png_scanline_reader< rgb16_image_t >( "BASN2C16.PNG" );
  333. // BASN3p01 - 1 bit (2 color) paletted
  334. test_file< rgb8_image_t >( "BASN3P01.PNG" );
  335. test_png_scanline_reader< rgb8_image_t >( "BASN3P01.PNG" );
  336. // BASN3p02 - 2 bit (4 color) paletted
  337. test_file< rgb8_image_t >( "BASN3P02.PNG" );
  338. test_png_scanline_reader< rgb8_image_t >( "BASN3P02.PNG" );
  339. // BASN3p04 - 4 bit (16 color) paletted
  340. test_file< rgb8_image_t >( "BASN3P04.PNG" );
  341. test_png_scanline_reader< rgb8_image_t >( "BASN3P04.PNG" );
  342. // BASN3p08 - 8 bit (256 color) paletted
  343. test_file< rgb8_image_t >( "BASN3P08.PNG" );
  344. test_png_scanline_reader< rgb8_image_t >( "BASN3P08.PNG" );
  345. // BASN4a08 - 8 bit grayscale + 8 bit alpha-channel
  346. test_file< gray_alpha8_image_t >( "BASN4A08.PNG" );
  347. test_png_scanline_reader< gray_alpha8_image_t >( "BASN4A08.PNG" );
  348. // BASN4a16 - 16 bit grayscale + 16 bit alpha-channel
  349. test_file< gray_alpha16_image_t >( "BASN4A16.PNG" );
  350. test_png_scanline_reader< gray_alpha16_image_t >( "BASN4A16.PNG" );
  351. // BASN6a08 - 3x8 bits rgb color + 8 bit alpha-channel
  352. test_file< rgba8_image_t >( "BASN6A08.PNG" );
  353. test_png_scanline_reader< rgba8_image_t >( "BASN6A08.PNG" );
  354. // BASN6a16 - 3x16 bits rgb color + 16 bit alpha-channel
  355. test_file< rgba16_image_t >( "BASN6A16.PNG" );
  356. test_png_scanline_reader< rgba16_image_t >( "BASN6A16.PNG" );
  357. }
  358. BOOST_AUTO_TEST_CASE( BASIc_format_interlaced_test )
  359. {
  360. // Basic format test files (Adam-7 interlaced)
  361. // BASI0g01 - black & white
  362. test_file< gray1_image_t >( "BASI0G01.PNG" );
  363. // BASI0g02 - 2 bit (4 level) grayscale
  364. test_file< gray2_image_t >( "BASI0G02.PNG" );
  365. // BASI0g04 - 4 bit (16 level) grayscale
  366. test_file< gray4_image_t >( "BASI0G04.PNG" );
  367. // BASI0g08 - 8 bit (256 level) grayscale
  368. test_file< gray8_image_t >( "BASI0G08.PNG" );
  369. // BASI0g16 - 16 bit (64k level) grayscale
  370. test_file< gray16_image_t >( "BASI0G16.PNG" );
  371. // BASI2c08 - 3x8 bits rgb color
  372. test_file< rgb8_image_t >( "BASI2C08.PNG" );
  373. // BASI2c16 - 3x16 bits rgb color
  374. test_file< rgb16_image_t >( "BASI2C16.PNG" );
  375. // BASI3p01 - 1 bit (2 color) paletted
  376. test_file< rgb8_image_t >( "BASI3P01.PNG" );
  377. // BASI3p02 - 2 bit (4 color) paletted
  378. test_file< rgb8_image_t >( "BASI3P02.PNG" );
  379. // BASI3p04 - 4 bit (16 color) paletted
  380. test_file< rgb8_image_t >( "BASI3P04.PNG" );
  381. // BASI3p08 - 8 bit (256 color) paletted
  382. test_file< rgb8_image_t >( "BASI3P08.PNG" );
  383. // BASI4a08 - 8 bit grayscale + 8 bit alpha-channel
  384. test_file< gray_alpha8_image_t >( "BASI4A08.PNG" );
  385. // BASI4a16 - 16 bit grayscale + 16 bit alpha-channel
  386. test_file< gray_alpha16_image_t >( "BASI4A16.PNG" );
  387. // BASI6a08 - 3x8 bits rgb color + 8 bit alpha-channel
  388. test_file< rgba8_image_t >( "BASI6A08.PNG" );
  389. // BASI6a16 - 3x16 bits rgb color + 16 bit alpha-channel
  390. test_file< rgba16_image_t >( "BASI6A16.PNG" );
  391. }
  392. BOOST_AUTO_TEST_CASE( odd_sizes_test )
  393. {
  394. // S01I3P01 - 1x1 paletted file, interlaced
  395. test_file< rgb8_image_t >( "S01I3P01.PNG" );
  396. // S01N3P01 - 1x1 paletted file, no interlacing
  397. test_file< rgb8_image_t >( "S01N3P01.PNG" );
  398. test_png_scanline_reader< rgb8_image_t >( "S01N3P01.PNG" );
  399. // S02I3P01 - 2x2 paletted file, interlaced
  400. test_file< rgb8_image_t >( "S02I3P01.PNG" );
  401. // S02N3P01 - 2x2 paletted file, no interlacing
  402. test_file< rgb8_image_t >( "S02N3P01.PNG" );
  403. test_png_scanline_reader< rgb8_image_t >( "S02N3P01.PNG" );
  404. // S03I3P01 - 3x3 paletted file, interlaced
  405. test_file< rgb8_image_t >( "S03I3P01.PNG" );
  406. // S03N3P01 - 3x3 paletted file, no interlacing
  407. test_file< rgb8_image_t >( "S03N3P01.PNG" );
  408. test_png_scanline_reader< rgb8_image_t >( "S03N3P01.PNG" );
  409. // S04I3P01 - 4x4 paletted file, interlaced
  410. test_file< rgb8_image_t >( "S04I3P01.PNG" );
  411. // S04N3P01 - 4x4 paletted file, no interlacing
  412. test_file< rgb8_image_t >( "S04N3P01.PNG" );
  413. test_png_scanline_reader< rgb8_image_t >( "S04N3P01.PNG" );
  414. // S05I3P02 - 5x5 paletted file, interlaced
  415. test_file< rgb8_image_t >( "S05I3P02.PNG" );
  416. // S05N3P02 - 5x5 paletted file, no interlacing
  417. test_file< rgb8_image_t >( "S05N3P02.PNG" );
  418. test_png_scanline_reader< rgb8_image_t >( "S05N3P02.PNG" );
  419. // S06I3P02 - 6x6 paletted file, interlaced
  420. test_file< rgb8_image_t >( "S06I3P02.PNG" );
  421. // S06N3P02 - 6x6 paletted file, no interlacing
  422. test_file< rgb8_image_t >( "S06N3P02.PNG" );
  423. test_png_scanline_reader< rgb8_image_t >( "S06N3P02.PNG" );
  424. // S07I3P02 - 7x7 paletted file, interlaced
  425. test_file< rgb8_image_t >( "S07I3P02.PNG" );
  426. // S07N3P02 - 7x7 paletted file, no interlacing
  427. test_file< rgb8_image_t >( "S07N3P02.PNG" );
  428. test_png_scanline_reader< rgb8_image_t >( "S07N3P02.PNG" );
  429. // S08I3P02 - 8x8 paletted file, interlaced
  430. test_file< rgb8_image_t >( "S08I3P02.PNG" );
  431. // S08N3P02 - 8x8 paletted file, no interlacing
  432. test_file< rgb8_image_t >( "S08N3P02.PNG" );
  433. test_png_scanline_reader< rgb8_image_t >( "S08N3P02.PNG" );
  434. // S09I3P02 - 9x9 paletted file, interlaced
  435. test_file< rgb8_image_t >( "S09I3P02.PNG" );
  436. // S09N3P02 - 9x9 paletted file, no interlacing
  437. test_file< rgb8_image_t >( "S09N3P02.PNG" );
  438. test_png_scanline_reader< rgb8_image_t >( "S09N3P02.PNG" );
  439. // S32I3P04 - 32x32 paletted file, interlaced
  440. test_file< rgb8_image_t >( "S32I3P04.PNG" );
  441. // S32N3P04 - 32x32 paletted file, no interlacing
  442. test_file< rgb8_image_t >( "S32N3P04.PNG" );
  443. test_png_scanline_reader< rgb8_image_t >( "S32N3P04.PNG" );
  444. // S33I3P04 - 33x33 paletted file, interlaced
  445. test_file< rgb8_image_t >( "S33I3P04.PNG" );
  446. // S33N3P04 - 33x33 paletted file, no interlacing
  447. test_file< rgb8_image_t >( "S33N3P04.PNG" );
  448. test_png_scanline_reader< rgb8_image_t >( "S33N3P04.PNG" );
  449. // S34I3P04 - 34x34 paletted file, interlaced
  450. test_file< rgb8_image_t >( "S34I3P04.PNG" );
  451. // S34N3P04 - 34x34 paletted file, no interlacing
  452. test_file< rgb8_image_t >( "S34N3P04.PNG" );
  453. test_png_scanline_reader< rgb8_image_t >( "S34N3P04.PNG" );
  454. // S35I3P04 - 35x35 paletted file, interlaced
  455. test_file< rgb8_image_t >( "S35I3P04.PNG" );
  456. // S35N3P04 - 35x35 paletted file, no interlacing
  457. test_file< rgb8_image_t >( "S35N3P04.PNG" );
  458. test_png_scanline_reader< rgb8_image_t >( "S35N3P04.PNG" );
  459. // S36I3P04 - 36x36 paletted file, interlaced
  460. test_file< rgb8_image_t >( "S36I3P04.PNG" );
  461. // S36N3P04 - 36x36 paletted file, no interlacing
  462. test_file< rgb8_image_t >( "S36N3P04.PNG" );
  463. test_png_scanline_reader< rgb8_image_t >( "S36N3P04.PNG" );
  464. // S37I3P04 - 37x37 paletted file, interlaced
  465. test_file< rgb8_image_t >( "S37I3P04.PNG" );
  466. // S37N3P04 - 37x37 paletted file, no interlacing
  467. test_file< rgb8_image_t >( "S37N3P04.PNG" );
  468. test_png_scanline_reader< rgb8_image_t >( "S37N3P04.PNG" );
  469. // S38I3P04 - 38x38 paletted file, interlaced
  470. test_file< rgb8_image_t >( "S38I3P04.PNG" );
  471. // S38N3P04 - 38x38 paletted file, no interlacing
  472. test_file< rgb8_image_t >( "S38N3P04.PNG" );
  473. test_png_scanline_reader< rgb8_image_t >( "S38N3P04.PNG" );
  474. // S39I3P04 - 39x39 paletted file, interlaced
  475. test_file< rgb8_image_t >( "S39I3P04.PNG" );
  476. // S39N3P04 - 39x39 paletted file, no interlacing
  477. test_file< rgb8_image_t >( "S39N3P04.PNG" );
  478. test_png_scanline_reader< rgb8_image_t >( "S39N3P04.PNG" );
  479. // S40I3P04 - 40x40 paletted file, interlaced
  480. test_file< rgb8_image_t >( "S40I3P04.PNG" );
  481. // S40N3P04 - 40x40 paletted file, no interlacing
  482. test_file< rgb8_image_t >( "S40N3P04.PNG" );
  483. test_png_scanline_reader< rgb8_image_t >( "S40N3P04.PNG" );
  484. }
  485. BOOST_AUTO_TEST_CASE( background_test )
  486. {
  487. // BGAI4A08 - 8 bit grayscale, alpha, no background chunk, interlaced
  488. test_file< gray_alpha8_image_t >( "BGAI4A08.PNG" );
  489. // BGAI4A16 - 16 bit grayscale, alpha, no background chunk, interlaced
  490. test_file< gray_alpha16_image_t >( "BGAI4A16.PNG" );
  491. // BGAN6A08 - 3x8 bits rgb color, alpha, no background chunk
  492. test_file< rgba8_image_t >( "BGAN6A08.PNG" );
  493. // BGAN6A16 - 3x16 bits rgb color, alpha, no background chunk
  494. test_file< rgba16_image_t >( "BGAN6A16.PNG" );
  495. // BGBN4A08 - 8 bit grayscale, alpha, black background chunk
  496. test_file< gray_alpha8_image_t >( "BGBN4A08.PNG" );
  497. // BGGN4A16 - 16 bit grayscale, alpha, gray background chunk
  498. test_file< gray_alpha16_image_t >( "BGGN4A16.PNG" );
  499. // BGWN6A08 - 3x8 bits rgb color, alpha, white background chunk
  500. test_file< rgba8_image_t >( "BGWN6A08.PNG" );
  501. // BGYN6A16 - 3x16 bits rgb color, alpha, yellow background chunk
  502. test_file< rgba16_image_t >( "BGYN6A16.PNG" );
  503. }
  504. BOOST_AUTO_TEST_CASE( transparency_test )
  505. {
  506. // TBBN1G04 - transparent, black background chunk
  507. // file missing
  508. //test_file< gray_alpha8_image_t >( "TBBN1G04.PNG" );
  509. // TBBN2C16 - transparent, blue background chunk
  510. test_file< rgba16_image_t >( "TBBN2C16.PNG" );
  511. // TBBN3P08 - transparent, black background chunk
  512. test_file< rgba8_image_t >( "TBBN3P08.PNG" );
  513. // TBGN2C16 - transparent, green background chunk
  514. test_file< rgba16_image_t >( "TBGN2C16.PNG" );
  515. // TBGN3P08 - transparent, light-gray background chunk
  516. test_file< rgba8_image_t >( "TBGN3P08.PNG" );
  517. // TBRN2C08 - transparent, red background chunk
  518. test_file< rgba8_image_t >( "TBRN2C08.PNG" );
  519. // TBWN1G16 - transparent, white background chunk
  520. test_file< gray_alpha16_image_t >( "TBWN0G16.PNG" );
  521. // TBWN3P08 - transparent, white background chunk
  522. test_file< rgba8_image_t >( "TBWN3P08.PNG" );
  523. // TBYN3P08 - transparent, yellow background chunk
  524. test_file< rgba8_image_t >( "TBYN3P08.PNG" );
  525. // TP0N1G08 - not transparent for reference (logo on gray)
  526. test_file< gray8_image_t >( "TP0N0G08.PNG" );
  527. // TP0N2C08 - not transparent for reference (logo on gray)
  528. test_file< rgb8_image_t >( "TP0N2C08.PNG" );
  529. // TP0N3P08 - not transparent for reference (logo on gray)
  530. test_file< rgb8_image_t >( "TP0N3P08.PNG" );
  531. // TP1N3P08 - transparent, but no background chunk
  532. test_file< rgba8_image_t >( "TP1N3P08.PNG" );
  533. }
  534. BOOST_AUTO_TEST_CASE( gamma_test )
  535. {
  536. // G03N0G16 - grayscale, file-gamma = 0.35
  537. test_file< gray16_image_t >( "G03N0G16.PNG" );
  538. // G03N2C08 - color, file-gamma = 0.35
  539. test_file< rgb8_image_t >( "G03N2C08.PNG" );
  540. // G03N3P04 - paletted, file-gamma = 0.35
  541. test_file< rgb8_image_t >( "G03N3P04.PNG" );
  542. // G04N0G16 - grayscale, file-gamma = 0.45
  543. test_file< gray16_image_t >( "G04N0G16.PNG" );
  544. // G04N2C08 - color, file-gamma = 0.45
  545. test_file< rgb8_image_t >( "G04N2C08.PNG" );
  546. // G04N3P04 - paletted, file-gamma = 0.45
  547. test_file< rgb8_image_t >( "G04N3P04.PNG" );
  548. // G05N0G16 - grayscale, file-gamma = 0.55
  549. test_file< gray16_image_t >( "G05N0G16.PNG" );
  550. // G05N2C08 - color, file-gamma = 0.55
  551. test_file< rgb8_image_t >( "G05N2C08.PNG" );
  552. // G05N3P04 - paletted, file-gamma = 0.55
  553. test_file< rgb8_image_t >( "G05N3P04.PNG" );
  554. // G07N0G16 - grayscale, file-gamma = 0.70
  555. test_file< gray16_image_t >( "G07N0G16.PNG" );
  556. // G07N2C08 - color, file-gamma = 0.70
  557. test_file< rgb8_image_t >( "G07N2C08.PNG" );
  558. // G07N3P04 - paletted, file-gamma = 0.70
  559. test_file< rgb8_image_t >( "G07N3P04.PNG" );
  560. // G10N0G16 - grayscale, file-gamma = 1.00
  561. test_file< gray16_image_t >( "G10N0G16.PNG" );
  562. // G10N2C08 - color, file-gamma = 1.00
  563. test_file< rgb8_image_t >( "G10N2C08.PNG" );
  564. // G10N3P04 - paletted, file-gamma = 1.00
  565. test_file< rgb8_image_t >( "G10N3P04.PNG" );
  566. // G25N0G16 - grayscale, file-gamma = 2.50
  567. test_file< gray16_image_t >( "G25N0G16.PNG" );
  568. // G25N2C08 - color, file-gamma = 2.50
  569. test_file< rgb8_image_t >( "G25N2C08.PNG" );
  570. // G25N3P04 - paletted, file-gamma = 2.50
  571. test_file< rgb8_image_t >( "G25N3P04.PNG" );
  572. }
  573. #endif // BOOST_GIL_IO_USE_PNG_TEST_SUITE_IMAGES
  574. BOOST_AUTO_TEST_SUITE_END()