Ugh... Qt4 porting
Lars Knoll
lars at trolltech.com
Mon May 16 16:08:30 BST 2005
On Monday 16 May 2005 17:00, Ingo Klöcker wrote:
> On Monday 16 May 2005 15:06, Lars Knoll wrote:
> > On Monday 16 May 2005 14:55, Mosfet wrote:
> > > >Lars wrote:
> > > >> I'm also curious about what they are going to do with the new
> > > >> Premultiplied format. As far as I can tell it's a 32bpp format
> > > >> with the source part of the alpha already calculated. Good if
> > > >> your going to alphablend the image a lot, bad if you want to
> > > >> modify the original color channels.
> > > >
> > > >The image paint engine uses it. All drawing operations are a lot
> > > > faster when using premultiplied alpha. It's also the format used
> > > > by RENDER, so it matches fine there as well.
> > > >
> > > >And I don't see why you shouldn't be able to modify the color
> > > > channels in a premultiplied image more or less the same way then
> > > > in a non premultiplied one.
> > >
> > > Because a pixel's RGB values aren't the actual RGB values, they are
> > > averaged with the alpha value. So if your doing something like
> > > interpolating a color you'd be interpolating with the wrong color,
> > > no?
> >
> > As long as you don't take the premulitplication into account, yes.
> > But it's trivial to do it right.
> >
> > > Even
> > > simple things like the gray level would be wrong. A red value of 25
> > > may actually be 100 but with 1/4th the opacity. Most effects won't
> > > work properly with this.
> >
> > The math behind is trivial: Instead of the value being R directly,
> > it's A*R. As long as you know it's premultiplied it should be trivial
> > to adjust your code to do the same effect.
>
> The problem is that the precision of the premultiplied values is less
> than the precision of the non-premultiplied values due to integer
> arithmetic being used. In general
> ( A*R ) / A != R
> So you can't recover the original values from the premultiplied values.
> Now if you do several iterations of this then the precision loss might
> increase dramatically
> (http://en.wikipedia.org/wiki/Propagation_of_errors_resulting_from_algebrai
>c_manipulations). And this is far from being trivial math.
If you convert back and forth all the time, while doing manipulations on the
data you are right. But then one could argue that 8bit precision is probably
not good enough anyways.
The good news is that the loss of precision you get when using premultiplied
values throughout will not result in something that is visually different on
the screen.
Cheers,
Lars
More information about the kde-core-devel
mailing list