summaryrefslogtreecommitdiffstats
path: root/libdimension/color.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-11-09 21:36:35 -0500
committerTavian Barnes <tavianator@gmail.com>2009-11-09 21:37:59 -0500
commit531368437bfb865247204fa78235428028170081 (patch)
tree151c642f624abe8c892532fb280fde08fa5e5d80 /libdimension/color.c
parentccaf1d7af81223169fba71fe613f439df87b6fd3 (diff)
downloaddimension-531368437bfb865247204fa78235428028170081.tar.xz
Correct dmnsn_color_illuminate().
Diffstat (limited to 'libdimension/color.c')
-rw-r--r--libdimension/color.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/libdimension/color.c b/libdimension/color.c
index 4589824..2089326 100644
--- a/libdimension/color.c
+++ b/libdimension/color.c
@@ -301,15 +301,23 @@ dmnsn_color_illuminate(dmnsn_color light, dmnsn_color color)
dmnsn_CIE_Lab Lab1 = dmnsn_Lab_from_color(light, dmnsn_whitepoint);
dmnsn_CIE_Lab Lab2 = dmnsn_Lab_from_color(color, dmnsn_whitepoint);
- double dot = Lab1.L*Lab2.L + Lab1.a*Lab2.a + Lab1.b*Lab2.b;
- double norm = sqrt(Lab2.L*Lab2.L + Lab2.a*Lab2.a + Lab2.b*Lab2.b);
-
- if (norm == 0.0)
- return dmnsn_black;
-
- dmnsn_CIE_Lab Lab = { .L = dot*Lab2.L/norm/100.0,
- .a = dot*Lab2.a/norm,
- .b = dot*Lab2.b/norm };
+ /*
+ * This is derived from the simple illumination equation for RGB color:
+ * RGB' = (R_light*R_color, G_light*G_color, B_light*B_color)
+ *
+ * CIE L*a*b* may be transformed to an RGB colorspace by considering `a'
+ * to be the green -> magenta opponent process (from negative to positive),
+ * and `b' to be the blue -> yellow opponent process:
+ * RGB = (L + a + b, L - a + b, L + a - b)
+ *
+ * The reverse transformation is:
+ * Lab = ((G + B)/2, (R - G)/2, (R - B)/2)
+ */
+ dmnsn_CIE_Lab Lab = {
+ .L = (Lab1.L*Lab2.L + (Lab1.b - Lab1.a)*(Lab2.b - Lab2.a))/100.0,
+ .a = (Lab1.a*(Lab2.L + Lab2.b) + Lab2.a*(Lab1.L + Lab1.b))/100.0,
+ .b = (Lab1.b*(Lab2.L + Lab2.a) + Lab2.b*(Lab1.L + Lab1.a))/100.0
+ };
dmnsn_color ret = dmnsn_color_from_Lab(Lab, dmnsn_whitepoint);
ret.filter = color.filter;
@@ -318,7 +326,7 @@ dmnsn_color_illuminate(dmnsn_color light, dmnsn_color color)
return ret;
}
-/* Find the perceptual difference between two colors, using CIE L*a*b*. */
+/* Find the perceptual difference between two colors, using CIE L*a*b* */
double
dmnsn_color_difference(dmnsn_color color1, dmnsn_color color2)
{