summaryrefslogtreecommitdiffstats
path: root/libdimension/color.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-01-13 20:03:09 -0500
committerTavian Barnes <tavianator@gmail.com>2010-01-13 20:03:09 -0500
commitd208c16c438e91e3f12af711b2348e69a54f63f3 (patch)
tree377e3f276aa72fdd5db2dc3c370186a72039a676 /libdimension/color.c
parent511e49993c30aff33a4b3719f1c712d81efedf7a (diff)
downloaddimension-d208c16c438e91e3f12af711b2348e69a54f63f3.tar.xz
New use dmnsn_color_gradient() for weighted reflections.
Diffstat (limited to 'libdimension/color.c')
-rw-r--r--libdimension/color.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/libdimension/color.c b/libdimension/color.c
index 5220dfa..9e1ef4f 100644
--- a/libdimension/color.c
+++ b/libdimension/color.c
@@ -323,31 +323,6 @@ 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)
@@ -363,6 +338,25 @@ dmnsn_color_mul(double n, dmnsn_color color)
return ret;
}
+/* For n in [0, 1] get the color in a gradient between c1 and c2 */
+dmnsn_color
+dmnsn_color_gradient(dmnsn_color c1, dmnsn_color c2, double n)
+{
+ dmnsn_sRGB sRGB1 = dmnsn_sRGB_from_color(c1);
+ dmnsn_sRGB sRGB2 = dmnsn_sRGB_from_color(c2);
+
+ dmnsn_sRGB sRGB = {
+ .R = n*(sRGB2.R - sRGB1.R) + sRGB1.R,
+ .G = n*(sRGB2.G - sRGB1.G) + sRGB1.G,
+ .B = n*(sRGB2.B - sRGB1.B) + sRGB1.B
+ };
+
+ dmnsn_color ret = dmnsn_color_from_sRGB(sRGB);
+ ret.filter = n*(c2.filter - c1.filter) + c1.filter;
+ ret.trans = n*(c2.trans - c1.trans) + c1.trans;
+ return ret;
+}
+
/* Filters `color' through `filter' */
dmnsn_color
dmnsn_color_filter(dmnsn_color color, dmnsn_color filter)