RealRGB32toYUV420Converter.cpp

Go to the documentation of this file.
00001 
00037 #ifdef _WINDOWS
00038 #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
00039 #include <windows.h>
00040 #else
00041 #include <stdio.h>
00042 #endif
00043 
00044 #include <math.h>
00045 #include <string.h>
00046 #include <stdlib.h>
00047 
00048 #include "RealRGB32toYUV420Converter.h"
00049 
00050 /*
00051 ===========================================================================
00052         Constants.
00053 ===========================================================================
00054 */
00055 #define RRGB32YUVC_00            0.299
00056 #define RRGB32YUVC_01            0.587
00057 #define RRGB32YUVC_02            0.114
00058 #define RRGB32YUVC_10           -0.147
00059 #define RRGB32YUVC_11           -0.289
00060 #define RRGB32YUVC_12            0.436
00061 #define RRGB32YUVC_20            0.615
00062 #define RRGB32YUVC_21           -0.515
00063 #define RRGB32YUVC_22           -0.100
00064 
00065 /*
00066 ===========================================================================
00067         Interface Methods.
00068 ===========================================================================
00069 */
00080 void RealRGB32toYUV420Converter::Convert(void* pRgb, void* pY, void* pU, void* pV)
00081 {
00082         yuvType*        py = (yuvType *)pY;
00083         yuvType*        pu = (yuvType *)pU;
00084         yuvType*        pv = (yuvType *)pV;
00085         unsigned char* src = (unsigned char *)pRgb;
00086 
00088         double  u,v;
00089         double  r,g,b;
00090 
00092         int xBlks = _width >> 1;
00093         int yBlks = _height >> 1;
00094         for(int yb = 0; yb < yBlks; yb++)
00095    for(int xb = 0; xb < xBlks; xb++)
00096         {
00097     int                                                 chrOff  = yb*xBlks + xb;
00098     int                                                 lumOff  = (yb*_width + xb) << 1;
00099     unsigned char*      t                               = src + lumOff*4;
00100 
00102                 b = (double)(*t++);
00103                 g = (double)(*t++);
00104                 r = (double)(*t++);
00105                 t++;    
00106                 py[lumOff] = (yuvType)((int)(0.5 + RRGB32YUVC_00*r + RRGB32YUVC_01*g + RRGB32YUVC_02*b));
00107 
00108                 u = 128.0 + RRGB32YUVC_10*r + RRGB32YUVC_11*g + RRGB32YUVC_12*b;
00109                 v = 128.0 + RRGB32YUVC_20*r + RRGB32YUVC_21*g + RRGB32YUVC_22*b;
00110 
00112                 b = (double)(*t++);
00113                 g = (double)(*t++);
00114                 r = (double)(*t++);
00115                 t++;    
00116                 py[lumOff+1] = (yuvType)((int)(0.5 + RRGB32YUVC_00*r + RRGB32YUVC_01*g + RRGB32YUVC_02*b));
00117 
00118                 u += 128.0 + RRGB32YUVC_10*r + RRGB32YUVC_11*g + RRGB32YUVC_12*b;
00119                 v += 128.0 + RRGB32YUVC_20*r + RRGB32YUVC_21*g + RRGB32YUVC_22*b;
00120 
00121     lumOff += _width;
00122     t = t + _width*4 - 8;
00124                 b = (double)(*t++);
00125                 g = (double)(*t++);
00126                 r = (double)(*t++);
00127                 t++;    
00128                 py[lumOff] = (yuvType)((int)(0.5 + RRGB32YUVC_00*r + RRGB32YUVC_01*g + RRGB32YUVC_02*b));
00129 
00130                 u += 128.0 + RRGB32YUVC_10*r + RRGB32YUVC_11*g + RRGB32YUVC_12*b;
00131                 v += 128.0 + RRGB32YUVC_20*r + RRGB32YUVC_21*g + RRGB32YUVC_22*b;
00132 
00134                 b = (double)(*t++);
00135                 g = (double)(*t++);
00136                 r = (double)(*t);
00137                 py[lumOff+1] = (yuvType)((int)(0.5 + RRGB32YUVC_00*r + RRGB32YUVC_01*g + RRGB32YUVC_02*b));
00138 
00139                 u += 128.0 + RRGB32YUVC_10*r + RRGB32YUVC_11*g + RRGB32YUVC_12*b;
00140                 v += 128.0 + RRGB32YUVC_20*r + RRGB32YUVC_21*g + RRGB32YUVC_22*b;
00141 
00143                 pu[chrOff] = (yuvType)( (int)((u + 0.5)/4) );
00144                 pv[chrOff] = (yuvType)( (int)((v + 0.5)/4) );
00145         }//end for xb & yb...
00146 
00147 }//end Convert.
00148 

Generated on Fri Mar 13 14:12:38 2009 for RTVC by  doxygen 1.5.3