输入的是 BGR24, rgbIncrement = 3, 如果需要翻转, 将flip 设置位 true
#define rgbtoyuv(b, g, r, y, u, v) /
y=(BYTE)(((int)30*r +(int)59*g +(int)11*b)/100);
/
u=(BYTE)(((int)-17*r -(int)33*g +(int)50*b+12800)/100);
/
v=(BYTE)(((int)50*r -(int)42*g -(int)8*b+12800)/100);
/
BOOL ConvertRGBtoYUV420P(const BYTE * rgb,BYTE * yuv, unsigned rgbIncrement,BOOL flip) const
{
unsigned width = this->width;
unsigned height = this->height;
const unsigned planeSize = width*height;
const unsigned halfWidth = width >> 1;
unsigned count = 0;
// get pointers to the data
BYTE * yplane = yuv;
BYTE * uplane = yuv + planeSize;
BYTE * vplane = yuv + planeSize + (planeSize >> 2);
const BYTE * rgbIndex = rgb;
for (unsigned y = 0;
y < height;
y++) {
BYTE * yline = yplane + (y * width);
BYTE * uline = uplane + ((y >> 1) * halfWidth);
BYTE * vline = vplane + ((y >> 1) * halfWidth);
if (flip)
rgbIndex = rgb + (width*(height-1-y)*rgbIncrement);
for (unsigned x = 0;
x < width;
x+=2) {
rgbtoyuv(rgbIndex[0], rgbIndex[1], rgbIndex[2],*yline, *uline, *vline);
rgbIndex += rgbIncrement;
count++;
yline++;
rgbtoyuv(rgbIndex[0], rgbIndex[1], rgbIndex[2],*yline, *uline, *vline);
rgbIndex += rgbIncrement;
count++;
yline++;
uline++;
vline++;
}
}
return TRUE;
}}