These color mixing formulas are quite complex if you need to also enable the alpha channel. I could not reproduce the mixing Photoshop, but Gimp works like this:
Color mix_hsv(
ColorMixMode::Enum mode,
Color cd,
Color cs)
{
float dh, ds, dv;
float sh, ss, sv;
cd.GetHsv(dh, ds, dv);
cs.GetHsv(sh, ss, sv);
switch (mode) {
case HUE: cs.InitFromHsv(sh, ds, dv); break;
case SATURATION: cs.InitFromHsv(dh, ss, dv); break;
case COLOR: cs.InitFromHsv(sh, ss, dv); break;
case LUMINOSITY: cs.InitFromHsv(dh, ds, sv); break;
}
cs.A = std::min(cd.A, cs.A);
unsigned char cd_A_orig = cd.A;
cd = mix(NORMAL, cd, cs);
cd.A = cd_A_orig;
return cd;
}
If you use pre-multiplex alpha, be sure to process it correctly in the code above. I could not find the mixing code in the Gimp source code, but the resulting images are very similar.
Photoshop's color mixing is clearly different, so if anyone finds a way to implement it, let us all know: o)
miso
source
share