tags.hpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. //
  2. // Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
  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. #ifndef BOOST_GIL_EXTENSION_IO_PNG_TAGS_HPP
  9. #define BOOST_GIL_EXTENSION_IO_PNG_TAGS_HPP
  10. #include <boost/gil/io/base.hpp>
  11. #include <string>
  12. #include <vector>
  13. #ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
  14. #ifdef BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
  15. # error "Cannot set both symbols"
  16. #endif // BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
  17. #endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
  18. #ifndef BOOST_GIL_EXTENSION_IO_PNG_C_LIB_COMPILED_AS_CPLUSPLUS
  19. extern "C" {
  20. #endif
  21. #include <png.h>
  22. #ifndef BOOST_GIL_EXTENSION_IO_PNG_C_LIB_COMPILED_AS_CPLUSPLUS
  23. }
  24. #endif
  25. #ifndef BOOST_GIL_EXTENSION_IO_ZLIB_C_LIB_COMPILED_AS_CPLUSPLUS
  26. extern "C" {
  27. #endif
  28. #include <zlib.h>
  29. #ifndef BOOST_GIL_EXTENSION_IO_ZLIB_C_LIB_COMPILED_AS_CPLUSPLUS
  30. }
  31. #endif
  32. #if PNG_LIBPNG_VER_MAJOR == 1
  33. #if PNG_LIBPNG_VER_MINOR <= 4
  34. #define BOOST_GIL_IO_PNG_1_4_OR_LOWER
  35. #endif // PNG_LIBPNG_VER_MAJOR == 1
  36. #endif // PNG_LIBPNG_VER_MINOR <= 4
  37. namespace boost { namespace gil {
  38. /// Defines png tag.
  39. struct png_tag : format_tag {};
  40. /// see http://en.wikipedia.org/wiki/Portable_Network_Graphics for reference
  41. /// Defines type for image width property.
  42. struct png_image_width : property_base< png_uint_32 > {};
  43. /// Defines type for image height property.
  44. struct png_image_height : property_base< png_uint_32 > {};
  45. /// Defines type for interlace method property.
  46. struct png_interlace_method : property_base< int > {};
  47. /// Defines type for filter method property.
  48. struct png_filter_method : property_base< int > {};
  49. /// Defines type for bit depth method property.
  50. struct png_bitdepth : property_base< int > {};
  51. /// Defines type for bit depth method property.
  52. struct png_color_type : property_base< int > {};
  53. /// Defines type for number of channels property.
  54. struct png_num_channels : property_base< png_byte > {};
  55. #ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
  56. /// Defines type for CIE chromacities property.
  57. struct png_chromacities_type : property_base< double > {};
  58. /// Defines type for gamma correction property.
  59. struct png_gamma : property_base< double > {};
  60. /// Defines type for physical scale unit property.
  61. struct png_unit : property_base< int > {};
  62. /// Defines type for physical scale property.
  63. struct png_scale : property_base< double > {};
  64. #else
  65. /// Defines type for CIE chromacities property.
  66. struct png_chromacities_type : property_base< png_fixed_point > {};
  67. /// Defines type for gamma correction property.
  68. struct png_gamma : property_base< png_fixed_point > {};
  69. /// Defines type for physical scale unit property.
  70. struct png_unit : property_base< int > {};
  71. #ifdef BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
  72. /// Defines type for physical scale property.
  73. struct png_scale : property_base< png_fixed_point > {};
  74. #else
  75. /// Defines type for physical scale property.
  76. struct png_scale : property_base< std::string > {};
  77. #endif // BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
  78. #endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
  79. /// Returns image resolution in pixels per meter, from pHYs chunk data.
  80. struct png_pixels_per_meter : property_base< png_uint_32 > {};
  81. /// Defines type for ICC profile name property.
  82. struct png_ICC_name : property_base< std::string > {};
  83. /// Defines type for ICC profile property.
  84. #if PNG_LIBPNG_VER_MINOR >= 5
  85. struct png_ICC_profile : property_base< std:: vector <uint8_t> > {};
  86. #else
  87. struct png_ICC_profile : property_base< std:: vector <char> > {};
  88. #endif
  89. /// Defines type for ICC profile length property.
  90. struct png_ICC_profile_length : property_base< png_uint_32 > {};
  91. /// Defines type for ICC compression property.
  92. struct png_ICC_compression_type : property_base< int > {};
  93. /// Defines type for rendering intent property.
  94. struct png_intent : property_base< int > {};
  95. /// Defines type for color palette property.
  96. struct png_color_palette : property_base< std::vector< png_color > > {};
  97. /// Defines type for number of colors property.
  98. struct png_num_palette : property_base< int > {};
  99. /// Defines type for background property.
  100. struct png_background : property_base< png_color_16 > {};
  101. /// Defines type for histogram property.
  102. struct png_histrogram : property_base< std::vector< png_uint_16 > > {};
  103. /// Defines type for screen offset property.
  104. struct png_offset : property_base< png_int_32 > {};
  105. /// Defines type for screen offset type property.
  106. struct png_offset_type : property_base< int > {};
  107. /// Defines type pixel calibration for property.
  108. struct png_CAL : property_base< std::string > {};
  109. /// Defines type for pixel calibration parameters property.
  110. struct png_CAL_params : property_base< std::vector< std::string > > {};
  111. /// Defines type for pixel calibration x property.
  112. struct png_CAL_X : property_base< png_int_32 > {};
  113. /// Defines type for pixel calibration type property.
  114. struct png_CAL_type : property_base< int > {};
  115. /// Defines type for number of pixel calibration properties.
  116. struct png_CAL_nparam : property_base< int > {};
  117. /// Defines type for physical resolution property.
  118. struct png_resolution : property_base< png_uint_32 > {};
  119. /// Defines type for physical resolution unit property.
  120. struct png_unit_type : property_base< int > {};
  121. /// Defines type for significant bits property.
  122. struct png_significant_bits : property_base< png_color_8 > {};
  123. /// Helper structure for reading text property.
  124. struct gil_io_png_text
  125. {
  126. /// Compression type
  127. int _compression;
  128. // Key
  129. std::string _key;
  130. /// Text
  131. std::string _text;
  132. };
  133. /// Defines type for text property.
  134. struct png_text_ : property_base< std::vector< gil_io_png_text > > {};
  135. /// Defines type for number of text property.
  136. struct png_num_text : property_base< int > {};
  137. /// Defines type for modification time property.
  138. struct png_mod_time : property_base< png_time > {};
  139. /// Defines type for transparency data property.
  140. struct png_trans : property_base< std::vector< png_byte > > {};
  141. /// Defines type for number of transparency data property.
  142. struct png_num_trans : property_base< int > {};
  143. /// Defines type for transparency data values property.
  144. struct png_trans_values : property_base< std::vector< png_color_16 > > {};
  145. /// Defines type for png function return type.
  146. struct png_return_value : property_base< png_uint_32 > {};
  147. ////////////////////////
  148. // Write properties
  149. ////////////////////////
  150. // relates to info_ptr->compression_type
  151. struct png_compression_type : property_base< png_byte >
  152. {
  153. static const type default_value = PNG_COMPRESSION_TYPE_BASE;
  154. };
  155. // compression level - default values taken from libpng manual.
  156. // Look for png_set_compression_level
  157. struct png_compression_level : property_base< int >
  158. {
  159. static const type default_value = 3;
  160. };
  161. struct png_compression_mem_level : property_base< int >
  162. {
  163. static const type default_value = MAX_MEM_LEVEL;
  164. };
  165. struct png_compression_strategy : property_base< int >
  166. {
  167. static const type default_value = Z_DEFAULT_STRATEGY;
  168. };
  169. struct png_compression_window_bits : property_base< int >
  170. {
  171. static const type default_value = 9;
  172. };
  173. struct png_compression_method : property_base< int >
  174. {
  175. static const type default_value = 8;
  176. };
  177. struct png_compression_buffer_size : property_base< int >
  178. {
  179. static const type default_value = 8192;
  180. };
  181. // dithering
  182. struct png_dithering_palette : property_base< std::vector< png_color > >
  183. {};
  184. struct png_dithering_num_palette : property_base< int >
  185. {
  186. static const type default_value = 0;
  187. };
  188. struct png_dithering_maximum_colors : property_base< int >
  189. {
  190. static const type default_value = 0;
  191. };
  192. struct png_dithering_histogram : property_base< std::vector< png_uint_16 > >
  193. {};
  194. struct png_full_dither : property_base< int >
  195. {
  196. static const type default_value = 0;
  197. };
  198. // filter
  199. struct png_filter : property_base< int >
  200. {
  201. static const type default_value = 0;
  202. };
  203. // invert mono
  204. struct png_invert_mono : property_base< bool >
  205. {
  206. static const type default_value = false;
  207. };
  208. // true bits
  209. struct png_true_bits : property_base< std::vector< png_color_8 > >
  210. {};
  211. // sRGB Intent
  212. struct png_srgb_intent : property_base< int >
  213. {
  214. static const type default_value = 0;
  215. };
  216. // strip alpha
  217. struct png_strip_alpha : property_base< bool >
  218. {
  219. static const type default_value = false;
  220. };
  221. struct png_swap_alpha : property_base< bool >
  222. {
  223. static const type default_value = false;
  224. };
  225. /// PNG info base class. Containing all header information both for reading and writing.
  226. ///
  227. /// This base structure was created to avoid code doubling.
  228. struct png_info_base
  229. {
  230. /// Default constructor
  231. png_info_base()
  232. : _width ( 0 )
  233. , _height( 0 )
  234. , _bit_depth ( 0 )
  235. , _color_type ( 0 )
  236. , _interlace_method ( PNG_INTERLACE_NONE )
  237. , _compression_method( PNG_COMPRESSION_TYPE_DEFAULT )
  238. , _filter_method ( PNG_FILTER_TYPE_DEFAULT )
  239. , _num_channels( 0 )
  240. #ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
  241. , _valid_cie_colors( 0 )
  242. , _white_x ( 0.0 )
  243. , _white_y ( 0.0 )
  244. , _red_x ( 0.0 )
  245. , _red_y ( 0.0 )
  246. , _green_x ( 0.0 )
  247. , _green_y ( 0.0 )
  248. , _blue_x ( 0.0 )
  249. , _blue_y ( 0.0 )
  250. , _valid_file_gamma( 0 )
  251. , _file_gamma ( 1.0 )
  252. #else
  253. , _valid_cie_colors( 0 )
  254. , _white_x ( 0 )
  255. , _white_y ( 0 )
  256. , _red_x ( 0 )
  257. , _red_y ( 0 )
  258. , _green_x ( 0 )
  259. , _green_y ( 0 )
  260. , _blue_x ( 0 )
  261. , _blue_y ( 0 )
  262. , _valid_file_gamma( 0 )
  263. , _file_gamma ( 1 )
  264. #endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
  265. , _valid_icc_profile ( 0 )
  266. , _icc_name ( )
  267. , _iccp_compression_type( PNG_COMPRESSION_TYPE_BASE )
  268. , _profile ( )
  269. , _profile_length ( 0 )
  270. , _valid_intent( 0 )
  271. , _intent ( 0 )
  272. , _valid_palette( 0 )
  273. , _palette ( )
  274. , _num_palette ( 0 )
  275. , _valid_background( 0 )
  276. , _background ( )
  277. , _valid_histogram( 0 )
  278. , _histogram ( )
  279. , _valid_offset ( 0 )
  280. , _offset_x ( 0 )
  281. , _offset_y ( 0 )
  282. , _off_unit_type( PNG_OFFSET_PIXEL )
  283. , _valid_pixel_calibration( 0 )
  284. , _purpose ( )
  285. , _X0 ( 0 )
  286. , _X1 ( 0 )
  287. , _cal_type ( 0 )
  288. , _num_params ( 0 )
  289. , _units ( )
  290. , _params ( )
  291. , _valid_resolution( 0 )
  292. , _res_x ( 0 )
  293. , _res_y ( 0 )
  294. , _phy_unit_type ( PNG_RESOLUTION_UNKNOWN )
  295. , _pixels_per_meter( 0 )
  296. , _valid_significant_bits( 0 )
  297. , _sig_bits ( )
  298. , _valid_scale_factors( 0 )
  299. , _scale_unit ( PNG_SCALE_UNKNOWN )
  300. #ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
  301. , _scale_width ( 0.0 )
  302. , _scale_height( 0.0 )
  303. #else
  304. #ifdef BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
  305. , _scale_width ( 0 )
  306. , _scale_height( 0 )
  307. #else
  308. , _scale_width ()
  309. , _scale_height()
  310. #endif // BOOST_GIL_IO_PNG_FIXED_POINT_SUPPORTED
  311. #endif // BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
  312. , _valid_text( 0 )
  313. , _text ( )
  314. , _num_text ( 0 )
  315. , _valid_modification_time( 0 )
  316. , _mod_time ( )
  317. , _valid_transparency_factors( 0 )
  318. , _trans ( )
  319. , _num_trans ( 0 )
  320. , _trans_values ( )
  321. {}
  322. /// The image width.
  323. png_image_width::type _width;
  324. /// The image height.
  325. png_image_height::type _height;
  326. /// The bit depth per channel.
  327. png_bitdepth::type _bit_depth;
  328. /// The color space type.
  329. png_color_type::type _color_type;
  330. /// The interlace methos.
  331. png_interlace_method::type _interlace_method;
  332. /// The compression method.
  333. png_compression_method::type _compression_method;
  334. /// The filer method.
  335. png_filter_method::type _filter_method;
  336. /// The number of channels.
  337. png_num_channels::type _num_channels;
  338. // CIE chromacities
  339. /// The return value when reading CIE chromacities.
  340. png_return_value::type _valid_cie_colors;
  341. /// The white x value.
  342. png_chromacities_type::type _white_x;
  343. /// The white y value.
  344. png_chromacities_type::type _white_y;
  345. /// The red x value.
  346. png_chromacities_type::type _red_x;
  347. /// The red y value.
  348. png_chromacities_type::type _red_y;
  349. /// The green x value.
  350. png_chromacities_type::type _green_x;
  351. /// The green y value.
  352. png_chromacities_type::type _green_y;
  353. /// The blue x value.
  354. png_chromacities_type::type _blue_x;
  355. /// The blue y value.
  356. png_chromacities_type::type _blue_y;
  357. // Gamma Value
  358. /// The return value when reading gamma value.
  359. png_return_value::type _valid_file_gamma;
  360. /// The file gamma value.
  361. png_gamma::type _file_gamma;
  362. // Embedded ICC profile
  363. /// The return value when reading ICC profile.
  364. png_return_value::type _valid_icc_profile;
  365. /// The ICC name.
  366. png_ICC_name::type _icc_name;
  367. /// The icc compression type.
  368. png_ICC_compression_type::type _iccp_compression_type;
  369. /// The ICC profile.
  370. png_ICC_profile::type _profile;
  371. /// The ICC profile length.
  372. png_ICC_profile_length::type _profile_length;
  373. // Rendering intent
  374. /// The return value when reading rendering intent.
  375. png_return_value::type _valid_intent;
  376. /// The rendering intent value.
  377. png_intent::type _intent;
  378. // Image palette
  379. /// The return value when reading image palette.
  380. png_return_value::type _valid_palette;
  381. /// The color palette.
  382. png_color_palette::type _palette;
  383. /// The number of colors in the palettes.
  384. png_num_palette::type _num_palette;
  385. // Background
  386. /// The return value when reading background.
  387. png_return_value::type _valid_background;
  388. /// The background color.
  389. png_background::type _background;
  390. // Histogram
  391. /// The return value when reading histogram.
  392. png_return_value::type _valid_histogram;
  393. /// The histogram.
  394. png_histrogram::type _histogram;
  395. // Screen offsets
  396. /// The return value when reading screen offsets.
  397. png_return_value::type _valid_offset;
  398. /// The x offset.
  399. png_offset::type _offset_x;
  400. /// The y offset.
  401. png_offset::type _offset_y;
  402. /// The offset unit.
  403. png_offset_type::type _off_unit_type;
  404. // Pixel Calibration
  405. /// The return value when reading pixel calibration.
  406. png_return_value::type _valid_pixel_calibration;
  407. /// The purpose.
  408. png_CAL::type _purpose;
  409. /// The x_0 value.
  410. png_CAL_X::type _X0;
  411. /// The x_1 value.
  412. png_CAL_X::type _X1;
  413. /// The calibration type.
  414. png_CAL_type::type _cal_type;
  415. /// The number of calibration parameters.
  416. png_CAL_nparam::type _num_params;
  417. /// The calibration unit type.
  418. png_CAL::type _units;
  419. /// The calibration parameters.
  420. png_CAL_params::type _params;
  421. // Physical resolution
  422. /// The return value when reading physical resolution properties.
  423. png_return_value::type _valid_resolution;
  424. /// The x physical resolution.
  425. png_resolution::type _res_x;
  426. /// The y physical resolution.
  427. png_resolution::type _res_y;
  428. /// The physical resolution unit.
  429. png_unit_type::type _phy_unit_type;
  430. /// The Image resolution in pixels per meter.
  431. png_pixels_per_meter::type _pixels_per_meter;
  432. // Number of significant bits
  433. /// The return value when reading significant bits.
  434. png_return_value::type _valid_significant_bits;
  435. /// The significant bits.
  436. png_significant_bits::type _sig_bits;
  437. // Scale Factors
  438. /// The return value when reading scale factors.
  439. png_return_value::type _valid_scale_factors;
  440. /// The scaling unit.
  441. png_unit::type _scale_unit;
  442. /// The scaling width.
  443. png_scale::type _scale_width;
  444. /// The scaling height.
  445. png_scale::type _scale_height;
  446. // Comments information
  447. /// The return value when reading image comments.
  448. png_return_value::type _valid_text;
  449. /// The comments.
  450. png_text_::type _text;
  451. /// The number of comments.
  452. png_num_text::type _num_text;
  453. // Last modification time
  454. /// The return value when reading modification time.
  455. png_return_value::type _valid_modification_time;
  456. /// The modification time.
  457. png_mod_time::type _mod_time;
  458. // Transparency data
  459. /// The return value when reading transparency data.
  460. png_return_value::type _valid_transparency_factors;
  461. /// The transparency data.
  462. png_trans::type _trans;
  463. /// The number of transparency data.
  464. png_num_trans::type _num_trans;
  465. /// The transparency data values.
  466. png_trans_values::type _trans_values;
  467. };
  468. /// Read information for png images.
  469. ///
  470. /// The structure is returned when using read_image_info.
  471. template<>
  472. struct image_read_info< png_tag > : public png_info_base
  473. {
  474. /// Default constructor.
  475. image_read_info< png_tag >()
  476. : png_info_base()
  477. {}
  478. };
  479. /// PNG settings base class.
  480. ///
  481. /// This base structure was created to avoid code doubling.
  482. struct png_read_settings_base
  483. {
  484. /// Default Constructor.
  485. png_read_settings_base()
  486. {
  487. _read_cie_chromacities = false;
  488. _read_file_gamma = false;
  489. _read_icc_profile = false;
  490. _read_intent = false;
  491. _read_palette = false;
  492. _read_background = false;
  493. _read_histogram = false;
  494. _read_screen_offsets = false;
  495. _read_pixel_calibration = false;
  496. _read_physical_resolution = false;
  497. _read_pixels_per_meter = false;
  498. _read_number_of_significant_bits = false;
  499. _read_scale_factors = false;
  500. _read_comments = false;
  501. _read_last_modification_time = false;
  502. _read_transparency_data = false;
  503. }
  504. /// Helper function to enabling reading all png properties.
  505. void set_read_members_true()
  506. {
  507. _read_cie_chromacities = true;
  508. _read_file_gamma = true;
  509. _read_icc_profile = true;
  510. _read_intent = true;
  511. _read_palette = true;
  512. _read_background = true;
  513. _read_histogram = true;
  514. _read_screen_offsets = true;
  515. _read_pixel_calibration = true;
  516. _read_physical_resolution = true;
  517. _read_pixels_per_meter = true;
  518. _read_number_of_significant_bits = true;
  519. _read_scale_factors = true;
  520. _read_comments = true;
  521. _read_last_modification_time = true;
  522. _read_transparency_data = true;
  523. }
  524. /// Enable reading CIE chromacities.
  525. bool _read_cie_chromacities;
  526. /// Enable reading file gamma.
  527. bool _read_file_gamma;
  528. /// Enable reading ICC profile.
  529. bool _read_icc_profile;
  530. /// Enable reading rendering intent.
  531. bool _read_intent;
  532. /// Enable reading color palette.
  533. bool _read_palette;
  534. /// Enable reading background color.
  535. bool _read_background;
  536. /// Enable reading histogram.
  537. bool _read_histogram;
  538. /// Enable reading screen offsets.
  539. bool _read_screen_offsets;
  540. /// Enable reading pixel calibration.
  541. bool _read_pixel_calibration;
  542. /// Enable reading physical resolution.
  543. bool _read_physical_resolution;
  544. /// Enable reading pixels per meter information.
  545. bool _read_pixels_per_meter;
  546. /// Enable reading significant bits.
  547. bool _read_number_of_significant_bits;
  548. /// Enable reading scaling factors.
  549. bool _read_scale_factors;
  550. /// Enable reading comments.
  551. bool _read_comments;
  552. /// Enable reading modification time.
  553. bool _read_last_modification_time;
  554. /// Enable reading transparency data.
  555. bool _read_transparency_data;
  556. };
  557. #ifdef BOOST_GIL_IO_PNG_FLOATING_POINT_SUPPORTED
  558. /// Read settings for png images.
  559. ///
  560. /// The structure can be used for all read_xxx functions, except read_image_info.
  561. template<>
  562. struct image_read_settings< png_tag > : public image_read_settings_base
  563. , public png_read_settings_base
  564. {
  565. /// Default Constructor
  566. image_read_settings< png_tag >()
  567. : image_read_settings_base()
  568. , png_read_settings_base()
  569. , _screen_gamma( 1.0 )
  570. {}
  571. /// Constructor
  572. /// \param top_left Top left coordinate for reading partial image.
  573. /// \param dim Dimensions for reading partial image.
  574. /// \param gamma Screen gamma value.
  575. image_read_settings( const point_t& top_left
  576. , const point_t& dim
  577. , const bool apply_screen_gamma = false
  578. , const png_gamma::type& screen_gamma = 1.0
  579. )
  580. : image_read_settings_base( top_left
  581. , dim
  582. )
  583. , png_read_settings_base()
  584. , _apply_screen_gamma( apply_screen_gamma )
  585. , _screen_gamma( screen_gamma )
  586. {}
  587. /// Apply screen gamma value.
  588. bool _apply_screen_gamma;
  589. /// The screen gamma value.
  590. png_gamma::type _screen_gamma;
  591. };
  592. #else
  593. /// Read settings for png images.
  594. ///
  595. /// The structure can be used for all read_xxx functions, except read_image_info.
  596. template<>
  597. struct image_read_settings< png_tag > : public image_read_settings_base
  598. , public png_read_settings_base
  599. {
  600. /// Default Constructor.
  601. image_read_settings< png_tag >()
  602. : image_read_settings_base()
  603. , png_read_settings_base()
  604. , _apply_screen_gamma( false )
  605. , _screen_gamma ( 2 )
  606. {}
  607. image_read_settings( const point_t& top_left
  608. , const point_t& dim
  609. )
  610. : image_read_settings_base( top_left
  611. , dim
  612. )
  613. , png_read_settings_base()
  614. , _apply_screen_gamma( false )
  615. , _screen_gamma ( 2 )
  616. {}
  617. /// Apply screen gamma value.
  618. bool _apply_screen_gamma;
  619. /// The screen gamma value.
  620. png_gamma::type _screen_gamma;
  621. };
  622. #endif
  623. /// Write information for png images.
  624. ///
  625. /// The structure can be used for write_view() function.
  626. template<>
  627. struct image_write_info< png_tag > : public png_info_base
  628. {
  629. image_write_info( const png_compression_type::type compression_type = png_compression_type::default_value
  630. , const png_compression_level::type compression_level = png_compression_level::default_value
  631. , const png_compression_mem_level::type compression_mem_level = png_compression_mem_level::default_value
  632. , const png_compression_strategy::type compression_strategy = png_compression_strategy::default_value
  633. , const png_compression_window_bits::type compression_window_bits = png_compression_window_bits::default_value
  634. , const png_compression_method::type compression_method = png_compression_method::default_value
  635. , const png_compression_buffer_size::type compression_buffer_size = png_compression_buffer_size::default_value
  636. , const png_dithering_num_palette::type num_palette = png_dithering_num_palette::default_value
  637. , const png_dithering_maximum_colors::type maximum_colors = png_dithering_maximum_colors::default_value
  638. , const png_full_dither::type full_dither = png_full_dither::default_value
  639. , const png_filter::type filter = png_filter::default_value
  640. , const png_invert_mono::type invert_mono = png_invert_mono::default_value
  641. , const png_srgb_intent::type srgb_intent = png_srgb_intent::default_value
  642. , const png_strip_alpha::type strip_alpha = png_strip_alpha::default_value
  643. , const png_swap_alpha::type swap_alpha = png_swap_alpha::default_value
  644. )
  645. : png_info_base()
  646. , _compression_type( compression_type )
  647. , _compression_level( compression_level )
  648. , _compression_mem_level( compression_mem_level )
  649. , _compression_strategy( compression_strategy )
  650. , _compression_window_bits( compression_window_bits )
  651. , _compression_method( compression_method )
  652. , _compression_buffer_size( compression_buffer_size )
  653. , _set_dithering( false )
  654. , _dithering_palette()
  655. , _dithering_num_palette( num_palette )
  656. , _dithering_maximum_colors( maximum_colors )
  657. , _dithering_histogram()
  658. , _full_dither( full_dither )
  659. , _set_filter( false )
  660. , _filter( filter )
  661. , _invert_mono( invert_mono )
  662. , _set_true_bits( false )
  663. , _true_bits()
  664. , _set_srgb_intent( false )
  665. , _srgb_intent( srgb_intent )
  666. , _strip_alpha( strip_alpha )
  667. , _swap_alpha( swap_alpha )
  668. {}
  669. // compression stuff
  670. png_compression_type::type _compression_type;
  671. png_compression_level::type _compression_level;
  672. png_compression_mem_level::type _compression_mem_level;
  673. png_compression_strategy::type _compression_strategy;
  674. png_compression_window_bits::type _compression_window_bits;
  675. png_compression_method::type _compression_method;
  676. png_compression_buffer_size::type _compression_buffer_size;
  677. // png_set_dither
  678. bool _set_dithering;
  679. png_dithering_palette::type _dithering_palette;
  680. png_dithering_num_palette::type _dithering_num_palette;
  681. png_dithering_maximum_colors::type _dithering_maximum_colors;
  682. png_dithering_histogram::type _dithering_histogram;
  683. png_full_dither::type _full_dither;
  684. //png_set_filter
  685. bool _set_filter;
  686. png_filter::type _filter;
  687. // png_set_invert_mono
  688. png_invert_mono::type _invert_mono;
  689. // png_set_sBIT
  690. bool _set_true_bits;
  691. png_true_bits::type _true_bits;
  692. // png_set_sRGB
  693. bool _set_srgb_intent;
  694. png_srgb_intent::type _srgb_intent;
  695. // png_set_strip_alpha
  696. png_strip_alpha::type _strip_alpha;
  697. // png_set_swap_alpha
  698. png_swap_alpha::type _swap_alpha;
  699. };
  700. } // namespace gil
  701. } // namespace boost
  702. #endif