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

Øyvind Kolås islewind
Sun Mar 22 13:51:18 CET 2009

On Tue, Mar 17, 2009 at 4:40 PM, C?dric Schieli <cschieli at gmail.com> wrote:
> 2009/3/17 ?yvind Kol?s <islewind at gmail.com>:
> Or are you suggesting that scaling non-premultiplied alpha can't work
> ? What I'm sure is that fully transparent stays fully transparent, and
> fully opaque stays fully opaque.

Yes the alpha component is treated correctly, the color components are not.

Scaling non-premultiplied alpha will not work correctly it will lead
to artifacts around
edges between transparent and non-transparent parts of the frame, a
form of haloing.
The relative contributions of color from two pixels with different
alpha values should
not only be determined by the weightings of the resampler but also the coverage
contribution of the pixel as described by the alpha.

As an example I'll linearly blend two floating point RGBA pixels 50/50:

0.50, 1.00, 1.00, 0.20    and
1.00, 0.50, 1.00, 1.00    50/50 yields

0.75, 0.75, 0.50, 0.60

And again on premultiplied values:   Ra=R*A, Ba=B*A, Ga=G*A

0.10, 0.20, 0.00, 0.20,
1.00, 0.50, 1.00, 1.00,

0.55, 0.35, 0.50, 0.60 and then back to non-premultiplied:  R=Ra/A, Ga/A, Ba/a

0.92 0.58, 0.83, 0.60  which is the correctly weighted midway point.

Another concern for quality when performing resampling is whether the
data is gamma corrected or linear
operating on non-linear data doesn't lead to as disturbing artifacts
as treating the components separately

/?yvind K.
?The future is already here. It's just not very evenly distributed?
                                                 -- William Gibson
http://pippin.gimp.org/                            http://ffii.org/

More information about the ffmpeg-devel mailing list