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 11 #include <boost/gil/extension/io/tiff/detail/log.hpp> 12 13 #include <boost/gil/detail/mp11.hpp> 14 #include <boost/gil/io/base.hpp> 15 16 #include <type_traits> 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 23 #include <tiff.h> 24 25 #ifndef BOOST_GIL_EXTENSION_IO_TIFF_C_LIB_COMPILED_AS_CPLUSPLUS 26 } 27 #endif 28 29 namespace boost { namespace gil { 30 31 /// Defines tiff tag. 32 struct tiff_tag : format_tag {}; 33 34 /// http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html 35 /// http://www.remotesensing.org/libtiff/ 36 37 /// TIFF property base class 38 template< typename T, int Value > 39 struct tiff_property_base : property_base< T > 40 { 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 44 /// for 45 /// this property: 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>; 49 }; 50 51 /// baseline tags 52 53 /// Defines type for new subfile property. 54 struct tiff_new_subfile_type : tiff_property_base< uint32_t, TIFFTAG_SUBFILETYPE > {}; 55 56 /// Defines type for subfile property. 57 struct tiff_subfile_type : tiff_property_base< uint16_t, TIFFTAG_OSUBFILETYPE > {}; 58 59 /// Defines type for image width property. 60 struct tiff_image_width : tiff_property_base< uint32_t, TIFFTAG_IMAGEWIDTH > {}; 61 62 /// Defines type for image height property. 63 struct tiff_image_height : tiff_property_base< uint32_t, TIFFTAG_IMAGELENGTH > {}; 64 65 /// Defines type for bits per sample property. 66 struct tiff_bits_per_sample : tiff_property_base< uint16_t, TIFFTAG_BITSPERSAMPLE > {}; 67 68 /// Defines type for compression property. 69 struct tiff_compression : tiff_property_base< uint16_t, TIFFTAG_COMPRESSION > {}; 70 71 /// Defines type for photometric interpretation property. 72 struct tiff_photometric_interpretation : tiff_property_base< uint16_t, TIFFTAG_PHOTOMETRIC > {}; 73 74 /// Defines type for threshold property. 75 struct tiff_thresholding : tiff_property_base< uint16_t, TIFFTAG_THRESHHOLDING > {}; 76 77 /// Defines type for cell width property. 78 struct tiff_cell_width : tiff_property_base< uint16_t, TIFFTAG_CELLWIDTH > {}; 79 80 /// Defines type for cell length property. 81 struct tiff_cell_length : tiff_property_base< uint16_t, TIFFTAG_CELLLENGTH > {}; 82 83 /// Defines type for fill order property. 84 struct tiff_fill_order : tiff_property_base< std::string, TIFFTAG_FILLORDER > {}; 85 86 /// Defines type for image description. 87 struct tiff_image_description : tiff_property_base< std::string, TIFFTAG_IMAGEDESCRIPTION > {}; 88 89 /// Defines type for make property. 90 struct tiff_make : tiff_property_base< std::string, TIFFTAG_MAKE > {}; 91 92 /// Defines type for model property. 93 struct tiff_model : tiff_property_base< std::string, TIFFTAG_MODEL > {}; 94 95 /// Defines type for image orientation. 96 struct tiff_orientation : tiff_property_base< uint16_t, TIFFTAG_ORIENTATION > {}; 97 98 /// Defines type for samples per pixel property. 99 struct tiff_samples_per_pixel : tiff_property_base< uint16_t, TIFFTAG_SAMPLESPERPIXEL > {}; 100 101 /// Defines type for rows per strip property. 102 struct tiff_rows_per_strip : tiff_property_base< uint32_t, TIFFTAG_ROWSPERSTRIP > {}; 103 104 /// Defines type for min sample property. 105 struct tiff_min_sample_value : tiff_property_base< uint16_t, TIFFTAG_MINSAMPLEVALUE > {}; 106 107 /// Defines type for max sample property. 108 struct tiff_max_sample_value : tiff_property_base< uint16_t, TIFFTAG_MAXSAMPLEVALUE > {}; 109 110 /// Defines type for x resolution property. 111 struct tiff_x_resolution : tiff_property_base< float, TIFFTAG_XRESOLUTION > {}; 112 113 /// Defines type for y resolution property. 114 struct tiff_y_resolution : tiff_property_base< float, TIFFTAG_YRESOLUTION > {}; 115 116 /// Defines type for resolution unit property. 117 enum class tiff_resolution_unit_value: std:: uint16_t { 118 NONE = RESUNIT_NONE, 119 INCH = RESUNIT_INCH, 120 CENTIMETER = RESUNIT_CENTIMETER 121 }; 122 123 struct tiff_resolution_unit : tiff_property_base< tiff_resolution_unit_value, TIFFTAG_RESOLUTIONUNIT > {}; 124 125 /// Defines type for planar configuration property. 126 struct tiff_planar_configuration : tiff_property_base< uint16_t, TIFFTAG_PLANARCONFIG > {}; 127 128 /// Defines type for gray response unit property. 129 struct tiff_gray_response_unit : tiff_property_base< uint16_t, TIFFTAG_GRAYRESPONSEUNIT > {}; 130 131 /// Defines type for gray response curve property. 132 struct tiff_gray_response_curve : tiff_property_base< uint16_t*, TIFFTAG_GRAYRESPONSECURVE > {}; 133 134 /// Defines type for software vendor property. 135 struct tiff_software : tiff_property_base< std::string, TIFFTAG_SOFTWARE > {}; 136 137 /// Defines type for date time property. 138 struct tiff_date_time : tiff_property_base< std::string, TIFFTAG_DATETIME > {}; 139 140 /// Defines type for artist information property. 141 struct tiff_artist : tiff_property_base< std::string, TIFFTAG_ARTIST > {}; 142 143 /// Defines type for host computer property. 144 struct tiff_host_computer : tiff_property_base< std::string, TIFFTAG_HOSTCOMPUTER > {}; 145 146 /// Helper structure for reading a color mapper. 147 struct tiff_color_map 148 { 149 using red_t = uint16_t *; 150 using green_t = uint16_t *; 151 using blue_t = uint16_t *; 152 153 static const unsigned int tag = TIFFTAG_COLORMAP; 154 }; 155 156 /// Defines type for extra samples property. 157 struct tiff_extra_samples : tiff_property_base<std::vector<uint16_t>, TIFFTAG_EXTRASAMPLES> 158 { 159 using arg_types = mp11::mp_list<uint16_t, uint16_t const*>; 160 }; 161 162 /// Defines type for copyright property. 163 struct tiff_copyright : tiff_property_base< std::string, TIFFTAG_COPYRIGHT > {}; 164 165 /// non-baseline tags 166 167 /// Defines type for sample format property. 168 struct tiff_sample_format : tiff_property_base< uint16_t, TIFFTAG_SAMPLEFORMAT > {}; 169 170 /// Defines type for indexed property. 171 /// Not supported yet 172 //struct tiff_indexed : tiff_property_base< bool, TIFFTAG_INDEXED > {}; 173 174 /// Tile related tags 175 176 /// Defines type for a (not) tiled tiff image 177 struct tiff_is_tiled : tiff_property_base< bool, false > {}; 178 179 /// Defines type for tile width 180 struct tiff_tile_width : tiff_property_base< long, TIFFTAG_TILEWIDTH > {}; 181 182 /// Defines type for tile length 183 struct tiff_tile_length : tiff_property_base< long, TIFFTAG_TILELENGTH > {}; 184 185 /// Defines the page to read in a multipage tiff file. 186 struct tiff_directory : property_base< tdir_t > 187 { 188 using default_value = std::integral_constant<type, 0>; 189 }; 190 191 /// Non-baseline tags 192 193 /// Defines type for icc profile property. 194 struct tiff_icc_profile : tiff_property_base<std::vector<uint8_t>, TIFFTAG_ICCPROFILE> 195 { 196 using arg_types = mp11::mp_list<uint32_t, void const*>; 197 }; 198 199 /// Read information for tiff images. 200 /// 201 /// The structure is returned when using read_image_info. 202 template<> 203 struct image_read_info< tiff_tag > 204 { image_read_infoboost::gil::image_read_info205 image_read_info() 206 : _width( 0 ) 207 , _height( 0 ) 208 209 , _compression( COMPRESSION_NONE ) 210 211 , _bits_per_sample( 0 ) 212 , _samples_per_pixel( 0 ) 213 , _sample_format( SAMPLEFORMAT_UINT ) 214 215 , _planar_configuration( PLANARCONFIG_CONTIG ) 216 217 , _photometric_interpretation( PHOTOMETRIC_MINISWHITE ) 218 219 , _is_tiled( false ) 220 221 , _tile_width ( 0 ) 222 , _tile_length( 0 ) 223 224 , _x_resolution( 1 ) 225 , _y_resolution( 1 ) 226 , _resolution_unit( tiff_resolution_unit_value:: NONE ) 227 228 , _icc_profile( ) 229 {} 230 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; 235 236 /// Compression scheme used on the image data. 237 tiff_compression::type _compression; 238 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; 245 246 /// How the components of each pixel are stored. 247 tiff_planar_configuration::type _planar_configuration; 248 249 /// The color space of the image data. 250 tiff_photometric_interpretation::type _photometric_interpretation; 251 252 /// Is tiled? 253 tiff_is_tiled::type _is_tiled; 254 /// Tile width 255 tiff_tile_width::type _tile_width; 256 /// Tile length 257 tiff_tile_length::type _tile_length; 258 259 tiff_x_resolution::type _x_resolution; 260 tiff_y_resolution::type _y_resolution; 261 tiff_resolution_unit::type _resolution_unit; 262 263 tiff_icc_profile:: type _icc_profile; 264 }; 265 266 /// Read settings for tiff images. 267 /// 268 /// The structure can be used for all read_xxx functions, except read_image_info. 269 template<> 270 struct image_read_settings< tiff_tag > : public image_read_settings_base 271 { 272 /// Default constructor image_read_settingsboost::gil::image_read_settings273 image_read_settings< tiff_tag >() 274 : image_read_settings_base() 275 , _directory( tiff_directory::default_value::value ) 276 {} 277 278 /// Constructor 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. image_read_settingsboost::gil::image_read_settings282 image_read_settings( const point_t& top_left 283 , const point_t& dim 284 , const tiff_directory::type& directory = tiff_directory::default_value::value 285 ) 286 : image_read_settings_base( top_left 287 , dim 288 ) 289 , _directory( directory ) 290 {} 291 292 /// Defines the page to read in a multipage tiff file. 293 tiff_directory::type _directory; 294 }; 295 296 /// Write settings for tiff images. 297 /// 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 > 301 { 302 /// Default constructor image_write_infoboost::gil::image_write_info303 image_write_info() 304 : _photometric_interpretation ( PHOTOMETRIC_MINISBLACK ) 305 , _photometric_interpretation_user_defined( false ) 306 307 , _compression ( COMPRESSION_NONE ) 308 , _orientation ( ORIENTATION_TOPLEFT ) 309 , _planar_configuration ( PLANARCONFIG_CONTIG ) 310 , _is_tiled ( false ) 311 , _tile_width ( 0 ) 312 , _tile_length ( 0 ) 313 , _x_resolution ( 1 ) 314 , _y_resolution ( 1 ) 315 , _resolution_unit ( tiff_resolution_unit_value::NONE ) 316 , _icc_profile ( ) 317 {} 318 319 /// The color space of the image data. 320 tiff_photometric_interpretation::type _photometric_interpretation; 321 bool _photometric_interpretation_user_defined; 322 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; 329 330 /// Is the image tiled? 331 tiff_is_tiled::type _is_tiled; 332 /// Tiles width 333 tiff_tile_width::type _tile_width; 334 /// Tiles length 335 tiff_tile_length::type _tile_length; 336 337 /// x, y resolution 338 tiff_x_resolution::type _x_resolution; 339 tiff_y_resolution::type _y_resolution; 340 tiff_resolution_unit::type _resolution_unit; 341 342 tiff_icc_profile:: type _icc_profile; 343 344 /// A log to transcript error and warning messages issued by libtiff. 345 Log _log; 346 }; 347 348 } // namespace gil 349 } // namespace boost 350 351 #endif 352