[Theora-dev] yuv2rgb

Timothy B. Terriberry tterribe at vt.edu
Thu Dec 9 10:35:13 PST 2004


lluis wrote:
> thank's all for this value informations ... i'm reading a lot now ;=) 
> 
> however my problem is that i don't understand how to get the numeric values 
> from the yuv_buffer ::
> 
> typedef struct {
>     int   y_width;
>     int   y_height;
>     int   y_stride;
> 
>     int   uv_width;
>     int   uv_height;
>     int   uv_stride;
>     char *y;
>     char *u;
>     char *v;
> 
> } yuv_buffer;
> 
> for example i supose that in the "y" char pointer we have 1 byte foreach 
> pixel ... correct? 
> 
> so ...
> 
>   char value;
>   int x,y;
>   int lumi[320][240];
>    for(y=0;y<240;y++) {
>             for(x=0;x<320;x++) {
>               value = *yuv.y++;
>               p = value;
>               lumi[x][y]=p;
>             }
>   }
> 
> this will take me an integer array for all the luminance values for each 
> pixel ....
> 
> but don't works ... 
> what's wrong in my aproach? 

While individual rows are always themselves contiguous in memory, each 
consecutive row is not. The distance between the first pixel of one row 
and the first pixel of the next row is stored in the y_stride field (and 
the uv_stride field for the u and v planes). This distance can be 
negative! And in fact, the way the library is currently written, it 
usually is.

(The reasons for this are that internally libtheora needs to add padding 
around the image during the decode process, and for simplicity also 
currently stores it from bottom to top instead of top to bottom; by 
specifying the stride, libtheora lets you access the reversed, padded 
image directly without copying it into a more compact form)

So, better code would be:

    unsigned char *y_row;
    unsigned char *y_col;
    int x,y;
    int lumi[320][240];
    y_row = yuv.y;
    for(y=0;y<240;y++) {
       y_col = y_row;
       for(x=0;x<320;x++) {
          lumi[x][y]=*y_col++;
       }
       y_row += yuv.y_stride;
    }


More information about the Theora-dev mailing list