Merge pull request #815 from lovell/premultiply-match-types

(Un)premultiply: ~10-15% speedup by matching clipped alpha type with IN/OUT
This commit is contained in:
John Cupitt 2017-11-24 22:08:50 +00:00 committed by GitHub
commit bb0772da51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -78,7 +78,7 @@ G_DEFINE_TYPE( VipsPremultiply, vips_premultiply, VIPS_TYPE_CONVERSION );
for( x = 0; x < width; x++ ) { \
IN alpha = p[bands - 1]; \
IN clip_alpha = VIPS_CLIP( 0, alpha, max_alpha ); \
double nalpha = (double) clip_alpha / max_alpha; \
OUT nalpha = (OUT) clip_alpha / max_alpha; \
\
for( i = 0; i < bands - 1; i++ ) \
q[i] = p[i] * nalpha; \
@ -98,7 +98,7 @@ G_DEFINE_TYPE( VipsPremultiply, vips_premultiply, VIPS_TYPE_CONVERSION );
for( x = 0; x < width; x++ ) { \
IN alpha = p[3]; \
IN clip_alpha = VIPS_CLIP( 0, alpha, max_alpha ); \
double nalpha = (double) clip_alpha / max_alpha; \
OUT nalpha = (OUT) clip_alpha / max_alpha; \
\
q[0] = p[0] * nalpha; \
q[1] = p[1] * nalpha; \

View File

@ -75,8 +75,8 @@ G_DEFINE_TYPE( VipsUnpremultiply, vips_unpremultiply, VIPS_TYPE_CONVERSION );
\
for( x = 0; x < width; x++ ) { \
IN alpha = p[bands - 1]; \
int clip_alpha = VIPS_CLIP( 0, alpha, max_alpha ); \
double nalpha = (double) clip_alpha / max_alpha; \
IN clip_alpha = VIPS_CLIP( 0, alpha, max_alpha ); \
OUT nalpha = (OUT) clip_alpha / max_alpha; \
\
if( clip_alpha == 0 ) \
for( i = 0; i < bands - 1; i++ ) \
@ -99,8 +99,8 @@ G_DEFINE_TYPE( VipsUnpremultiply, vips_unpremultiply, VIPS_TYPE_CONVERSION );
\
for( x = 0; x < width; x++ ) { \
IN alpha = p[3]; \
int clip_alpha = VIPS_CLIP( 0, alpha, max_alpha ); \
double nalpha = (double) clip_alpha / max_alpha; \
IN clip_alpha = VIPS_CLIP( 0, alpha, max_alpha ); \
OUT nalpha = (OUT) clip_alpha / max_alpha; \
\
if( clip_alpha == 0 ) { \
q[0] = 0; \