Original Post
I've been writting a Video Compression system, and whilst everything is currently going fine, I've hit a problem - my color conversion code works fine, as long as there are no inaccuracies, but the inaccuracies that are introduced by the DCT cause it to go awol on extreme colors, ie black goes pink.
The code is as follows...
A possible solution is commeted out in the RGB to Y'CbCr conversion - which is to reduce the color ranges, but it makes the image go slightly grey, which I concider to look horible. As it stands, it also tints everything slightly green and makes it very slightly darker, but this is not really a problem.
Whilst a solution to this problem is my main concern, (The compression increses 4 fold - down to 10-20k per frame if I use it.) any help to optimise this would be great, though only the Y'CbCr to RGB needs to be fast. Thanks in advance.
-Lethe
Edited by - Lethe on 11/6/00 3:30:38 AM
// Lookup tables setup-
for (register int i=0;i<256;i++)
{
RedCr<i> = (unsigned char)(1.402*((char)((unsigned char)i)));
GreenCb<i> = (unsigned char)(0.34414*((char)((unsigned char)i)));
GreenCr<i> = (unsigned char)(0.71414*((char)((unsigned char)i)));
BlueCb[i] = (unsigned char)(1.772*((char)((unsigned char)i)));
}
// Conversion from RGB to Y'CbCr-
unsigned char * Targ = Data;
for (register unsigned int i=0;i<(640*480);i++)
{
register unsigned char R = (*(Targ)); //if (R<32) R=32; if (R>248) R=248;
register unsigned char G = (*(Targ+1)); //if (G<32) G=32; if (G>248) G=248;
register unsigned char B = (*(Targ+2)); //if (B<32) B=32; if (B>248) B=248;
(*Targ) = (unsigned char)((0.299*R+0.587*G+0.114*B));
Targ++;
(*Targ) = (unsigned char)((char)((-0.1687*R-0.3313*G+0.5*B)+128));
Targ++;
(*Targ) = (unsigned char)((char)((0.5*R-0.4187*G-0.0813*B)+128));
Targ++;
}
// And conversion from Y'CbCr back to RGB-
register unsigned char * Targ = Data;
for (register unsigned int i=0;i<(640*480);i++)
{
register unsigned char Y = (*(Targ));
register unsigned char Cb = (char)((*(Targ+1))-128);
register unsigned char Cr = (char)((*(Targ+2))-128);
(*Targ) = (Y+RedCr[Cr]);
Targ++;
(*Targ) = (unsigned char)(char)(Y-GreenCb[Cb]-GreenCr[Cr]);
Targ++;
(*Targ) = (unsigned char)(char)(Y + BlueCb[Cb]);
Targ++;
}
|