tags.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // Copyright 2010 Kenneth Riddile
  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_TARGA_TAGS_HPP
  9. #define BOOST_GIL_EXTENSION_IO_TARGA_TAGS_HPP
  10. #include <boost/gil/io/base.hpp>
  11. namespace boost { namespace gil {
  12. /// Defines targa tag.
  13. struct targa_tag : format_tag {};
  14. /// See http://en.wikipedia.org/wiki/Truevision_TGA#Header for reference.
  15. /// http://local.wasp.uwa.edu.au/~pbourke/dataformats/tga/
  16. /// Defines type for header sizes.
  17. struct targa_header_size : property_base< uint8_t >
  18. {
  19. static const type _size = 18; /// Constant size for targa file header size.
  20. };
  21. /// Defines type for offset value.
  22. struct targa_offset : property_base< uint8_t > {};
  23. /// Defines type for color map type property.
  24. struct targa_color_map_type : property_base< uint8_t >
  25. {
  26. static const type _rgb = 0;
  27. static const type _indexed = 1;
  28. };
  29. /// Defines type for image type property.
  30. struct targa_image_type : property_base< uint8_t >
  31. {
  32. static const type _none = 0; /// no image data
  33. static const type _indexed = 1; /// indexed
  34. static const type _rgb = 2; /// RGB
  35. static const type _greyscale = 3; /// greyscale
  36. static const type _rle_indexed = 9; /// indexed with RLE compression
  37. static const type _rle_rgb = 10; /// RGB with RLE compression
  38. static const type _rle_greyscale = 11; /// greyscale with RLE compression
  39. };
  40. /// Defines type for color map start property.
  41. struct targa_color_map_start : property_base< uint16_t > {};
  42. /// Defines type for color map length property.
  43. struct targa_color_map_length : property_base< uint16_t > {};
  44. /// Defines type for color map bit depth property.
  45. struct targa_color_map_depth : property_base< uint8_t > {};
  46. /// Defines type for origin x and y value properties.
  47. struct targa_origin_element : property_base< uint16_t > {};
  48. /// Defines type for image dimension properties.
  49. struct targa_dimension : property_base< uint16_t > {};
  50. /// Defines type for image bit depth property.
  51. struct targa_depth : property_base< uint8_t > {};
  52. /// Defines type for image descriptor property.
  53. struct targa_descriptor : property_base< uint8_t > {};
  54. struct targa_screen_origin_bit : property_base< bool > {};
  55. /// Read information for targa images.
  56. ///
  57. /// The structure is returned when using read_image_info.
  58. template<>
  59. struct image_read_info< targa_tag >
  60. {
  61. /// Default contructor.
  62. image_read_info< targa_tag >()
  63. : _screen_origin_bit(false)
  64. , _valid( false )
  65. {}
  66. /// The size of this header:
  67. targa_header_size::type _header_size;
  68. /// The offset, i.e. starting address, of the byte where the targa data can be found.
  69. targa_offset::type _offset;
  70. /// The type of color map used by the image, i.e. RGB or indexed.
  71. targa_color_map_type::type _color_map_type;
  72. /// The type of image data, i.e compressed, indexed, uncompressed RGB, etc.
  73. targa_image_type::type _image_type;
  74. /// Index of first entry in the color map table.
  75. targa_color_map_start::type _color_map_start;
  76. /// Number of entries in the color map table.
  77. targa_color_map_length::type _color_map_length;
  78. /// Bit depth for each color map entry.
  79. targa_color_map_depth::type _color_map_depth;
  80. /// X coordinate of the image origin.
  81. targa_origin_element::type _x_origin;
  82. /// Y coordinate of the image origin.
  83. targa_origin_element::type _y_origin;
  84. /// Width of the image in pixels.
  85. targa_dimension::type _width;
  86. /// Height of the image in pixels.
  87. targa_dimension::type _height;
  88. /// Bit depth of the image.
  89. targa_depth::type _bits_per_pixel;
  90. /// The targa image descriptor.
  91. targa_descriptor::type _descriptor;
  92. // false: Origin in lower left-hand corner.
  93. // true: Origin in upper left-hand corner.
  94. targa_screen_origin_bit::type _screen_origin_bit;
  95. /// Used internally to identify if the header has been read.
  96. bool _valid;
  97. };
  98. /// Read settings for targa images.
  99. ///
  100. /// The structure can be used for all read_xxx functions, except read_image_info.
  101. template<>
  102. struct image_read_settings< targa_tag > : public image_read_settings_base
  103. {
  104. /// Default constructor
  105. image_read_settings()
  106. : image_read_settings_base()
  107. {}
  108. /// Constructor
  109. /// \param top_left Top left coordinate for reading partial image.
  110. /// \param dim Dimensions for reading partial image.
  111. image_read_settings( const point_t& top_left
  112. , const point_t& dim
  113. )
  114. : image_read_settings_base( top_left
  115. , dim
  116. )
  117. {}
  118. };
  119. /// Write information for targa images.
  120. ///
  121. /// The structure can be used for write_view() function.
  122. template<>
  123. struct image_write_info< targa_tag >
  124. {
  125. };
  126. } // namespace gil
  127. } // namespace boost
  128. #endif