yuv420p to rgb24

179 views
Skip to first unread message

petrkalos

unread,
Jun 25, 2012, 4:16:11 PM6/25/12
to pixfc-sse
Hello, i have low experience using libraries. I cannot understand how
to write my application using pixfc-sse library.
I have big problem to understand the example.

I have 3 buffers for y,u,v(420) with my data and i want to convert
this to rgb24.

how the data must be stored so lib can read it?

my input data is "unsigned char *y,*u,*v"

Can someone give me a little reference code?

Thanks

Pix FC

unread,
Jun 26, 2012, 12:31:04 AM6/26/12
to pixf...@googlegroups.com
Hi,
To convert YUV420 with pixfc, the three planes (Y, U and V) must be contiguous. What this means is that you must have a single buffer of size (width * height * 3 / 2), the Y plane must be at the start of the buffer, followed by the U plane (at offset width * height), followed by the V plane (at offset width * height + width * height / 4). Translated into C, this gives:

struct pixFcSSE* pixfc;
uint32_t width = 1920, height = 1080;
unsigned char *y, *u, *v;
unsigned char *yuv420p_pixfc_buffer;
unsigned char *rgb24_pixfc_buffer;

posix_memalign(yuv420p_pixfc_buffer, 16, width * height * 3 / 2);
// check return value to make sure it succeeded.

posix_memalign(rgb24_pixfc_buffer, 16, width * height * 3);
// check return value to make sure it succeeded.

// Copy the three separate Y, U, V planes into one single buffer
memcpy(yuv420p_pixfc_buffer, y, width * height);
memcpy((yuv420p_pixfc_buffer + width * height),  u, (width * height  / 4));
memcpy((yuv420p_pixfc_buffer + width * height + width * height / 4), v, (width * height));

create_pixfc(&pixfc, PixFcYUV420P, PixFcRGB24, width, height, PixFcFlag_Default);
// check return value to make sure it succeeded

pixfc->convert(pixfc, yuv420p_pixfc_buffer, rgb24_pixfc_buffer);

//when finished:
destroy_pixfc(pixfc);

// Also free yuv420p_pixfc_buffer and rgb24_pixfc_buffer

The above approach will be slower because of the three memcpy's before the actual YUV to RGB conversion. You might also be able to optimise and get rid of the first memcpy if you can re-allocate the Y plane buffer and increase its size. but ultimately, you will get much better performance if you obtain your YUV420p data in one single contiguous buffer rather than in 3 separate buffers.

Frank

petrkalos

unread,
Jun 26, 2012, 5:18:10 AM6/26/12
to pixf...@googlegroups.com
Actually i have a struct with the yuv,rgb like this.

struct yuv{
  unsigned char *y;
  unsigned char *u;
  unsigned char *v;
}

same for rgb.

I think this is contignuous memory right? so i don't need the memcpy.
Reply all
Reply to author
Forward
0 new messages