问题描述
以下是将NV12转换为RGB的代码。
我想要的是从RGB转换为NV12。
无效CFramePump: :NV12ToRGB(BYTE * pOut,BYTE * pIn,unsigned int Width,unsigned int Height)
{
HRESULT hr = S_OK;
DWORD dexOut = 0;
unsigned int PX,PY;
int y [4];
int u;
int v;
int rbg_off;
int y_off = 0;
int v_off =高度*宽度;
unsigned int rgb;
rbg_off = 0;
int ppy = 0;
int ppx = 0;
int off;
for(PY = 0; PY< Height; PY + = 2)
{
for(PX = 0; PX
{
//获取YUV值
y_off = PY *宽度+ PX;
y [0] = pIn [y_off] ;
y [1] = pIn [y_off + 1];
y [2] = pIn [y_off + Width];
y [3] = pIn [y_off + Width + 1];
u = pIn [v_off ++];
v = pIn [v_off ++];
off =(PY *宽度* 3)+(PX * 3);
rgb = yuv2rgb(y [0],u,v);
pOut [off] =(rgb& 0x000000ff);
pOut [off + 1] =(rgb& 0x0000ff00)>> 8;
pOut [off + 2] =(rgb& 0x00ff0000)>> 16;
rgb = yuv2rgb(y [1],u,v);
pOut [ off + 3] =(rgb& 0x000000ff);
pOut [off + 4] =(rgb& 0x0000ff00)>> 8;
pOut [off + 5] =(rgb& 0x00ff0000)>> 16;
off + =(宽* 3);
rgb = yuv2rgb(y [2] ,u,v);
pOut [off] =(rgb& 0x000000ff);
pOut [off + 1] =(rgb& 0x0000ff00)>> ; 8;
pOut [off + 2] =(rgb& 0x00ff0000)>> 16;
rgb = yuv2rgb(y [3],u,v);
pOut [off + 3] =(rgb& ; 0x000000ff);
pOut [off + 4] =(rgb& 0x0000ff00)>> 8;
pOut [off + 5] =(rgb& 0x00ff0000)>> 16;
}
}
$ / b $ b $
unsigned int yuv2rgb(int Y,int Cr,int Cb)
{
int Ey,Epb,Epr;
int例如,Eb,Er;
unsigned int result;
Ey =(Y-16);
Epb =(Cb-128);
Epr =(Cr-128);
Eg =(298 * Ey - 100 * Epb - 208 * Epr)/ 256;
Eb =(298 * Ey + 516 * Epb)/ 256;
Er =(298 * Ey + 408 * Epr)/ 256;
if(例如> 255)
Eg = 255;
if(例如< 0)
Eg = 0;
if(Eb> 255)
Eb = 255;
if(Eb< 0)
Eb = 0;
if(Er> 255)
Er = 255;
if(Er< 0)
Er = 0;
result =(Eb<< 16)| (例如<< 8)|尔;
返回结果;
}
我的尝试:
从NV12转换为RGB。
我想要RGB到NV12转换例程。
Below is the code for converting NV12 to RGB.
What i want is conversion from RGB to NV12.
void CFramePump::NV12ToRGB( BYTE* pOut, BYTE* pIn,unsigned int Width, unsigned int Height)
{
HRESULT hr = S_OK;
DWORD dexOut = 0;
unsigned int PX,PY;
int y[4];
int u;
int v;
int rbg_off;
int y_off = 0;
int v_off=Height*Width;
unsigned int rgb;
rbg_off = 0;
int ppy=0;
int ppx =0;
int off;
for (PY=0;PY<Height;PY+=2)
{
for (PX=0;PX<Width;PX+=2)
{
// getting the YUV values
y_off =PY*Width+PX;
y[0] = pIn[y_off];
y[1] = pIn[y_off+1];
y[2] = pIn[y_off+Width];
y[3] = pIn[y_off+Width+1];
u = pIn[v_off++];
v = pIn[v_off++];
off = (PY*Width*3)+(PX*3);
rgb = yuv2rgb(y[0], u, v);
pOut[off] = (rgb & 0x000000ff);
pOut[off+1] = (rgb & 0x0000ff00) >> 8;
pOut[off+2] = (rgb & 0x00ff0000) >> 16;
rgb = yuv2rgb( y[1],u,v);
pOut[off+3] = (rgb & 0x000000ff);
pOut[off+4] = (rgb & 0x0000ff00) >> 8;
pOut[off+5] = (rgb & 0x00ff0000) >> 16;
off+=(Width*3);
rgb = yuv2rgb( y[2],u,v);
pOut[off] = (rgb & 0x000000ff);
pOut[off+1] = (rgb & 0x0000ff00) >> 8;
pOut[off+2] = (rgb & 0x00ff0000) >> 16;
rgb = yuv2rgb( y[3],u,v);
pOut[off+3] = (rgb & 0x000000ff);
pOut[off+4] = (rgb & 0x0000ff00) >> 8;
pOut[off+5] = (rgb & 0x00ff0000) >> 16;
}
}
}
unsigned int yuv2rgb( int Y, int Cr ,int Cb )
{
int Ey, Epb, Epr;
int Eg, Eb, Er;
unsigned int result;
Ey = (Y-16);
Epb = (Cb-128);
Epr = (Cr-128);
Eg = (298*Ey - 100*Epb - 208*Epr)/256;
Eb = (298*Ey + 516*Epb)/256;
Er = (298*Ey + 408*Epr)/256;
if(Eg > 255)
Eg = 255;
if(Eg < 0)
Eg = 0;
if(Eb > 255)
Eb = 255;
if(Eb < 0)
Eb = 0;
if(Er > 255)
Er = 255;
if(Er < 0)
Er = 0;
result = (Eb << 16) | (Eg << 8) | Er;
return result;
}
What I have tried:
Conversion from NV12 to RGB.
I want RGB to NV12 conversion routine.
这篇关于如何将RGB转换为NV12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!