Re: Alpha-channeled images fade to black?
Re: Alpha-channeled images fade to black?
- Subject: Re: Alpha-channeled images fade to black?
- From: Shaun Wexler <email@hidden>
- Date: Thu, 18 Mar 2004 15:10:04 -0800
On Mar 18, 2004, at 12:02 PM, Jonathan del Strother wrote:
Hi,
I'm loading .tiff files through NSImage into an OpenGL texture. Where
the texture is semi-transparent, it's much darker than the opaque
areas, as if the image color is getting multiplied by the color of the
alpha channel, in addition to the alpha channel providing the
transparency.
Anyone know if this is a Photoshop, NSImage, or OpenGL problem? How
can I fix it?
Unpremultiply the pixels before creating your texture from them. An
non-optimized method might be:
pixels = (UInt32)textureSize.width * (UInt32)textureSize.height;
pixel = (UInt32 *)textureBitmap;
while (pixels--) {
register UInt32 pm = *pixel;
register UInt32 upm = pm & 0x000000ff;
register Float32 inv_alpha = 255.0f / (Float32)upm;
upm |= (UInt32)(inv_alpha * ((Float32)((pm & 0xff000000) >> 24))) <<
24;
upm |= (UInt32)(inv_alpha * ((Float32)((pm & 0x00ff0000) >> 16))) <<
16;
upm |= (UInt32)(inv_alpha * ((Float32)((pm & 0x0000ff00) >> 8))) << 8;
*pixel++ = upm;
}
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.