[FFmpeg-devel] [PATCH] swscale alpha channel support

Cédric Schieli cschieli
Tue Mar 10 17:05:53 CET 2009


2009/3/5 Michael Niedermayer <michaelni at gmx.at>:
> On Thu, Mar 05, 2009 at 03:09:26PM +0100, C?dric Schieli wrote:
>> 2009/3/2 Michael Niedermayer <michaelni at gmx.at>:
>> > On Fri, Feb 27, 2009 at 11:30:25PM +0100, C?dric Schieli wrote:

[...]

>> #5 : sws_configure_alpha.patch
>> add --swscale-alpha configure option

patch updated to take care of Mans' comment

>
> not maintained by me
>
>
>>
>> #6 : sws_yuva2rgb.patch
>> updated to have a mmx version even without HAVE_7REGS
>
> I would prefer to have simple code over working around gcc bugs
> with #ifdefs

ok, patch updated

[...]

>> @@ -2144,11 +2293,17 @@
>> ? ? ?}
>> ? ? ?else if (srcFormat==PIX_FMT_RGB32)
>> ? ? ?{
>> + ? ? ? ?if (isAlpha)
>> + ? ? ? ? ? ?RENAME(bgr32ToA)(formatConvBuffer, src+3, srcW, pal);
>> + ? ? ? ?else
>> ? ? ? ? ?RENAME(bgr32ToY)(formatConvBuffer, src, srcW, pal);
>> ? ? ? ? ?src= formatConvBuffer;
>> ? ? ?}
>> ? ? ?else if (srcFormat==PIX_FMT_RGB32_1)
>> ? ? ?{
>> + ? ? ? ?if (isAlpha)
>> + ? ? ? ? ? ?RENAME(bgr32ToA)(formatConvBuffer, src, srcW, pal);
>> + ? ? ? ?else
>> ? ? ? ? ?RENAME(bgr32ToY)(formatConvBuffer, src+ALT32_CORR, srcW, pal);
>> ? ? ? ? ?src= formatConvBuffer;
>> ? ? ?}
>> @@ -2169,11 +2324,17 @@
>> ? ? ?}
>> ? ? ?else if (srcFormat==PIX_FMT_BGR32)
>> ? ? ?{
>> + ? ? ? ?if (isAlpha)
>> + ? ? ? ? ? ?RENAME(bgr32ToA)(formatConvBuffer, src+3, srcW, pal);
>> + ? ? ? ?else
>> ? ? ? ? ?RENAME(rgb32ToY)(formatConvBuffer, src, srcW, pal);
>> ? ? ? ? ?src= formatConvBuffer;
>> ? ? ?}
>> ? ? ?else if (srcFormat==PIX_FMT_BGR32_1)
>> ? ? ?{
>> + ? ? ? ?if (isAlpha)
>> + ? ? ? ? ? ?RENAME(bgr32ToA)(formatConvBuffer, src, srcW, pal);
>> + ? ? ? ?else
>> ? ? ? ? ?RENAME(rgb32ToY)(formatConvBuffer, src+ALT32_CORR, srcW, pal);
>> ? ? ? ? ?src= formatConvBuffer;
>> ? ? ?}
>
> This doesnt look like it would work on big endian systems

I think it will work (but I can't test). Only one byte is read,
through a uint8_t* pointer.
Or I misunderstood the way RGB32/RGB32_1 vs. ARGB/BGRA is handled.
What I understand is that RGB32 is the same as BGRA on disk and in
memory, while it is the same as ARGB in LE CPUs and BGRA in BE CPUs.
Am I wrong ?

>
>
> [...]
>
>>
>> + ? ?if (CONFIG_SWSCALE_ALPHA && (dstFormat == PIX_FMT_YUVA420P) && !alpPixBuf)
>> + ? ? ? ?memset(dst[3], 255, dstStride[3]*(dstY-lastDstY));
>> +
>
> you cant write outside 0..width per line, also stride can be negative
>
>
> [...]
>
> #8
>> Index: ffmpeg/libswscale/swscale.c
>> ===================================================================
>> --- ffmpeg.orig/libswscale/swscale.c ?2009-03-03 09:31:07.000000000 +0100
>> +++ ffmpeg/libswscale/swscale.c ? ? ? 2009-03-03 10:00:28.000000000 +0100
>> @@ -133,6 +133,7 @@
>> ? ? ?)
>> ?#define isSupportedOut(x) ? ( ? ? ? \
>> ? ? ? ? ? ? (x)==PIX_FMT_YUV420P ? ? \
>> + ? ? ? ?|| (x)==PIX_FMT_YUVA420P ? ?\
>> ? ? ? ? ?|| (x)==PIX_FMT_YUYV422 ? ? \
>> ? ? ? ? ?|| (x)==PIX_FMT_UYVY422 ? ? \
>> ? ? ? ? ?|| (x)==PIX_FMT_YUV444P ? ? \
>> @@ -2053,12 +2054,16 @@
>> ? ? ? ? ? ? ? ? ? ? ? ?int srcSliceH, uint8_t* dst[], int dstStride[])
>> ?{
>> ? ? ?int plane;
>> - ? ?for (plane=0; plane<3; plane++)
>> + ? ?for (plane=0; plane<4; plane++)
>> ? ? ?{
>> - ? ? ? ?int length= plane==0 ? c->srcW ?: -((-c->srcW ?)>>c->chrDstHSubSample);
>> - ? ? ? ?int y= ? ? ?plane==0 ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample);
>> - ? ? ? ?int height= plane==0 ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample);
>> -
>> + ? ? ? ?int length= (plane==0 || plane==3) ? c->srcW ?: -((-c->srcW ?)>>c->chrDstHSubSample);
>> + ? ? ? ?int y= ? ? ?(plane==0 || plane==3) ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample);
>> + ? ? ? ?int height= (plane==0 || plane==3) ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample);
>> +
>
>> + ? ? ? ?if (((!isALPHA(c->srcFormat)) || (!isALPHA(c->dstFormat))) && plane == 3){
>
> !(isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) && plane == 3
>
>
>> + ? ? ? ? ? ?if (isALPHA(c->dstFormat))
>> + ? ? ? ? ? ? ? ?memset(dst[3], 255, dstStride[3]*height);
>
> as said elewhere writing must be limited to 0..width
>

Patch updated


#1 : sws_fix_initMMX2HScaler.patch
#2 : swscale-example_yuva.patch
#3 : sws_parametrized_yscaleyuv2packed.patch
#4 : sws_configure_alpha.patch
#5 : sws_yuva2rgb.patch
#6 : sws_scale_alpha.patch
#7 : sws_output_yuva420p.patch
#8 : swscale-example_use_alpha.patch


Regards,
C?dric Schieli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_fix_initMMX2HScaler.patch
Type: text/x-patch
Size: 520 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090310/221e5747/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swscale-example_yuva.patch
Type: text/x-patch
Size: 4800 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090310/221e5747/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_parametrized_yscaleyuv2packed.patch
Type: text/x-patch
Size: 2436 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090310/221e5747/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_configure_alpha.patch
Type: text/x-patch
Size: 835 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090310/221e5747/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_yuva2rgb.patch
Type: text/x-patch
Size: 11621 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090310/221e5747/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_scale_alpha.patch
Type: text/x-patch
Size: 50353 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090310/221e5747/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_output_yuva420p.patch
Type: text/x-patch
Size: 3924 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090310/221e5747/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swscale-example_use_alpha.patch
Type: text/x-patch
Size: 5391 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090310/221e5747/attachment-0007.bin>



More information about the ffmpeg-devel mailing list