Languages

Menu
Sites
Language
Converting RGB image sequence to a single YUV file

Hi,

Is there any way to convert JPG,BMP or PNG image sequence into a single YUV(4:2:0) file ?

Which API can be used ? If there any sample code please share

Responses

3 Replies
Jean Yang

Hello,

maybe below code can help you

/**
 * @brief RGBA <=> YUV420 format converion
 * @see https://en.wikipedia.org/wiki/YUV#Y.27UV420p_.28and_Y.27V12_or_YV12.29_to_RGB888_conversion
 */
static void _convert_rgb565_to_yuv420( uchar *dest, const uchar *src,
                                         const int width, const int height,
                                         const int d_size, const int s_size)
{
    unsigned int src_stride = (s_size / height);
    unsigned int pix_count = width * height;
    unsigned int upos = pix_count;
    unsigned int vpos = upos + upos / 4;

    unsigned int y;
    for (y = 0; y < height; ++y )
    {
        const rgb16* src_pixel = (const rgb16*) &(src[y * src_stride]);
        unsigned int dest_line_pos = width * y;

        if ( !(y % 2) )
        {
            unsigned int x;
            for (x = 0; x < width; x += 2 )
            {
                bgra32 pixel = rgb_to_bgra(src_pixel[x]);

                dest[dest_line_pos + x] = bgra_to_yuv_y(pixel);
                dest[upos++] = bgra_to_yuv_u(pixel);
                dest[vpos++] = bgra_to_yuv_v(pixel);

                pixel = rgb_to_bgra(src_pixel[x + 1]);
                dest[dest_line_pos + x + 1] = bgra_to_yuv_y(pixel);
            }
        }
        else
        {
            unsigned int x;
            for (x = 0; x < width; ++x)
            {
                bgra32 pixel = rgb_to_bgra(src_pixel[x]);
                dest[dest_line_pos + x] = bgra_to_yuv_y(pixel);
            }
        }
    }
}

 

 

 

 

Jean Yang

for more details, you can find in media sample, image_sample_utils.c file.

Carsten Haitzler

you can load any image object just by using an evas image object and then setting file and getting the data. the data will be ARGB (MSB to LSB per 32bit word).

obj = evas_object_image_add(evas_object_evas_get(win));

evas_object_image_file_set(obj, "/path/to/file.png", NULL);

evas_object_image_data_get(obj, &width, &height);

data = evas_object_image_data_get(obj, EINA_FALSE);

 

then loop over the argb data given width.height... every int (32bit word) is a pixel