GNOME Bugzilla – Bug 162395
Soft Light and Overlay modes are identical
Last modified: 2016-10-26 00:41:51 UTC
I was experimenting with different compositing modes yesterday, trying to understand how they work, and happened to notice that switching between Soft Light and Overlay modes never altered the result, no matter what variations I tried. I then looked at the formulas for the two, in paint-funcs-generic.h, and found that although they are written differently, they are algebraically equivalent. ViewCVS indicates that neither of these formulas has been changed since Guillermo Romero introduced Soft Light on 2002-11-5 (in a patch committed by Sven). The question is what to do about it.
After some discussion with UnNamed, and with reference to http://www.pegtop.net/delphi/blendmodes/ the story seems to be as follows: GIMP soft light mode is about the same as the soft light mode in the program XFader, and seems to be nearly the same as PS soft light mode. However, GIMP overlay mode is nothing like PS overlay mode, which is actually identical to GIMP hard light mode with the top and and bottom layers reversed. Instead, GIMP overlay mode is simply identical to GIMP and PS soft light mode, as stated above. (GIMP hard light mode = PS hard light mode.) I hope this makes sense.
None of these mode names make any sense anyway, and there's your proof. Perhaps they relate to archaic photochemical processes? In any case, the huge list of meaningless names is unhelpful. If the math expression isn't way too long, just display that.
Congratulations, you have just taken the lead in the race for the Worst Idea of the Year award. But don't feel too bad, it's only January. Seriously, you're right that it would be nice to do a better job of explaining the modes. But inflicting equations on people would be obnoxious.
Well, how about the equation in a tooltip or some such? People come to the gimp from different backgrounds. There may be a few (very rare!) people with a clue about those old photochemical and printing press processes. There will be a decent number of people coming from other paint programs, PhotoShop being the prime example. There will be a decent number of people like me, who come to the gimp with a background that involves doing math operations on pixel data. We will be utterly lost without seeing the equations; provide the equations and all questions have been answered. Most people will be just plain clueless in any case. :-(
The equations belong into the user manual if at all. People with a mathematical background are usually rather good in reading. It should also be easy for someone with a mathematical background to have a look at the source and to contribute the equations to the gimp-docs team working on the user manual.
Back to the original bug report: it looks like the Overlay mode should be changed. Does anyone have a description of what it should be replaced with? In the GIMP distribution, there are only three scripts using the Overlay mode (they were written before Soft Light was introduced) and it should not be a big deal to update them. As for third-party plug-ins, scripts and tutorials, this is another issue but we could limit the breakage by announcing clearly that the Overlay mode is going to be changed.
I'm afraid you missed the most important part: saved xcf files. If Overlay mode changes, any saved images that use it will change their appearance. I, at least, have used Overlay mode quite a bit, and I don't think that's acceptable. The only way around it would be an increment to the xcf version, combined with some kind of hack that changes Overlay mode to Soft Light mode when xcf files with earlier versions are loaded.
Yes, I looked at the XCF code and we should of course not break the old files. Basically, the old code for GIMP_OVERLAY_MODE (5) should be kept and probably renamed GIMP_OLD_OVERLAY_MODE or something similar in the enum. It would be handled in the same way as Soft Light. A new value for GIMP_OVERLAY_MODE would have to be added at the end of the GimpLayerModeEffects enum so that plug-ins such as psd.c and psp.c give the expected results when loading files generated by other programs.
To avoid misunderstandings, s/the old code/the old value/.
Regarding what it should be replaced with, if it is done at all, the site referenced in comment #1 suggests that Overlay mode should be the same as Hard Light mode with the top and bottom layers switched. So that should be very easy.
I think that I looked at all relevant parts of the code and this change seems to be doable. However, I am a bit afraid of touching the MMX and SSE compositing code as I am not familiar with these extended asm instructions. I still have one question: assuming that the we rename the current enum value to GIMP_OLD_OVERLAY_MODE (5) in order to be able to load old XCF files and interact with old scripts or plug-ins, what is the best place to substitute this value with GIMP_SOFTLIGHT_MODE (19)? It should probably be done in xcf-load.c, but should it also be done somewhere in the PDB? By the way, while investigating this I found that gimp-composite-generic.c has a bug in its documentation. It says that the formula for Overlay is: D = A * (B + (2 * B) * (255 - A)) while it is actually: D = A * (A + (2 * B) * (255 - A)) which is algebraically equivalent to Soft Light. I will commit this minor fix this evening.
We have a perfect opportunity now to address as we port the layer modes to GEGL.
When using GEGL for the projection, blending with Overlay uses the blending formula in the SVG 1.2 draft. This is the same formula Photoshop uses as well and it has the properties compared to Hard light as described earlier in this bug report. GEGL Soft light behaves as legacy Soft light (i.e. also as legacy Overlay). Relevant commit, rev 27541: 2008-11-03 Martin Nordholts <martinn@svn.gnome.org> * app/gegl/gimpoperationpointlayermode.c (gimp_operation_point_layer_mode_process): Reuse the blending formula from the legacy Soft light. (Actually the formula comes from legacy Overlay but legacy Overlay and Soft light blends pixels exactly the same.) I hereby declare the porting of the layer modes to this GEGL operation complete. Summary: Completely works the same: Normal, Dissolve, Behind, Color Erase, Erase, Anti Erase Works the same for 100% opaque layers: Lighten only, Screen, Dodge, Addition, Darken only, Multiply, Dodge, Soft light, Hard light, Difference, Subtract, Grain extract, Grain merge, Divide, Hue, Saturation, Color, Value Works different but similar: Overlay now uses the SVG 1.2 overlay formula which is different but similar to legacy Overlay Replace needs to be externally masked to not replace too much, but that is outside the scope of the layer mode porting. Since making sure old xcfs renders correctly also when using GEGL for the projection is a general problem and not specific to this bug report, I am closing this as OBSOLETE.
Martin, I did a fix for Gimp 2.9 Overlay Mode. Can you check it? https://bugzilla.gnome.org/show_bug.cgi?id=673501 - issue https://bugzilla.gnome.org/attachment.cgi?id=228551 - my patch The Overlay mode fully compatible with Krita, Photoshop, ORA, Painter. The formula was taken from here: http://en.wikipedia.org/wiki/Blend_modes Mitch said that it's possible to set "New Overlay" and remain "Legecy Overlay".
Paul, adding comments to closed bug has no effect, please stick to the open bug :)
This needs to be reopened. In GIMP 2.9, Overlay Mode and Soft Light mode are exactly equivalent in every case ((RGB|Greyscale), (8bit int|16bit int|32bit int|16bit float|32bit float) (gamma|linear))