I am converting a YUV422 frame to a PPM file - (RGB888).
The image is converting mostly. Colors are fine. But each seems row is askew, as if extra
Here is the frame conversion function:
BYTE* CYUV::toRGB()
{
BYTE* rgb = new BYTE[m_width*m_height*3];
BYTE* rgb_ret = rgb;
BYTE* p_yuv = m_yuv_frame;
for (int i=m_width*m_height/2; i--;)
{
BYTE y, u, v, y2;
BYTE r,g, b;
y2 = *p_yuv++;
v = *p_yuv++;
y = *p_yuv++;
u = *p_yuv++;
r = (y + 1.370705 * (v - 128));
g = (y - (0.698001 * (v - 128)) - (0.337633 * (u - 128)));
b = (y + (1.732446 * (u - 128)));
*rgb++ = b < 0 ? 0 : b > 255 ? 255 : b;
*rgb++ = g < 0 ? 0 : g > 255 ? 255 : g;
*rgb++ = r < 0 ? 0 : r > 255 ? 255 : r;
r = (y2 + 1.370705 * (v - 128));
g = (y2 - (0.698001 * (v - 128)) - (0.337633 * (u - 128)));
b = (y2 + (1.732446 * (u - 128)));
*rgb++ = b < 0 ? 0 : b > 255 ? 255 : b;
*rgb++ = g < 0 ? 0 : g > 255 ? 255 : g;
*rgb++ = r < 0 ? 0 : r > 255 ? 255 : r;
}
return rgb_ret;
}
I believe the actual yuv-to-rgb pixel conversion is correct, because I had tried many other formulae, with color distorted results.
As for the PPM file, that is good also, since all image readers handle it.
As for the original YUV4222 frame, it to is fine - I display it using SDL without this distortion.
Any suggestions?
TIA
ken