[FFmpeg-devel] [PATCH] Swscale YUV2RGB table generator

Michael Niedermayer michaelni
Mon Feb 9 14:49:51 CET 2009


On Mon, Feb 09, 2009 at 10:49:57AM +0200, Kostya wrote:
> On Sun, Feb 08, 2009 at 09:08:01PM +0100, Michael Niedermayer wrote:
> > On Sun, Feb 08, 2009 at 08:27:49PM +0200, Kostya wrote:
> > > Here's LGPLed version of YUV2RGB tables generator.
> > > While it may be not perfect, it seems to work.
> > > 
> > > Please test and/or give your comments.
> [...]
> > > +#define RGB(i)                                      \
> > > +    U = pu[i];                                      \
> > > +    V = pv[i];                                      \
> > > +    r = (void *)c->table_rV[V];                     \
> > > +    g = (void *)(c->table_gU[U] + c->table_gV[V]);  \
> > > +    b = (void *)c->table_bU[U];
> > > +
> > > +#define DST1(i)                         \
> > > +    Y = py_1[2*i];                      \
> > > +    dst_1[2*i] = r[Y] + g[Y] + b[Y];    \
> > > +    Y = py_1[2*i+1];                    \
> > > +    dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
> > > +
> > > +#define DST2(i)                         \
> > > +    Y = py_2[2*i];                      \
> > > +    dst_2[2*i] = r[Y] + g[Y] + b[Y];    \
> > > +    Y = py_2[2*i+1];                    \
> > > +    dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
> > > +
> > > +#define DST1RGB(i)                                                \
> > > +    Y = py_1[2*i];                                                \
> > > +    dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y];  \
> > > +    Y = py_1[2*i+1];                                              \
> > > +    dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];
> > > +
> > > +#define DST2RGB(i)                                                \
> > > +    Y = py_2[2*i];                                                \
> > > +    dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y];  \
> > > +    Y = py_2[2*i+1];                                              \
> > > +    dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];
> > > +
> > > +#define DST1BGR(i)                                                \
> > > +    Y = py_1[2*i];                                                \
> > > +    dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y];  \
> > > +    Y = py_1[2*i+1];                                              \
> > > +    dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];
> > > +
> > > +#define DST2BGR(i)                                                \
> > > +    Y = py_2[2*i];                                                \
> > > +    dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y];  \
> > > +    Y = py_2[2*i+1];                                              \
> > > +    dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];
> > > +
> > 
> > this doesnt look rewritten
> > i think this has to be split out into a seperate GPL file or it has to
> > be rewritten as well
>  
> Rewritten (our goal is to get rid of GPL there, isn't it?)

yes but there is more generic (and slow) code in swscale that could have
handled it ...


[...]
> Index: swscale.c
> ===================================================================
> --- swscale.c	(revision 28473)
> +++ swscale.c	(working copy)
> @@ -174,7 +174,7 @@
>  #define RV ( (int)(0.500*224/255*(1<<RGB2YUV_SHIFT)+0.5))
>  #define RU (-(int)(0.169*224/255*(1<<RGB2YUV_SHIFT)+0.5))
>  
> -extern const int32_t Inverse_Table_6_9[8][4];
> +extern const int32_t ff_yuv2rgb_coeffs[8][4];
>  
>  static const double rgb2yuv_table[8][9]={
>      {0.7152, 0.0722, 0.2126, -0.386, 0.5, -0.115, -0.454, -0.046, 0.5},

ok, feel free to just commit renames that add ff_ to private symbols lacking
a prefix (this stuff has to be a seperate commit anyway)


[...]
> +SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)

ff_ or sws_


> +{
> +#if HAVE_MMX2 || HAVE_MMX
> +    if(c->flags & SWS_CPU_CAPS_MMX2){
> +        switch(c->dstFormat){
> +        case PIX_FMT_RGB32:  return yuv420_rgb32_MMX2;
> +        case PIX_FMT_BGR24:  return yuv420_rgb24_MMX2;
> +        case PIX_FMT_RGB565: return yuv420_rgb16_MMX2;
> +        case PIX_FMT_RGB555: return yuv420_rgb15_MMX2;
> +        }
> +    }
> +    if(c->flags & SWS_CPU_CAPS_MMX){
> +        switch(c->dstFormat){
> +        case PIX_FMT_RGB32:  return yuv420_rgb32_MMX;
> +        case PIX_FMT_BGR24:  return yuv420_rgb24_MMX;
> +        case PIX_FMT_RGB565: return yuv420_rgb16_MMX;
> +        case PIX_FMT_RGB555: return yuv420_rgb15_MMX;
> +        }
> +    }
> +#endif
> +#if HAVE_VIS
> +    {
> +        SwsFunc t= yuv2rgb_init_vis(c);
> +        if (t) return t;
> +    }
> +#endif
> +#if CONFIG_MLIB
> +    {
> +        SwsFunc t= yuv2rgb_init_mlib(c);
> +        if (t) return t;
> +    }
> +#endif
> +#if HAVE_ALTIVEC
> +    if(c->flags & SWS_CPU_CAPS_ALTIVEC){
> +        SwsFunc t = yuv2rgb_init_altivec(c);
> +        if (t) return t;
> +    }
> +#endif
> +
> +#if ARCH_BFIN
> +    if(c->flags & SWS_CPU_CAPS_BFIN){
> +        SwsFunc t = ff_bfin_yuv2rgb_get_func_ptr (c);
> +        if (t) return t;
> +    }
> +#endif

the if(t) return t
looks like it can be factored out


> +
> +    av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found.\n");
> +

> +    switch(c->dstFormat){
> +    case PIX_FMT_BGR32_1:
> +    case PIX_FMT_RGB32_1:
> +    case PIX_FMT_BGR32:
> +    case PIX_FMT_RGB32: return yuv2rgb_c_32;
> +    case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb;
> +    case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr;
> +    case PIX_FMT_RGB565:
> +    case PIX_FMT_BGR565:
> +    case PIX_FMT_RGB555:
> +    case PIX_FMT_BGR555: return yuv2rgb_c_16;
> +    case PIX_FMT_RGB8:
> +    case PIX_FMT_BGR8:  return yuv2rgb_c_8_ordered_dither;
> +    case PIX_FMT_RGB4:
> +    case PIX_FMT_BGR4:  return yuv2rgb_c_4_ordered_dither;
> +    case PIX_FMT_RGB4_BYTE:
> +    case PIX_FMT_BGR4_BYTE:  return yuv2rgb_c_4b_ordered_dither;
> +    case PIX_FMT_MONOBLACK:  return yuv2rgb_c_1_ordered_dither;
> +    default:
> +        assert(0);

vertical align


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090209/b23933a1/attachment.pgp>



More information about the ffmpeg-devel mailing list