avoid multiply/divide when converting opaque pixels
This commit is contained in:
parent
6676b9a24f
commit
3f6f3bd3c1
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Benjamin Gilbert
|
* Benjamin Gilbert
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011-2014 Carnegie Mellon University
|
* Copyright (c) 2011-2015 Carnegie Mellon University
|
||||||
*
|
*
|
||||||
* 26/11/11
|
* 26/11/11
|
||||||
* - initial version
|
* - initial version
|
||||||
|
@ -45,6 +45,8 @@
|
||||||
* - add autocrop toggle
|
* - add autocrop toggle
|
||||||
* 9/8/14
|
* 9/8/14
|
||||||
* - do argb -> rgba for associated as well
|
* - do argb -> rgba for associated as well
|
||||||
|
* 27/1/15
|
||||||
|
* - improve unpremultiplication performance for opaque pixels
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -414,13 +416,13 @@ argb2rgba( uint32_t *buf, int n, uint32_t bg )
|
||||||
uint8_t a = x >> 24;
|
uint8_t a = x >> 24;
|
||||||
VipsPel *out = (VipsPel *) p;
|
VipsPel *out = (VipsPel *) p;
|
||||||
|
|
||||||
if( a != 0 ) {
|
if( a == 255 ) {
|
||||||
out[0] = 255 * ((x >> 16) & 255) / a;
|
out[0] = (x >> 16) & 255;
|
||||||
out[1] = 255 * ((x >> 8) & 255) / a;
|
out[1] = (x >> 8) & 255;
|
||||||
out[2] = 255 * (x & 255) / a;
|
out[2] = x & 255;
|
||||||
out[3] = 255;
|
out[3] = 255;
|
||||||
}
|
}
|
||||||
else {
|
else if( a == 0 ) {
|
||||||
/* Use background color.
|
/* Use background color.
|
||||||
*/
|
*/
|
||||||
out[0] = (bg >> 16) & 255;
|
out[0] = (bg >> 16) & 255;
|
||||||
|
@ -428,6 +430,14 @@ argb2rgba( uint32_t *buf, int n, uint32_t bg )
|
||||||
out[2] = bg & 255;
|
out[2] = bg & 255;
|
||||||
out[3] = 255;
|
out[3] = 255;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/* Undo premultiplication.
|
||||||
|
*/
|
||||||
|
out[0] = 255 * ((x >> 16) & 255) / a;
|
||||||
|
out[1] = 255 * ((x >> 8) & 255) / a;
|
||||||
|
out[2] = 255 * (x & 255) / a;
|
||||||
|
out[3] = 255;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue