diff options
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. */ |