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/dimension | |
parent | 126211b917626fe7531310971981ee5d06026625 (diff) | |
download | dimension-b2e1763c7d54e76a49f6f4434996f37882ae2171.tar.xz |
Round correctly when converting colors to integers.
Diffstat (limited to 'libdimension/dimension')
-rw-r--r-- | libdimension/dimension/color.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libdimension/dimension/color.h b/libdimension/dimension/color.h index ecf7005..9664d22 100644 --- a/libdimension/dimension/color.h +++ b/libdimension/dimension/color.h @@ -81,6 +81,18 @@ dmnsn_color_is_black(dmnsn_color color) && fabs(color.trans) < dmnsn_epsilon; } +/** Saturate the color components to [0.0, 1.0]. */ +DMNSN_INLINE dmnsn_color +dmnsn_color_saturate(dmnsn_color color) +{ + color.R = dmnsn_min(dmnsn_max(color.R, 0.0), 1.0); + color.G = dmnsn_min(dmnsn_max(color.G, 0.0), 1.0); + color.B = dmnsn_min(dmnsn_max(color.B, 0.0), 1.0); + color.trans = dmnsn_min(dmnsn_max(color.trans, 0.0), 1.0); + color.filter = dmnsn_min(dmnsn_max(color.filter, 0.0), 1.0); + return color; +} + /* Perceptual color manipulation */ /** Convert from sRGB space. */ |