MMaciek
27th April 2011, 13:37
Greetings to all,
I am about to do conversion from RGB to YUV 4:2:0, which is simple and well documented, but I need to populate x264_image_t with aquired RGB and then converted data and here comes my problem.
What is the exact interpretation of bytes in x264_image_t storing YUV?
typedef struct
{
int i_csp; /* Colorspace */
int i_plane; /* Number of image planes */
int i_stride[4]; /* Strides for each plane */
uint8_t *plane[4]; /* Pointers to each plane */
} x264_image_t;
At first I thought it straightforward:
plane[0] = YYYYYYYY...
plane[1] = UUUU...
plane[2] = VVVV....
but it's not. Such assumption led me to strangely colored and noisy pictures.
How should I interpret data from this object?
For reference - my conversion:
static char clamp(int in)
{
if(in < 0)
return 0;
if(in > 255)
return 255;
return (char)in;
}
static void YUV_TO_RGB(float Y, float U, float V, char* R, char* G, char* B)
{
float C,D,E;
C = Y - 16;
D = U - 128;
E = V - 128;
*R = clamp((int)(298 * C + 409*E + 128) >> 8);
*G = clamp((int)(298 * C - 100*D - 208*E+128) >> 8);
*B = clamp((int)(298 * C + 516*D + 128) >> 8);
}
Thanks!
I am about to do conversion from RGB to YUV 4:2:0, which is simple and well documented, but I need to populate x264_image_t with aquired RGB and then converted data and here comes my problem.
What is the exact interpretation of bytes in x264_image_t storing YUV?
typedef struct
{
int i_csp; /* Colorspace */
int i_plane; /* Number of image planes */
int i_stride[4]; /* Strides for each plane */
uint8_t *plane[4]; /* Pointers to each plane */
} x264_image_t;
At first I thought it straightforward:
plane[0] = YYYYYYYY...
plane[1] = UUUU...
plane[2] = VVVV....
but it's not. Such assumption led me to strangely colored and noisy pictures.
How should I interpret data from this object?
For reference - my conversion:
static char clamp(int in)
{
if(in < 0)
return 0;
if(in > 255)
return 255;
return (char)in;
}
static void YUV_TO_RGB(float Y, float U, float V, char* R, char* G, char* B)
{
float C,D,E;
C = Y - 16;
D = U - 128;
E = V - 128;
*R = clamp((int)(298 * C + 409*E + 128) >> 8);
*G = clamp((int)(298 * C - 100*D - 208*E+128) >> 8);
*B = clamp((int)(298 * C + 516*D + 128) >> 8);
}
Thanks!