Live data from Hacker News

Beware of Transparent Pixels

adriancourreges.com

11–20 of 97 posts

Re: Beware of Transparent Pixels

#11
post #9

> Even with an alpha of 0, a pixel still has some RGB color value associated with it. Wish the article was more clear as to why this happens. Let me elucidate: this happens because, per the PNG standard[0], 0-alpha pixels have their color technically undefined . This means that image editors can use these values (e.g. XX XX XX 00) for whatever -- generally some way of optimizing, or, more often than not, just garbage…

I remember this giving me headaches years ago when I tried to save color data in a PNG with 0-alpha values that contain color. I needed the color and the alpha and thought it would make sense to save both in one image, basically, but nope. This was with GIMP and I remember looking it up and the GIMP devs insisting it was correct behavior by the PNG standard even when it made oh-so-much sense to at least give an option to bypass this shit for niche cases.

Re: Beware of Transparent Pixels

#12
post #2

> pay attention to what color you put inside the transparent pixels I don't understand this. When I make transparency I don't use any color? I use the Eraser tool or Ctrl-X, not a color with 0 opacity.

This is actually a very common problem with 3-D stuff and transparency in textures. This isn't an issue with the colors of the pixels themselves, it's an issue with texture filtering. nVidia has a pretty good explanation as it applies to games and 3d graphics: https://developer.nvidia.com/content/alpha-blending-pre-or-n... Say you have two adjacent pixels using floating point RGBA values of (0,0,0,0) and (1,1,1,1), a…

Surely the answer if you want this is to weight the final RGB by the transparency. E.g. the final red channel would be (R1xT1 + R2xT2)/(T1+T2)

Re: Beware of Transparent Pixels

#13
post #9

> Even with an alpha of 0, a pixel still has some RGB color value associated with it. Wish the article was more clear as to why this happens. Let me elucidate: this happens because, per the PNG standard[0], 0-alpha pixels have their color technically undefined . This means that image editors can use these values (e.g. XX XX XX 00) for whatever -- generally some way of optimizing, or, more often than not, just garbage…

While what you wrote is correct, it's not actually the problem being described in the posted link. The problem in the posted link is just as relevant if the alpha value was "01" for "you pretty much can't see it but it's meaningfully there", and has to do with image filtering artifacts as opposed to purely data representation.

Re: Beware of Transparent Pixels

#14
post #11
post #9

> Even with an alpha of 0, a pixel still has some RGB color value associated with it. Wish the article was more clear as to why this happens. Let me elucidate: this happens because, per the PNG standard[0], 0-alpha pixels have their color technically undefined . This means that image editors can use these values (e.g. XX XX XX 00) for whatever -- generally some way of optimizing, or, more often than not, just garbage…

I remember this giving me headaches years ago when I tried to save color data in a PNG with 0-alpha values that contain color. I needed the color and the alpha and thought it would make sense to save both in one image, basically, but nope. This was with GIMP and I remember looking it up and the GIMP devs insisting it was correct behavior by the PNG standard even when it made oh-so-much sense to at least give an optio…

This seems to have been since fixed. GIMP's "Export as PNG" dialog has for some time had an option "Save color values from transparent pixels".

Re: Beware of Transparent Pixels

#15

Earlier quoted context omitted.

This is actually a very common problem with 3-D stuff and transparency in textures. This isn't an issue with the colors of the pixels themselves, it's an issue with texture filtering. nVidia has a pretty good explanation as it applies to games and 3d graphics: https://developer.nvidia.com/content/alpha-blending-pre-or-n... Say you have two adjacent pixels using floating point RGBA values of (0,0,0,0) and (1,1,1,1), a…

Surely the answer if you want this is to weight the final RGB by the transparency. E.g. the final red channel would be (R1xT1 + R2xT2)/(T1+T2)

You're mostly right. The industry-wide accepted answer is to multiply the opacity into the colors before interpolating, so the formula would be (R1xT1 + R2xT2)/2 for the average, and then to do later transparency blending as if the opacity term was already multiplied in.

Re: Beware of Transparent Pixels

#16
post #9

> Even with an alpha of 0, a pixel still has some RGB color value associated with it. Wish the article was more clear as to why this happens. Let me elucidate: this happens because, per the PNG standard[0], 0-alpha pixels have their color technically undefined . This means that image editors can use these values (e.g. XX XX XX 00) for whatever -- generally some way of optimizing, or, more often than not, just garbage…

While what you wrote is correct, it's not actually the problem being described in the posted link. The problem in the posted link is just as relevant if the alpha value was "01" for "you pretty much can't see it but it's meaningfully there", and has to do with image filtering artifacts as opposed to purely data representation.

Also the problem can occur with any image format; what matters is how it's stored in the texture not on disc.

Re: Beware of Transparent Pixels

#18
post #2

> pay attention to what color you put inside the transparent pixels I don't understand this. When I make transparency I don't use any color? I use the Eraser tool or Ctrl-X, not a color with 0 opacity.

When you erase, it has a soft edge, right? And in the edge, you see the colour that was there before is still there, just more transparent. Well similarly, in the area that is fully erased, it is fully transparent.

Re: Beware of Transparent Pixels

#19

Using premultiplied alpha avoids this. Jim Blinn's books from the 90s give a very thoughtful treatment of the topic.

The Porter and Duff compositing paper is good, too.

One clarification, though: With premultiplied colors, something like (1,1,1,0) is either illegal or a light source. It's not a valid normal color.

Re: Beware of Transparent Pixels

#20
post #11
post #9

> Even with an alpha of 0, a pixel still has some RGB color value associated with it. Wish the article was more clear as to why this happens. Let me elucidate: this happens because, per the PNG standard[0], 0-alpha pixels have their color technically undefined . This means that image editors can use these values (e.g. XX XX XX 00) for whatever -- generally some way of optimizing, or, more often than not, just garbage…

I remember this giving me headaches years ago when I tried to save color data in a PNG with 0-alpha values that contain color. I needed the color and the alpha and thought it would make sense to save both in one image, basically, but nope. This was with GIMP and I remember looking it up and the GIMP devs insisting it was correct behavior by the PNG standard even when it made oh-so-much sense to at least give an optio…

fought with this recently while creating pdf having image overlays, ended up having to draw the underlining image on top image's pixel having full alpha to avoid aliasing on the edges
Post reply on HN