Skip to content

Ensure output in range [0.0, 1.0] from blending functions (Fix: #5968)

Mayank Suman requested to merge mayanksuman/gimp:blend_bug_5968 into master

Rationale: All blending functions should return values in range of [0.0, 1.0]; however under the current implementation, some of the blending functions returning values outside this range (i.e., either negative values or positive values > 1), which leads to issues like #5968.

This merge request consist of three commits:

  1. First commit aims to fix issue #5968 : Some blending functions (for Burn, Linear Burn and Soft Light as mentioned in the issue) are returning negative values (resulting in issue #5968). Hence, in this commit the output from these blending functions is clamped in range of [0.0, 1.0].
  2. Second comment ensures that output from all other blending functions should be in range of [0.0, 1.0].
  3. Third commit simplifies the expression for different blending modes (keeping mathematical accuracy intact). All float divisions inside blend functions are now safe. The reference for blending functions are taken from multiple sources: http://www.simplefilter.de/en/basics/mixmods.html https://en.wikipedia.org/wiki/Blend_modes http://www.pegtop.net/delphi/articles/blendmodes/ https://www.shadertoy.com/view/XdS3RW

The effect can be checked by using the attached file blend_fix_check.xcf. Without this Merge request the output is

Screenshot_from_2021-05-31_21-53-15

After applying this merge request

Screenshot_from_2021-05-31_21-53-44

Expected bug-free behaviour: Both ovals should have same color.

Fixes #5968

Edited by Mayank Suman

Merge request reports