Commit 35576bf067624e18397e3a72148b82c7cf3b849b

Alexei Podtelezhnikov 2014-07-11T22:40:34

[base] Clean up bitmap conversion. * src/base/ftbitmap.c (ft_gray_for_premultiplied_srgb_bgra): Use appropriate FT_DivFix and remove superfluous upscaling.

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 );
   }