1 // This is core/vil/vil_pixel_format.h
2 #ifndef vil_pixel_format_h_
3 #define vil_pixel_format_h_
4 //:
5 // \file
6 // \author Ian Scott.
7 // Note that a std::complex<float> is thought of as a scalar
8 // pixel type for vil's purposes.
9 //
10 // \verbatim
11 // Modifications
12 // 23 Oct.2003 - Peter Vanroose - Added support for 64-bit int pixels
13 // \endverbatim
14
15 #include <iosfwd>
16 #include <complex>
17 #include "vil_rgb.h"
18 #include "vil_rgba.h"
19 #include <vxl_config.h> // for vxl_uint_32 etc.
20 #ifdef _MSC_VER
21 # include <vcl_msvc_warnings.h>
22 #endif
23
24 //: Describes the type of the concrete data.
25 enum vil_pixel_format
26 {
27 VIL_PIXEL_FORMAT_UNKNOWN = 0,
28
29 #if VXL_HAS_INT_64
30 VIL_PIXEL_FORMAT_UINT_64 = 1,
31 VIL_PIXEL_FORMAT_INT_64 = 2,
32 #endif
33 VIL_PIXEL_FORMAT_UINT_32 = 3,
34 VIL_PIXEL_FORMAT_INT_32 = 4,
35 VIL_PIXEL_FORMAT_UINT_16 = 5,
36 VIL_PIXEL_FORMAT_INT_16 = 6,
37 VIL_PIXEL_FORMAT_BYTE = 7,
38 VIL_PIXEL_FORMAT_SBYTE = 8,
39 VIL_PIXEL_FORMAT_FLOAT = 9,
40 VIL_PIXEL_FORMAT_DOUBLE = 10,
41 // VIL_PIXEL_FORMAT_LONG_DOUBLE = 11,
42 VIL_PIXEL_FORMAT_BOOL = 12,
43
44 #if VXL_HAS_INT_64
45 VIL_PIXEL_FORMAT_RGB_UINT_64 = 13,
46 VIL_PIXEL_FORMAT_RGB_INT_64 = 14,
47 #endif
48 VIL_PIXEL_FORMAT_RGB_UINT_32 = 15,
49 VIL_PIXEL_FORMAT_RGB_INT_32 = 16,
50 VIL_PIXEL_FORMAT_RGB_UINT_16 = 17,
51 VIL_PIXEL_FORMAT_RGB_INT_16 = 18,
52 VIL_PIXEL_FORMAT_RGB_BYTE = 19,
53 VIL_PIXEL_FORMAT_RGB_SBYTE = 20,
54 VIL_PIXEL_FORMAT_RGB_FLOAT = 21,
55 VIL_PIXEL_FORMAT_RGB_DOUBLE = 22,
56 // VIL_PIXEL_FORMAT_RGB_LONG_DOUBLE = 23,
57
58 #if VXL_HAS_INT_64
59 VIL_PIXEL_FORMAT_RGBA_UINT_64 = 24,
60 VIL_PIXEL_FORMAT_RGBA_INT_64 = 25,
61 #endif
62 VIL_PIXEL_FORMAT_RGBA_UINT_32 = 26,
63 VIL_PIXEL_FORMAT_RGBA_INT_32 = 27,
64 VIL_PIXEL_FORMAT_RGBA_UINT_16 = 28,
65 VIL_PIXEL_FORMAT_RGBA_INT_16 = 29,
66 VIL_PIXEL_FORMAT_RGBA_BYTE = 30,
67 VIL_PIXEL_FORMAT_RGBA_SBYTE = 31,
68 VIL_PIXEL_FORMAT_RGBA_FLOAT = 32,
69 VIL_PIXEL_FORMAT_RGBA_DOUBLE = 33,
70 // VIL_PIXEL_FORMAT_RGBA_LONG_DOUBLE = 34,
71
72 //: std::complex<float> is a scalar for vil's purposes.
73 VIL_PIXEL_FORMAT_COMPLEX_FLOAT = 35,
74 //: std::complex<double> is a scalar for vil's purposes.
75 VIL_PIXEL_FORMAT_COMPLEX_DOUBLE = 36,
76
77 // Add values here and be careful to keep values in vil_pixel_format.cxx in sync
78 // Don't forget to increase the end value. Also add to vil_convert_cast in vil_convert.h
79
80 VIL_PIXEL_FORMAT_ENUM_END = 37
81 };
82
83
84 //: The pixel format enumeration corresponding to the C++ type.
85 //
86 template <class T>
vil_pixel_format_of(T)87 inline vil_pixel_format vil_pixel_format_of(T){return VIL_PIXEL_FORMAT_UNKNOWN;}
88
89
90 //: The C++ type corresponding to an invalid pixel format
91 //
92 // See vil_pixel_format_type_of.
93 //
94 typedef void* vil_pixel_format_invalid_type;
95
96 //: The C++ type corresponding to a pixel format enumeration.
97 // Use like
98 // \code
99 // typedef vil_pixel_format_type_of<VIL_PIXEL_FORMAT_BYTE>::type byte_type;
100 // \endcode
101 // This is specialized for each pixel type enumeration for which a C++
102 // type exists.
103 //
104 // If the resulting type is vil_pixel_format_invalid_type, then the
105 // pixel format enumeration is not valid.
106 //
107 template <vil_pixel_format pix_type>
108 struct vil_pixel_format_type_of
109 {
110 typedef vil_pixel_format_invalid_type type;
111 typedef vil_pixel_format_invalid_type component_type;
112 };
113
114
115 //: Get the vil_pixel_format value for a given type.
116 #define vil_pixel_format_macro(T,C,V)\
117 template <> inline vil_pixel_format vil_pixel_format_of(T /*dummy*/) { return V; }\
118 template <> struct vil_pixel_format_type_of<V> { typedef T type; typedef C component_type; }
119
120 #if VXL_HAS_INT_64
121 vil_pixel_format_macro(vxl_uint_64, vxl_uint_64, VIL_PIXEL_FORMAT_UINT_64);
122 vil_pixel_format_macro(vxl_int_64, vxl_int_64, VIL_PIXEL_FORMAT_INT_64);
123 #endif
124 vil_pixel_format_macro(vxl_uint_32, vxl_uint_32, VIL_PIXEL_FORMAT_UINT_32);
125 vil_pixel_format_macro(vxl_int_32, vxl_int_32, VIL_PIXEL_FORMAT_INT_32);
126 vil_pixel_format_macro(vxl_uint_16, vxl_uint_16, VIL_PIXEL_FORMAT_UINT_16);
127 vil_pixel_format_macro(vxl_int_16, vxl_int_16, VIL_PIXEL_FORMAT_INT_16);
128 vil_pixel_format_macro(vxl_byte, vxl_byte, VIL_PIXEL_FORMAT_BYTE);
129 vil_pixel_format_macro(vxl_sbyte, vxl_sbyte, VIL_PIXEL_FORMAT_SBYTE);
130 vil_pixel_format_macro(float, float, VIL_PIXEL_FORMAT_FLOAT);
131 vil_pixel_format_macro(double, double, VIL_PIXEL_FORMAT_DOUBLE);
132 vil_pixel_format_macro(bool, bool, VIL_PIXEL_FORMAT_BOOL);
133
134 #if VXL_HAS_INT_64
135 vil_pixel_format_macro(vil_rgb<vxl_uint_64>, vxl_uint_64, VIL_PIXEL_FORMAT_RGB_UINT_64);
136 vil_pixel_format_macro(vil_rgb<vxl_int_64>, vxl_int_64, VIL_PIXEL_FORMAT_RGB_INT_64);
137 #endif
138 vil_pixel_format_macro(vil_rgb<vxl_uint_32>, vxl_uint_32, VIL_PIXEL_FORMAT_RGB_UINT_32);
139 vil_pixel_format_macro(vil_rgb<vxl_int_32>, vxl_int_32, VIL_PIXEL_FORMAT_RGB_INT_32);
140 vil_pixel_format_macro(vil_rgb<vxl_uint_16>, vxl_uint_16, VIL_PIXEL_FORMAT_RGB_UINT_16);
141 vil_pixel_format_macro(vil_rgb<vxl_int_16>, vxl_int_16, VIL_PIXEL_FORMAT_RGB_INT_16);
142 vil_pixel_format_macro(vil_rgb<vxl_byte>, vxl_byte, VIL_PIXEL_FORMAT_RGB_BYTE);
143 vil_pixel_format_macro(vil_rgb<vxl_sbyte>, vxl_sbyte, VIL_PIXEL_FORMAT_RGB_SBYTE);
144 vil_pixel_format_macro(vil_rgb<float>, float, VIL_PIXEL_FORMAT_RGB_FLOAT);
145 vil_pixel_format_macro(vil_rgb<double>, double, VIL_PIXEL_FORMAT_RGB_DOUBLE);
146
147 #if VXL_HAS_INT_64
148 vil_pixel_format_macro(vil_rgba<vxl_uint_64>, vxl_uint_64, VIL_PIXEL_FORMAT_RGBA_UINT_64);
149 vil_pixel_format_macro(vil_rgba<vxl_int_64>, vxl_int_64, VIL_PIXEL_FORMAT_RGBA_INT_64);
150 #endif
151 vil_pixel_format_macro(vil_rgba<vxl_uint_32>, vxl_uint_32, VIL_PIXEL_FORMAT_RGBA_UINT_32);
152 vil_pixel_format_macro(vil_rgba<vxl_int_32>, vxl_int_32, VIL_PIXEL_FORMAT_RGBA_INT_32);
153 vil_pixel_format_macro(vil_rgba<vxl_uint_16>, vxl_uint_16, VIL_PIXEL_FORMAT_RGBA_UINT_16);
154 vil_pixel_format_macro(vil_rgba<vxl_int_16>, vxl_int_16, VIL_PIXEL_FORMAT_RGBA_INT_16);
155 vil_pixel_format_macro(vil_rgba<vxl_byte>, vxl_byte, VIL_PIXEL_FORMAT_RGBA_BYTE);
156 vil_pixel_format_macro(vil_rgba<vxl_sbyte>, vxl_sbyte, VIL_PIXEL_FORMAT_RGBA_SBYTE);
157 vil_pixel_format_macro(vil_rgba<float>, float, VIL_PIXEL_FORMAT_RGBA_FLOAT);
158 vil_pixel_format_macro(vil_rgba<double>, double, VIL_PIXEL_FORMAT_RGBA_DOUBLE);
159
160 vil_pixel_format_macro(std::complex<float>, std::complex<float>, VIL_PIXEL_FORMAT_COMPLEX_FLOAT);
161 vil_pixel_format_macro(std::complex<double>,std::complex<double>,VIL_PIXEL_FORMAT_COMPLEX_DOUBLE);
162
163 #undef vil_pixel_format_macro
164
165 //: Return the number of bytes used by each component of pixel format f
166 unsigned vil_pixel_format_sizeof_components(enum vil_pixel_format f);
167
168 //: Return the number of components in pixel format f
169 unsigned vil_pixel_format_num_components(enum vil_pixel_format f);
170
171 //: Return the format of each component of pixel format f
172 vil_pixel_format vil_pixel_format_component_format(enum vil_pixel_format f);
173
174 //: Output a pretty string representing the pixel format.
175 std::ostream & operator << (std::ostream &os, vil_pixel_format f);
176
177 //: Convert a string into a pixel format.
178 // This uses the same encoding as operator<<.
179 vil_pixel_format vil_pixel_format_from_string(const char * s);
180
181 #endif // vil_pixel_format_h_
182