最近在做DSP图像处理,需要将采集到的图像从YCrCb转换成RGB格式后,进行图像处理,再将RGB图像转换成YCrCb进行显示,下面是我的图像处理的程序,不知道为什么显示出来的结果总是一片黑,求高手指点。
void videoReverse()
{
int i,j,temp;
int r,g,b,y,cr,cb,pr,pg,pb;
Uint8 *Y,*Cr,*Cb;
for(i=intALines;i
{
for(j=intAPixels;j
{
Y=(Uint8 *)(tempYbuffer + i*numPixels + j);
Cr=(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j);
Cb=(Uint8 *)(tem
PCBbuffer + i * (numPixels >> 1) + j);
y=(*Y);cr=(*Cr);cb=(*Cb);
y-=16;cr-=128;cb-=128;
r=1.164*y+1.596*cr;
g=1.164*y-0.813*cr-0.392*cb;
b=1.164*y+2.017*cb;
if ( r>255 ) r=255;
else if ( r<0 ) r=0;
if ( g>255 ) g=255;
else if ( g<0 ) g=0;
if ( b>255 ) b=255;
else if ( b<0 ) b=0;
temp=2*g-r-b;
if ( temp>255 ) temp=255;
else if ( temp<0 ) temp=0;
r=abs(temp);g=abs(temp);b=abs(temp);
pr=abs(0.257*r+0.504*g+0.098*b+16);
*(Uint8 *)(tempYbuffer + i*numPixels + j)=pr;
pb=abs(-0.148*r-0.291*g+0.439*b+128);
*(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j)=pb;
pr=abs(0.439*r-0.368*g-0.071*b+128);
*(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j)=pg;
Y++;Cr++;Cb++;
}
}
for(i=numLines/2+intALines;i
{
for(j=intAPixels;j
{
Y=(Uint8 *)(tempYbuffer + i*numPixels + j);
Cr=(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j);
Cb=(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j);
y=(*Y);cr=(*Cr);cb=(*Cb);
y-=16;cr-=128;cb-=128;
r=1.164*y+1.596*cr;
g=1.164*y-0.813*cr-0.392*cb;
b=1.164*y+2.017*cb;
if ( r>255 ) r=255;
else if ( r<0 ) r=0;
if ( g>255 ) g=255;
else if ( g<0 ) g=0;
if ( b>255 ) b=255;
else if ( b<0 ) b=0;
temp=2*g-r-b;
if ( temp>255 ) temp=255;
else if ( temp<0 ) temp=0;
r=abs(temp);g=abs(temp);b=abs(temp);
pr=abs(0.257*r+0.504*g+0.098*b+16);
*(Uint8 *)(tempYbuffer + i*numPixels + j)=pr;
pb=abs(-0.148*r-0.291*g+0.439*b+128);
*(Uint8 *)(tempCbbuffer + i * (numPixels >> 1) + j)=pb;
pr=abs(0.439*r-0.368*g-0.071*b+128);
*(Uint8 *)(tempCrbuffer + i * (numPixels >> 1) + j)=pg;
Y++;Cr++;Cb++;
}
}
}