PersonalCorpus 版 (精华区)
发信人: hjt (浪子小猴◎学习ing), 信区: ShareCode
标 题: RGB2YCrCb
发信站: 哈工大紫丁香 (2003年05月17日11:22:37 星期六), 站内信件
RGB2YUV(int nWidth, int nHeight, LPBYTE lpRGB, LPBYTE lpYUV)
{
//this by hjt
unsigned char *b, *g, *r;
unsigned char *y, *u, *v;
int i,j;
long size = nHeight * nWidth;
b = lpRGB;
g = b + 1;
r = g + 1;
y = lpYUV;
u = y + size;
v = u + size/4;
int h = nHeight;
int w = 3*nWidth;
for(i=0; i<nHeight/2; i++)
{
for(j=0; j<nWidth/2; j++)
{
*(y+(nHeight-2*i-1)*nWidth+2*j) = (unsigned char)(0.299 *
(*(r+2*i*w+2*j*3)) + 0.587 * (*(g+2*i*w+2*j*3)) + 0.114 * (*(b+2*i*w+2*j*3)));
*(y+(nHeight-2*i-1)*nWidth+2*j+1) = (unsigned char)(0.299 *
(*(r+2*i*w+(2*j+1)*3)) + 0.587 * (*(g+2*i*w+(2*j+1)*3)) + 0.114 *
(*(b+2*i*w+(2*j+1)*3)));
*(y+(nHeight-2*i)*nWidth+2*j) = (unsigned char)(0.299 *
(*(r+(2*i+1)*w+2*j*3)) + 0.587 * (*(g+(2*i+1)*w+2*j*3)) + 0.114 *
(*(b+(2*i+1)*w+2*j*3)));
*(y+(nHeight-2*i)*nWidth+2*j+1) = (unsigned char)(0.299 *
(*(r+(2*i+1)*w+(2*j+1)*3)) + 0.587 * (*(g+(2*i+1)*w+(2*j+1)*3)) + 0.114 *
(*(b+(2*i+1)*w+(2*j+1)*3)));
*(u+(nHeight/2-i-1)*nWidth/2+j) = (unsigned char)(-0.1684 *
(*(r+2*i*w+2*j*3)) -0.3316 * (*(g+2*i*w+2*j*3)) + (*(b+2*i*w+2*j*3))/2 +
128);
*(v+(nHeight/2-i-1)*nWidth/2+j) = (unsigned
char)((*(r+2*i*w+2*j*3))/2 - 0.4187 * (*(g+2*i*w+2*j*3)) - 0.0813 *
(*(b+2*i*w+2*j*3)) +128);
}
}
}
--
_.-._ ..-.. _.-._
(_-.-_) /|'.'|\ (_'.'_)
.\-/. \)\-/(/ ,-.-.
__/ /-. \__ __/ ' ' \__ __/'-'-'\__
( (___/___) ) ( (_/-._\_) ) ( (_/ \_) ) Asciiman说这几个是猴
'.Oo___oO.' '.Oo___oO.' '.Oo___oO.'
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 159.226.42.200]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.174毫秒