summaryrefslogtreecommitdiffstats
path: root/libdimension/color_map.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-05-28 18:05:05 -0600
committerTavian Barnes <tavianator@gmail.com>2011-05-28 18:05:05 -0600
commitefd3c1c2b42ffda0c8f7e5cd9b03fba07eead1ea (patch)
treec522f2bafe5def3eb68a79005c049e130ef76b24 /libdimension/color_map.c
parent1bf306d4d93cc21c220a3f31835023e49e84dd2d (diff)
downloaddimension-efd3c1c2b42ffda0c8f7e5cd9b03fba07eead1ea.tar.xz
Handle sRGB gamma correctly.
Diffstat (limited to 'libdimension/color_map.c')
-rw-r--r--libdimension/color_map.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/libdimension/color_map.c b/libdimension/color_map.c
index 6390fe5..e7a25a6 100644
--- a/libdimension/color_map.c
+++ b/libdimension/color_map.c
@@ -35,6 +35,7 @@ dmnsn_new_color_map(void)
typedef struct dmnsn_color_map_payload {
dmnsn_pattern *pattern;
dmnsn_map *map;
+ dmnsn_pigment_map_flags flags;
} dmnsn_color_map_payload;
/** Free a color_map payload. */
@@ -56,7 +57,17 @@ dmnsn_color_map_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v)
dmnsn_color color1, color2;
dmnsn_evaluate_map(payload->map, dmnsn_pattern_value(payload->pattern, v),
&n, &color1, &color2);
- return dmnsn_color_gradient(color1, color2, n);
+
+ if (payload->flags == DMNSN_PIGMENT_MAP_SRGB) {
+ color1 = dmnsn_color_to_sRGB(color1);
+ color2 = dmnsn_color_to_sRGB(color2);
+ }
+ dmnsn_color ret = dmnsn_color_gradient(color1, color2, n);
+ if (payload->flags == DMNSN_PIGMENT_MAP_SRGB) {
+ ret = dmnsn_color_from_sRGB(ret);
+ }
+
+ return ret;
}
/** color_map initialization callback. */
@@ -70,7 +81,8 @@ dmnsn_color_map_initialize_fn(dmnsn_pigment *pigment)
}
dmnsn_pigment *
-dmnsn_new_color_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map)
+dmnsn_new_color_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map,
+ dmnsn_pigment_map_flags flags)
{
dmnsn_pigment *pigment = dmnsn_new_pigment();
@@ -78,6 +90,7 @@ dmnsn_new_color_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map)
= dmnsn_malloc(sizeof(dmnsn_color_map_payload));
payload->pattern = pattern;
payload->map = map;
+ payload->flags = flags;
pigment->pigment_fn = dmnsn_color_map_pigment_fn;
pigment->initialize_fn = dmnsn_color_map_initialize_fn;