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 | |
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')
-rw-r--r-- | source/blender/blenlib/BLI_math_color.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 28 |
2 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h index 3831ec3cbb4..1af6985deaa 100644 --- a/source/blender/blenlib/BLI_math_color.h +++ b/source/blender/blenlib/BLI_math_color.h @@ -106,6 +106,8 @@ MINLINE void premul_to_straight_v4(float straight[4], const float premul[4]); MINLINE void straight_to_premul_v4(float straight[4], const float premul[4]); MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4]); MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4]); +MINLINE void straight_uchar_to_premul_int(int result[4], const unsigned char color[4]); +MINLINE void premul_int_to_straight_uchar(unsigned char *result, const int color[4]); /************************** Other *************************/ 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__ */ |