core/vil/vil_pixel_format.h
Go to the documentation of this file.
00001 // This is core/vil/vil_pixel_format.h
00002 #ifndef vil_pixel_format_h_
00003 #define vil_pixel_format_h_
00004 //:
00005 // \file
00006 // \author Ian Scott.
00007 // Note that a vcl_complex<float> is thought of as a scalar
00008 // pixel type for vil's purposes.
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   23 Oct.2003 - Peter Vanroose - Added support for 64-bit int pixels
00013 // \endverbatim
00014 
00015 #include <vil/vil_rgb.h>
00016 #include <vil/vil_rgba.h>
00017 #include <vxl_config.h> // for vxl_uint_32 etc.
00018 #include <vcl_iosfwd.h>
00019 #include <vcl_complex.h>
00020 
00021 //: Describes the type of the concrete data.
00022 enum vil_pixel_format
00023 {
00024   VIL_PIXEL_FORMAT_UNKNOWN = 0,
00025 
00026 #if VXL_HAS_INT_64
00027   VIL_PIXEL_FORMAT_UINT_64 = 1,
00028   VIL_PIXEL_FORMAT_INT_64 = 2,
00029 #endif
00030   VIL_PIXEL_FORMAT_UINT_32 = 3,
00031   VIL_PIXEL_FORMAT_INT_32 = 4,
00032   VIL_PIXEL_FORMAT_UINT_16 = 5,
00033   VIL_PIXEL_FORMAT_INT_16 = 6,
00034   VIL_PIXEL_FORMAT_BYTE = 7,
00035   VIL_PIXEL_FORMAT_SBYTE = 8,
00036   VIL_PIXEL_FORMAT_FLOAT = 9,
00037   VIL_PIXEL_FORMAT_DOUBLE = 10,
00038 //  VIL_PIXEL_FORMAT_LONG_DOUBLE = 11,
00039   VIL_PIXEL_FORMAT_BOOL = 12,
00040 
00041 #if VXL_HAS_INT_64
00042   VIL_PIXEL_FORMAT_RGB_UINT_64 = 13,
00043   VIL_PIXEL_FORMAT_RGB_INT_64 = 14,
00044 #endif
00045   VIL_PIXEL_FORMAT_RGB_UINT_32 = 15,
00046   VIL_PIXEL_FORMAT_RGB_INT_32 = 16,
00047   VIL_PIXEL_FORMAT_RGB_UINT_16 = 17,
00048   VIL_PIXEL_FORMAT_RGB_INT_16 = 18,
00049   VIL_PIXEL_FORMAT_RGB_BYTE = 19,
00050   VIL_PIXEL_FORMAT_RGB_SBYTE = 20,
00051   VIL_PIXEL_FORMAT_RGB_FLOAT = 21,
00052   VIL_PIXEL_FORMAT_RGB_DOUBLE = 22,
00053 //  VIL_PIXEL_FORMAT_RGB_LONG_DOUBLE = 23,
00054 
00055 #if VXL_HAS_INT_64
00056   VIL_PIXEL_FORMAT_RGBA_UINT_64 = 24,
00057   VIL_PIXEL_FORMAT_RGBA_INT_64 = 25,
00058 #endif
00059   VIL_PIXEL_FORMAT_RGBA_UINT_32 = 26,
00060   VIL_PIXEL_FORMAT_RGBA_INT_32 = 27,
00061   VIL_PIXEL_FORMAT_RGBA_UINT_16 = 28,
00062   VIL_PIXEL_FORMAT_RGBA_INT_16 = 29,
00063   VIL_PIXEL_FORMAT_RGBA_BYTE = 30,
00064   VIL_PIXEL_FORMAT_RGBA_SBYTE = 31,
00065   VIL_PIXEL_FORMAT_RGBA_FLOAT = 32,
00066   VIL_PIXEL_FORMAT_RGBA_DOUBLE = 33,
00067 //  VIL_PIXEL_FORMAT_RGBA_LONG_DOUBLE = 34,
00068 
00069 //: vcl_complex<float> is a scalar for vil's purposes.
00070   VIL_PIXEL_FORMAT_COMPLEX_FLOAT = 35,
00071 //: vcl_complex<double> is a scalar for vil's purposes.
00072   VIL_PIXEL_FORMAT_COMPLEX_DOUBLE = 36,
00073 
00074 // Add values here and be careful to keep values in vil_pixel_format.cxx in sync
00075 // Don't forget to increase the end value. Also add to vil_convert_cast in vil_convert.h
00076 
00077   VIL_PIXEL_FORMAT_ENUM_END = 37
00078 };
00079 
00080 
00081 //: The pixel format enumeration corresponding to the C++ type.
00082 //
00083 template <class T>
00084 inline vil_pixel_format vil_pixel_format_of(T){return VIL_PIXEL_FORMAT_UNKNOWN;}
00085 
00086 
00087 //: The C++ type corresponding to an invalid pixel format
00088 //
00089 // See vil_pixel_format_type_of.
00090 //
00091 typedef void* vil_pixel_format_invalid_type;
00092 
00093 //: The C++ type corresponding to a pixel format enumeration.
00094 // Use like
00095 // \code
00096 //    typedef vil_pixel_format_type_of<VIL_PIXEL_FORMAT_BYTE>::type byte_type;
00097 // \endcode
00098 // This is specialized for each pixel type enumeration for which a C++
00099 // type exists.
00100 //
00101 // If the resulting type is vil_pixel_format_invalid_type, then the
00102 // pixel format enumeration is not valid.
00103 //
00104 template <vil_pixel_format pix_type>
00105 struct vil_pixel_format_type_of
00106 {
00107   typedef vil_pixel_format_invalid_type type;
00108   typedef vil_pixel_format_invalid_type component_type;
00109 };
00110 
00111 
00112 //: Get the vil_pixel_format value for a given type.
00113 #define vil_pixel_format_macro(T,C,V)\
00114 VCL_DEFINE_SPECIALIZATION inline vil_pixel_format vil_pixel_format_of(T /*dummy*/) { return V; }\
00115 VCL_DEFINE_SPECIALIZATION struct vil_pixel_format_type_of<V> { typedef T type; typedef C component_type; }
00116 
00117 #if VXL_HAS_INT_64
00118 vil_pixel_format_macro(vxl_uint_64, vxl_uint_64, VIL_PIXEL_FORMAT_UINT_64);
00119 vil_pixel_format_macro(vxl_int_64,  vxl_int_64,  VIL_PIXEL_FORMAT_INT_64);
00120 #endif
00121 vil_pixel_format_macro(vxl_uint_32, vxl_uint_32, VIL_PIXEL_FORMAT_UINT_32);
00122 vil_pixel_format_macro(vxl_int_32,  vxl_int_32,  VIL_PIXEL_FORMAT_INT_32);
00123 vil_pixel_format_macro(vxl_uint_16, vxl_uint_16, VIL_PIXEL_FORMAT_UINT_16);
00124 vil_pixel_format_macro(vxl_int_16,  vxl_int_16,  VIL_PIXEL_FORMAT_INT_16);
00125 vil_pixel_format_macro(vxl_byte,    vxl_byte,    VIL_PIXEL_FORMAT_BYTE);
00126 vil_pixel_format_macro(vxl_sbyte,   vxl_sbyte,   VIL_PIXEL_FORMAT_SBYTE);
00127 vil_pixel_format_macro(float,       float,       VIL_PIXEL_FORMAT_FLOAT);
00128 vil_pixel_format_macro(double,      double,      VIL_PIXEL_FORMAT_DOUBLE);
00129 vil_pixel_format_macro(bool,        bool,        VIL_PIXEL_FORMAT_BOOL);
00130 
00131 #if VXL_HAS_INT_64
00132 vil_pixel_format_macro(vil_rgb<vxl_uint_64>, vxl_uint_64, VIL_PIXEL_FORMAT_RGB_UINT_64);
00133 vil_pixel_format_macro(vil_rgb<vxl_int_64>,  vxl_int_64,  VIL_PIXEL_FORMAT_RGB_INT_64);
00134 #endif
00135 vil_pixel_format_macro(vil_rgb<vxl_uint_32>, vxl_uint_32, VIL_PIXEL_FORMAT_RGB_UINT_32);
00136 vil_pixel_format_macro(vil_rgb<vxl_int_32>,  vxl_int_32,  VIL_PIXEL_FORMAT_RGB_INT_32);
00137 vil_pixel_format_macro(vil_rgb<vxl_uint_16>, vxl_uint_16, VIL_PIXEL_FORMAT_RGB_UINT_16);
00138 vil_pixel_format_macro(vil_rgb<vxl_int_16>,  vxl_int_16,  VIL_PIXEL_FORMAT_RGB_INT_16);
00139 vil_pixel_format_macro(vil_rgb<vxl_byte>,    vxl_byte,    VIL_PIXEL_FORMAT_RGB_BYTE);
00140 vil_pixel_format_macro(vil_rgb<vxl_sbyte>,   vxl_sbyte,   VIL_PIXEL_FORMAT_RGB_SBYTE);
00141 vil_pixel_format_macro(vil_rgb<float>,       float,       VIL_PIXEL_FORMAT_RGB_FLOAT);
00142 vil_pixel_format_macro(vil_rgb<double>,      double,      VIL_PIXEL_FORMAT_RGB_DOUBLE);
00143 
00144 #if VXL_HAS_INT_64
00145 vil_pixel_format_macro(vil_rgba<vxl_uint_64>, vxl_uint_64, VIL_PIXEL_FORMAT_RGBA_UINT_64);
00146 vil_pixel_format_macro(vil_rgba<vxl_int_64>,  vxl_int_64,  VIL_PIXEL_FORMAT_RGBA_INT_64);
00147 #endif
00148 vil_pixel_format_macro(vil_rgba<vxl_uint_32>, vxl_uint_32, VIL_PIXEL_FORMAT_RGBA_UINT_32);
00149 vil_pixel_format_macro(vil_rgba<vxl_int_32>,  vxl_int_32,  VIL_PIXEL_FORMAT_RGBA_INT_32);
00150 vil_pixel_format_macro(vil_rgba<vxl_uint_16>, vxl_uint_16, VIL_PIXEL_FORMAT_RGBA_UINT_16);
00151 vil_pixel_format_macro(vil_rgba<vxl_int_16>,  vxl_int_16,  VIL_PIXEL_FORMAT_RGBA_INT_16);
00152 vil_pixel_format_macro(vil_rgba<vxl_byte>,    vxl_byte,    VIL_PIXEL_FORMAT_RGBA_BYTE);
00153 vil_pixel_format_macro(vil_rgba<vxl_sbyte>,   vxl_sbyte,   VIL_PIXEL_FORMAT_RGBA_SBYTE);
00154 vil_pixel_format_macro(vil_rgba<float>,       float,       VIL_PIXEL_FORMAT_RGBA_FLOAT);
00155 vil_pixel_format_macro(vil_rgba<double>,      double,      VIL_PIXEL_FORMAT_RGBA_DOUBLE);
00156 
00157 vil_pixel_format_macro(vcl_complex<float>, vcl_complex<float>, VIL_PIXEL_FORMAT_COMPLEX_FLOAT);
00158 vil_pixel_format_macro(vcl_complex<double>,vcl_complex<double>,VIL_PIXEL_FORMAT_COMPLEX_DOUBLE);
00159 
00160 #undef vil_pixel_format_macro
00161 
00162 //: Return the number of bytes used by each component of pixel format f
00163 unsigned vil_pixel_format_sizeof_components(enum vil_pixel_format f);
00164 
00165 //: Return the number of components in pixel format f
00166 unsigned vil_pixel_format_num_components(enum vil_pixel_format f);
00167 
00168 //: Return the format of each component of pixel format f
00169 vil_pixel_format vil_pixel_format_component_format(enum vil_pixel_format f);
00170 
00171 //: Output a pretty string representing the pixel format.
00172 vcl_ostream & operator << (vcl_ostream &os, vil_pixel_format f);
00173 
00174 //: Convert a string into a pixel format.
00175 // This uses the same encoding as operator<<.
00176 vil_pixel_format vil_pixel_format_from_string(const char * s);
00177 
00178 #endif // vil_pixel_format_h_