After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 757686 - There is no easy way to do a radiometrically correct invert operation
There is no easy way to do a radiometrically correct invert operation
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: General
git master
Other All
: Normal normal
: 2.10
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2015-11-06 14:13 UTC by Elle Stone
Modified: 2016-12-30 14:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Colors>Invert: use gegl:invert for linear drawables (1.38 KB, patch)
2016-02-13 01:59 UTC, Jonathan Tait
reviewed Details | Review

Description Elle Stone 2015-11-06 14:13:54 UTC
A radiometrically correct inversion of colors requires that the inversion be done using linear RGB. The current behavior for both "Colors/Invert" and "Colors/Value invert" is to invert using perceptually uniform RGB. 

See bug 702699, which was resolved by making it impossible for users to do a radiometrically correct inversion of colors without resorting to a convoluted workaround. 

There is already a GEGL operation for linear invert. It would be nice if users had access to this function. Currently the workaround to get a radiometrically correct inversion of colors (that is, invert using linear RGB) is as follows:

1. Switch to linear precision
2. Open the Levels dialog
3. Swap the lower slider ends points
4. Make the gamma hack box is checked.

Or the user can do the above four steps using Curves, which unlike Levels will clip any out of gamut RGB values. 

Personally I would find the option to choose between inverting perceptually uniform and linear RGB very useful, so I'm not suggesting removing the option to invert using perceptually uniform RGB. But users shouldn't have to resort to convoluted workarounds to be able to do a radiometrically correct inversion of the colors in a layer. So it would be nice to have the GEGL linear invert operation available in the menu.

Similar considerations probably apply to the Value invert operation, though I'm not sure what the use cases are for inverting Luma/Luminance without also inverting color.
Comment 1 Massimo 2015-11-10 19:14:20 UTC
Another workaround for the time being is to use the
Brightness Contrast operation from the 

Tools->Gegl Operation... 

list and set -1 in the Contrast entry.
Comment 2 Massimo 2015-11-11 11:54:37 UTC
Also, users access gegl:invert-linear activating the
funnily named menu item

Filters->Goat-exercise 

It is hard to discover though
Comment 3 Elle Stone 2015-11-11 12:23:03 UTC
(In reply to Massimo from comment #1)
> Another workaround for the time being is to use the
> Brightness Contrast operation from the 
> 
> Tools->Gegl Operation... 
> 
> list and set -1 in the Contrast entry.

I don't see an entry in the Gegl Operations list for Contrast.
Comment 4 Elle Stone 2015-11-11 12:55:36 UTC
(In reply to Massimo from comment #2)
> Also, users access gegl:invert-linear activating the
> funnily named menu item
> 
> Filters->Goat-exercise 
> 
> It is hard to discover though

(Hypothetical scenario: explaining to a group of photographers trying to use GIMP to do radiometrically correct editing that the way to invert on linear RGB is to go to Filters, scroll to the bottom and select "Goat-exercise".)

What is needed is an operation in the Colors menu with equal status as the current "Colors/Invert".

"Colors/Invert" could be renamed to "Colors/Invert (linear RGB)"
and the new operation could be put just above the current operation, and named "Colors/Invert (not linearized)"

It might make sense to move "Colors/Value Invert" to the Filters menu, under "Artistic", and provide options to invert using Luma or Luminance.
Comment 5 Elle Stone 2015-11-11 12:57:25 UTC
(In reply to Elle Stone from comment #4)

> "Colors/Invert" could be renamed to "Colors/Invert (linear RGB)"
> and the new operation could be put just above the current operation, and
> named "Colors/Invert (not linearized)"

Hmm, I said that wrong. Two operations with equal status in the Colors menu:

Colors/Invert (linear RGB)
Colors/Invert (not linearized)
Comment 6 Massimo 2015-11-11 16:47:43 UTC
(In reply to Elle Stone from comment #3)
> (In reply to Massimo from comment #1)
> > Another workaround for the time being is to use the
> > Brightness Contrast operation from the 
> > 
> > Tools->Gegl Operation... 
> > 
> > list and set -1 in the Contrast entry.
> 
> I don't see an entry in the Gegl Operations list for Contrast.

In that list I have a "Brightness Contrast (brightness-contrast)"
choice that when selected has two entries: "Contrast" and "Brightness".
Brightness defaults to 0 which is fine, whereas "Contrast" has to
be changed from 1 to -1 to get the invert behaviour.

The Goat exercise is not the way a linear invert operation
should be presented, but it is an example that power users
can use to add customized operations, more complex graphs etc
modifying a plug-in.

For the time being it is also an easy way to do a 
radiometrically correct invert operation that among other things
does not add one or two precision conversion steps to the undo history.
Comment 7 Jonathan Tait 2016-02-13 01:56:37 UTC
Do we really need separate menu entries for linear and gamma invert ?

As far a I can see the vast majority of user's workflow requirements would be satisfied simply by GIMP automatically inverting in the appropriate manner for the currently-selected precision:
 - "Perceptual gamma (rRGB)" ...invoke gegl:invert-gamma
 - "Linear light" ..............invoke gegl:invert
Done.

In the (surely?) rare circumstances under which a user really does want to apply invert-gamma on a linear-light image or invert-linear on a gamma image, they can temporarily convert the image precision or improvise a simple workaround (eg.: copy layer to a new image, change precision, invert, copy back to original image).
Comment 8 Jonathan Tait 2016-02-13 01:59:42 UTC
Created attachment 321053 [details] [review]
Colors>Invert: use gegl:invert for linear drawables


The attached patch adds the automatic switch. 
This also seems the satisfy the outstanding requirement to invert layer masks properly:
ref: https://git.gnome.org/browse/gimp/tree/app/actions/drawable-commands.c#n70
simply:
 <Layers> Show Layer Mask (check)
 Colors > Invert
[Since the layer mask is of babl format "Y" (linear grayscale), the Invert action automatically selects gegl:invert, even if the image itself is set to Perceptual gamma.]
Comment 9 Jonathan Tait 2016-02-13 03:14:59 UTC
s/ Show Layer Mask (check) / select layer mask
Comment 10 Jehan 2016-02-15 18:51:30 UTC
Review of attachment 321053 [details] [review]:

I can't say much about whether we need 2 menu items or if it makes more sense that a drawable in linear light is always linearly inverted, and reciprocally with gamma. Are there cases where you would work in gamma and want linear invert, or oppositely?

Anyway for the review part: "gegl:invert" is a compatibility name for "gegl:invert-linear" operation. For the sake of clarity (and code self-documentation), please use the full name. Other than this, this patch looks like it would do what it claims: run one or the other operation depending on the drawable color format. If we decide to go with a single menu item, it looks good to me.

Elle? Was it what you wanted, or you definitely think that 2 items are needed?
Comment 11 Elle Stone 2016-02-15 19:23:25 UTC
I'd recommend having two menu items for invert, maybe something like "Invert perceptual" and "Invert linear". 

Having to convert the entire layer stack from one precision to another just to choose "the other way to invert" can be time-consuming, and pulling the layer over as a new layer and then changing the precision also is fairly time-consuming.

I'd also recommend moving the "Value Invert" menu item to the Filter tree, under "Artistic" filters, to avoid adding more clutter to the Color Menu.

Doing a radiometrically correct "desaturate to Luminance", followed by an inversion (whether radiometrically correct inversion or not), set to either Lightness or Luminance blend mode over the original color layer, produces very different results than the current Value Invert. 

Value Invert seems to be what you'd get by duplicating the color layer, "somehow" desaturating, and then inverting the top layer, and setting the blend mode to HSV Value blend mode. 

If HSV will eventually be deprecated, it seems logical to put Value Invert (which is used by whom? for what?) somewhere in a corner.
Comment 12 Elle Stone 2016-02-15 19:46:38 UTC
The other consideration is that currently, afaik, the only operations that change the default choice of "operate on linear" vs "operate on gamma" when you change precision is the layer blend modes/paint modes. 

It might be confusing if "blend modes and invert" change the default action depending on the precision.
Comment 13 Øyvind Kolås (pippin) 2016-12-23 00:48:34 UTC
It would be better if the TRC of the pixelformat used to store layers of an image impacted neither layer modes nor inversion. Adding a menu entry that always performs a linear RGB invert seems most reasonable to me and is the approach I plan for the experimental pippin/linear-is-the-new-black branch.
Comment 14 Michael Natterer 2016-12-30 14:39:12 UTC
There we go, picked from pippin's branch, with two menu items:

commit 41674893b2651f9421d23bc1ca77b35a90571987
Author: Øyvind Kolås <pippin@gimp.org>
Date:   Sat Dec 24 03:53:19 2016 +0100

    Bug 757686 - There is no easy way to do a radiometrically correct...
    
    ...invert operation
    
    Add linear invert menu item, and improve invert tooltips.

 app/actions/drawable-actions.c  | 12 ++++++++++--
 app/actions/drawable-commands.c | 20 ++++++++++++++++++--
 app/actions/drawable-commands.h |  2 ++
 menus/image-menu.xml.in         |  1 +
 4 files changed, 31 insertions(+), 4 deletions(-)