summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-12-11 16:42:04 -0500
committerTavian Barnes <tavianator@gmail.com>2010-12-11 16:42:04 -0500
commit16d25a964b90c7902606c06c8a26676820288517 (patch)
tree1c266e06355a0fb7bd307e54bc2e49501a91e986
parent97c10ba7d73ed0e7505ad2f804fe79aec4f55239 (diff)
downloaddimension-16d25a964b90c7902606c06c8a26676820288517.tar.xz
color.c fixes.
-rw-r--r--libdimension/color.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/libdimension/color.c b/libdimension/color.c
index 6d2078f..02fc07e 100644
--- a/libdimension/color.c
+++ b/libdimension/color.c
@@ -350,13 +350,12 @@ dmnsn_color_add(dmnsn_color c1, dmnsn_color c2)
dmnsn_color ret = dmnsn_color_from_sRGB(sRGB);
- /* Weighted average of transparencies by intensity */
- double L1 = dmnsn_color_intensity(c1)*(1.0 - c1.filter - c1.trans);
- double L2 = dmnsn_color_intensity(c2)*(1.0 - c2.filter - c2.trans);
- if (L1 + L2) {
- ret.filter = (L1*c1.filter + L2*c2.filter)/(L1 + L2);
- ret.trans = (L1*c1.trans + L2*c2.trans) /(L1 + L2);
+ double n1 = dmnsn_color_intensity(c1), n2 = dmnsn_color_intensity(c2);
+ if (n1 + n2 != 0.0) {
+ ret.filter = (n1*c1.filter + n2*c2.filter)/(n1 + n2);
}
+ ret.trans = c1.trans + c2.trans;
+
return ret;
}
@@ -403,8 +402,8 @@ dmnsn_color_filter(dmnsn_color color, dmnsn_color filter)
dmnsn_color_illuminate(filter, color));
dmnsn_color ret = dmnsn_color_add(transmitted, filtered);
- ret.filter = filter.filter*(color.filter + color.trans)/2
- + color.filter*(filter.filter + filter.trans)/2;
+ ret.filter = color.filter*dmnsn_color_intensity(filtered)
+ + filter.filter*color.trans + filter.trans*color.filter;
ret.trans = filter.trans*color.trans;
return ret;
}