RealRGB24toYUV420Converter.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 "RealRGB24toYUV420Converter.h"
00049 
00050 /*
00051 ===========================================================================
00052         Constants.
00053 ===========================================================================
00054 */
00055 #define RRGB24YUVC_00            0.299
00056 #define RRGB24YUVC_01            0.587
00057 #define RRGB24YUVC_02            0.114
00058 #define RRGB24YUVC_10           -0.147
00059 #define RRGB24YUVC_11           -0.289
00060 #define RRGB24YUVC_12            0.436
00061 #define RRGB24YUVC_20            0.615
00062 #define RRGB24YUVC_21           -0.515
00063 #define RRGB24YUVC_22           -0.100
00064 
00065 /*
00066 ===========================================================================
00067         Interface Methods.
00068 ===========================================================================
00069 */
00080 void RealRGB24toYUV420Converter::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*3;
00100 
00102                 b = (double)(*t++);
00103                 g = (double)(*t++);
00104                 r = (double)(*t++);
00105                 py[lumOff] = (yuvType)((int)(0.5 + RRGB24YUVC_00*r + RRGB24YUVC_01*g + RRGB24YUVC_02*b));
00106 
00107                 u = 128.0 + RRGB24YUVC_10*r + RRGB24YUVC_11*g + RRGB24YUVC_12*b;
00108                 v = 128.0 + RRGB24YUVC_20*r + RRGB24YUVC_21*g + RRGB24YUVC_22*b;
00109 
00111                 b = (double)(*t++);
00112                 g = (double)(*t++);
00113                 r = (double)(*t++);
00114                 py[lumOff+1] = (yuvType)((int)(0.5 + RRGB24YUVC_00*r + RRGB24YUVC_01*g + RRGB24YUVC_02*b));
00115 
00116                 u += 128.0 + RRGB24YUVC_10*r + RRGB24YUVC_11*g + RRGB24YUVC_12*b;
00117                 v += 128.0 + RRGB24YUVC_20*r + RRGB24YUVC_21*g + RRGB24YUVC_22*b;
00118 
00119     lumOff += _width;
00120     t = t + _width*3 - 6;
00122                 b = (double)(*t++);
00123                 g = (double)(*t++);
00124                 r = (double)(*t++);
00125                 py[lumOff] = (yuvType)((int)(0.5 + RRGB24YUVC_00*r + RRGB24YUVC_01*g + RRGB24YUVC_02*b));
00126 
00127                 u += 128.0 + RRGB24YUVC_10*r + RRGB24YUVC_11*g + RRGB24YUVC_12*b;
00128                 v += 128.0 + RRGB24YUVC_20*r + RRGB24YUVC_21*g + RRGB24YUVC_22*b;
00129 
00131                 b = (double)(*t++);
00132                 g = (double)(*t++);
00133                 r = (double)(*t++);
00134                 py[lumOff+1] = (yuvType)((int)(0.5 + RRGB24YUVC_00*r + RRGB24YUVC_01*g + RRGB24YUVC_02*b));
00135 
00136                 u += 128.0 + RRGB24YUVC_10*r + RRGB24YUVC_11*g + RRGB24YUVC_12*b;
00137                 v += 128.0 + RRGB24YUVC_20*r + RRGB24YUVC_21*g + RRGB24YUVC_22*b;
00138 
00140                 pu[chrOff] = (yuvType)( (int)((u + 0.5)/4) );
00141                 pv[chrOff] = (yuvType)( (int)((v + 0.5)/4) );
00142         }//end for xb & yb...
00143 
00144 }//end Convert.
00145 

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