diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-25 18:16:22 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-25 18:16:22 +0400 |
commit | c2d5c72245cfebb612ccb11c60777262c9c5994a (patch) | |
tree | b5636494f274c84d9e47d61c32866f222a34c455 /source/blender/blenlib | |
parent | 631f2b94efe9d438a6a8027279d9e665f31653b6 (diff) |
Fix part of #34640: colors darkening when using the vertex paint blur tool.
The problem was that vertex colors only have 8 bits of precision, and integer
division always rounds down, so after some color blending iterations everything
gets darker. Instead use integer division that behaves like round() instead of
floor() for blending operations.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_base.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 67c1ffcebc0..04cf0b9d275 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -213,6 +213,8 @@ MINLINE int is_power_of_2_i(int n); MINLINE int power_of_2_max_i(int n); MINLINE int power_of_2_min_i(int n); +MINLINE int divide_round_i(int a, int b); + MINLINE float shell_angle_to_dist(const float angle); #if (defined(WIN32) || defined(WIN64)) && !defined(FREE_WINDOWS) diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index d7c950f651a..61af5b5079a 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -145,6 +145,13 @@ MINLINE int power_of_2_min_i(int n) return n; } +/* integer division that rounds 0.5 up, particularly useful for color blending + * with integers, to avoid gradual darkening when rounding down */ +MINLINE int divide_round_i(int a, int b) +{ + return (2*a + b)/(2*b); +} + MINLINE unsigned int highest_order_bit_i(unsigned int n) { n |= (n >> 1); |