diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-01-09 20:38:51 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-01-09 20:38:51 -0500 |
commit | 6787a9219748575cd63aaadd483f49a4fd83b543 (patch) | |
tree | 24291f7948ce2e7712260d6b76e48b68c086987e /libdimension/color.c | |
parent | e541fdb578ee9755c78d4f835edf0fa6bf8aea92 (diff) | |
download | dimension-6787a9219748575cd63aaadd483f49a4fd83b543.tar.xz |
Implement reflection.
Diffstat (limited to 'libdimension/color.c')
-rw-r--r-- | libdimension/color.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/libdimension/color.c b/libdimension/color.c index 4421224..8201a8f 100644 --- a/libdimension/color.c +++ b/libdimension/color.c @@ -292,7 +292,7 @@ dmnsn_sRGB_from_color(dmnsn_color color) return sRGB; } -/* Add two colors in a perceptually correct manner, using CIE L*a*b*. */ +/* Add two colors */ dmnsn_color dmnsn_color_add(dmnsn_color c1, dmnsn_color c2) { @@ -317,6 +317,31 @@ dmnsn_color_add(dmnsn_color c1, dmnsn_color c2) return ret; } +/* Subtract two colors */ +dmnsn_color +dmnsn_color_sub(dmnsn_color c1, dmnsn_color c2) +{ + dmnsn_sRGB sRGB1 = dmnsn_sRGB_from_color(c1); + dmnsn_sRGB sRGB2 = dmnsn_sRGB_from_color(c2); + + dmnsn_sRGB sRGB = { + .R = sRGB1.R - sRGB2.R, + .G = sRGB1.G - sRGB2.G, + .B = sRGB1.B - sRGB2.B + }; + + dmnsn_color ret = dmnsn_color_from_sRGB(sRGB); + + /* Weighted average of transparencies by intensity */ + dmnsn_CIE_Lab Lab1 = dmnsn_Lab_from_color(ret, dmnsn_whitepoint); + dmnsn_CIE_Lab Lab2 = dmnsn_Lab_from_color(ret, dmnsn_whitepoint); + if (Lab1.L + Lab2.L) { + ret.filter = (Lab1.L*c1.filter - Lab2.L*c2.filter)/(Lab1.L + Lab2.L); + ret.trans = (Lab1.L*c1.trans - Lab2.L*c2.trans )/(Lab1.L + Lab2.L); + } + return ret; +} + /* Multiply a color by a scalar */ dmnsn_color dmnsn_color_mul(double n, dmnsn_color color) |