[Ffmpeg-devel] (L)GPLed yuv2rgb code

Michael Niedermayer michaelni
Fri Dec 22 20:06:51 CET 2006


Hi

On Fri, Dec 22, 2006 at 04:53:16PM +0100, Benjamin Larsson wrote:
> Luca Abeni skrev:
> >Hi all,
> >
> >so, I disabled the compilation of libswscale under LGPL.
> >
> >At this point, I do not think there is anything to do: if a table must
> >map i in (cy*(((i - YTABLE_MIN)<<16) - oy) + (1<<31))>>32, I can rewrite
> >the code 100 times, but I will alway end up writing
> >value = (cy*(((i - YTABLE_MIN)<<16) - oy) + (1<<31))>>32;
> >or an equivalent expression.
> >Idem, if table_b[i] must contain a value shifted right by 3 and then
> >shifted left by 11 if bpp=16 or by 10 if bpp=15, I will always end up by
> >writing something equivalent to
> >value = ytable[i + YTABLE_MIN] >> 3;
> >if (!isBGR(c->dstFormat)) {
> >    value <<= ((fmt_depth(c->dstFormat) == 16) ? 11 : 10);
> >}
> >((uint16_t *)table_b)[i] = value;
> >
> >
> >So, at this point I think libswscale cannot be LGPLed (I would have
> >preferred knowing this from the beginning, before spending too much time
> >on this, but...)
> >
> >
> >Unless someone proves me wrong again, I'll remove yuv2rgb_init.c from
> >the subversion repository in few days.
> >  
> 
> Well describe the process in words (not to detailed) and then let 
> someone else reimplement it. That should be safe enough.

ok, let me first show the generic yuv -> rgb conversation

Red  = cliptoNbit(OFF + CY*y + CRV*v        )
Green= cliptoNbit(OFF + CY*y + CGV*v + CGU*u)
Blue = cliptoNbit(OFF + CY*y         + CBU*u)

the coefficients C* and OFF can be found from the respective standards and
have been already found by luca ... i belive noone claims copyright on them

each of the tables_AB[B] now does nothing else then multiplying by CAB and
then pointing into a table which is indexed by Y(=luma) with the needed
cliping and shifting of the value so that its in the correct format

as an example on how the tables are used (from swscale.c with some edits for
more readability)

func(type)\
    for(i=0; i<(dstW>>1); i++){\
        const int i2= 2*i;\
        int Y1= buf0[i2  ]>>7;\
        int Y2= buf0[i2+1]>>7;\
        int U= (uvbuf1[i     ])>>7;\
        int V= (uvbuf1[i+2048])>>7;\
        type *r, *b, *g;\
        r = c->table_rV[V];\
        g = c->table_gU[U] + c->table_gV[V];\
        b = c->table_bU[U];\

...
        case PIX_FMT_RGB32:
        case PIX_FMT_BGR32:
                func(uint32_t)
                        ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];
                        ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];
                }             
                break;
        case PIX_FMT_RGB24:
                func(uint8_t)
                        ((uint8_t*)dest)[0]= r[Y1];
                        ((uint8_t*)dest)[1]= g[Y1];
                        ((uint8_t*)dest)[2]= b[Y1];
                        ((uint8_t*)dest)[3]= r[Y2];
                        ((uint8_t*)dest)[4]= g[Y2];
                        ((uint8_t*)dest)[5]= b[Y2];
                        dest+=6;
                }
                break;
...
        case PIX_FMT_RGB555:
        case PIX_FMT_BGR555:
                {
                        const int dr1= dither_2x2_8[y&1    ][0];
                        const int dg1= dither_2x2_8[y&1    ][1];
                        const int db1= dither_2x2_8[(y&1)^1][0];
                        const int dr2= dither_2x2_8[y&1    ][1];
                        const int dg2= dither_2x2_8[y&1    ][0];
                        const int db2= dither_2x2_8[(y&1)^1][1];
                        func(uint16_t)
                                ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];
                                ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];
                        }
                }
                break;


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

I count him braver who overcomes his desires than him who conquers his
enemies for the hardest victory is over self. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20061222/e2c45386/attachment.pgp>



More information about the ffmpeg-devel mailing list