I'm coding a video codec using the JPEG compression technic for each frame. Until here I've already coded YUV, DCT and quantized DCT (encoding and decoding). I already have coded YUV422 encoding too but I don't understand how to do the inverse (decoding).
To compute my YUV for each pixel I used the following equations :
Encoding :
Y = 0.299 * R + 0.587 * G + 0.114 * B
U = -0.1687 * R - 0.4187 * G + 0.5 * B + 128
V = 0.5 * R - 0.4187 * G - 0.0813 * B + 128
Decoding :
R = Y + 1.402 * (V - 128)
G = Y - 0.34414 * (U - 128) - 0.71414 * (V - 128)
B = Y + 1.772 * (U - 128)
This equations do the perfect job.
Now to do the sub-sampling encoding, I take my image encoded in YUV and I compute the sum of 2 adjacent pixels and I divide the result by 2. The result is set for the 2 pixels.
Ex :
For sake of simplicity I will take a pixel value between 0 and 255 (not using RGB components).
Just below : 2 examples with the same result.
Pixel_1 = 15, Pixel_2 = 5 -> (Pixel_1 + Pixel_2) / 2 = 10
Pixel_3 = 10, Pixel_4 = 10 -> (Pixel_3 + Pixel_4) / 2 = 10
If I apply this equation for all the pixels of my YUV image, I get a new image but this time encoded in YUV422 sub-sampling.
So I wonder how can I get back the YUV image from the YUV422 image. My example just above demonstrate that it's impossible to get back the original YUV image because there are a lot of combinations which lead to the same result (10 here). However, I think there is a way to have, give or take a few, the same original YUV pixel values. Does anyone can help me, please ? I'm really lost. Thanks a lot in advance for your help.