Last active
December 18, 2015 15:45
-
-
Save thedeemon/8052fb98f8ba154510d7 to your computer and use it in GitHub Desktop.
RGB24 to YV12 conversion (from a DirectShow filter by Infognition) www.infognition.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HRESULT YV12ConverterFromRGB24::Convert(BYTE *pInData, BYTE *pOutData) | |
{ | |
const int swidth = width/2; | |
const int sheight = height/2; | |
BYTE* ydata = pOutData; | |
BYTE* udata = pOutData + width * height; | |
BYTE* vdata = pOutData + width * height * 5/4; | |
for(int sy=0;sy<sheight;sy++) { | |
const int ty = height-1-sy*2; | |
BYTE *pSrc = &pInData[ty*3*width]; | |
BYTE *pSrc2 = &pInData[(ty-1)*3*width]; | |
for(int sx=0;sx<swidth; sx++) { | |
//make 4 Y values and 1 U and V | |
int R = pSrc[0], G = pSrc[1], B = pSrc[2]; | |
int Y = ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16; | |
int U = ( ( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128; | |
int V = ( ( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128; | |
ydata[sx*2] = Y; | |
udata[sx] = U; | |
vdata[sx] = V; | |
R = pSrc[3]; G = pSrc[4]; B = pSrc[5]; | |
Y = ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16; | |
ydata[sx*2+1] = Y; | |
pSrc += 6; | |
R = pSrc2[0]; G = pSrc2[1]; B = pSrc2[2]; | |
Y = ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16; | |
ydata[sx*2+width] = Y; | |
R = pSrc2[3]; G = pSrc2[4]; B = pSrc2[5]; | |
Y = ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16; | |
ydata[sx*2+width+1] = Y; | |
pSrc2 += 6; | |
} | |
ydata += width*2; | |
udata += swidth; | |
vdata += swidth; | |
} | |
return S_OK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment