diff options
author | 2011-11-22 14:20:55 +0000 | |
---|---|---|
committer | 2011-11-22 14:20:55 +0000 | |
commit | 1f6b4ae0f723317d01b158ce1498dabf4d93a67b (patch) | |
tree | 1f35887dac6e449ab2c7ee0226c967f27f858ef0 /src/core | |
parent | 897e66cb0b80dd0294a2ac897b0df568adb49307 (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
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkPaint.cpp | 39 | ||||
-rw-r--r-- | src/core/SkScalerContext.cpp | 34 |
2 files changed, 38 insertions, 35 deletions
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) { |