diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-09-18 14:04:19 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-09-18 14:04:19 -0400 |
commit | b2e1763c7d54e76a49f6f4434996f37882ae2171 (patch) | |
tree | cefad99c5d5d2724d432c43ef762bc9e23f2eb2e /libdimension/gl.c | |
parent | 126211b917626fe7531310971981ee5d06026625 (diff) | |
download | dimension-b2e1763c7d54e76a49f6f4434996f37882ae2171.tar.xz |
Round correctly when converting colors to integers.
Diffstat (limited to 'libdimension/gl.c')
-rw-r--r-- | libdimension/gl.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/libdimension/gl.c b/libdimension/gl.c index be79094..a2825f9 100644 --- a/libdimension/gl.c +++ b/libdimension/gl.c @@ -37,12 +37,12 @@ dmnsn_gl_optimizer_fn(const dmnsn_canvas *canvas, dmnsn_color color = dmnsn_get_pixel(canvas, x, y); color = dmnsn_remove_filter(color); color = dmnsn_color_to_sRGB(color); + color = dmnsn_color_saturate(color); - /* Saturate R, G, and B to [0, UINT16_MAX] */ - pixel[0] = dmnsn_min(dmnsn_max(color.R, 0.0), 1.0)*UINT16_MAX; - pixel[1] = dmnsn_min(dmnsn_max(color.G, 0.0), 1.0)*UINT16_MAX; - pixel[2] = dmnsn_min(dmnsn_max(color.B, 0.0), 1.0)*UINT16_MAX; - pixel[3] = dmnsn_min(dmnsn_max(color.trans, 0.0), 1.0)*UINT16_MAX; + pixel[0] = lround(color.R*UINT16_MAX); + pixel[1] = lround(color.G*UINT16_MAX); + pixel[2] = lround(color.B*UINT16_MAX); + pixel[3] = lround(color.trans*UINT16_MAX); } /* Optimize canvas for GL drawing */ @@ -97,12 +97,12 @@ dmnsn_gl_write_canvas(const dmnsn_canvas *canvas) color = dmnsn_get_pixel(canvas, x, y); color = dmnsn_remove_filter(color); color = dmnsn_color_to_sRGB(color); + color = dmnsn_color_saturate(color); - /* Saturate R, G, and B to [0, UINT16_MAX] */ - pixel[0] = dmnsn_min(dmnsn_max(color.R, 0.0), 1.0)*UINT16_MAX; - pixel[1] = dmnsn_min(dmnsn_max(color.G, 0.0), 1.0)*UINT16_MAX; - pixel[2] = dmnsn_min(dmnsn_max(color.B, 0.0), 1.0)*UINT16_MAX; - pixel[3] = dmnsn_min(dmnsn_max(color.trans, 0.0), 1.0)*UINT16_MAX; + pixel[0] = lround(color.R*UINT16_MAX); + pixel[1] = lround(color.G*UINT16_MAX); + pixel[2] = lround(color.B*UINT16_MAX); + pixel[3] = lround(color.trans*UINT16_MAX); } } |