• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Alpha-channeled images fade to black?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Alpha-channeled images fade to black?
      • From: Jonathan del Strother <email@hidden>
References: 
 >Alpha-channeled images fade to black? (From: Jonathan del Strother <email@hidden>)

  • Prev by Date: Re: Alpha-channeled images fade to black?
  • Next by Date: Re: NSView setHidden vs. setTransparent
  • Previous by thread: Re: Alpha-channeled images fade to black?
  • Next by thread: Re: Alpha-channeled images fade to black?
  • Index(es):
    • Date
    • Thread