Im sampling an image in YCbCr from an ov7670 camera and using jpegant library to encode a jpeg file. Whenever I do it directly using Y,Cb,Cr values from my camera, I get a pink-violet version of the image. As far as I can understand on Wikipedia, there are different YCbCr standards, so I guess my camera use a different YCbCr standard.
Since the Jpegant library comes with an RGB example, if I convert my YCbCr values to RGB and then again rgb to YCbCr (an then JPEG) through the provided example, I get the a decent result.
Is there any way to get jpeg-YCbCr from my camera YCbCr (or any other YCbCr standard)?
EDIT:
The camera sends me YCbCr in 4:2:2 format (that means that two sequential pixel share the same Cb and Cr channels), I proceed to downsample them to 4:2:0 ;
Encode those samples into jpeg and get a pink-violet image ;
I convert camera YCbCr to RGB this way :
.
R = Y + 1.402 * (Cr - 128)
G = Y + 1.772 * (Cb - 128)
B = Y - 0.34414 * (Cb - 128) - 0.71414 * (Cr- 128)
Those values are good, I checked. I then convert them back into YCbCr using the formula provided with the library example:
Y' = 0.299*R + 0.587*G + 0.114*B
Cb' = -0.1687*R - 0.3313*G + 0.5*B + 128
Cr' = 0.5*R - 0.4187*G - 0.0813*B + 128
With new values, it encodes correctly .
Example YCbCr of values :
before:
156 144 145
after:
177 105 129

You are right, on a desktop pc it works fine, but im doing it on a microcontroller and this way it takes about 2-3 times the original conversion time.
Plus, wikipedia says that the first transform is supposed to be the inverse of the second one, but that's not so true as you can see it gives me back different results.
Here, at jpeg conversion: en.wikipedia.org/wiki/YCbCr
– Eraclea Jul 29 '17 at 02:41