Tim Stump Posted September 19, 2020 Share Posted September 19, 2020 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? Quote Link to comment Share on other sites More sharing options...
BoltBait Posted September 19, 2020 Share Posted September 19, 2020 Technically, if Alpha is 0, then R, G, and B are undefined. 1 Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
LoudSilence Posted September 19, 2020 Share Posted September 19, 2020 set the alpha to 1, only the computer will notice it, not your eyes. Quote Unofficial PDN Discord Server Link to comment Share on other sites More sharing options...
MJW Posted September 19, 2020 Share Posted September 19, 2020 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). Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted September 19, 2020 Share Posted September 19, 2020 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. 1 Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Rick Brewster Posted September 19, 2020 Share Posted September 19, 2020 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. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
MJW Posted September 19, 2020 Share Posted September 19, 2020 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.) Quote Link to comment Share on other sites More sharing options...
LoudSilence Posted September 19, 2020 Share Posted September 19, 2020 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. Quote Unofficial PDN Discord Server Link to comment Share on other sites More sharing options...
MJW Posted September 19, 2020 Share Posted September 19, 2020 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.) Quote Link to comment Share on other sites More sharing options...
LoudSilence Posted September 19, 2020 Share Posted September 19, 2020 Well I'm no plugin writer, neither do I know C# or how it works, but I guess that makes sense. Quote Unofficial PDN Discord Server Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.