summaryrefslogtreecommitdiffstats
path: root/src/base/ftbitmap.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@google.com>2014-08-08 17:55:11 -0400
committerBehdad Esfahbod <behdad@google.com>2014-08-08 17:59:36 -0400
commit9c745321260bb728ab1cd1c8fd5f075854b2ad49 (patch)
tree86c9ee0214cac2870a94905e4240732413ed768b /src/base/ftbitmap.c
parentec0bab5697bb31ba980810145f62e3799946ec60 (diff)
downloadandroid_external_freetype-staging/cm-12.0-caf.tar.gz
android_external_freetype-staging/cm-12.0-caf.tar.bz2
android_external_freetype-staging/cm-12.0-caf.zip
Update freetype to e1394d56752cac3bd68ab2358a8e1384ce7b9aaastaging/cm-12.0-cafstaging/cm-12.0
Integrated patches from freetype2 git repository, up to hashval e1394d56752cac3bd68ab2358a8e1384ce7b9aaa, which is post-2.5.3. Most recent commit message from freetype git: Minor documentation improvement. Noteworthy patches included: Fix Savannah bug #41697, part 2. Fix Savannah bug #41697, part 1. Bug: 16575323 Change-Id: I4f8f9375afd2540618b3ebf6152d77b743975dce
Diffstat (limited to 'src/base/ftbitmap.c')
-rw-r--r--src/base/ftbitmap.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c
index 182b1cc..6542c79 100644
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -4,7 +4,7 @@
/* */
/* FreeType utility functions for bitmaps (body). */
/* */
-/* Copyright 2004-2009, 2011, 2013 by */
+/* Copyright 2004-2009, 2011, 2013, 2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -375,14 +375,11 @@
}
- FT_Byte
+ static FT_Byte
ft_gray_for_premultiplied_srgb_bgra( const FT_Byte* bgra )
{
- FT_Long a = bgra[3];
- FT_Long b = bgra[0];
- FT_Long g = bgra[1];
- FT_Long r = bgra[2];
- FT_Long l;
+ FT_Byte a = bgra[3];
+ FT_ULong l;
/* Short-circuit transparent color to avoid div-by-zero. */
@@ -397,38 +394,30 @@
*
* http://accessibility.kde.org/hsl-adjusted.php
*
- * We do the computation with integers only.
+ * We do the computation with integers only, applying a gamma of 2.0.
+ * The following will never overflow 32 bits; it is a scaled-up
+ * luminosity with premultiplication not yet undone.
+ *
*/
- /* 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;
-
- /* Apply gamma of 2.0 instead of 2.2. */
- b = FT_MulFix( b, b );
- g = FT_MulFix( g, g );
- r = FT_MulFix( r, r );
-
- /* Apply coefficients. */
- b = FT_MulFix( b, 4731 /* 0.0722 * 65536 */ );
- g = FT_MulFix( g, 46871 /* 0.7152 * 65536 */ );
- r = FT_MulFix( r, 13933 /* 0.2126 * 65536 */ );
-
- l = r + g + b;
+ l = 4731UL /* 0.0722 * 65536 */ * bgra[0] * bgra[0] +
+ 46871UL /* 0.7152 * 65536 */ * bgra[1] * bgra[1] +
+ 13933UL /* 0.2126 * 65536 */ * bgra[2] * bgra[2];
/*
- * Final transparency can be determined this way:
+ * Final transparency can be determined as follows.
*
* - If alpha is zero, we want 0.
* - 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.
+ *
+ * In the actual code, we undo premultiplication and scale down again.
+ *
*/
- return (FT_Byte)( FT_MulFix( 65535 - l, a ) >> 8 );
+ return a - (FT_Byte)( ( l / a ) >> 16 );
}