summaryrefslogtreecommitdiffstats
path: root/libdimension/pigment_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/pigment_map.c
parent1bf306d4d93cc21c220a3f31835023e49e84dd2d (diff)
downloaddimension-efd3c1c2b42ffda0c8f7e5cd9b03fba07eead1ea.tar.xz
Handle sRGB gamma correctly.
Diffstat (limited to 'libdimension/pigment_map.c')
-rw-r--r--libdimension/pigment_map.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/libdimension/pigment_map.c b/libdimension/pigment_map.c
index 9864152..e97553f 100644
--- a/libdimension/pigment_map.c
+++ b/libdimension/pigment_map.c
@@ -53,6 +53,7 @@ dmnsn_new_pigment_map(void)
typedef struct dmnsn_pigment_map_payload {
dmnsn_pattern *pattern;
dmnsn_map *map;
+ dmnsn_pigment_map_flags flags;
} dmnsn_pigment_map_payload;
/** Free a pigment_map payload. */
@@ -76,7 +77,17 @@ dmnsn_pigment_map_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v)
&n, &pigment1, &pigment2);
dmnsn_color color1 = pigment1->pigment_fn(pigment1, v);
dmnsn_color color2 = pigment2->pigment_fn(pigment2, v);
- 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;
}
/** pigment_map initialization callback. */
@@ -91,7 +102,8 @@ dmnsn_pigment_map_initialize_fn(dmnsn_pigment *pigment)
}
dmnsn_pigment *
-dmnsn_new_pigment_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map)
+dmnsn_new_pigment_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map,
+ dmnsn_pigment_map_flags flags)
{
dmnsn_pigment *pigment = dmnsn_new_pigment();
@@ -99,6 +111,7 @@ dmnsn_new_pigment_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map)
= dmnsn_malloc(sizeof(dmnsn_pigment_map_payload));
payload->pattern = pattern;
payload->map = map;
+ payload->flags = flags;
pigment->pigment_fn = dmnsn_pigment_map_pigment_fn;
pigment->initialize_fn = dmnsn_pigment_map_initialize_fn;