darktable-org / darktable

darktable is an open source photography workflow application and raw developer
https://www.darktable.org
GNU General Public License v3.0
9.11k stars 1.11k forks source link

[blend mode "multiply reverse" & masks] mask is partially ignored #7464

Closed AxelG-DE closed 3 years ago

AxelG-DE commented 3 years ago

Describe the bug

Using blend mode multiply reverse (RGB Scene) and a mask (regardless drawn or param. or both) results in partially ignored mask

@hlecleme may I ping you here...

To Reproduce

  1. Go to darkroom e.g. exposure module
  2. Set a drawn mask
  3. for illustration purposes increase exposure quite noticably and decrease black level compensation
  4. make sure blending options are at "RGB (scene)"
  5. set blending mode to multiply reverse
  6. observe, outside the mask, suddenly you will see above exposure settings
  7. (similar "mask ignorance" happens in "RGB (display)" when blend mode coloradjustment is used)
    • for coloradjustment I checkout at 3.1.0-1368-g5a7a82497 and still find the same behaviour, but this might be misleading, as I donno whether coloradjustment ignores masks on purpose

Expected behavior

Any changes should be applied within the mask and outside the mask there should be everything like the respective module has not been applied

Screencast

for simplification(!) I have shortened the history stack, to get filmic and std. exposure out of discussion [EDIT 1] at the end of the screencast I scroll thru all the other blend modes, to show, those desribed here, are the only ones [EDIT 2] you see me using here 3.3.0-1470-g4ab56d270, because I was trying to bisect. Same happens in current master.

https://user-images.githubusercontent.com/49004103/103152475-a425d800-4788-11eb-982b-b6ca07a12df5.mp4

Platform (please complete the following information):

johnny-bit commented 3 years ago

@aurelienpierre said:

the multiply reverse seems to behave correctly according to its maths you may not be used to the "reverse" part, where the layers are inverted so we blend the input on top of the output while the direct algos always blend output on top of input your mask builds an alpha layer what happens next is alpha arithmetic so if you want your alpha mask to be a clipping mask, you need the direct algos also, if you let the black level = 0, exposure in reverse multiply properly affects the painted area only but since you push a non-linear offset, it's all garbled then, in that linear operation but alpha is not generally a clipping mask, it's occlusion. In darktable, we use only a small subset of what it can do, which is blending transparent output over opaque input clipping mask is a particular case of alpha see https://en.wikipedia.org/wiki/Alpha_compositing

So... "Is not a bug, is a feature".

Given that alpha composing as well as clipping masks aren't really "intuitive" stuff, things like this are better suited for in-depth documentation and explanation.

AxelG-DE commented 3 years ago

@aurelienpierre said:

yes, that is what we discussed on IRC.

still need to get my head around the alpha compositing, just I assume, I am not the only user, who expects masks to be exclusively obeyed and "wrong expectation" will not be digested easily by everybody :-P

I could imagine, we will close this soon, but give it a bit more time pls., hoping of some more voices from the rear part of the bus :-)

jade-nl commented 3 years ago

I'm 100% with @AxelG-DE on this one.

This is not an intuitive/non-intuitive issue or a case of 'the maths is solid because...' If one sets a mask the actions should be limited within that mask and according to the mask settings. Period!

If the maths, in this case a specific blend mode, dictates that this cannot be so then one should not be able to use it in combination with a mask to begin with. If a separate, mask-less, module is created for this (assuming that this is possible/wanted) then users would not be confused when using a mask and being told that all is well even though the whole image is effected instead.

I really don't see why the effect of an action, any action (multiply reverse in this case, but I'm all but sure that it will not end here) cannot be limited after all the maths to the mask settings.

Also: Why is this only the case for multiply reverse and not for the other reverse blend modes? Seems that this 'input on top of the output / alpha arithmetic' doesn't like multiply very much :-)

People, as in normal users, are going to be very confused about this.

Anyway, just my 2c.

AxelG-DE commented 3 years ago

@johnny-bit I am a little bit confused, you closed it now in conjunction with #4189 and also I think @jade-nl commented in a way, that there might be more user seeing it the way I described in the issue

one should better open the eyes well :blush:

johnny-bit commented 3 years ago

@AxelG-DE - I haven't closed THIS issue, I closed #4189 because the scene was affected by non-linear blending which was clamping values

This issue is still valid since it is still confusing how masks work. I believe that both alpha composing masks and occlusion masks (cliping) are valid. AFAIU in dt we have apha composing with no clipping masks (except value clamping non-linear ones ;)) and me too would like to see clipping masks

pinging @hlecleme to chime in here.

AxelG-DE commented 3 years ago

@AxelG-DE - I haven't closed THIS issue,

Sorry I was crosseyed :-) my bad

I pinged @hlecleme already above :-P

hlecleme commented 3 years ago

Agree that this can be improved. Would it help to add the multiply reverse mode in a separate “category” (e.g. reversed arithmetic modes)?

jade-nl commented 3 years ago

Would it help to add the multiply reverse mode in a separate “category”

That depends: If that category makes using a mask not possible I would be in favour of this. If the core issue (a mask not doing what it is supposed to do) is not addressed then what would be the point?

Having the ability to use masks while it cannot do what it is designed to do, keep the changes within the confines of the mask, is pointless.

johnny-bit commented 3 years ago

looks like "reversed arithmetic modes" would have to be in blend-only mode where you can controll opacity? or in addition have actual clipping masks?

hlecleme commented 3 years ago

In the case of the multiply reverse blending mode, the masking is working as expected. If there is an issue, it would be more in the naming/implementation of subtract reverse and divide reverse.

What is probably surprising here is that we don't apply the blending/masking in the same way.

Forward/direct blending operations

blend_normal

The output image of the module (the green image) is masked. The resulting image is the input image of the module (the red image) outside of the masked region and the result of the blending operation inside the masked region (the yellowish circle).

Reversed blending operations

The same operation is performed, but the images are inverted.

blend_reversed

The input image of the module is masked. The resulting image is the output image of the module outside of the masked region and the result of the blending operation inside the masked region.

Normal blending operation

The normal bend is actually able to perform both because the blending operation is straightforward: alpha output + (1-alpha) input. Taking alpha2 = (1-alpha) by reversing the mask we are able to perform the reversed blending.

Multiply blending operation

Because the multiplication is commutative (output input = input output), the effect inside the masked region is the same for the multiply and multiply reverse blending modes. The outside of the masked region will change as it will depend on which image is the base image:

There are at least two options for improving things:

  1. dropping the multiply reverse as it causes confusion (and check naming of the other two)
  2. rearranging the blending modes to group the reversed blending modes together + explaining it better in the manual
johnny-bit commented 3 years ago

Well... TBH the difference would be seen better if you used same placing for input and output on both diagrams ;)

the option 2 is good because it still allows to use multiply reverse, but the operation without clip blend is weirdo...

the"clip" operation where users would like to have effects of multiply-reverse applied, but still clip it so that "not masked area is not affected" would be a bit hard since for most blending modes it would behave as normal masking, but would be very tempting to have for reverse blending modes (and some weirdo blending/clipping mode)

todd-prior commented 3 years ago

May I ask what the normal use case for this type of blend mode would be ie I have a choice to use it why would I choose that blend mode...someone had mentioned it was like the scene-referred version of screen blend mode but I am not able to make that connection from this discussion...I guess I will have to try it on a couple of images to see what happens

hlecleme commented 3 years ago

the"clip" operation where users would like to have effects of multiply-reverse applied, but still clip it so that "not masked area is not affected" would be a bit hard since for most blending modes it would behave as normal masking, but would be very tempting to have for reverse blending modes (and some weirdo blending/clipping mode)

Sorry, I think I don't fully understand, please correct me if I'm wrong: as said above the effect inside the clipped region is identical for multiply and multiply reverse. If someone wants a multiply reverse blending mode that clips where the mask is, he may use the multiply blending which is exactly what is wanted.

May I ask what the normal use case for this type of blend mode would be ie I have a choice to use it why would I choose that blend mode...someone had mentioned it was like the scene-referred version of screen blend mode but I am not able to make that connection from this discussion...I guess I will have to try it on a couple of images to see what happens

I'm not sure to have enough experience to answer really that question. Some bits of information:

@TurboGit: what is your opinion on this: should we “temporarily” deprecate the multiply reverse blending mode as it currently causes confusion, or should we add (and group together) the minimal set of reverse blending modes (multiply, divide and perhaps also add and subtract) with documentation explaining what they do?

Thanks

todd-prior commented 3 years ago

This is a pretty clear explanation with the diagram..I would have to check if it is in the manual if so then I think it is no more complicated than many other aspects of DT.

https://github.com/darktable-org/darktable/issues/7464#issuecomment-751490701

TurboGit commented 3 years ago

@hlecleme : I would go to group them together.

One point, I understand the explanation for the multiply reverse, all good. But now I'm wondering why the divide & subtract reverse are not modifying the outside ?

hlecleme commented 3 years ago

They should, but they don't. It's something I overlooked when writing the functions. The least I could do is to rename them (e.g. divide inverse instead of divide reverse) to have a consistent naming across the blending operations, if that's acceptable and enough distinctive to avoid confusion.

TurboGit commented 3 years ago

Ok, so to summaries :

Is that your thinking too ?

todd-prior commented 3 years ago

I think maybe some comments in the manual would help ...neither multiply or any of the reverse modes are discussed. There is a reference to to to the Gimp manual which again does not explain the reverse logic. Some comments along with the diagram above might be useful to complete the work you suggest above....at least I didn't see any in the blending sections...maybe there are comments else where??

TurboGit commented 3 years ago

I think maybe some comments in the manual would help

Yes of course, a manual update is also needed.

github-actions[bot] commented 3 years ago

This issue did not get any activity in the past 30 days and will be closed in 365 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.