diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-01-04 21:28:58 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-01-04 21:28:58 +0400 |
commit | 499088366421d2a240721267f46bf5ca335e1ed4 (patch) | |
tree | 2e7cf13ee61578a87c0b23b62de2ac8431839828 /source/blender/blenlib/intern/math_color_inline.c | |
parent | 419016928216707f95fa7b94d233b0bb8707ff3c (diff) |
Optimization for speed regression in mipmap generation
Regression was caused by alpha premul cleanup commit and the reason
of slowdown was uchar <-> float conversion which is slow.
Replaced with uchar <-> int conversion which seeps to be accurate
enough and mostly eliminates slowdown.
Slowdown was easy to notice when movie clip is used for 3d vierport
background and undistortion is enabled. In this case every frame
will re-calculate mipmaps.
It's still a nit slower than mipmap generation before cleanup
commit, but couldn't think about extra boost here atm.
Diffstat (limited to 'source/blender/blenlib/intern/math_color_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index b8eeca50db6..f8bb6b81a1d 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -326,4 +326,32 @@ MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float c } } +MINLINE void straight_uchar_to_premul_int(int result[4], const unsigned char color[4]) +{ + int alpha = color[3]; + + result[0] = (color[0] * alpha) / 255; + result[1] = (color[1] * alpha) / 255; + result[2] = (color[2] * alpha) / 255; + result[3] = alpha; +} + +MINLINE void premul_int_to_straight_uchar(unsigned char *result, const int color[4]) +{ + if (color[3] == 0 || color[3] == 255) { + result[0] = color[0]; + result[1] = color[1]; + result[2] = color[2]; + result[3] = color[3]; + } + else { + int alpha = color[3]; + + result[0] = color[0] * 255 / alpha; + result[0] = color[1] * 255 / alpha; + result[0] = color[2] * 255 / alpha; + result[3] = alpha; + } +} + #endif /* __MATH_COLOR_INLINE_C__ */ |