Since HCL colorspace is wider than RGB, we should choose a saturation strategy when converting into RGB colorspace. Existing code simply clamps into [0, 1], not so bad.
But it's more useful if hue and luma are preserved, as my code below does. (patch for branches/ImageMagick-6)
As as result, Colorize composite operator will be more compatible with Photoshop's "color" blending mode. Please take it into account.
Code: Select all
--- a/magick/gem.c
+++ b/magick/gem.c
@@ -93,5 +93,6 @@
m,
r,
- x;
+ x,
+ z;
/*
@@ -143,7 +144,21 @@
}
m=luma-(0.298839*r+0.586811*g+0.114350*b);
- *red=ClampToQuantum(QuantumRange*(r+m));
- *green=ClampToQuantum(QuantumRange*(g+m));
- *blue=ClampToQuantum(QuantumRange*(b+m));
+ /* we should choose saturation strategy to clip it into the RGB cube; */
+ /* hue and luma are always preserved and chroma may be changed. */
+ z=1.0;
+ if (m < 0.0)
+ {
+ z=luma/(luma-m);
+ m=0.0;
+ }
+ else
+ if (m+c > 1.0)
+ {
+ z=(1.0-luma)/(m+c-luma);
+ m=1.0-z*c;
+ }
+ *red=ClampToQuantum(QuantumRange*(z*r+m));
+ *green=ClampToQuantum(QuantumRange*(z*g+m));
+ *blue=ClampToQuantum(QuantumRange*(z*b+m));
}
^L