• Dmitry Kazakov's avatar
    Add the latest lightness blending algorithm by Peter Schatz · 7e3f6c76
    Dmitry Kazakov authored
    "We needed a formula f(x) where f(0) = 0, f(1) = 1, and f(.5) = z,
    where z is the lightness of the color chosen. This can’t be
    linear unless the color chosen is also .5. So I went with
    a quadratic equation and solved it.
    
    f(x) = ax^2 + b^x +c
    0,0 -> 0 = a0^2 + b0 + c -> c = 0
    1,1 -> 1 = a1^2 +b1 + c -> 1 = a + b + 0 -> a = 1 - b
    .5,z -> z = a*.5^2 + b*.5 + c -> z
              = a/4 + b/2 + 0 -> z =
              = 1/4 - b/4 + b/2 -> z = 1/4 + b/4 -> b = 4z - 1
    
    f(x) = (1 - (4z - 1)) * x^2 + (4z - 1) * x
    
    So yes, the equation will be different for every value of
    color chosen, because that’s the only possible way to
    achieve the goal of an equation that runs through (0,0),
    (.5,z), and (1,1)."
    7e3f6c76
KoColorSpacePreserveLightnessUtils.h 3.49 KB