[base] Clean up bitmap conversion. * src/base/ftbitmap.c (ft_gray_for_premultiplied_srgb_bgra): Use appropriate FT_DivFix and remove superfluous upscaling.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/ChangeLog b/ChangeLog
index 30626ce..d1c241a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-07-11 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [base] Clean up bitmap conversion.
+
+ * src/base/ftbitmap.c (ft_gray_for_premultiplied_srgb_bgra): Use
+ appropriate FT_DivFix and remove superfluous upscaling.
+
2014-07-04 Alexei Podtelezhnikov <apodtele@gmail.com>
[base] Small optimization of the ancient code.
diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c
index 5606745..d0d1ebb 100644
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -401,10 +401,9 @@
*/
/* Undo premultification, get the number in a 16.16 form. */
- b = FT_MulDiv( b, 65536, a );
- g = FT_MulDiv( g, 65536, a );
- r = FT_MulDiv( r, 65536, a );
- a = a * 256;
+ b = FT_DivFix( b, a );
+ g = FT_DivFix( g, a );
+ r = FT_DivFix( r, a );
/* Apply gamma of 2.0 instead of 2.2. */
b = FT_MulFix( b, b );
@@ -425,10 +424,10 @@
* - If alpha is zero and luminosity is zero, we want 255.
* - If alpha is zero and luminosity is one, we want 0.
*
- * So the formula is a * (1 - l).
+ * So the formula is a * (1 - l) = a - l * a.
*/
- return (FT_Byte)( FT_MulFix( 65535 - l, a ) >> 8 );
+ return a - (FT_Byte)FT_MulFix( l, a );
}