yuvtorgb.cpp - ISee图像浏览器 JPEG颜色转换实现文件
版权所有(C) VCHelp-coPathway-ISee workgroup 2000 all member's
这一程序是自由软件,你可以遵照自由软件基金会出版的GNU 通用公共许
可证条款来修改和重新发布这一程序。或者用许可证的第二版,或者(根
据你的选择)用任何更新的版本。
发布这一程序的目的是希望它有用,但没有任何担保。甚至没有适合特定
目地的隐含的担保。更详细的情况请参阅GNU通用公共许可证。
你应该已经和程序一起收到一份GNU通用公共许可证的副本。如果还没有,
写信给:
The Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
MA02139, USA
如果你在使用本软件时有什么问题或建议,用以下地址可以与我们取得联
系:
http://isee.126.com
http://www.vchelp.net
或:
yzfree@sina.com
作者: analyst
文件版本:
Build 00523
Date 2000-5-23
********************************************************************/
static int Cr1_402[256],Cb0_34414[256],Cr0_71414[256],Cb1_772[256];
init()
{
///............
for (i=0;i<256;i++)
{
Cr1_402[i]=(int)(1.402*(signed char)i+1);
Cb0_34414[i]=(int)(-0.34414*(signed char)i+1);
Cr0_71414[i]=(int)(-0.71414*(signed char)i+1);
Cb1_772[i]=(int)(1.772*(signed char)i+1);
}
///............
}
DWORD YUV_RGB32(int y,int r,int g,int b)
{
y+=128; r+=y;
b+=y; g+=y;
if(r<0)r=0; if(g<0)g=0; if(b<0)b=0;
if(r>255)r=255; if(g>255)g=255; if(b>255)b=255;
return r<<16¦g<<8¦b;
};
void YCbCr411_RGB32(DWORD *bmppixel,int pitch)
{
int i,j,Cb,Cr,m;
int r,g,b;
signed char *CrBuf=(signed char *)jpeg_crbuf;
signed char *CbBuf=(signed char *)jpeg_cbbuf;
signed char *YBuf=(signed char *)jpeg_ybuf;
for (m=0;m<4;m++,bmppixel-=(m&1)*pitch*2-8+16*(m==2))
for (i=0;i<8;i+=2) {
for (j=0;j<8;j+=2) {
Cb=CbBuf[(i/2+4*(m/2))*8+j/2+4*(m&1)];
Cr=CrBuf[(i/2+4*(m/2))*8+j/2+4*(m&1)];
r=Cr1_402[(BYTE)Cr];
g=Cb0_34414[(BYTE)Cb]+Cr0_71414w[(BYTE)Cr];
b=Cb1_772[(BYTE)Cb];
*bmppixel=YUV_RGB32(YBuf[i*8+j+128*m],r,g,b),++bmppixel;
*bmppixel=YUV_RGB32(YBuf[i*8+j+1+128*m],r,g,b),++bmppixel;
*(bmppixel+pitch/4-2)=YUV_RGB32(YBuf[i*8+j+8+128*m],r,g,b);
*(bmppixel+pitch/4-1)=YUV_RGB32(YBuf[i*8+j+9+128*m],r,g,b);
}
bmppixel=(DWORD*)((unsigned)bmppixel+pitch*2-32);
}
}
void YCbCr111_RGB32(DWORD *bmppixel,int pitch)
{
int i,j,Cb,Cr;
int r,g,b;
signed char *CrBuf=(signed char *)jpeg_crbuf;
signed char *CbBuf=(signed char *)jpeg_cbbuf;
signed char *YBuf=(signed char *)jpeg_ybuf;
for (i=0;i<8;i++) {
for (j=0;j<8;j++) {
Cb=CbBuf[i*8+j];
Cr=CrBuf[i*8+j];
r=Cr1_402[(BYTE)Cr];
g=Cb0_34414[(BYTE)Cb]+Cr0_71414w[(BYTE)Cr];
b=Cb1_772[(BYTE)Cb];
*bmppixel=YUV_RGB32(YBuf[i*8+j],r,g,b),++bmppixel;
}
bmppixel=(DWORD*)((unsigned)bmppixel+pitch-32);
}
}
/*灰度模式*/
void YYY_RGB32(DWORD *bmppixel,int pitch)
{
int i,j;
int Y;
signed char *YBuf=(signed char *)jpeg_ybuf;
for (i=0;i<8;i++) {
for (j=0;j<8;j++) {
Y=YBuf[i*8+j]+128;
*bmppixel=Y<<16¦Y<<8¦Y;
++bmppixel;
}
bmppixel=(DWORD*)((unsigned)bmppixel+pitch-32);
}
}
其他文档:
<script type="text/javascript"> google_ad_client = "pub-2416224910262877"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_channel = ""; google_color_border = "E1771E"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_text = "000000"; google_color_url = "008000"; </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>