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

Cédric Schieli cschieli
Thu Mar 5 15:09:26 CET 2009


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

[...]

>> @@ -972,6 +986,14 @@
>> ? ? ? ? ? ? ? ? ? ? ?: "%"REG_a
>> ? ? ? ? ? ? ? ? ?);
>> ? ? ? ? ? ? ?}
>> + ? ? ? ? ? ?if (CONFIG_SWSCALE_ALPHA && aDest){
>> + ? ? ? ? ? ? ? ?__asm__ volatile(
>> + ? ? ? ? ? ? ? ? ? ?YSCALEYUV2YV121_ACCURATE
>> + ? ? ? ? ? ? ? ? ? ?:: "r" (alpSrc+dstW), "r" (aDest+dstW),
>> + ? ? ? ? ? ? ? ? ? ?"g" (-dstW)
>> + ? ? ? ? ? ? ? ? ? ?: "%"REG_a
>> + ? ? ? ? ? ? ? ?);
>> + ? ? ? ? ? ?}
>> ? ? ? ? ?}else{
>> ? ? ? ? ? ? ?while(p--){
>> ? ? ? ? ? ? ? ? ?__asm__ volatile(
>> @@ -981,6 +1003,14 @@
>> ? ? ? ? ? ? ? ? ? ? ?: "%"REG_a
>> ? ? ? ? ? ? ? ? ?);
>> ? ? ? ? ? ? ?}
>> + ? ? ? ? ? ?if (CONFIG_SWSCALE_ALPHA && aDest){
>> + ? ? ? ? ? ? ? ?__asm__ volatile(
>> + ? ? ? ? ? ? ? ? ? ?YSCALEYUV2YV121
>> + ? ? ? ? ? ? ? ? ? ?:: "r" (alpSrc+dstW), "r" (aDest+dstW),
>> + ? ? ? ? ? ? ? ? ? ?"g" (-dstW)
>> + ? ? ? ? ? ? ? ? ? ?: "%"REG_a
>> + ? ? ? ? ? ? ? ?);
>> + ? ? ? ? ? ?}
>> ? ? ? ? ?}
>> ? ? ? ? ?return;
>> ? ? ?}
>
> i would prefer if these wouldnt be duplicated in the generated code

patch updated

> [...]
>> @@ -1095,11 +1147,28 @@
>> ? ? ? ? ? ? ?switch(c->dstFormat)
>> ? ? ? ? ? ? ?{
>> ? ? ? ? ? ? ?case PIX_FMT_RGB32:
>> + ? ? ? ? ? ? ? ?if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf){
>> + ? ? ? ? ? ? ? ? ? ?YSCALEYUV2PACKEDX
>> + ? ? ? ? ? ? ? ? ? ?YSCALEYUV2RGBX
>> + ? ? ? ? ? ? ? ? ? ?"movq ? ? ? ? ? ? ? ? ? ? ?%%mm2, "U_TEMP"(%0) ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?"movq ? ? ? ? ? ? ? ? ? ? ?%%mm4, "V_TEMP"(%0) ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?"movq ? ? ? ? ? ? ? ? ? ? ?%%mm5, "Y_TEMP"(%0) ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?YSCALEYUV2PACKEDX_YA(ALP_MMX_FILTER_OFFSET)
>> + ? ? ? ? ? ? ? ? ? ?"psraw ? ? ? ? ? ? ? ? ? ? ? ?$3, %%mm1 ? ? ? ? \n\t"
>> + ? ? ? ? ? ? ? ? ? ?"psraw ? ? ? ? ? ? ? ? ? ? ? ?$3, %%mm7 ? ? ? ? \n\t"
>> + ? ? ? ? ? ? ? ? ? ?"packuswb ? ? ? ? ? ? ? ? ?%%mm7, %%mm1 ? ? ? ? \n\t"
>> + ? ? ? ? ? ? ? ? ? ?"movq ? ? ? ? ? ? ? "U_TEMP"(%0), %%mm2 ? ? ? ? \n\t"
>> + ? ? ? ? ? ? ? ? ? ?"movq ? ? ? ? ? ? ? "V_TEMP"(%0), %%mm4 ? ? ? ? \n\t"
>> + ? ? ? ? ? ? ? ? ? ?"movq ? ? ? ? ? ? ? "Y_TEMP"(%0), %%mm5 ? ? ? ? \n\t"
>
> it seems that YSCALEYUV2PACKEDX_YA could be changed to take teh registers as
> parameters to avoid the movq TEMP stuff ?
> also same applies to all other cases where its possible

patch updated

> [...]
>> @@ -1191,6 +1260,32 @@
>> ? ? ? ? ?{
>> ? ? ? ? ? ? ?//Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :(
>> ? ? ? ? ? ? ?case PIX_FMT_RGB32:
>> + ? ? ? ? ? ? ? ?if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf){
>> + ? ? ? ? ? ? ? ? ? ?*(uint16_t **)(&c->u_temp)=abuf0;
>> + ? ? ? ? ? ? ? ? ? ?*(uint16_t **)(&c->v_temp)=abuf1;
>> + ? ? ? ? ? ? ? ? ? ?__asm__ volatile(
>> + ? ? ? ? ? ? ? ? ? ?"mov %%"REG_b", "ESP_OFFSET"(%5) ? ? ? ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?"mov ? ? ? ?%4, %%"REG_b" ? ? ? ? ? ? ? \n\t"
>> + ? ? ? ? ? ? ? ? ? ?"push %%"REG_BP" ? ? ? ? ? ? ? ? ? ? ? ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?YSCALEYUV2RGB(%%REGBP, %5)
>> + ? ? ? ? ? ? ? ? ? ?"push ? ? ? ? ? ? ? ? ? %0 ? ? ? ? ? ? ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?"push ? ? ? ? ? ? ? ? ? %1 ? ? ? ? ? ? ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?"mov ? ? ? ? ?"U_TEMP"(%5), %0 ? ? ? ? ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?"mov ? ? ? ? ?"V_TEMP"(%5), %1 ? ? ? ? ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?YSCALEYUV2RGB_YA(%%REGBP, %5)
>> + ? ? ? ? ? ? ? ? ? ?"psraw ? ? ? ? ? ? ? ? ?$3, %%mm1 ? ? ? \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
>> + ? ? ? ? ? ? ? ? ? ?"psraw ? ? ? ? ? ? ? ? ?$3, %%mm7 ? ? ? \n\t" /* abuf0[eax] - abuf1[eax] >>7*/
>> + ? ? ? ? ? ? ? ? ? ?"packuswb ? ? ? ? ? ?%%mm7, %%mm1 ? ? ? \n\t"
>> + ? ? ? ? ? ? ? ? ? ?"pop ? ? ? ? ? ? ? ? ? ?%1 ? ? ? ? ? ? ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?"pop ? ? ? ? ? ? ? ? ? ?%0 ? ? ? ? ? ? ?\n\t"
>> + ? ? ? ? ? ? ? ? ? ?WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6)
>> + ? ? ? ? ? ? ? ? ? ?"pop %%"REG_BP" ? ? ? ? ? ? ? ? ? ? ? ? \n\t"
>> + ? ? ? ? ? ? ? ? ? ?"mov "ESP_OFFSET"(%5), %%"REG_b" ? ? ? ?\n\t"
>> +
>> + ? ? ? ? ? ? ? ? ? ?:: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest),
>> + ? ? ? ? ? ? ? ? ? ?"a" (&c->redDither)
>
> the push/pop in the inner loop can at least on x86_64 be avoided

patch updated

> [...]
>
>> +static inline void RENAME(bgr32ToA)(uint8_t *dst, uint8_t *src, long width, uint32_t *unused){
>> + ? ?int i;
>> + ? ?for (i=0; i<width; i++){
>> +#ifdef WORDS_BIGENDIAN
>> + ? ? ? ?dst[i]= ((uint32_t *)src)[i]&0xFF;
>> +#else
>> + ? ? ? ?dst[i]= ((uint32_t *)src)[i]>>24;
>> +#endif
>> + ? ?}
>> +}
>> +
>> +static inline void RENAME(bgr32_1ToA)(uint8_t *dst, uint8_t *src, long width, uint32_t *unused){
>> + ? ?int i;
>> + ? ?for (i=0; i<width; i++){
>> +#ifdef WORDS_BIGENDIAN
>> + ? ? ? ?dst[i]= ((uint32_t *)src)[i]>>24;
>> +#else
>> + ? ? ? ?dst[i]= ((uint32_t *)src)[i]&0xFF;
>> +#endif
>> + ? ?}
>> +}
>> +
>
> for(i=0; i<w; i++)
> ? ?dst[i]= src[4*i];
> and adjust src when calling
> 1 function less

patch updated


Here is the updated patch set :

#1 : sws_yuva420p_isPlanarYUV.patch
YUVA420P is a planar YUV format, isn't it ?

#2 : sws_scale_use_4_planes.patch
don't ignore 4th plane

#3 : swscale-example_yuva.patch
fake rgb32->yuva420p to be able to test #4 to #8
this one don't aim to be commited

#4 : sws_parametrized_yscaleyuv2packed.patch
like in my previous mail, posted here for completeness

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

#6 : sws_yuva2rgb.patch
updated to have a mmx version even without HAVE_7REGS

#7 : sws_scale_alpha.patch
updated

#8 : sws_output_yuva420p.patch
updated

#9 : swscale-example_use_alpha.patch
updated
the second hunk in this one needs some explanations :
without it, swscale-example will segfault
even without any of my patches, simply adding a uint16_t** field to
struct SwsContext and av_malloc'ing between 13 and 236 bytes (or 26
and 408 on x86_64) will make swscale-example to segfault (see
bug.diff)
after some debugging, I found that my alpPixBuf data get corrupted somehow
disabling MMX code with --disable-mmx prevent this from happening
running swscale-example under valgrind (even without bug.diff) will segfault
can someone can help on this ?


Regards,
C?dric Schieli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_yuva420p_isPlanarYUV.patch
Type: text/x-patch
Size: 563 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/ceabc5e1/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_scale_use_4_planes.patch
Type: text/x-patch
Size: 2427 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/ceabc5e1/attachment-0001.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/20090305/ceabc5e1/attachment-0002.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/20090305/ceabc5e1/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_configure_alpha.patch
Type: text/x-patch
Size: 877 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/ceabc5e1/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_yuva2rgb.patch
Type: text/x-patch
Size: 11885 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/ceabc5e1/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_scale_alpha.patch
Type: text/x-patch
Size: 50220 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/ceabc5e1/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sws_output_yuva420p.patch
Type: text/x-patch
Size: 1553 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/ceabc5e1/attachment-0007.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swscale-example_use_alpha.patch
Type: text/x-patch
Size: 6583 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/ceabc5e1/attachment-0008.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: results.tgz
Type: application/x-gzip
Size: 43126 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/ceabc5e1/attachment-0009.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug.diff
Type: text/x-patch
Size: 1357 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090305/ceabc5e1/attachment-0010.bin>



More information about the ffmpeg-devel mailing list