Re: Problem with TIFF alpha channel
Re: Problem with TIFF alpha channel
- Subject: Re: Problem with TIFF alpha channel
- From: Andrew Platzer <email@hidden>
- Date: Tue, 9 Oct 2001 10:55:38 -0700
On Monday, October 8, 2001, at 08:36 , Jeff Disher wrote:
I am working on a program that reads in a 24-bit RGB
TIFF image from a file and adds an alpha channel to
make it into a 32-bit RGBA TIFF image which it then
displays on the screen.
So far, whenever I am adding the alpha channel to 100%
opacity (255 unsigned integer) the image displays
perfectly opaque and with the proper RGB data
expressed just as if it were a 24-bit RGB image.
However, if the alpha channel of any pixel is set less
than 100% the pixel appears as if it were black (but
the alpha value seems to be properly expressed). I
tried logging one of the pixels and its values are
what they are supposed to be. I also put the image in
the dock and it did properly act semi-transparent. I
also am confused by the way that an outline appears
around where the image should be.
Cocoa uses what is called 'premultiplied alpha' (Porter-Duff). This means
that the RGB values are multiplied by the alpha value. A lossy conversion
but it improves performance since it skips a multiplication per pixel when
rendering. So if you set an alpha value that is not 255, scale the RGB
values by that 'alpha/255'. Otherwise, you will get fringes and weird
colours when rendering as the calculations wrap around.
And as someone else pointed out, use NSCompositeSourceOver rather than
NSCompositeCopy to draw otherwise the alpha is ignored and partial alpha
pixels will appear grey or black.
Andrew
__________________________________________________________________
A n d r e w P l a t z e r
A p p l i c a t i o n F r a m e w o r k s
A p p l e