/* for 320*240 YUV420 */
void Camera::yuv2rgb( uchar * m_bmp,const uchar * m_yuv,const int w,const int h )
{
/*-------------------------- convert arithmetic ----------------------
R = Y + 1.140(Cr-128)
G = Y - 0.395(Cb-128) - 0.581(Cr-128)
B = Y + 2.032(Cb-128)
--------------------------------------------------------------------*/
int y2r_table[4] = {
292, /* 1.140*256 for Cr */
-101, /* -0.395*256 for Cb */
-149, /* -0.581*256 for Cr */
520 /* 2.032*256 for Cb */
};
uchar * p_ye =(uchar *) m_yuv;
uchar * p_yo = p_ye+w;
uchar * p_cr = p_ye+w*h;
uchar * p_cb = p_cr + w*h/4;
uchar * p_rgb = m_bmp;
for (int i=0;i<120;i++)
{
for (int j=0; j<160; j++)
{
int r,g,b;
int rd,gd,bd;
int sy,su,sv;
sy = *(p_ye+j*2);
su = *(p_cb++); su = su - 128;
sv = *(p_cr++); sv = sv - 128;
rd = y2r_table[0]*sv; rd = rd>>8;
gd = y2r_table[1]*su + y2r_table[2]*sv; gd = gd>>8;
bd = y2r_table[3]*su; bd = bd>>8;
r = sy + rd; if(r>255) r = 255; if(r<0) r = 0;
g = sy + gd; if(g>255) g = 255; if(g<0) g = 0;
b = sy + bd; if(b>255) b = 255; if(b<0) b = 0;
*(p_rgb++) = r;
*(p_rgb++) = g;
*(p_rgb++) = b;
*(p_rgb++) = 0xFF;
sy = *(p_ye+j*2+1);
r = sy + rd; if(r>255) r = 255; if(r<0) r = 0;
g = sy + gd; if(g>255) g = 255; if(g<0) g = 0;
b = sy + bd; if(b>255) b = 255; if(b<0) b = 0;
*(p_rgb++) = r;
*(p_rgb++) = g;
*(p_rgb++) = b;
*(p_rgb++) = 0xFF;
uchar * p_rgbo = p_rgb+w*4-8;
sy = *(p_yo+j*2);
r = sy + rd; if(r>255) r = 255; if(r<0) r = 0;
g = sy + gd; if(g>255) g = 255; if(g<0) g = 0;
b = sy + bd; if(b>255) b = 255; if(b<0) b = 0;
*(p_rgbo++) = r;
*(p_rgbo++) = g;
*(p_rgbo++) = b;
*(p_rgbo++) = 0xFF;
sy = *(p_yo+j*2+1);
r = sy + rd; if(r>255) r = 255; if(r<0) r = 0;
g = sy + gd; if(g>255) g = 255; if(g<0) g = 0;
b = sy + bd; if(b>255) b = 255; if(b<0) b = 0;
*(p_rgbo++) = r;
*(p_rgbo++) = g;
*(p_rgbo++) = b;
*(p_rgbo++) = 0xFF;
}
p_ye += 640;
p_yo += 640;
p_rgb += (w*4);
}
}
yuv2rgb
最新推荐文章于 2024-09-03 18:29:17 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)