summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-04-22 12:23:25 -0400
committerTavian Barnes <tavianator@gmail.com>2011-04-22 12:23:25 -0400
commit1208ac55766e410f7cac3ad9d6cf588e7846ca64 (patch)
tree3ab0da80e8724fc51c8294f90b34ab8afc3d528e /libdimension
parenta7cd3703ea1ff4686d49888f014c746b56411fdf (diff)
downloaddimension-1208ac55766e410f7cac3ad9d6cf588e7846ca64.tar.xz
Take into account color intensity for filtered transparency in canvas export.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/color.c4
-rw-r--r--libdimension/dimension/color.h2
-rw-r--r--libdimension/gl.c20
-rw-r--r--libdimension/png.c2
4 files changed, 21 insertions, 7 deletions
diff --git a/libdimension/color.c b/libdimension/color.c
index 0b74adf..0af063f 100644
--- a/libdimension/color.c
+++ b/libdimension/color.c
@@ -326,8 +326,8 @@ dmnsn_Luv_from_color(dmnsn_color color, dmnsn_CIE_XYZ white)
return ret;
}
-/** Greyscale color intensity. */
-static double
+/* Greyscale color intensity */
+double
dmnsn_color_intensity(dmnsn_color color)
{
dmnsn_sRGB sRGB = dmnsn_sRGB_from_color(color);
diff --git a/libdimension/dimension/color.h b/libdimension/dimension/color.h
index c9d777b..887c2c7 100644
--- a/libdimension/dimension/color.h
+++ b/libdimension/dimension/color.h
@@ -121,6 +121,8 @@ dmnsn_CIE_Luv dmnsn_Luv_from_color(dmnsn_color color, dmnsn_CIE_XYZ white);
/* Perceptual color manipulation */
+/** Greyscale color intensity. */
+double dmnsn_color_intensity(dmnsn_color color);
/** Add two colors together. */
dmnsn_color dmnsn_color_add(dmnsn_color color1, dmnsn_color color2);
/** Multiply a color's intensity by \p n. */
diff --git a/libdimension/gl.c b/libdimension/gl.c
index 77eefcd..857c7de 100644
--- a/libdimension/gl.c
+++ b/libdimension/gl.c
@@ -112,8 +112,14 @@ dmnsn_gl_write_canvas(const dmnsn_canvas *canvas)
pixel[2] = sRGB.B*UINT16_MAX;
}
- /* color.filter + color.trans is in [0.0, 1.0] by definition */
- pixel[3] = (color.filter + color.trans)*UINT16_MAX;
+ double alpha = dmnsn_color_intensity(color)*color.filter + color.trans;
+ if (alpha <= 0.0) {
+ pixel[3] = 0;
+ } else if (alpha >= 1.0) {
+ pixel[3] = UINT16_MAX;
+ } else {
+ pixel[3] = alpha*UINT16_MAX;
+ }
}
}
@@ -201,6 +207,12 @@ dmnsn_gl_optimizer_fn(const dmnsn_canvas *canvas,
pixel[2] = sRGB.B*UINT16_MAX;
}
- /* color.filter + color.trans is in [0.0, 1.0] by definition */
- pixel[3] = (color.filter + color.trans)*UINT16_MAX;
+ double alpha = dmnsn_color_intensity(color)*color.filter + color.trans;
+ if (alpha <= 0.0) {
+ pixel[3] = 0;
+ } else if (alpha >= 1.0) {
+ pixel[3] = UINT16_MAX;
+ } else {
+ pixel[3] = alpha*UINT16_MAX;
+ }
}
diff --git a/libdimension/png.c b/libdimension/png.c
index 9ff2afc..7a327d6 100644
--- a/libdimension/png.c
+++ b/libdimension/png.c
@@ -94,7 +94,7 @@ dmnsn_png_optimizer_fn(const dmnsn_canvas *canvas,
pixel[2] = sRGB.B*UINT16_MAX;
}
- double alpha = color.filter + color.trans;
+ double alpha = dmnsn_color_intensity(color)*color.filter + color.trans;
if (alpha <= 0.0) {
pixel[3] = 0;
} else if (alpha >= 1.0) {