diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-01-29 21:23:45 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-01-29 21:23:57 +0300 |
commit | ebc064f5c0c9bc5a5f67c82ea564bf170d135bd0 (patch) | |
tree | 10d09df96b5d5bc0b0c958ae328cdddd19e6f4a7 /source/blender/blenlib/intern/math_color_inline.c | |
parent | 12a38abac6696992bc383a7745c4e15b316936d1 (diff) |
Gooseberry request: Dithering support for byte images when painting on
projection painting (2D will be separate commit).
Diffstat (limited to 'source/blender/blenlib/intern/math_color_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index 9233749d5df..dc62d04ad55 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -31,6 +31,8 @@ #include "BLI_math_color.h" #include "BLI_utildefines.h" +#include "math.h" + #ifndef __MATH_COLOR_INLINE_C__ #define __MATH_COLOR_INLINE_C__ @@ -269,6 +271,24 @@ MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned char return 0; } +MINLINE float dither_random_value(float s, float t) +{ + static float vec[2] = {12.9898f, 78.233f}; + float value; + + value = sinf(s * vec[0] + t * vec[1]) * 43758.5453f; + return value - floorf(value); +} + +MINLINE void float_to_byte_dither_v3(unsigned char b[3], const float f[3], float dither, float s, float t) +{ + float dither_value = dither_random_value(s, t) * 0.005f * dither; + + b[0] = FTOCHAR(dither_value + f[0]); + b[1] = FTOCHAR(dither_value + f[1]); + b[2] = FTOCHAR(dither_value + f[2]); +} + /**************** Alpha Transformations *****************/ MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4]) |