mypaint / libmypaint

libmypaint, a.k.a. "brushlib", is a library for making brushstrokes which is used by MyPaint and other projects.
http://mypaint.org
Other
307 stars 87 forks source link

possible issue in mix_colors (helpers.c) #185

Open teadrinker opened 2 years ago

teadrinker commented 2 years ago

I was comparing color blending functions and I noticed this one did not seem to be symmetrical (swapping a,b and using 1-t instead if t, is expected to give the same result)

I think the reason is that this expression in helpers.c

opa_a * a[3] / (a[3] + b[3] * opa_b);

Should probably be

opa_a * a[3] / (opa_a * a[3] + b[3] * opa_b);

since blending.hpp from mypaint is using

Sa / (Sa + one_minus_Sa * dst[i+3] / (1<<15));

Not entirely sure since I translated the code to another language first, but adding opa_a seem to solve the issue I was having, so I will just leave this here...