aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-22 14:20:55 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-22 14:20:55 +0000
commit1f6b4ae0f723317d01b158ce1498dabf4d93a67b (patch)
tree1f35887dac6e449ab2c7ee0226c967f27f858ef0
parent897e66cb0b80dd0294a2ac897b0df568adb49307 (diff)
remove GetGammaFlag from SkFontHost
prep for retooling of gamma support git-svn-id: http://skia.googlecode.com/svn/trunk@2730 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkFontHost.h7
-rw-r--r--src/core/SkPaint.cpp39
-rw-r--r--src/core/SkScalerContext.cpp34
-rw-r--r--src/ports/SkFontHost_FreeType.cpp19
-rw-r--r--src/ports/SkFontHost_gamma.cpp26
-rw-r--r--src/ports/SkFontHost_gamma_none.cpp5
-rw-r--r--src/ports/SkFontHost_mac_atsui.cpp9
-rw-r--r--src/ports/SkFontHost_mac_coretext.cpp44
-rw-r--r--src/ports/SkFontHost_none.cpp11
-rwxr-xr-xsrc/ports/SkFontHost_win.cpp42
10 files changed, 59 insertions, 177 deletions
diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h
index 2ac5165d50..c549519acf 100644
--- a/include/core/SkFontHost.h
+++ b/include/core/SkFontHost.h
@@ -232,12 +232,9 @@ public:
///////////////////////////////////////////////////////////////////////////
- /** Return SkScalerContext gamma flag, or 0, based on the paint that will be
- used to draw something with antialiasing.
- */
- static int ComputeGammaFlag(const SkPaint& paint);
+ /** DEPRECATED -- only called by SkFontHost_FreeType internally
- /** Return NULL or a pointer to 256 bytes for the black (table[0]) and
+ Return NULL or a pointer to 256 bytes for the black (table[0]) and
white (table[1]) gamma tables.
*/
static void GetGammaTables(const uint8_t* tables[2]);
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 06201d3694..e89e281406 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -1266,6 +1266,43 @@ static SkPaint::Hinting computeHinting(const SkPaint& paint) {
return h;
}
+// return true if the paint is just a single color (i.e. not a shader). If its
+// a shader, then we can't compute a const luminance for it :(
+static bool justAColor(const SkPaint& paint, SkColor* color) {
+ if (paint.getShader()) {
+ return false;
+ }
+ SkColor c = paint.getColor();
+ if (paint.getColorFilter()) {
+ c = paint.getColorFilter()->filterColor(c);
+ }
+ if (color) {
+ *color = c;
+ }
+ return true;
+}
+
+// returns 0..kLuminance_Max
+static unsigned computeGammaFlag(const SkPaint& paint) {
+ SkColor c;
+ if (justAColor(paint, &c)) {
+ int r = SkColorGetR(c);
+ int g = SkColorGetG(c);
+ int b = SkColorGetB(c);
+ // compute luminance to 11 bits (0..0x3F)
+ int luminance = r * 2 + g * 5 + b >> 3;
+
+ if (luminance <= 0x40) {
+ return SkScalerContext::kGammaForBlack_Flag;
+ }
+ if (luminance >= 0xA0) {
+ return SkScalerContext::kGammaForWhite_Flag;
+ }
+ }
+ // if we're not a single color, return the middle of the luminance range
+ return 0;
+}
+
// Beyond this size, LCD doesn't appreciably improve quality, but it always
// cost more RAM and draws slower, so we set a cap.
#ifndef SK_MAX_SIZE_FOR_LCDTEXT
@@ -1317,7 +1354,7 @@ void SkScalerContext::MakeRec(const SkPaint& paint,
SkPaint::Style style = paint.getStyle();
SkScalar strokeWidth = paint.getStrokeWidth();
- unsigned flags = SkFontHost::ComputeGammaFlag(paint);
+ unsigned flags = computeGammaFlag(paint);
if (paint.isFakeBoldText()) {
#ifdef SK_USE_FREETYPE_EMBOLDEN
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index 27481f8a1f..8727bb7a17 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -21,9 +21,6 @@
#define ComputeBWRowBytes(width) (((unsigned)(width) + 7) >> 3)
-static const uint8_t* gBlackGammaTable;
-static const uint8_t* gWhiteGammaTable;
-
void SkGlyph::toMask(SkMask* mask) const {
SkASSERT(mask);
@@ -77,15 +74,6 @@ static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag) {
SkScalerContext::SkScalerContext(const SkDescriptor* desc)
: fPathEffect(NULL), fMaskFilter(NULL)
{
- static bool gHaveGammaTables;
- if (!gHaveGammaTables) {
- const uint8_t* tables[2];
- SkFontHost::GetGammaTables(tables);
- gBlackGammaTable = tables[0];
- gWhiteGammaTable = tables[1];
- gHaveGammaTables = true;
- }
-
fBaseGlyphCount = 0;
fNextContext = NULL;
@@ -563,28 +551,6 @@ void SkScalerContext::getImage(const SkGlyph& origGlyph) {
SkMask::FreeImage(dstM.fImage);
}
}
-
- // check to see if we should filter the alpha channel
-
- if (NULL == fMaskFilter &&
- fRec.fMaskFormat != SkMask::kBW_Format &&
- fRec.fMaskFormat != SkMask::kLCD16_Format &&
- fRec.fMaskFormat != SkMask::kLCD32_Format &&
- (fRec.fFlags & (kGammaForBlack_Flag | kGammaForWhite_Flag)) != 0)
- {
- const uint8_t* table = (fRec.fFlags & kGammaForBlack_Flag) ? gBlackGammaTable : gWhiteGammaTable;
- if (NULL != table) {
- uint8_t* dst = (uint8_t*)origGlyph.fImage;
- unsigned rowBytes = origGlyph.rowBytes();
-
- for (int y = origGlyph.fHeight - 1; y >= 0; --y) {
- for (int x = origGlyph.fWidth - 1; x >= 0; --x) {
- dst[x] = table[dst[x]];
- }
- dst += rowBytes;
- }
- }
- }
}
void SkScalerContext::getPath(const SkGlyph& glyph, SkPath* path) {
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 14dd19b419..4bc7870f9c 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -1229,6 +1229,25 @@ void SkScalerContext_FreeType::generateImage(const SkGlyph& glyph) {
SkASSERT(!"unknown glyph format");
goto ERROR;
}
+
+ if ((fRec.fFlags & (kGammaForBlack_Flag | kGammaForBlack_Flag)) &&
+ SkMask::kA8_Format == glyph.fMaskFormat) {
+ const uint8_t* tables[2];
+ SkFontHost::GetGammaTables(tables);
+ int index = (fRec.fFlags & kGammaForBlack_Flag) ? 0 : 1;
+ if (tables[index]) {
+ const uint8_t* SK_RESTRICT table = tables[index];
+ uint8_t* SK_RESTRICT dst = (uint8_t*)glyph.fImage;
+ unsigned rowBytes = glyph.rowBytes();
+
+ for (int y = glyph.fHeight - 1; y >= 0; --y) {
+ for (int x = glyph.fWidth - 1; x >= 0; --x) {
+ dst[x] = table[dst[x]];
+ }
+ dst += rowBytes;
+ }
+ }
+ }
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/ports/SkFontHost_gamma.cpp b/src/ports/SkFontHost_gamma.cpp
index 4a7f2f7677..0d154142fc 100644
--- a/src/ports/SkFontHost_gamma.cpp
+++ b/src/ports/SkFontHost_gamma.cpp
@@ -105,29 +105,3 @@ void SkFontHost::GetGammaTables(const uint8_t* tables[2]) {
tables[1] = gWhiteGamma;
}
-// If the luminance is <= this value, then apply the black gamma table
-#define BLACK_GAMMA_THRESHOLD 0x40
-
-// If the luminance is >= this value, then apply the white gamma table
-#define WHITE_GAMMA_THRESHOLD 0xC0
-
-int SkFontHost::ComputeGammaFlag(const SkPaint& paint) {
- if (paint.getShader() == NULL) {
- SkColor c = paint.getColor();
- int r = SkColorGetR(c);
- int g = SkColorGetG(c);
- int b = SkColorGetB(c);
- int luminance = (r * 2 + g * 5 + b) >> 3;
-
- if (luminance <= BLACK_GAMMA_THRESHOLD) {
- // printf("------ black gamma for [%d %d %d]\n", r, g, b);
- return SkScalerContext::kGammaForBlack_Flag;
- }
- if (luminance >= WHITE_GAMMA_THRESHOLD) {
- // printf("------ white gamma for [%d %d %d]\n", r, g, b);
- return SkScalerContext::kGammaForWhite_Flag;
- }
- }
- return 0;
-}
-
diff --git a/src/ports/SkFontHost_gamma_none.cpp b/src/ports/SkFontHost_gamma_none.cpp
index d54a2fb9a5..18f113c888 100644
--- a/src/ports/SkFontHost_gamma_none.cpp
+++ b/src/ports/SkFontHost_gamma_none.cpp
@@ -21,8 +21,3 @@ void SkFontHost::GetGammaTables(const uint8_t* tables[2])
tables[1] = NULL;
}
-int SkFontHost::ComputeGammaFlag(const SkPaint& paint)
-{
- return 0;
-}
-
diff --git a/src/ports/SkFontHost_mac_atsui.cpp b/src/ports/SkFontHost_mac_atsui.cpp
index 3c3abb4647..a94b042b94 100644
--- a/src/ports/SkFontHost_mac_atsui.cpp
+++ b/src/ports/SkFontHost_mac_atsui.cpp
@@ -505,15 +505,6 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
}
}
-int SkFontHost::ComputeGammaFlag(const SkPaint& paint) {
- return 0;
-}
-
-void SkFontHost::GetGammaTables(const uint8_t* tables[2]) {
- tables[0] = NULL; // black gamma (e.g. exp=1.4)
- tables[1] = NULL; // white gamma (e.g. exp= 1/1.4)
-}
-
///////////////////////////////////////////////////////////////////////////////
struct SkSFNTHeader {
diff --git a/src/ports/SkFontHost_mac_coretext.cpp b/src/ports/SkFontHost_mac_coretext.cpp
index d4c5b55f74..866721e0dd 100644
--- a/src/ports/SkFontHost_mac_coretext.cpp
+++ b/src/ports/SkFontHost_mac_coretext.cpp
@@ -1674,50 +1674,6 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec) {
///////////////////////////////////////////////////////////////////////////
-#include "SkColorFilter.h"
-
-static bool justAColor(const SkPaint& paint, SkColor* color) {
- if (paint.getShader()) {
- return false;
- }
- SkColor c = paint.getColor();
- if (paint.getColorFilter()) {
- c = paint.getColorFilter()->filterColor(c);
- }
- if (color) {
- *color = c;
- }
- return true;
-}
-
-#define BLACK_GAMMA_THRESHOLD 0x40
-#define WHITE_GAMMA_THRESHOLD 0xA0
-
-int SkFontHost::ComputeGammaFlag(const SkPaint& paint) {
- SkColor c;
- if (justAColor(paint, &c)) {
- int r = SkColorGetR(c);
- int g = SkColorGetG(c);
- int b = SkColorGetB(c);
- int luminance = (r * 2 + g * 5 + b) >> 3;
-
- if (luminance <= BLACK_GAMMA_THRESHOLD) {
- return SkScalerContext::kGammaForBlack_Flag;
- }
- if (luminance >= WHITE_GAMMA_THRESHOLD) {
- return SkScalerContext::kGammaForWhite_Flag;
- }
- }
- return 0;
-}
-
-void SkFontHost::GetGammaTables(const uint8_t* tables[2]) {
- tables[0] = NULL; // black gamma (e.g. exp=1.4)
- tables[1] = NULL; // white gamma (e.g. exp= 1/1.4)
-}
-
-///////////////////////////////////////////////////////////////////////////
-
int SkFontHost::CountTables(SkFontID fontID) {
int numTables;
CFArrayRef cfArray;
diff --git a/src/ports/SkFontHost_none.cpp b/src/ports/SkFontHost_none.cpp
index 94bfe0b3ae..d205bfdabc 100644
--- a/src/ports/SkFontHost_none.cpp
+++ b/src/ports/SkFontHost_none.cpp
@@ -79,14 +79,3 @@ SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
}
-///////////////////////////////////////////////////////////////////////////////
-
-int SkFontHost::ComputeGammaFlag(const SkPaint& paint) {
- return 0;
-}
-
-void SkFontHost::GetGammaTables(const uint8_t* tables[2]) {
- tables[0] = NULL; // black gamma (e.g. exp=1.4)
- tables[1] = NULL; // white gamma (e.g. exp= 1/1.4)
-}
-
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index bce43a1e45..141cb41247 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -1322,46 +1322,4 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec) {
}
}
-//////////////////////////////////////////////////////////////////////////
-
-void SkFontHost::GetGammaTables(const uint8_t* tables[2]) {
- tables[0] = NULL;
- tables[1] = NULL;
-}
-
-static bool justAColor(const SkPaint& paint, SkColor* color) {
- if (paint.getShader()) {
- return false;
- }
- SkColor c = paint.getColor();
- if (paint.getColorFilter()) {
- c = paint.getColorFilter()->filterColor(c);
- }
- if (color) {
- *color = c;
- }
- return true;
-}
-
-#define BLACK_GAMMA_THRESHOLD 0x40
-#define WHITE_GAMMA_THRESHOLD 0xA0
-
-int SkFontHost::ComputeGammaFlag(const SkPaint& paint) {
- SkColor c;
- if (justAColor(paint, &c)) {
- int r = SkColorGetR(c);
- int g = SkColorGetG(c);
- int b = SkColorGetB(c);
- int luminance = (r * 2 + g * 5 + b) >> 3;
-
- if (luminance <= BLACK_GAMMA_THRESHOLD) {
- return SkScalerContext::kGammaForBlack_Flag;
- }
- if (luminance >= WHITE_GAMMA_THRESHOLD) {
- return SkScalerContext::kGammaForWhite_Flag;
- }
- }
- return 0;
-}
-
#endif // WIN32