tags.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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_TIFF_TAGS_HPP
  9. #define BOOST_GIL_EXTENSION_IO_TIFF_TAGS_HPP
  10. #include <boost/gil/extension/io/tiff/detail/log.hpp>
  11. #include <boost/gil/detail/mp11.hpp>
  12. #include <boost/gil/io/base.hpp>
  13. #include <type_traits>
  14. // taken from jpegxx - https://bitbucket.org/edd/jpegxx/src/ea2492a1a4a6/src/ijg_headers.hpp
  15. #ifndef BOOST_GIL_EXTENSION_IO_TIFF_C_LIB_COMPILED_AS_CPLUSPLUS
  16. extern "C" {
  17. #endif
  18. #include <tiff.h>
  19. #ifndef BOOST_GIL_EXTENSION_IO_TIFF_C_LIB_COMPILED_AS_CPLUSPLUS
  20. }
  21. #endif
  22. namespace boost { namespace gil {
  23. /// Defines tiff tag.
  24. struct tiff_tag : format_tag {};
  25. /// http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
  26. /// http://www.remotesensing.org/libtiff/
  27. /// TIFF property base class
  28. template< typename T, int Value >
  29. struct tiff_property_base : property_base< T >
  30. {
  31. /// Tag, needed when reading or writing image properties.
  32. static const ttag_t tag = Value;
  33. /// The list of argument types used in the interface of LibTIFF
  34. /// for
  35. /// this property:
  36. /// http://www.remotesensing.org/libtiff/man/TIFFGetField.3tiff.html
  37. /// http://www.remotesensing.org/libtiff/man/TIFFSetField.3tiff.html
  38. using arg_types = mp11::mp_list<typename property_base<unsigned short>::type>;
  39. };
  40. /// baseline tags
  41. /// Defines type for new subfile property.
  42. struct tiff_new_subfile_type : tiff_property_base< uint32_t, TIFFTAG_SUBFILETYPE > {};
  43. /// Defines type for subfile property.
  44. struct tiff_subfile_type : tiff_property_base< uint16_t, TIFFTAG_OSUBFILETYPE > {};
  45. /// Defines type for image width property.
  46. struct tiff_image_width : tiff_property_base< uint32_t, TIFFTAG_IMAGEWIDTH > {};
  47. /// Defines type for image height property.
  48. struct tiff_image_height : tiff_property_base< uint32_t, TIFFTAG_IMAGELENGTH > {};
  49. /// Defines type for bits per sample property.
  50. struct tiff_bits_per_sample : tiff_property_base< uint16_t, TIFFTAG_BITSPERSAMPLE > {};
  51. /// Defines type for compression property.
  52. struct tiff_compression : tiff_property_base< uint16_t, TIFFTAG_COMPRESSION > {};
  53. /// Defines type for photometric interpretation property.
  54. struct tiff_photometric_interpretation : tiff_property_base< uint16_t, TIFFTAG_PHOTOMETRIC > {};
  55. /// Defines type for threshold property.
  56. struct tiff_thresholding : tiff_property_base< uint16_t, TIFFTAG_THRESHHOLDING > {};
  57. /// Defines type for cell width property.
  58. struct tiff_cell_width : tiff_property_base< uint16_t, TIFFTAG_CELLWIDTH > {};
  59. /// Defines type for cell length property.
  60. struct tiff_cell_length : tiff_property_base< uint16_t, TIFFTAG_CELLLENGTH > {};
  61. /// Defines type for fill order property.
  62. struct tiff_fill_order : tiff_property_base< std::string, TIFFTAG_FILLORDER > {};
  63. /// Defines type for image description.
  64. struct tiff_image_description : tiff_property_base< std::string, TIFFTAG_IMAGEDESCRIPTION > {};
  65. /// Defines type for make property.
  66. struct tiff_make : tiff_property_base< std::string, TIFFTAG_MAKE > {};
  67. /// Defines type for model property.
  68. struct tiff_model : tiff_property_base< std::string, TIFFTAG_MODEL > {};
  69. /// Defines type for image orientation.
  70. struct tiff_orientation : tiff_property_base< uint16_t, TIFFTAG_ORIENTATION > {};
  71. /// Defines type for samples per pixel property.
  72. struct tiff_samples_per_pixel : tiff_property_base< uint16_t, TIFFTAG_SAMPLESPERPIXEL > {};
  73. /// Defines type for rows per strip property.
  74. struct tiff_rows_per_strip : tiff_property_base< uint32_t, TIFFTAG_ROWSPERSTRIP > {};
  75. /// Defines type for min sample property.
  76. struct tiff_min_sample_value : tiff_property_base< uint16_t, TIFFTAG_MINSAMPLEVALUE > {};
  77. /// Defines type for max sample property.
  78. struct tiff_max_sample_value : tiff_property_base< uint16_t, TIFFTAG_MAXSAMPLEVALUE > {};
  79. /// Defines type for x resolution property.
  80. struct tiff_x_resolution : tiff_property_base< float, TIFFTAG_XRESOLUTION > {};
  81. /// Defines type for y resolution property.
  82. struct tiff_y_resolution : tiff_property_base< float, TIFFTAG_YRESOLUTION > {};
  83. /// Defines type for resolution unit property.
  84. enum class tiff_resolution_unit_value: std:: uint16_t {
  85. NONE = RESUNIT_NONE,
  86. INCH = RESUNIT_INCH,
  87. CENTIMETER = RESUNIT_CENTIMETER
  88. };
  89. struct tiff_resolution_unit : tiff_property_base< tiff_resolution_unit_value, TIFFTAG_RESOLUTIONUNIT > {};
  90. /// Defines type for planar configuration property.
  91. struct tiff_planar_configuration : tiff_property_base< uint16_t, TIFFTAG_PLANARCONFIG > {};
  92. /// Defines type for gray response unit property.
  93. struct tiff_gray_response_unit : tiff_property_base< uint16_t, TIFFTAG_GRAYRESPONSEUNIT > {};
  94. /// Defines type for gray response curve property.
  95. struct tiff_gray_response_curve : tiff_property_base< uint16_t*, TIFFTAG_GRAYRESPONSECURVE > {};
  96. /// Defines type for software vendor property.
  97. struct tiff_software : tiff_property_base< std::string, TIFFTAG_SOFTWARE > {};
  98. /// Defines type for date time property.
  99. struct tiff_date_time : tiff_property_base< std::string, TIFFTAG_DATETIME > {};
  100. /// Defines type for artist information property.
  101. struct tiff_artist : tiff_property_base< std::string, TIFFTAG_ARTIST > {};
  102. /// Defines type for host computer property.
  103. struct tiff_host_computer : tiff_property_base< std::string, TIFFTAG_HOSTCOMPUTER > {};
  104. /// Helper structure for reading a color mapper.
  105. struct tiff_color_map
  106. {
  107. using red_t = uint16_t *;
  108. using green_t = uint16_t *;
  109. using blue_t = uint16_t *;
  110. static const unsigned int tag = TIFFTAG_COLORMAP;
  111. };
  112. /// Defines type for extra samples property.
  113. struct tiff_extra_samples : tiff_property_base<std::vector<uint16_t>, TIFFTAG_EXTRASAMPLES>
  114. {
  115. using arg_types = mp11::mp_list<uint16_t, uint16_t const*>;
  116. };
  117. /// Defines type for copyright property.
  118. struct tiff_copyright : tiff_property_base< std::string, TIFFTAG_COPYRIGHT > {};
  119. /// non-baseline tags
  120. /// Defines type for sample format property.
  121. struct tiff_sample_format : tiff_property_base< uint16_t, TIFFTAG_SAMPLEFORMAT > {};
  122. /// Defines type for indexed property.
  123. /// Not supported yet
  124. //struct tiff_indexed : tiff_property_base< bool, TIFFTAG_INDEXED > {};
  125. /// Tile related tags
  126. /// Defines type for a (not) tiled tiff image
  127. struct tiff_is_tiled : tiff_property_base< bool, false > {};
  128. /// Defines type for tile width
  129. struct tiff_tile_width : tiff_property_base< long, TIFFTAG_TILEWIDTH > {};
  130. /// Defines type for tile length
  131. struct tiff_tile_length : tiff_property_base< long, TIFFTAG_TILELENGTH > {};
  132. /// Defines the page to read in a multipage tiff file.
  133. struct tiff_directory : property_base< tdir_t >
  134. {
  135. using default_value = std::integral_constant<type, 0>;
  136. };
  137. /// Non-baseline tags
  138. /// Defines type for icc profile property.
  139. struct tiff_icc_profile : tiff_property_base<std::vector<uint8_t>, TIFFTAG_ICCPROFILE>
  140. {
  141. using arg_types = mp11::mp_list<uint32_t, void const*>;
  142. };
  143. /// Read information for tiff images.
  144. ///
  145. /// The structure is returned when using read_image_info.
  146. template<>
  147. struct image_read_info< tiff_tag >
  148. {
  149. image_read_info()
  150. : _width( 0 )
  151. , _height( 0 )
  152. , _compression( COMPRESSION_NONE )
  153. , _bits_per_sample( 0 )
  154. , _samples_per_pixel( 0 )
  155. , _sample_format( SAMPLEFORMAT_UINT )
  156. , _planar_configuration( PLANARCONFIG_CONTIG )
  157. , _photometric_interpretation( PHOTOMETRIC_MINISWHITE )
  158. , _is_tiled( false )
  159. , _tile_width ( 0 )
  160. , _tile_length( 0 )
  161. , _x_resolution( 1 )
  162. , _y_resolution( 1 )
  163. , _resolution_unit( tiff_resolution_unit_value:: NONE )
  164. , _icc_profile( )
  165. {}
  166. /// The number of rows of pixels in the image.
  167. tiff_image_width::type _width;
  168. /// The number of columns in the image, i.e., the number of pixels per row.
  169. tiff_image_height::type _height;
  170. /// Compression scheme used on the image data.
  171. tiff_compression::type _compression;
  172. /// Number of bits per component.
  173. tiff_bits_per_sample::type _bits_per_sample;
  174. /// The number of components per pixel.
  175. tiff_samples_per_pixel::type _samples_per_pixel;
  176. /// Specifies how to interpret each data sample in a pixel.
  177. tiff_sample_format::type _sample_format;
  178. /// How the components of each pixel are stored.
  179. tiff_planar_configuration::type _planar_configuration;
  180. /// The color space of the image data.
  181. tiff_photometric_interpretation::type _photometric_interpretation;
  182. /// Is tiled?
  183. tiff_is_tiled::type _is_tiled;
  184. /// Tile width
  185. tiff_tile_width::type _tile_width;
  186. /// Tile length
  187. tiff_tile_length::type _tile_length;
  188. tiff_x_resolution::type _x_resolution;
  189. tiff_y_resolution::type _y_resolution;
  190. tiff_resolution_unit::type _resolution_unit;
  191. tiff_icc_profile:: type _icc_profile;
  192. };
  193. /// Read settings for tiff images.
  194. ///
  195. /// The structure can be used for all read_xxx functions, except read_image_info.
  196. template<>
  197. struct image_read_settings< tiff_tag > : public image_read_settings_base
  198. {
  199. /// Default constructor
  200. image_read_settings< tiff_tag >()
  201. : image_read_settings_base()
  202. , _directory( tiff_directory::default_value::value )
  203. {}
  204. /// Constructor
  205. /// \param top_left Top left coordinate for reading partial image.
  206. /// \param dim Dimensions for reading partial image.
  207. /// \param directory Defines the page to read in a multipage tiff file.
  208. image_read_settings( const point_t& top_left
  209. , const point_t& dim
  210. , const tiff_directory::type& directory = tiff_directory::default_value::value
  211. )
  212. : image_read_settings_base( top_left
  213. , dim
  214. )
  215. , _directory( directory )
  216. {}
  217. /// Defines the page to read in a multipage tiff file.
  218. tiff_directory::type _directory;
  219. };
  220. /// Write settings for tiff images.
  221. ///
  222. /// The structure can be used for all write_xxx functions, except write_image_info.
  223. template< typename Log >
  224. struct image_write_info< tiff_tag, Log >
  225. {
  226. /// Default constructor
  227. image_write_info()
  228. : _photometric_interpretation ( PHOTOMETRIC_MINISBLACK )
  229. , _photometric_interpretation_user_defined( false )
  230. , _compression ( COMPRESSION_NONE )
  231. , _orientation ( ORIENTATION_TOPLEFT )
  232. , _planar_configuration ( PLANARCONFIG_CONTIG )
  233. , _is_tiled ( false )
  234. , _tile_width ( 0 )
  235. , _tile_length ( 0 )
  236. , _x_resolution ( 1 )
  237. , _y_resolution ( 1 )
  238. , _resolution_unit ( tiff_resolution_unit_value::NONE )
  239. , _icc_profile ( )
  240. {}
  241. /// The color space of the image data.
  242. tiff_photometric_interpretation::type _photometric_interpretation;
  243. bool _photometric_interpretation_user_defined;
  244. /// Compression scheme used on the image data.
  245. tiff_compression::type _compression;
  246. /// The orientation of the image with respect to the rows and columns.
  247. tiff_orientation::type _orientation;
  248. /// How the components of each pixel are stored.
  249. tiff_planar_configuration::type _planar_configuration;
  250. /// Is the image tiled?
  251. tiff_is_tiled::type _is_tiled;
  252. /// Tiles width
  253. tiff_tile_width::type _tile_width;
  254. /// Tiles length
  255. tiff_tile_length::type _tile_length;
  256. /// x, y resolution
  257. tiff_x_resolution::type _x_resolution;
  258. tiff_y_resolution::type _y_resolution;
  259. tiff_resolution_unit::type _resolution_unit;
  260. tiff_icc_profile:: type _icc_profile;
  261. /// A log to transcript error and warning messages issued by libtiff.
  262. Log _log;
  263. };
  264. } // namespace gil
  265. } // namespace boost
  266. #endif