Bug 352837

Summary: Split-alpha on 16-bit EXR images destroys alpha channel (needs high bitdepth selections)
Product: [Applications] krita Reporter: João Queiroz e Lima <joao.queiroz.lima>
Component: File formatsAssignee: Krita Bugs <krita-bugs-null>
Status: CONFIRMED ---    
Severity: wishlist CC: dimula73, halla, joao.queiroz.lima
Priority: NOR    
Version First Reported In: 2.9.8   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description João Queiroz e Lima 2015-09-17 11:42:49 UTC
If you work on an EXR file that has a single layer with RGB and Alpha as the following example file:

https://app.box.com/s/dxmmvrdnm5aal76krb3slh5toeoqal5a

- Splitting Layer's Alpha into Mask messes with RGB info (seems to remove) from layer and breaks the image;
- The same thing might be happening when tonemapping as filters as the curves, levels, etc, also break the image.

Reproducible: Always

Steps to Reproduce:
1. Open the example image
2. Split alpha on the single layer
3. Or Tonemap using Curve Filter/Levels Filter.

Actual Results:  
Image broke.
RGB values disappeared.
Alpha didn't seem right.

Expected Results:  
When Splitting Layer alpha should turn into a transparency layer

When Tonemapping RGB should change and Alpha should be kept as it was

For any additional info feel free to contact me by email.
Comment 1 Halla Rempt 2015-09-21 08:25:20 UTC
Hm, but this image has pixels with zero alpha channel and non-zero color channels. That's a problem in itself, which is why you get a warning when loading the image. There are several issues possible:

    1) The image has zero alpha + non-zero color pixels. We artificially raise
       the alpha value to allow premultiplication.
    
    2) The image has tiny non-zero alpha + non-zero color pixels, but division
       is possible without overflow of color channels. Then we must not change
       anything.
    
    3) The image has tiny non-zero alpha + non-zero color pixels, but division
       is not possible due to a half overflow. In this case we must also raise
       alpha a bit (as in case 1) ) to allow correct rendering of the image.

See https://bugs.kde.org/show_bug.cgi?id=301443 for more information. I'm not sure whether this is actually fixable in Krita at this moment, I need to discuss it with Dmitry, who is on vacation at the moment.
Comment 2 João Queiroz e Lima 2015-09-21 20:08:15 UTC
Hi Boidewijn,

I'm sorry for the late reply.

I was trying to follow on everything you say on your post and I presume that alpha zero means fully transparent pixel.

I also understand, by premultiplied, that the image has info for RGBA in each pixel and that is what Krita does not support.

Am I right on those two assertions?

If so, with the info the image I sent provides, would it be possible to make Krita distribute the RGB values to a paint layer and use the alpha values to build a transparency mask assigned to that layer?

I'm sorry, I want to contribute to solving the problem, but I'm afraid I can't understand everything you said...
Comment 3 João Queiroz e Lima 2015-09-21 20:09:23 UTC
Sorry for mispelling Boudewijn...
Comment 4 João Queiroz e Lima 2015-10-06 09:42:24 UTC
Any news on this issue Boudewijn?
Comment 5 João Queiroz e Lima 2015-10-15 19:34:47 UTC
Thanks for fixing multilayer EXR!

However I've noticed that EXR RGBa isn't yet fixed for single layered images.

I don't understand why this is behaving differently than what's supposed but I'm sharing 4 files in a folder:

https://app.box.com/s/ew5uo4vykxmu16tbu1l1s87llsypcc9f

[b]FILE 1
"01 RGBa Test.exr"[/b] - The test file wich has 4 channels (RGB + Alpha) for you to import into Krita. The first thing you'll notice is, of course, the dialog below. The result is that background colors disappear. What I'd like for you to test is to split alpha on the existing layer by right clicking on it. RGB info is gone as soon as you split alpha.

Dialog:
https://app.box.com/s/03adxdb5zu54w8wmmln3okc7w5ybbjzp

[b]FILE 2
"02 RGBa Test.png "[/b]- A test file for you to compare what is happening with another file with the same 4 channels (RGB + Alpha). Try the same thing: Import into Krita and split alpha like above. The result is what you'd expect. Transparency mask is created but the background colors are still there. RGB info isn't disturbed when you split alpha. This is what should happen with EXR too.

[b]FILE 3
"03 RGBa Test EXR Its Importing Like This.kra"[/b] - This shows the result of the process described for [b]FILE 1[/b]

[b]FILE 4
"04 RGBa Test EXR Should Import Like this.kra"[/b] - This file shows what should happen when using the process from [b]FILE 1[/b]

[b]FILE 5
"05 RGBa Multilayer Alpha Test.exr"[/b] - Was created from the same renderer (Thea) but alpha channel was rendered along with other channels (Color, Alpha, Material ID, Reflection, Refraction, Shadow). It was then saved as a Multilayer EXR. In this file, alpha is being interpreted as a separated channel. This was the base file I used to produce "FILE 4". What I did was:
a) Import the multilayered EXR wich is now working flawlessly [i][u][b](Thanks!)[/b][/u][/i];  :D 
b) Converted Alpha channel into a transparency mask attached to the first layer (RGB);
c) Erased all other channels.

What I find interesting is that dialog that shows up saying that a colored pixel cannot have 0 alpha? Why is that? It is allowed with PNG as shown with "FILE 2", why can't the EXR in "FILE 1" behave the same?

I'll relate this BUG with the original post hoping you won't mind.

Thanks for all the attention and effort put into this.

Best regards,

João
Comment 6 João Queiroz e Lima 2015-10-15 19:35:49 UTC
Forum post:

https://forum.kde.org/viewtopic.php?f=281&t=128306&p=343628#p343628
Comment 7 Halla Rempt 2016-03-20 14:38:39 UTC
I think I might have to add a dialog that allows the user to add interpretative hints for the layers... It's pretty hard to figure out what something should look like from the file, it depends too much on the app that generates the exr.
Comment 8 Dmitry Kazakov 2020-08-20 12:41:42 UTC
I can reproduce this bug on CandleGlass.exr. I'll check what we can do with it
Comment 9 Dmitry Kazakov 2020-08-20 13:14:21 UTC
Okay, the problem happens because all the selections in Krita are 8-bit. Therefore one cannot split alpha from a 16-bit EXR image without precision loss. I don't think it is fixable without implementing high-bitdepth selections.
Comment 10 Dmitry Kazakov 2020-08-20 13:29:47 UTC
I will downgrade this bug to a wishlist, because it needs high bitdepth selections, which is not in our roadmap currently.

Perhaps we should provide some other algorithm for working with alpha channel in high bitdepth images.