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