00001
00002 #ifndef vgui_pixel_h_
00003 #define vgui_pixel_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <vgui/vgui_gl.h>
00019 #include <vxl_config.h>
00020
00021
00022
00023 template <int r, int g, int b> struct vgui_pixel_rgb;
00024 template <int b, int g, int r> struct vgui_pixel_bgr;
00025 template <int r, int g, int b, int a> struct vgui_pixel_rgba;
00026 template <int a, int b, int g, int r> struct vgui_pixel_abgr;
00027 template <int b, int g, int r, int a> struct vgui_pixel_bgra;
00028 struct vgui_pixel_rgbfloat;
00029
00030 VCL_DEFINE_SPECIALIZATION
00031 struct vgui_pixel_rgb<8,8,8>
00032 {
00033 GLubyte R;
00034 GLubyte G;
00035 GLubyte B;
00036 vgui_pixel_rgb<8,8,8>() { }
00037 vgui_pixel_rgb<8,8,8>( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte = 0 )
00038 : R(red), G(green), B(blue) {}
00039 };
00040 typedef vgui_pixel_rgb<8,8,8> vgui_pixel_rgb888;
00041
00042 VCL_DEFINE_SPECIALIZATION
00043 struct vgui_pixel_rgb<16,16,16>
00044 {
00045 GLushort R;
00046 GLushort G;
00047 GLushort B;
00048 vgui_pixel_rgb<16,16,16>() { }
00049 vgui_pixel_rgb<16,16,16>( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte = 0 )
00050 : R(red), G(green), B(blue) {}
00051 };
00052 typedef vgui_pixel_rgb<16,16,16> vgui_pixel_rgb161616;
00053
00054
00055
00056
00057
00058
00059 VCL_DEFINE_SPECIALIZATION
00060 struct vgui_pixel_rgb<5,6,5>
00061 {
00062 #if VXL_LITTLE_ENDIAN
00063 GLushort B : 5;
00064 GLushort G : 6;
00065 GLushort R : 5;
00066 #else
00067 GLushort R : 5;
00068 GLushort G : 6;
00069 GLushort B : 5;
00070 #endif
00071 vgui_pixel_rgb<5,6,5>() { }
00072 vgui_pixel_rgb<5,6,5>( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte = 0 )
00073 #if VXL_LITTLE_ENDIAN
00074 : B(blue>>3), G(green>>2), R(red>>3) {}
00075 #else
00076 : R(red>>3), G(green>>2), B(blue>>3) {}
00077 #endif
00078 };
00079
00080 typedef vgui_pixel_rgb<5,6,5> vgui_pixel_rgb565;
00081
00082 VCL_DEFINE_SPECIALIZATION
00083 struct vgui_pixel_bgr<5,6,5>
00084 {
00085 #if VXL_LITTLE_ENDIAN
00086 GLushort R : 5;
00087 GLushort G : 6;
00088 GLushort B : 5;
00089 #else
00090 GLushort B : 5;
00091 GLushort G : 6;
00092 GLushort R : 5;
00093 #endif
00094 vgui_pixel_bgr<5,6,5>() { }
00095 vgui_pixel_bgr<5,6,5>( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte = 0 )
00096 #if VXL_LITTLE_ENDIAN
00097 : R(red>>3), G(green>>2), B(blue>>3) {}
00098 #else
00099 : B(blue>>3), G(green>>2), R(red>>3) {}
00100 #endif
00101 };
00102
00103 typedef vgui_pixel_bgr<5,6,5> vgui_pixel_bgr565;
00104
00105 VCL_DEFINE_SPECIALIZATION
00106 struct vgui_pixel_bgr<8,8,8>
00107 {
00108 GLubyte B;
00109 GLubyte G;
00110 GLubyte R;
00111 vgui_pixel_bgr<8,8,8>() {}
00112 vgui_pixel_bgr<8,8,8>( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte = 0 )
00113 : B(blue), G(green), R(red) {}
00114 };
00115 typedef vgui_pixel_bgr<8,8,8> vgui_pixel_bgr888;
00116
00117 VCL_DEFINE_SPECIALIZATION
00118 struct vgui_pixel_rgba<5,5,5,1>
00119 {
00120 GLushort B:5;
00121 GLushort G:5;
00122 GLushort R:5;
00123 GLushort A:1;
00124 vgui_pixel_rgba<5,5,5,1>() { }
00125 vgui_pixel_rgba<5,5,5,1>( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte alpha )
00126 : B(blue>>3), G(green>>3), R(red>>3), A(alpha) {}
00127 };
00128 typedef vgui_pixel_rgba<5,5,5,1> vgui_pixel_bgra5551;
00129
00130 VCL_DEFINE_SPECIALIZATION
00131 struct vgui_pixel_rgba<8,8,8,8>
00132 {
00133 GLubyte R;
00134 GLubyte G;
00135 GLubyte B;
00136 GLubyte A;
00137 vgui_pixel_rgba<8,8,8,8>() { }
00138 vgui_pixel_rgba<8,8,8,8>( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte alpha )
00139 : R(red), G(green), B(blue), A(alpha) {}
00140 };
00141 typedef vgui_pixel_rgba<8,8,8,8> vgui_pixel_rgba8888;
00142
00143 VCL_DEFINE_SPECIALIZATION
00144 struct vgui_pixel_abgr<8,8,8,8>
00145 {
00146 GLubyte A;
00147 GLubyte B;
00148 GLubyte G;
00149 GLubyte R;
00150 vgui_pixel_abgr<8,8,8,8>() { }
00151 vgui_pixel_abgr<8,8,8,8>( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte alpha )
00152 : A(alpha), B(blue), G(green), R(red) {}
00153 };
00154 typedef vgui_pixel_abgr<8,8,8,8> vgui_pixel_abgr8888;
00155
00156 VCL_DEFINE_SPECIALIZATION
00157 struct vgui_pixel_bgra<8,8,8,8>
00158 {
00159 GLubyte B;
00160 GLubyte G;
00161 GLubyte R;
00162 GLubyte A;
00163 vgui_pixel_bgra<8,8,8,8>() { }
00164 vgui_pixel_bgra<8,8,8,8>( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte alpha )
00165 : B(blue), G(green), R(red), A(alpha) {}
00166 };
00167 typedef vgui_pixel_bgra<8,8,8,8> vgui_pixel_bgra8888;
00168
00169 struct vgui_pixel_rgbfloat
00170 {
00171 float R;
00172 float G;
00173 float B;
00174 vgui_pixel_rgbfloat() {}
00175 vgui_pixel_rgbfloat( vxl_byte red, vxl_byte green, vxl_byte blue, vxl_byte = 0 )
00176 : R(red), G(green), B(blue) {}
00177 };
00178
00179
00180
00181
00182 template <class T>
00183 inline
00184 vxl_byte vgui_pixel_clamp( T in )
00185 {
00186 if ( in > 255 ) return 255u;
00187 if ( in < 0 ) return 0u;
00188 return vxl_byte(in);
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 inline
00198 vxl_byte vgui_pixel_clamp( bool in )
00199 {
00200 return in ? 255u : 0u;
00201 }
00202
00203
00204
00205
00206 inline
00207 vxl_byte vgui_pixel_clamp( vxl_byte in )
00208 {
00209 return in;
00210 }
00211
00212
00213
00214
00215 inline
00216 vxl_byte vgui_pixel_clamp( vxl_sbyte in )
00217 {
00218 if ( in < 0 ) return 0u;
00219 else return in;
00220 }
00221
00222
00223
00224
00225
00226 inline
00227 vxl_byte vgui_pixel_clamp( vxl_uint_16 in )
00228 {
00229 if ( in > 255 ) return 255u;
00230 else return static_cast<vxl_byte>(in);
00231 }
00232
00233
00234
00235
00236
00237 inline
00238 vxl_byte vgui_pixel_clamp( vxl_uint_32 in )
00239 {
00240 if ( in > 255 ) return 255u;
00241 else return static_cast<vxl_byte>(in);
00242 }
00243
00244
00245
00246 template <class InT, class OutT>
00247 inline void
00248 vgui_pixel_convert( InT const& in, OutT& out )
00249 {
00250 out = OutT( vgui_pixel_clamp( in ), vgui_pixel_clamp( in ),
00251 vgui_pixel_clamp( in ), 255 );
00252 }
00253
00254
00255 template <class InT, class OutT>
00256 inline void
00257 vgui_pixel_convert( InT const& R, InT const& G, InT const& B,
00258 OutT& out )
00259 {
00260 out = OutT( vgui_pixel_clamp( R ), vgui_pixel_clamp( G ),
00261 vgui_pixel_clamp( B ), 255 );
00262 }
00263
00264
00265 template <class InT, class OutT>
00266 inline void
00267 vgui_pixel_convert( InT const& R, InT const& G, InT const& B, InT const& A,
00268 OutT& out )
00269 {
00270 out = OutT( vgui_pixel_clamp( R ), vgui_pixel_clamp( G ),
00271 vgui_pixel_clamp( B ), vgui_pixel_clamp( A ) );
00272 }
00273
00274
00275
00276
00277
00278 void vgui_pixel_convert_span(GLubyte const *, vgui_pixel_rgb888 *, unsigned size);
00279 void vgui_pixel_convert_span(GLubyte const *, vgui_pixel_bgr888 *, unsigned size);
00280 void vgui_pixel_convert_span(GLubyte const *, vgui_pixel_rgb565 *, unsigned size);
00281 void vgui_pixel_convert_span(GLubyte const *, vgui_pixel_bgra5551 *, unsigned size);
00282 void vgui_pixel_convert_span(GLubyte const *, vgui_pixel_rgba8888 *, unsigned size);
00283 void vgui_pixel_convert_span(GLubyte const *, vgui_pixel_abgr8888 *, unsigned size);
00284 void vgui_pixel_convert_span(GLubyte const *, vgui_pixel_bgra8888 *, unsigned size);
00285
00286 void vgui_pixel_convert_span(GLfloat const *, vgui_pixel_rgb888 *, unsigned size);
00287 void vgui_pixel_convert_span(GLfloat const *, vgui_pixel_bgr888 *, unsigned size);
00288 void vgui_pixel_convert_span(GLfloat const *, vgui_pixel_rgb565 *, unsigned size);
00289 void vgui_pixel_convert_span(GLfloat const *, vgui_pixel_bgra5551 *, unsigned size);
00290 void vgui_pixel_convert_span(GLfloat const *, vgui_pixel_rgba8888 *, unsigned size);
00291 void vgui_pixel_convert_span(GLfloat const *, vgui_pixel_abgr8888 *, unsigned size);
00292 void vgui_pixel_convert_span(GLfloat const *, vgui_pixel_bgra8888 *, unsigned size);
00293
00294 void vgui_pixel_convert_span(GLdouble const *, vgui_pixel_rgb888 *, unsigned size);
00295 void vgui_pixel_convert_span(GLdouble const *, vgui_pixel_bgr888 *, unsigned size);
00296 void vgui_pixel_convert_span(GLdouble const *, vgui_pixel_rgb565 *, unsigned size);
00297 void vgui_pixel_convert_span(GLdouble const *, vgui_pixel_bgra5551 *, unsigned size);
00298 void vgui_pixel_convert_span(GLdouble const *, vgui_pixel_rgba8888 *, unsigned size);
00299 void vgui_pixel_convert_span(GLdouble const *, vgui_pixel_abgr8888 *, unsigned size);
00300 void vgui_pixel_convert_span(GLdouble const *, vgui_pixel_bgra8888 *, unsigned size);
00301
00302 void vgui_pixel_convert_span(vgui_pixel_rgb888 const *, vgui_pixel_rgb888 *, unsigned size);
00303 void vgui_pixel_convert_span(vgui_pixel_rgb888 const *, vgui_pixel_bgr888 *, unsigned size);
00304 void vgui_pixel_convert_span(vgui_pixel_rgb888 const *, vgui_pixel_rgb565 *, unsigned size);
00305 void vgui_pixel_convert_span(vgui_pixel_rgb888 const *, vgui_pixel_bgra5551 *, unsigned size);
00306 void vgui_pixel_convert_span(vgui_pixel_rgb888 const *, vgui_pixel_rgba8888 *, unsigned size);
00307 void vgui_pixel_convert_span(vgui_pixel_rgb888 const *, vgui_pixel_abgr8888 *, unsigned size);
00308 void vgui_pixel_convert_span(vgui_pixel_rgb888 const *, vgui_pixel_bgra8888 *, unsigned size);
00309
00310 void vgui_pixel_convert_span(vgui_pixel_rgba8888 const *, vgui_pixel_rgb888 *, unsigned size);
00311 void vgui_pixel_convert_span(vgui_pixel_rgba8888 const *, vgui_pixel_bgr888 *, unsigned size);
00312 void vgui_pixel_convert_span(vgui_pixel_rgba8888 const *, vgui_pixel_rgb565 *, unsigned size);
00313 void vgui_pixel_convert_span(vgui_pixel_rgba8888 const *, vgui_pixel_bgra5551 *, unsigned size);
00314 void vgui_pixel_convert_span(vgui_pixel_rgba8888 const *, vgui_pixel_rgba8888 *, unsigned size);
00315 void vgui_pixel_convert_span(vgui_pixel_rgba8888 const *, vgui_pixel_abgr8888 *, unsigned size);
00316 void vgui_pixel_convert_span(vgui_pixel_rgba8888 const *, vgui_pixel_bgra8888 *, unsigned size);
00317
00318 void vgui_pixel_convert_span(vgui_pixel_rgbfloat const *, vgui_pixel_rgb888 *, unsigned size);
00319 void vgui_pixel_convert_span(vgui_pixel_rgbfloat const *, vgui_pixel_bgr888 *, unsigned size);
00320 void vgui_pixel_convert_span(vgui_pixel_rgbfloat const *, vgui_pixel_rgb565 *, unsigned size);
00321 void vgui_pixel_convert_span(vgui_pixel_rgbfloat const *, vgui_pixel_bgra5551 *, unsigned size);
00322 void vgui_pixel_convert_span(vgui_pixel_rgbfloat const *, vgui_pixel_rgba8888 *, unsigned size);
00323 void vgui_pixel_convert_span(vgui_pixel_rgbfloat const *, vgui_pixel_abgr8888 *, unsigned size);
00324 void vgui_pixel_convert_span(vgui_pixel_rgbfloat const *, vgui_pixel_bgra8888 *, unsigned size);
00325
00326 #endif // vgui_pixel_h_