00001
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef __VETLIB_VETUTILITY_H__
00052 #define __VETLIB_VETUTILITY_H__
00053
00054 #include "vetDefs.h"
00055 #include "vetFrameT.h"
00056 #include "vetFrameYUV420.h"
00057 #include "vetFrameRGB24.h"
00058
00059
00060 class vetUtility
00061 {
00062 protected:
00063
00064
00065 vetUtility() {}
00066
00067 public:
00068
00069 virtual ~vetUtility() {}
00070
00071
00072 static double getTime_usec();
00073 static void vetSleep(long millisec);
00074
00075
00076 static char* getTypeNameFromClassTypeID(int classType_id);
00077
00078
00082
00083 template<class T, class S>
00084 static VETRESULT conv_PixelPackedToChannelPacked(T* out, S* in, unsigned int width, unsigned int height, unsigned int channels = 3)
00085 {
00086 if ( out == NULL || in == NULL || width == 0 || height == 0)
00087 return VETRET_PARAM_ERR;
00088
00089 T* outPtr;
00090 S* inPtr;
00091 unsigned int i;
00092
00093 for (unsigned int ch=0; ch < channels; ch++)
00094 {
00095 inPtr = in + ch;
00096 outPtr = out + width*height*ch;
00097
00098 for (i=0; i< width*height; i++)
00099 {
00100 *outPtr = (T)*inPtr;
00101 outPtr++;
00102 inPtr+= 3;
00103 }
00104 }
00105
00106 return VETRET_OK;
00107 };
00108
00109
00110
00111 template<class T, class S>
00112 static VETRESULT conv_ChannelPackedToPixelPacked(T* out, S* in, unsigned int width, unsigned int height, unsigned int channels)
00113 {
00114 if ( out == NULL || in == NULL || width == 0 || height == 0)
00115 return VETRET_PARAM_ERR;
00116
00117 T* outPtr;
00118 S* inPtr;
00119 unsigned int i;
00120
00121 for (unsigned int ch=0; ch < channels; ch++)
00122 {
00123 inPtr = in + width*height*ch;
00124 outPtr = out + ch;
00125
00126 for (i=0; i< width*height; i++)
00127 {
00128 *outPtr = (T)*inPtr;
00129 inPtr++;
00130 outPtr+= 3;
00131 }
00132 }
00133
00134 return VETRET_OK;
00135 };
00136
00137
00138 template<class RGB, class YUV>
00139 static VETRESULT conv_PixelRGBtoPlanarYUV(RGB* RGB_Packed_Ptr, YUV* YUV_Planar_ptr, unsigned int width, unsigned int height, unsigned int formula = 0)
00140 {
00141 switch ( formula )
00142 {
00143 case 0:
00144 {
00145 RGB* rgb = RGB_Packed_Ptr;
00146 YUV* y = YUV_Planar_ptr;
00147 YUV* u = YUV_Planar_ptr[width*height];
00148 YUV* v = YUV_Planar_ptr[width*height*2];
00149
00150 for (int i=0; i<width*height*3; i++, y++, u++, v++)
00151 {
00152 *y = (YUV)( (( rgb[i] * 66 + rgb[i+1] * 129 + rgb[i+2] * 25 + 128 ) >> 8) + 16 );
00153 *u = (YUV)( (( rgb[i] * -38 + rgb[i+1] * 74 + rgb[i+2] * 112 + 128 ) >> 8) + 128 );
00154 *v = (YUV)( (( rgb[i] * 112 + rgb[i+1] * 94 + rgb[i+2] * 18 + 128 ) >> 8) + 128 );
00155 rgb = rgb+3;
00156 }
00157
00158 }
00159 break;
00160
00161 case 1:
00162 {
00163 RGB* rgb = RGB_Packed_Ptr;
00164 YUV* y = YUV_Planar_ptr;
00165 YUV* u = YUV_Planar_ptr[width*height];
00166 YUV* v = YUV_Planar_ptr[width*height*2];
00167
00168 for (int i=0; i<width*height*3; i++, y++, u++, v++)
00169 {
00170 *y = (YUV)( 0.257 * rgb[i] + 0.504 * rgb[i+1] + 0.098 * rgb[i+2] + 16 );
00171 *u = (YUV)( 0.439 * rgb[i] - 0.368 * rgb[i+1] + 0.071 * rgb[i+2] + 128 );
00172 *v = (YUV)(-0.148 * rgb[i] - 0.291 * rgb[i+1] + 0.439 * rgb[i+2] + 128 );
00173 rgb = rgb+3;
00174 }
00175
00176 }
00177 break;
00178
00179 case 2:
00180 {
00181 RGB* rgb = RGB_Packed_Ptr;
00182 YUV* y = YUV_Planar_ptr;
00183 YUV* u = YUV_Planar_ptr[width*height];
00184 YUV* v = YUV_Planar_ptr[width*height*2];
00185
00186 for (int i=0; i<width*height*3; i++, y++, u++, v++)
00187 {
00188 *y = (YUV)( rgb[i] * .299 + rgb[i+1] * .587 + rgb[i+2] * .114 );
00189 *u = (YUV)( rgb[i] *-.169 + rgb[i+1] *-.332 + rgb[i+2] * .500 + 128. );
00190 *v = (YUV)( rgb[i] * .500 + rgb[i+1] * .419 + rgb[i+2] *-.0813 + 128. );
00191 rgb = rgb+3;
00192 }
00193
00194 }
00195 break;
00196
00197 default:
00198 return VETRET_PARAM_ERR;
00199 }
00200
00201 return VETRET_OK;
00202 };
00203
00204
00205 template<class RGB, class YUV>
00206 static VETRESULT conv_PlanarYUVtoPixelRGB(YUV* YUV_Planar_ptr, RGB* RGB_Packed_Ptr, unsigned int width, unsigned int height, unsigned int formula = 0)
00207 {
00208 switch ( formula )
00209 {
00210 case 0:
00211 {
00212 RGB* rgb = RGB_Packed_Ptr;
00213 YUV* y = YUV_Planar_ptr;
00214 YUV* u = YUV_Planar_ptr+width*height;
00215 YUV* v = YUV_Planar_ptr+width*height*2;
00216
00217 for (unsigned int i=0; i<width*height*3; i++, y++, u++, v++)
00218 {
00219 rgb[i] = (RGB)( (298* (*y-16) + 409* (*v-128) + 128) >> 8);
00220 rgb[i+1] = (RGB)( (298* (*y-16) - 100* (*u-128) - 208* (*v-128) + 128) >> 8);
00221 rgb[i+2] = (RGB)( (298* (*y-16) + 516* (*u-128) + 128) >> 8 );
00222 rgb = rgb+3;
00223 }
00224
00225 }
00226 break;
00227
00228 case 1:
00229 {
00230 RGB* rgb = RGB_Packed_Ptr;
00231 YUV* y = YUV_Planar_ptr;
00232 YUV* u = YUV_Planar_ptr+width*height;
00233 YUV* v = YUV_Planar_ptr+width*height*2;
00234
00235 for (unsigned int i=0; i<width*height*3; i++, y++, u++, v++)
00236 {
00237
00238
00239
00240 rgb = rgb+3;
00241 }
00242
00243 }
00244 break;
00245
00246 case 2:
00247 {
00248 RGB* rgb = RGB_Packed_Ptr;
00249 YUV* y = YUV_Planar_ptr;
00250 YUV* u = YUV_Planar_ptr+width*height;
00251 YUV* v = YUV_Planar_ptr+width*height*2;
00252
00253 for (unsigned int i=0; i<width*height*3; i++, y++, u++, v++)
00254 {
00255 rgb[i] = (RGB)( *y + (*v - 128) * 1.4075 );
00256 rgb[i+1] = (RGB)( *y - (*u - 128) * 0.3455 + (*v - 128) * 0.7196 );
00257 rgb[i+2] = (RGB)( *y + (*u - 128) * 1.7790 );
00258 rgb = rgb+3;
00259 }
00260
00261 }
00262 break;
00263
00264 default:
00265 return VETRET_PARAM_ERR;
00266 }
00267
00268 return VETRET_OK;
00269 };
00270
00271
00272
00273
00274 template<class T, class S>
00275 static VETRESULT conv_bgr_rgb(T* out, S* in, unsigned int width, unsigned int height)
00276 {
00277 if ( out == NULL || in == NULL || width == 0 || height == 0)
00278 return VETRET_PARAM_ERR;
00279
00280 T* outPtr = out + 2;
00281 S* inPtr = in;
00282
00283 for (unsigned int i=0; i< width*height; i++)
00284 {
00285 *(outPtr--) = *(inPtr++);
00286 *(outPtr--) = *(inPtr++);
00287 *(outPtr) = *(inPtr++);
00288 outPtr += 5;
00289 }
00290
00291 return VETRET_OK;
00292 };
00293
00294
00295
00296 template<class T, class S>
00297 static VETRESULT conv_linear(T* out, S* in, double* matrix, unsigned int width, unsigned int height)
00298 {
00299 if ( out == NULL || in == NULL || width == 0 || height == 0)
00300 return VETRET_PARAM_ERR;
00301
00302 T* outPtr = out;
00303 S* inPtr = in;
00304
00305 for (unsigned int i=0; i < width*height; i++)
00306 {
00307 *(outPtr++) = *inPtr * matrix[0] + *(inPtr+1) * matrix[1] + *(inPtr+2) * matrix[2];
00308 *(outPtr++) = *inPtr * matrix[3] - *(inPtr+1) * matrix[4] - *(inPtr+2) * matrix[5];
00309 *(outPtr++) = *inPtr * matrix[6] - *(inPtr+1) * matrix[7] + *(inPtr+2) * matrix[8];
00310 inPtr += 3;
00311 }
00312
00313 return VETRET_OK;
00314 };
00320
00321
00322
00323
00324
00326 template<class T, class S>
00327 static VETRESULT conv_rgb_yuv(T* out, S* in, unsigned int width, unsigned int height);
00328 template<class T, class S>
00329 static VETRESULT conv_yuv_rgb(T* out, S* in, unsigned int width, unsigned int height);
00330
00332 template<class T, class S>
00333 static VETRESULT conv_rgb_yiq(T* out, S* in, unsigned int width, unsigned int height);
00334 template<class T, class S>
00335 static VETRESULT conv_yiq_rgb(T* out, S* in, unsigned int width, unsigned int height);
00336
00338 template<class T, class S>
00339 static VETRESULT conv_rgb_xyz(T* out, S* in, unsigned int width, unsigned int height);
00340 template<class T, class S>
00341 static VETRESULT conv_xyz_rgb(T* out, S* in, unsigned int width, unsigned int height);
00342
00344 template<class T, class S>
00345 static VETRESULT conv_rgb_smpte_c(T* out, S* in, unsigned int width, unsigned int height);
00346 template<class T, class S>
00347 static VETRESULT conv_smpte_c_rgb(T* out, S* in, unsigned int width, unsigned int height);
00348
00350 template<class T, class S>
00351 static VETRESULT conv_rgb_bt709(T* out, S* in, unsigned int width, unsigned int height);
00352 template<class T, class S>
00353 static VETRESULT conv_bt709_rgb(T* out, S* in, unsigned int width, unsigned int height);
00354
00356 template<class T, class S>
00357 static VETRESULT conv_rgb_smpte240m(T* out, S* in, unsigned int width, unsigned int height);
00358 template<class T, class S>
00359 static VETRESULT conv_smpte240m_rgb(T* out, S* in, unsigned int width, unsigned int height);
00360
00362
00363
00364
00365 static VETRESULT conv_rgb24_420p(vetFrameRGB24& img, void* dataOut);
00366
00367
00368
00369 static void conv_420p_grey(int width, int height, void *src, void *dst);
00370
00371
00372
00373
00374 static void conv_rgb24_rgb96(void *src, unsigned char *dst, unsigned int width, unsigned int height);
00375 static void conv_bgr24_rgb96(void *src, unsigned char *dst, unsigned int width, unsigned int height);
00376
00377 static void conv_rgb24_rgb96_(void *src, int *dst, unsigned int width, unsigned int height);
00378
00379
00380 static void conv_rgb32_rgb96(int width, int height, void *src, void *dst);
00381
00382
00383
00384 };
00385
00386
00387 #endif //__VETLIB_VETUTILITY_H__
00388