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:

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


After applying this merge request


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

Fixes #5968

Edited by Mayank Suman

Merge request reports