PageRenderTime 29ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/include/boost/gil/extension/io/tiff_tags.hpp

https://bitbucket.org/boostorg/gil
C++ Header | 320 lines | 141 code | 79 blank | 100 comment | 0 complexity | 8a67d6cb04b037d4b430179f8260f76c MD5 | raw file
  1. /*
  2. Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. /*************************************************************************************************/
  8. #ifndef BOOST_GIL_EXTENSION_IO_TIFF_TAGS_HPP
  9. #define BOOST_GIL_EXTENSION_IO_TIFF_TAGS_HPP
  10. ////////////////////////////////////////////////////////////////////////////////////////
  11. /// \file
  12. /// \brief All supported tiff tags by the gil io extension.
  13. /// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
  14. ///
  15. /// \date 2007-2008 \n
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. // taken from jpegxx - https://bitbucket.org/edd/jpegxx/src/ea2492a1a4a6/src/ijg_headers.hpp
  19. #ifndef BOOST_GIL_EXTENSION_IO_TIFF_C_LIB_COMPILED_AS_CPLUSPLUS
  20. extern "C" {
  21. #endif
  22. #include <tiff.h>
  23. #ifndef BOOST_GIL_EXTENSION_IO_TIFF_C_LIB_COMPILED_AS_CPLUSPLUS
  24. }
  25. #endif
  26. #include "detail/base.hpp"
  27. #include "formats/tiff/log.hpp"
  28. namespace boost { namespace gil {
  29. /// Defines tiff tag.
  30. struct tiff_tag : format_tag {};
  31. /// http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
  32. /// http://www.remotesensing.org/libtiff/
  33. /// TIFF property base class
  34. template< typename T, int Value >
  35. struct tiff_property_base : property_base< T >
  36. {
  37. /// Tag, needed when reading or writing image properties.
  38. static const unsigned int tag = Value;
  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. struct tiff_resolution_unit : tiff_property_base< uint16_t, TIFFTAG_RESOLUTIONUNIT > {};
  85. /// Defines type for planar configuration property.
  86. struct tiff_planar_configuration : tiff_property_base< uint16_t, TIFFTAG_PLANARCONFIG > {};
  87. /// Defines type for gray response unit property.
  88. struct tiff_gray_response_unit : tiff_property_base< uint16_t, TIFFTAG_GRAYRESPONSEUNIT > {};
  89. /// Defines type for gray response curve property.
  90. struct tiff_gray_response_curve : tiff_property_base< uint16_t*, TIFFTAG_GRAYRESPONSECURVE > {};
  91. /// Defines type for software vendor property.
  92. struct tiff_software : tiff_property_base< std::string, TIFFTAG_SOFTWARE > {};
  93. /// Defines type for date time property.
  94. struct tiff_date_time : tiff_property_base< std::string, TIFFTAG_DATETIME > {};
  95. /// Defines type for artist information property.
  96. struct tiff_artist : tiff_property_base< std::string, TIFFTAG_ARTIST > {};
  97. /// Defines type for host computer property.
  98. struct tiff_host_computer : tiff_property_base< std::string, TIFFTAG_HOSTCOMPUTER > {};
  99. /// Helper structure for reading a color mapper.
  100. struct tiff_color_map
  101. {
  102. typedef uint16_t* red_t;
  103. typedef uint16_t* green_t;
  104. typedef uint16_t* blue_t;
  105. static const unsigned int tag = TIFFTAG_COLORMAP;
  106. };
  107. /// Defines type for extra samples property.
  108. struct tiff_extra_samples : tiff_property_base< uint16_t*, TIFFTAG_EXTRASAMPLES > {};
  109. /// Defines type for copyright property.
  110. struct tiff_copyright : tiff_property_base< std::string, TIFFTAG_COPYRIGHT > {};
  111. /// non-baseline tags
  112. /// Defines type for sample format property.
  113. struct tiff_sample_format : tiff_property_base< uint16_t, TIFFTAG_SAMPLEFORMAT > {};
  114. /// Defines type for indexed property.
  115. /// Not supported yet
  116. //struct tiff_indexed : tiff_property_base< bool, TIFFTAG_INDEXED > {};
  117. /// Tile related tags
  118. /// Defines type for a (not) tiled tiff image
  119. struct tiff_is_tiled : tiff_property_base< bool, false > {};
  120. /// Defines type for tile width
  121. struct tiff_tile_width : tiff_property_base< long, TIFFTAG_TILEWIDTH > {};
  122. /// Defines type for tile length
  123. struct tiff_tile_length : tiff_property_base< long, TIFFTAG_TILELENGTH > {};
  124. /// Defines the page to read in a multipage tiff file.
  125. #include <boost/mpl/integral_c.hpp>
  126. struct tiff_directory : property_base< tdir_t >
  127. {
  128. typedef boost::mpl::integral_c< type, 0 > default_value;
  129. };
  130. /// Read information for tiff images.
  131. ///
  132. /// The structure is returned when using read_image_info.
  133. template<>
  134. struct image_read_info< tiff_tag >
  135. {
  136. image_read_info()
  137. : _width( 0 )
  138. , _height( 0 )
  139. , _compression( COMPRESSION_NONE )
  140. , _bits_per_sample( 0 )
  141. , _samples_per_pixel( 0 )
  142. , _sample_format( SAMPLEFORMAT_UINT )
  143. , _planar_configuration( PLANARCONFIG_CONTIG )
  144. , _photometric_interpretation( PHOTOMETRIC_MINISWHITE )
  145. , _is_tiled( false )
  146. , _tile_width ( 0 )
  147. , _tile_length( 0 )
  148. {}
  149. /// The number of rows of pixels in the image.
  150. tiff_image_width::type _width;
  151. /// The number of columns in the image, i.e., the number of pixels per row.
  152. tiff_image_height::type _height;
  153. /// Compression scheme used on the image data.
  154. tiff_compression::type _compression;
  155. /// Number of bits per component.
  156. tiff_bits_per_sample::type _bits_per_sample;
  157. /// The number of components per pixel.
  158. tiff_samples_per_pixel::type _samples_per_pixel;
  159. /// Specifies how to interpret each data sample in a pixel.
  160. tiff_sample_format::type _sample_format;
  161. /// How the components of each pixel are stored.
  162. tiff_planar_configuration::type _planar_configuration;
  163. /// The color space of the image data.
  164. tiff_photometric_interpretation::type _photometric_interpretation;
  165. /// Is tiled?
  166. tiff_is_tiled::type _is_tiled;
  167. /// Tile width
  168. tiff_tile_width::type _tile_width;
  169. /// Tile length
  170. tiff_tile_length::type _tile_length;
  171. };
  172. /// Read settings for tiff images.
  173. ///
  174. /// The structure can be used for all read_xxx functions, except read_image_info.
  175. template<>
  176. struct image_read_settings< tiff_tag > : public image_read_settings_base
  177. {
  178. /// Default constructor
  179. image_read_settings< tiff_tag >()
  180. : image_read_settings_base()
  181. , _directory( tiff_directory::default_value::value )
  182. {}
  183. /// Constructor
  184. /// \param top_left Top left coordinate for reading partial image.
  185. /// \param dim Dimensions for reading partial image.
  186. /// \param directory Defines the page to read in a multipage tiff file.
  187. image_read_settings( const point_t& top_left
  188. , const point_t& dim
  189. , const tiff_directory::type& directory = tiff_directory::default_value::value
  190. )
  191. : image_read_settings_base( top_left
  192. , dim
  193. )
  194. , _directory( directory )
  195. {}
  196. /// Defines the page to read in a multipage tiff file.
  197. tiff_directory::type _directory;
  198. };
  199. /// Read settings for tiff images.
  200. ///
  201. /// The structure can be used for all read_xxx functions, except read_image_info.
  202. template< typename Log >
  203. struct image_write_info< tiff_tag, Log >
  204. {
  205. /// Default constructor
  206. image_write_info()
  207. : _photometric_interpretation ( PHOTOMETRIC_MINISBLACK )
  208. , _photometric_interpretation_user_defined( false )
  209. , _compression ( COMPRESSION_NONE )
  210. , _orientation ( ORIENTATION_TOPLEFT )
  211. , _planar_configuration ( PLANARCONFIG_CONTIG )
  212. , _is_tiled ( false )
  213. , _tile_width ( 0 )
  214. , _tile_length ( 0 )
  215. , _x_resolution ( 0 )
  216. , _y_resolution ( 0 )
  217. {}
  218. /// The color space of the image data.
  219. tiff_photometric_interpretation::type _photometric_interpretation;
  220. bool _photometric_interpretation_user_defined;
  221. /// Compression scheme used on the image data.
  222. tiff_compression::type _compression;
  223. /// The orientation of the image with respect to the rows and columns.
  224. tiff_orientation::type _orientation;
  225. /// How the components of each pixel are stored.
  226. tiff_planar_configuration::type _planar_configuration;
  227. /// Is the image tiled?
  228. tiff_is_tiled::type _is_tiled;
  229. /// Tiles width
  230. tiff_tile_width::type _tile_width;
  231. /// Tiles length
  232. tiff_tile_length::type _tile_length;
  233. /// x, y resolution
  234. tiff_x_resolution::type _x_resolution;
  235. tiff_y_resolution::type _y_resolution;
  236. /// A log to transcript error and warning messages issued by libtiff.
  237. Log _log;
  238. };
  239. } // namespace gil
  240. } // namespace boost
  241. #endif // BOOST_GIL_EXTENSION_IO_TIFF_TAGS_HPP