2 // Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
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 #ifndef BOOST_GIL_EXTENSION_IO_TIFF_TAGS_HPP
9 #define BOOST_GIL_EXTENSION_IO_TIFF_TAGS_HPP
11 #include <boost/gil/extension/io/tiff/detail/log.hpp>
13 #include <boost/gil/detail/mp11.hpp>
14 #include <boost/gil/io/base.hpp>
16 #include <type_traits>
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
25 #ifndef BOOST_GIL_EXTENSION_IO_TIFF_C_LIB_COMPILED_AS_CPLUSPLUS
29 namespace boost { namespace gil {
32 struct tiff_tag : format_tag {};
34 /// http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
35 /// http://www.remotesensing.org/libtiff/
37 /// TIFF property base class
38 template< typename T, int Value >
39 struct tiff_property_base : property_base< T >
41 /// Tag, needed when reading or writing image properties.
42 static const ttag_t tag = Value;
43 /// The list of argument types used in the interface of LibTIFF
46 /// http://www.remotesensing.org/libtiff/man/TIFFGetField.3tiff.html
47 /// http://www.remotesensing.org/libtiff/man/TIFFSetField.3tiff.html
48 using arg_types = mp11::mp_list<typename property_base<unsigned short>::type>;
53 /// Defines type for new subfile property.
54 struct tiff_new_subfile_type : tiff_property_base< uint32_t, TIFFTAG_SUBFILETYPE > {};
56 /// Defines type for subfile property.
57 struct tiff_subfile_type : tiff_property_base< uint16_t, TIFFTAG_OSUBFILETYPE > {};
59 /// Defines type for image width property.
60 struct tiff_image_width : tiff_property_base< uint32_t, TIFFTAG_IMAGEWIDTH > {};
62 /// Defines type for image height property.
63 struct tiff_image_height : tiff_property_base< uint32_t, TIFFTAG_IMAGELENGTH > {};
65 /// Defines type for bits per sample property.
66 struct tiff_bits_per_sample : tiff_property_base< uint16_t, TIFFTAG_BITSPERSAMPLE > {};
68 /// Defines type for compression property.
69 struct tiff_compression : tiff_property_base< uint16_t, TIFFTAG_COMPRESSION > {};
71 /// Defines type for photometric interpretation property.
72 struct tiff_photometric_interpretation : tiff_property_base< uint16_t, TIFFTAG_PHOTOMETRIC > {};
74 /// Defines type for threshold property.
75 struct tiff_thresholding : tiff_property_base< uint16_t, TIFFTAG_THRESHHOLDING > {};
77 /// Defines type for cell width property.
78 struct tiff_cell_width : tiff_property_base< uint16_t, TIFFTAG_CELLWIDTH > {};
80 /// Defines type for cell length property.
81 struct tiff_cell_length : tiff_property_base< uint16_t, TIFFTAG_CELLLENGTH > {};
83 /// Defines type for fill order property.
84 struct tiff_fill_order : tiff_property_base< std::string, TIFFTAG_FILLORDER > {};
86 /// Defines type for image description.
87 struct tiff_image_description : tiff_property_base< std::string, TIFFTAG_IMAGEDESCRIPTION > {};
89 /// Defines type for make property.
90 struct tiff_make : tiff_property_base< std::string, TIFFTAG_MAKE > {};
92 /// Defines type for model property.
93 struct tiff_model : tiff_property_base< std::string, TIFFTAG_MODEL > {};
95 /// Defines type for image orientation.
96 struct tiff_orientation : tiff_property_base< uint16_t, TIFFTAG_ORIENTATION > {};
98 /// Defines type for samples per pixel property.
99 struct tiff_samples_per_pixel : tiff_property_base< uint16_t, TIFFTAG_SAMPLESPERPIXEL > {};
101 /// Defines type for rows per strip property.
102 struct tiff_rows_per_strip : tiff_property_base< uint32_t, TIFFTAG_ROWSPERSTRIP > {};
104 /// Defines type for min sample property.
105 struct tiff_min_sample_value : tiff_property_base< uint16_t, TIFFTAG_MINSAMPLEVALUE > {};
107 /// Defines type for max sample property.
108 struct tiff_max_sample_value : tiff_property_base< uint16_t, TIFFTAG_MAXSAMPLEVALUE > {};
110 /// Defines type for x resolution property.
111 struct tiff_x_resolution : tiff_property_base< float, TIFFTAG_XRESOLUTION > {};
113 /// Defines type for y resolution property.
114 struct tiff_y_resolution : tiff_property_base< float, TIFFTAG_YRESOLUTION > {};
116 /// Defines type for resolution unit property.
117 enum class tiff_resolution_unit_value: std:: uint16_t {
120 CENTIMETER = RESUNIT_CENTIMETER
123 struct tiff_resolution_unit : tiff_property_base< tiff_resolution_unit_value, TIFFTAG_RESOLUTIONUNIT > {};
125 /// Defines type for planar configuration property.
126 struct tiff_planar_configuration : tiff_property_base< uint16_t, TIFFTAG_PLANARCONFIG > {};
128 /// Defines type for gray response unit property.
129 struct tiff_gray_response_unit : tiff_property_base< uint16_t, TIFFTAG_GRAYRESPONSEUNIT > {};
131 /// Defines type for gray response curve property.
132 struct tiff_gray_response_curve : tiff_property_base< uint16_t*, TIFFTAG_GRAYRESPONSECURVE > {};
134 /// Defines type for software vendor property.
135 struct tiff_software : tiff_property_base< std::string, TIFFTAG_SOFTWARE > {};
137 /// Defines type for date time property.
138 struct tiff_date_time : tiff_property_base< std::string, TIFFTAG_DATETIME > {};
140 /// Defines type for artist information property.
141 struct tiff_artist : tiff_property_base< std::string, TIFFTAG_ARTIST > {};
143 /// Defines type for host computer property.
144 struct tiff_host_computer : tiff_property_base< std::string, TIFFTAG_HOSTCOMPUTER > {};
146 /// Helper structure for reading a color mapper.
147 struct tiff_color_map
149 using red_t = uint16_t *;
150 using green_t = uint16_t *;
151 using blue_t = uint16_t *;
153 static const unsigned int tag = TIFFTAG_COLORMAP;
156 /// Defines type for extra samples property.
157 struct tiff_extra_samples : tiff_property_base<std::vector<uint16_t>, TIFFTAG_EXTRASAMPLES>
159 using arg_types = mp11::mp_list<uint16_t, uint16_t const*>;
162 /// Defines type for copyright property.
163 struct tiff_copyright : tiff_property_base< std::string, TIFFTAG_COPYRIGHT > {};
165 /// non-baseline tags
167 /// Defines type for sample format property.
168 struct tiff_sample_format : tiff_property_base< uint16_t, TIFFTAG_SAMPLEFORMAT > {};
170 /// Defines type for indexed property.
171 /// Not supported yet
172 //struct tiff_indexed : tiff_property_base< bool, TIFFTAG_INDEXED > {};
174 /// Tile related tags
176 /// Defines type for a (not) tiled tiff image
177 struct tiff_is_tiled : tiff_property_base< bool, false > {};
179 /// Defines type for tile width
180 struct tiff_tile_width : tiff_property_base< long, TIFFTAG_TILEWIDTH > {};
182 /// Defines type for tile length
183 struct tiff_tile_length : tiff_property_base< long, TIFFTAG_TILELENGTH > {};
185 /// Defines the page to read in a multipage tiff file.
186 struct tiff_directory : property_base< tdir_t >
188 using default_value = std::integral_constant<type, 0>;
191 /// Non-baseline tags
193 /// Defines type for icc profile property.
194 struct tiff_icc_profile : tiff_property_base<std::vector<uint8_t>, TIFFTAG_ICCPROFILE>
196 using arg_types = mp11::mp_list<uint32_t, void const*>;
199 /// Read information for tiff images.
201 /// The structure is returned when using read_image_info.
203 struct image_read_info< tiff_tag >
209 , _compression( COMPRESSION_NONE )
211 , _bits_per_sample( 0 )
212 , _samples_per_pixel( 0 )
213 , _sample_format( SAMPLEFORMAT_UINT )
215 , _planar_configuration( PLANARCONFIG_CONTIG )
217 , _photometric_interpretation( PHOTOMETRIC_MINISWHITE )
226 , _resolution_unit( tiff_resolution_unit_value:: NONE )
231 /// The number of rows of pixels in the image.
232 tiff_image_width::type _width;
233 /// The number of columns in the image, i.e., the number of pixels per row.
234 tiff_image_height::type _height;
236 /// Compression scheme used on the image data.
237 tiff_compression::type _compression;
239 /// Number of bits per component.
240 tiff_bits_per_sample::type _bits_per_sample;
241 /// The number of components per pixel.
242 tiff_samples_per_pixel::type _samples_per_pixel;
243 /// Specifies how to interpret each data sample in a pixel.
244 tiff_sample_format::type _sample_format;
246 /// How the components of each pixel are stored.
247 tiff_planar_configuration::type _planar_configuration;
249 /// The color space of the image data.
250 tiff_photometric_interpretation::type _photometric_interpretation;
253 tiff_is_tiled::type _is_tiled;
255 tiff_tile_width::type _tile_width;
257 tiff_tile_length::type _tile_length;
259 tiff_x_resolution::type _x_resolution;
260 tiff_y_resolution::type _y_resolution;
261 tiff_resolution_unit::type _resolution_unit;
263 tiff_icc_profile:: type _icc_profile;
266 /// Read settings for tiff images.
268 /// The structure can be used for all read_xxx functions, except read_image_info.
270 struct image_read_settings< tiff_tag > : public image_read_settings_base
272 /// Default constructor
273 image_read_settings< tiff_tag >()
274 : image_read_settings_base()
275 , _directory( tiff_directory::default_value::value )
279 /// \param top_left Top left coordinate for reading partial image.
280 /// \param dim Dimensions for reading partial image.
281 /// \param directory Defines the page to read in a multipage tiff file.
282 image_read_settings( const point_t& top_left
284 , const tiff_directory::type& directory = tiff_directory::default_value::value
286 : image_read_settings_base( top_left
289 , _directory( directory )
292 /// Defines the page to read in a multipage tiff file.
293 tiff_directory::type _directory;
296 /// Write settings for tiff images.
298 /// The structure can be used for all write_xxx functions, except write_image_info.
299 template< typename Log >
300 struct image_write_info< tiff_tag, Log >
302 /// Default constructor
304 : _photometric_interpretation ( PHOTOMETRIC_MINISBLACK )
305 , _photometric_interpretation_user_defined( false )
307 , _compression ( COMPRESSION_NONE )
308 , _orientation ( ORIENTATION_TOPLEFT )
309 , _planar_configuration ( PLANARCONFIG_CONTIG )
310 , _is_tiled ( false )
313 , _x_resolution ( 1 )
314 , _y_resolution ( 1 )
315 , _resolution_unit ( tiff_resolution_unit_value::NONE )
319 /// The color space of the image data.
320 tiff_photometric_interpretation::type _photometric_interpretation;
321 bool _photometric_interpretation_user_defined;
323 /// Compression scheme used on the image data.
324 tiff_compression::type _compression;
325 /// The orientation of the image with respect to the rows and columns.
326 tiff_orientation::type _orientation;
327 /// How the components of each pixel are stored.
328 tiff_planar_configuration::type _planar_configuration;
330 /// Is the image tiled?
331 tiff_is_tiled::type _is_tiled;
333 tiff_tile_width::type _tile_width;
335 tiff_tile_length::type _tile_length;
338 tiff_x_resolution::type _x_resolution;
339 tiff_y_resolution::type _y_resolution;
340 tiff_resolution_unit::type _resolution_unit;
342 tiff_icc_profile:: type _icc_profile;
344 /// A log to transcript error and warning messages issued by libtiff.