00001
00002 #include "vil_pixel_format.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <vcl_cassert.h>
00013 #include <vcl_complex.h>
00014 #include <vcl_string.h>
00015
00016 static unsigned component_size[] =
00017 {
00018 0,
00019
00020 #if VXL_HAS_INT_64
00021 sizeof(vxl_uint_64),
00022 sizeof(vxl_int_64),
00023 #else
00024 0,
00025 0,
00026 #endif
00027 sizeof(vxl_uint_32),
00028 sizeof(vxl_int_32),
00029 sizeof(vxl_uint_16),
00030 sizeof(vxl_int_16),
00031 sizeof(vxl_byte),
00032 sizeof(vxl_sbyte),
00033 sizeof(float),
00034 sizeof(double),
00035 0,
00036 sizeof(bool),
00037
00038 #if VXL_HAS_INT_64
00039 sizeof(vxl_uint_64),
00040 sizeof(vxl_int_64),
00041 #else
00042 0,
00043 0,
00044 #endif
00045 sizeof(vxl_uint_32),
00046 sizeof(vxl_int_32),
00047 sizeof(vxl_uint_16),
00048 sizeof(vxl_int_16),
00049 sizeof(vxl_byte),
00050 sizeof(vxl_sbyte),
00051 sizeof(float),
00052 sizeof(double),
00053 0,
00054
00055 #if VXL_HAS_INT_64
00056 sizeof(vxl_uint_64),
00057 sizeof(vxl_int_64),
00058 #else
00059 0,
00060 0,
00061 #endif
00062 sizeof(vxl_uint_32),
00063 sizeof(vxl_int_32),
00064 sizeof(vxl_uint_16),
00065 sizeof(vxl_int_16),
00066 sizeof(vxl_byte),
00067 sizeof(vxl_sbyte),
00068 sizeof(float),
00069 0,
00070
00071 sizeof(vcl_complex<float>),
00072 sizeof(vcl_complex<double>),
00073 };
00074
00075
00076 static unsigned num_components[] =
00077 {
00078 0,
00079
00080 #if VXL_HAS_INT_64
00081 1,
00082 1,
00083 #else
00084 0,
00085 0,
00086 #endif
00087 1,
00088 1,
00089 1,
00090 1,
00091 1,
00092 1,
00093 1,
00094 1,
00095 0,
00096 1,
00097
00098 #if VXL_HAS_INT_64
00099 3,
00100 3,
00101 #else
00102 0,
00103 0,
00104 #endif
00105 3,
00106 3,
00107 3,
00108 3,
00109 3,
00110 3,
00111 3,
00112 3,
00113 0,
00114
00115 #if VXL_HAS_INT_64
00116 4,
00117 4,
00118 #else
00119 0,
00120 0,
00121 #endif
00122 4,
00123 4,
00124 4,
00125 4,
00126 4,
00127 4,
00128 4,
00129 4,
00130 0,
00131
00132 1,
00133 1,
00134 };
00135
00136
00137 static vil_pixel_format component_format[] =
00138 {
00139 VIL_PIXEL_FORMAT_UNKNOWN,
00140
00141 #if VXL_HAS_INT_64
00142 VIL_PIXEL_FORMAT_UINT_64,
00143 VIL_PIXEL_FORMAT_INT_64,
00144 #else
00145 VIL_PIXEL_FORMAT_UNKNOWN,
00146 VIL_PIXEL_FORMAT_UNKNOWN,
00147 #endif
00148 VIL_PIXEL_FORMAT_UINT_32,
00149 VIL_PIXEL_FORMAT_INT_32,
00150 VIL_PIXEL_FORMAT_UINT_16,
00151 VIL_PIXEL_FORMAT_INT_16,
00152 VIL_PIXEL_FORMAT_BYTE,
00153 VIL_PIXEL_FORMAT_SBYTE,
00154 VIL_PIXEL_FORMAT_FLOAT,
00155 VIL_PIXEL_FORMAT_DOUBLE,
00156 VIL_PIXEL_FORMAT_UNKNOWN,
00157 VIL_PIXEL_FORMAT_BOOL,
00158
00159 #if VXL_HAS_INT_64
00160 VIL_PIXEL_FORMAT_UINT_64,
00161 VIL_PIXEL_FORMAT_INT_64,
00162 #else
00163 VIL_PIXEL_FORMAT_UNKNOWN,
00164 VIL_PIXEL_FORMAT_UNKNOWN,
00165 #endif
00166 VIL_PIXEL_FORMAT_UINT_32,
00167 VIL_PIXEL_FORMAT_INT_32,
00168 VIL_PIXEL_FORMAT_UINT_16,
00169 VIL_PIXEL_FORMAT_INT_16,
00170 VIL_PIXEL_FORMAT_BYTE,
00171 VIL_PIXEL_FORMAT_SBYTE,
00172 VIL_PIXEL_FORMAT_FLOAT,
00173 VIL_PIXEL_FORMAT_DOUBLE,
00174 VIL_PIXEL_FORMAT_UNKNOWN,
00175
00176 #if VXL_HAS_INT_64
00177 VIL_PIXEL_FORMAT_UINT_64,
00178 VIL_PIXEL_FORMAT_INT_64,
00179 #else
00180 VIL_PIXEL_FORMAT_UNKNOWN,
00181 VIL_PIXEL_FORMAT_UNKNOWN,
00182 #endif
00183 VIL_PIXEL_FORMAT_UINT_32,
00184 VIL_PIXEL_FORMAT_INT_32,
00185 VIL_PIXEL_FORMAT_UINT_16,
00186 VIL_PIXEL_FORMAT_INT_16,
00187 VIL_PIXEL_FORMAT_BYTE,
00188 VIL_PIXEL_FORMAT_SBYTE,
00189 VIL_PIXEL_FORMAT_FLOAT,
00190 VIL_PIXEL_FORMAT_DOUBLE,
00191 VIL_PIXEL_FORMAT_UNKNOWN,
00192
00193 VIL_PIXEL_FORMAT_COMPLEX_FLOAT,
00194 VIL_PIXEL_FORMAT_COMPLEX_DOUBLE,
00195 };
00196
00197
00198
00199 unsigned vil_pixel_format_sizeof_components(enum vil_pixel_format f)
00200 {
00201 assert (f >= VIL_PIXEL_FORMAT_UNKNOWN && f < VIL_PIXEL_FORMAT_ENUM_END);
00202 return component_size[f];
00203 }
00204
00205
00206 unsigned vil_pixel_format_num_components(enum vil_pixel_format f)
00207 {
00208 assert (f >= VIL_PIXEL_FORMAT_UNKNOWN && f < VIL_PIXEL_FORMAT_ENUM_END);
00209 return num_components[f];
00210 }
00211
00212
00213
00214 vil_pixel_format vil_pixel_format_component_format(enum vil_pixel_format f)
00215 {
00216 assert (f >= VIL_PIXEL_FORMAT_UNKNOWN && f < VIL_PIXEL_FORMAT_ENUM_END);
00217 return component_format[f];
00218 }
00219
00220
00221
00222 vcl_ostream & operator << (vcl_ostream &os, vil_pixel_format f)
00223 {
00224 switch (f)
00225 {
00226 case VIL_PIXEL_FORMAT_UNKNOWN: os << "VIL_PIXEL_FORMAT_UNKNOWN"; break;
00227
00228 #if VXL_HAS_INT_64
00229 case VIL_PIXEL_FORMAT_UINT_64: os << "vxl_uint_64"; break;
00230 case VIL_PIXEL_FORMAT_INT_64: os << "vxl_int_64"; break;
00231 #endif
00232 case VIL_PIXEL_FORMAT_UINT_32: os << "vxl_uint_32"; break;
00233 case VIL_PIXEL_FORMAT_INT_32: os << "vxl_int_32"; break;
00234 case VIL_PIXEL_FORMAT_UINT_16: os << "vxl_uint_16"; break;
00235 case VIL_PIXEL_FORMAT_INT_16: os << "vxl_int_16"; break;
00236 case VIL_PIXEL_FORMAT_BYTE: os << "vxl_byte"; break;
00237 case VIL_PIXEL_FORMAT_SBYTE: os << "vxl_sbyte"; break;
00238 case VIL_PIXEL_FORMAT_FLOAT: os << "float"; break;
00239 case VIL_PIXEL_FORMAT_DOUBLE: os << "double"; break;
00240 case VIL_PIXEL_FORMAT_BOOL: os << "bool"; break;
00241
00242 #if VXL_HAS_INT_64
00243 case VIL_PIXEL_FORMAT_RGB_INT_64: os << "vil_rgb<vxl_int_64>"; break;
00244 case VIL_PIXEL_FORMAT_RGB_UINT_64: os << "vil_rgb<vxl_uint_64>"; break;
00245 #endif
00246 case VIL_PIXEL_FORMAT_RGB_INT_32: os << "vil_rgb<vxl_int_32>"; break;
00247 case VIL_PIXEL_FORMAT_RGB_UINT_32: os << "vil_rgb<vxl_uint_32>"; break;
00248 case VIL_PIXEL_FORMAT_RGB_INT_16: os << "vil_rgb<vxl_int_16>"; break;
00249 case VIL_PIXEL_FORMAT_RGB_UINT_16: os << "vil_rgb<vxl_uint_16>"; break;
00250 case VIL_PIXEL_FORMAT_RGB_BYTE: os << "vil_rgb<vxl_byte>"; break;
00251 case VIL_PIXEL_FORMAT_RGB_SBYTE: os << "vil_rgb<vxl_sbyte>"; break;
00252 case VIL_PIXEL_FORMAT_RGB_FLOAT: os << "vil_rgb<float>"; break;
00253 case VIL_PIXEL_FORMAT_RGB_DOUBLE: os << "vil_rgb<double>"; break;
00254
00255 #if VXL_HAS_INT_64
00256 case VIL_PIXEL_FORMAT_RGBA_INT_64: os << "vil_rgba<vxl_int_64>"; break;
00257 case VIL_PIXEL_FORMAT_RGBA_UINT_64: os << "vil_rgba<vxl_uint_64>"; break;
00258 #endif
00259 case VIL_PIXEL_FORMAT_RGBA_INT_32: os << "vil_rgba<vxl_int_32>"; break;
00260 case VIL_PIXEL_FORMAT_RGBA_UINT_32: os << "vil_rgba<vxl_uint_32>"; break;
00261 case VIL_PIXEL_FORMAT_RGBA_INT_16: os << "vil_rgba<vxl_int_16>"; break;
00262 case VIL_PIXEL_FORMAT_RGBA_UINT_16: os << "vil_rgba<vxl_uint_16>"; break;
00263 case VIL_PIXEL_FORMAT_RGBA_BYTE: os << "vil_rgba<vxl_byte>"; break;
00264 case VIL_PIXEL_FORMAT_RGBA_SBYTE: os << "vil_rgba<vxl_sbyte>"; break;
00265 case VIL_PIXEL_FORMAT_RGBA_FLOAT: os << "vil_rgba<float>"; break;
00266 case VIL_PIXEL_FORMAT_RGBA_DOUBLE: os << "vil_rgba<double>"; break;
00267
00268 case VIL_PIXEL_FORMAT_COMPLEX_FLOAT: os << "complex<float>"; break;
00269 case VIL_PIXEL_FORMAT_COMPLEX_DOUBLE: os << "complex<double>"; break;
00270
00271 default: os << "VIL_PIXEL_FORMAT_INVALID"; break;
00272 }
00273 return os;
00274 }
00275
00276
00277
00278
00279 vil_pixel_format vil_pixel_format_from_string(const char * s)
00280 {
00281 vcl_string str(s);
00282 if (str == "VIL_PIXEL_FORMAT_UNKNOWN") return VIL_PIXEL_FORMAT_UNKNOWN;
00283 #if VXL_HAS_INT_64
00284 if (str == "vxl_uint_64") return VIL_PIXEL_FORMAT_UINT_64;
00285 if (str == "vxl_int_64") return VIL_PIXEL_FORMAT_INT_64;
00286 #endif
00287 if (str == "vxl_uint_32") return VIL_PIXEL_FORMAT_UINT_32;
00288 if (str == "vxl_int_32") return VIL_PIXEL_FORMAT_INT_32;
00289 if (str == "vxl_uint_16") return VIL_PIXEL_FORMAT_UINT_16;
00290 if (str == "vxl_int_16") return VIL_PIXEL_FORMAT_INT_16;
00291 if (str == "vxl_byte") return VIL_PIXEL_FORMAT_BYTE;
00292 if (str == "vxl_sbyte") return VIL_PIXEL_FORMAT_SBYTE;
00293 if (str == "float") return VIL_PIXEL_FORMAT_FLOAT;
00294 if (str == "double") return VIL_PIXEL_FORMAT_DOUBLE;
00295 if (str == "bool") return VIL_PIXEL_FORMAT_BOOL;
00296
00297 #if VXL_HAS_INT_64
00298 if (str == "vil_rgb<vxl_int_64>") return VIL_PIXEL_FORMAT_RGB_INT_64;
00299 if (str == "vil_rgb<vxl_uint_64>") return VIL_PIXEL_FORMAT_RGB_UINT_64;
00300 #endif
00301 if (str == "vil_rgb<vxl_int_32>") return VIL_PIXEL_FORMAT_RGB_INT_32;
00302 if (str == "vil_rgb<vxl_uint_32>") return VIL_PIXEL_FORMAT_RGB_UINT_32;
00303 if (str == "vil_rgb<vxl_int_16>") return VIL_PIXEL_FORMAT_RGB_INT_16;
00304 if (str == "vil_rgb<vxl_uint_16>") return VIL_PIXEL_FORMAT_RGB_UINT_16;
00305 if (str == "vil_rgb<vxl_byte>") return VIL_PIXEL_FORMAT_RGB_BYTE;
00306 if (str == "vil_rgb<vxl_sbyte>") return VIL_PIXEL_FORMAT_RGB_SBYTE;
00307 if (str == "vil_rgb<float>") return VIL_PIXEL_FORMAT_RGB_FLOAT;
00308 if (str == "vil_rgb<double>") return VIL_PIXEL_FORMAT_RGB_DOUBLE;
00309
00310 #if VXL_HAS_INT_64
00311 if (str == "vil_rgba<vxl_int_64>") return VIL_PIXEL_FORMAT_RGBA_INT_64;
00312 if (str == "vil_rgba<vxl_uint_64>") return VIL_PIXEL_FORMAT_RGBA_UINT_64;
00313 #endif
00314 if (str == "vil_rgba<vxl_int_32>") return VIL_PIXEL_FORMAT_RGBA_INT_32;
00315 if (str == "vil_rgba<vxl_uint_32>") return VIL_PIXEL_FORMAT_RGBA_UINT_32;
00316 if (str == "vil_rgba<vxl_int_16>") return VIL_PIXEL_FORMAT_RGBA_INT_16;
00317 if (str == "vil_rgba<vxl_uint_16>") return VIL_PIXEL_FORMAT_RGBA_UINT_16;
00318 if (str == "vil_rgba<vxl_byte>") return VIL_PIXEL_FORMAT_RGBA_BYTE;
00319 if (str == "vil_rgba<vxl_sbyte>") return VIL_PIXEL_FORMAT_RGBA_SBYTE;
00320 if (str == "vil_rgba<float>") return VIL_PIXEL_FORMAT_RGBA_FLOAT;
00321 if (str == "vil_rgba<double>") return VIL_PIXEL_FORMAT_RGBA_DOUBLE;
00322
00323 if (str == "complex<float>") return VIL_PIXEL_FORMAT_COMPLEX_FLOAT;
00324 if (str == "complex<double>") return VIL_PIXEL_FORMAT_COMPLEX_DOUBLE;
00325
00326 return VIL_PIXEL_FORMAT_UNKNOWN;
00327 }