Jump to content

PNG color channels going to black with alpha of 0


Recommended Posts

Hi,

 

Is there any particular reason the RGB channels get zero'd out when saving with an alpha of 0?  I feel like this used to work as I'd expect...  I'm storing coefficients in RGBA for a texture in a rendering engine and it's destroying those color channels on me.  I think Photoshop also has this same behaviour and there's a years-long argument still going on about whether or not it's the proper thing to do.  My feeling is preserving RGB when A is 0 is more likely the "correct" thing (as opposed to setting RGB to black).  Certainly it's significantly more useful.

 

Or is there a plugin or something I can use to not get that behaviour and preserve the RGB channels?

Link to post
Share on other sites

Probably to achieve better compression. Imagine a full-color image, but with all the alphas zero. It's a sizable file if the colors are kept, but can be compressed into practically nothing if all the transparent pixels are stored as (0, 0, 0, 0).

Link to post
Share on other sites

This is correct behavior, believe it or not. Or, if you don't believe it's "correct", then it is certainly intentional / "by design."

 

13 hours ago, Tim Stump said:

I think Photoshop also has this same behaviour and there's a years-long argument still going on about whether or not it's the proper thing to do.

 

This controversy probably stems from underlying math that goes into alpha compositing -- or, we might call it layer compositing, which involves blending the layers together to form the final output. The "final output" is 1 bitmap ("layer") that either goes to the screen, or to a file that is encoded with a single-layer container format such as PNG.

 

If you blend two colors together, X and Y, and they both have an alpha of 0 but the color channels are different ... what should the resulting RGB values be? In the math, you'd get a divide-by-zero if you wanted to output anything other than 0 for the color channels. Ultimately, blending together two invisible colors results in another invisible color. RGB would more properly be encoded as "null", but we can't encode that, so we get zeros (black).

 

For consistency, single layer images still go through this process. Otherwise you'd have color channel preservation sometimes, but not always, without a clear reason for it. At least, that's how I remember the decision. It's been a very long time since this issue has come up, so I may not be remembering correctly. And, this may not be the right design decision anymore.

 

In any case, you're trying to put information into the color channels. PDN just isn't currently equipped to preserve this -- once you have more than 1 layer, there's no good way to preserve the color channels through the layer compositing process. The math just doesn't work out.

 

Quote

I feel like this used to work as I'd expect

 

It never has, at least not in Paint.NET.

 

  • Upvote 1

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to post
Share on other sites
11 hours ago, MJW said:

Probably to achieve better compression.

 

Has nothing to do with compression. I'd never default to choosing compression over fidelity. Hence the repeated requests for the ability to set the default file type for saving single layer images as JPEG instead of PNG, and my unwavering stance against it.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to post
Share on other sites
1 hour ago, Rick Brewster said:

 

Has nothing to do with compression.

I don't see the choice between JPEG and PNG as equivalent. The better compression that's possible by setting all transparent colors to the same value is achieved with no loss of visual image quality, as it must be, since PNG is a lossless format. (The addition of "visual" to image quality isn't redundant: Tim Stump clearly believes there's a loss in quality by not maintaining transparent colors as they were.)

Link to post
Share on other sites
15 hours ago, Tim Stump said:

Is there any particular reason the RGB channels get zero'd out when saving with an alpha of 0

Im just gonna mention that this would really break lots of effects and plugins. For example, boltbait's transparency plugin would not work. All of the transparent pixels would have RGB channels meaning that the alpha can go up. Then if you deleted a background, then tried to increase transparency, the background would just come back. Also, compare it to real life. It would be like giving value to something that doesn't exist.

Link to post
Share on other sites
1 hour ago, LoudSilence said:

Im just gonna mention that this would really break lots of effects and plugins. For example, boltbait's transparency plugin would not work. All of the transparent pixels would have RGB channels meaning that the alpha can go up. Then if you deleted a background, then tried to increase transparency, the background would just come back

 

Nothing would break that wouldn't already break. Transparent pixels aren't handled consistently in PDN right now. Some plugins set transparent pixels to Transparent White, some to Transparent Black. I believe there are some that just zero alpha, leaving the RGB unmodified. If you use PDN's built-in Invert Color adjustment, the transparent pixels' RGBs are also inverted. If you load a PNG file that has transparency, the transparent RGB will be black, but if you erase a selection, the erased pixels' RGBs will be white. So what if you increase the transparency of transparent pixels and get back the original background? Is that somehow worse than getting back a patchwork of white, black, or whatever? Any Effect that depends the RGB values of transparent pixels has to expect the user to explicitly set those values.

 

I'm not advocating PDN save the original RGB of transparent pixels in PNG files, but if they were saved, it wouldn't cause a problem. I am glad that PDN files preserve the RGB of transparent pixels.

 

(BTW, BoltBait's Transparency adjustment handles completely-transparent pixels specially. No matter what the RGB, they're set to a particular color, which, as I recall, is the Secondary Color with the appropriate alpha. I'd prefer it just modify alpha and leave RGB alone.)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...