summaryrefslogtreecommitdiffstats
path: root/libdimension/color.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-04-12 14:09:46 -0400
committerTavian Barnes <tavianator@gmail.com>2011-04-12 14:09:46 -0400
commitb6d6b32a6f02965e1d088adaa6a0e051d620b878 (patch)
treec14af77cd111e37ac8cfb8b4cacf5e2229266ccf /libdimension/color.c
parent167fe4ff63713d7267eb1f11651e969b0dc108f8 (diff)
downloaddimension-b6d6b32a6f02965e1d088adaa6a0e051d620b878.tar.xz
Fix up translucency semantics and API.
Diffstat (limited to 'libdimension/color.c')
-rw-r--r--libdimension/color.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/libdimension/color.c b/libdimension/color.c
index 2424e61..0b74adf 100644
--- a/libdimension/color.c
+++ b/libdimension/color.c
@@ -393,21 +393,42 @@ dmnsn_color_gradient(dmnsn_color c1, dmnsn_color c2, double n)
return ret;
}
-/* Filters `color' through `filter' */
+/* Filters `light' through `filter' */
dmnsn_color
-dmnsn_color_filter(dmnsn_color color, dmnsn_color filter)
+dmnsn_filter_light(dmnsn_color light, dmnsn_color filter)
{
- dmnsn_color transmitted = dmnsn_color_mul(filter.trans, color);
- dmnsn_color filtered = dmnsn_color_mul(filter.filter,
- dmnsn_color_illuminate(filter, color));
-
+ dmnsn_color transmitted = dmnsn_color_mul(filter.trans, light);
+ dmnsn_color filtered = dmnsn_color_mul(
+ filter.filter,
+ dmnsn_color_illuminate(filter, light)
+ );
dmnsn_color ret = dmnsn_color_add(transmitted, filtered);
- ret.filter = color.filter*dmnsn_color_intensity(filtered)
- + filter.filter*color.trans + filter.trans*color.filter;
- ret.trans = filter.trans*color.trans;
+ ret.filter = light.filter*dmnsn_color_intensity(filtered)
+ + filter.filter*light.trans + filter.trans*light.filter;
+ ret.trans = filter.trans*light.trans;
+ return ret;
+}
+
+/* Adds the background contribution, `filtered', to `filter' */
+dmnsn_color
+dmnsn_apply_translucency(dmnsn_color filtered, dmnsn_color filter)
+{
+ dmnsn_color ret = dmnsn_color_add(
+ dmnsn_color_mul(1.0 - (filter.filter + filter.trans), filter),
+ filtered
+ );
+ ret.filter = filtered.filter;
+ ret.trans = filtered.trans;
return ret;
}
+/* Adds the background contribution of `color' to `filter' */
+dmnsn_color
+dmnsn_apply_filter(dmnsn_color color, dmnsn_color filter)
+{
+ return dmnsn_apply_translucency(dmnsn_filter_light(color, filter), filter);
+}
+
/* Illuminates `color' with `light' */
dmnsn_color
dmnsn_color_illuminate(dmnsn_color light, dmnsn_color color)