restore old no-gamma behavior when requested
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 2 Mar 2012 16:02:07 +0000 (16:02 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 2 Mar 2012 16:02:07 +0000 (16:02 +0000)
Review URL: https://codereview.appspot.com/5722047

git-svn-id: http://skia.googlecode.com/svn/trunk@3303 2bbb7eff-a529-9590-31e7-b0007b416f81

src/ports/SkFontHost_FreeType.cpp

index 39d6a08..da1040d 100644 (file)
@@ -1116,7 +1116,19 @@ static const uint8_t* getGammaTable(U8CPU luminance) {
     return gGammaTables[luminance >> 6];
 }
 
-
+#ifndef SK_USE_COLOR_LUMINANCE
+static const uint8_t* getIdentityTable() {
+    static bool gOnce;
+    static uint8_t gIdentityTable[256];
+    if (!gOnce) {
+        for (int i = 0; i < 256; ++i) {
+            gIdentityTable[i] = i;
+        }
+        gOnce = true;
+    }
+    return gIdentityTable;
+}
+#endif
 
 static uint16_t packTriple(unsigned r, unsigned g, unsigned b) {
     return SkPackRGB16(r >> 3, g >> 2, b >> 3);
@@ -1212,9 +1224,17 @@ void SkScalerContext_FreeType::generateImage(const SkGlyph& glyph) {
     const uint8_t* tableB = getGammaTable(SkColorGetB(lumColor));
 #else
     unsigned lum = fRec.getLuminanceByte();
-    const uint8_t* tableR = getGammaTable(lum);
-    const uint8_t* tableG = getGammaTable(lum);
-    const uint8_t* tableB = getGammaTable(lum);
+    const uint8_t* tableR;
+    const uint8_t* tableG;
+    const uint8_t* tableB;
+
+    bool isWhite = lum >= WHITE_LUMINANCE_LIMIT;
+    bool isBlack = lum <= BLACK_LUMINANCE_LIMIT;
+    if ((gGammaTables[0] || gGammaTables[1]) && (isBlack || isWhite)) {
+        tableR = tableG = tableB = gGammaTables[isBlack ? 0 : 1];
+    } else {
+        tableR = tableG = tableB = getIdentityTable();
+    }
 #endif
 
     switch ( fFace->glyph->format ) {
@@ -1328,7 +1348,9 @@ void SkScalerContext_FreeType::generateImage(const SkGlyph& glyph) {
         goto ERROR;
     }
 
-#ifdef SK_GAMMA_APPLY_TO_A8
+// We used to always do this pre-USE_COLOR_LUMINANCE, but with colorlum,
+// it is optional
+#if defined(SK_GAMMA_APPLY_TO_A8) || !defined(SK_USE_COLOR_LUMINANCE)
     if (SkMask::kA8_Format == glyph.fMaskFormat) {
         SkASSERT(tableR == tableG && tableR == tableB);
         const uint8_t* table = tableR;