diff options
author | 2012-02-13 21:37:57 +0000 | |
---|---|---|
committer | 2012-02-13 21:37:57 +0000 | |
commit | 813d38b7a07957f2990ccca52ddab55fe0b1c632 (patch) | |
tree | 1e068b9e27e6f24d91d74331a00669001fab52a1 /src | |
parent | d6e2c7cf08df73503b81cf901de3a3b2b278c2c5 (diff) |
if SK_USE_COLOR_LUMINANCE is defined, then we store 2 bits of each component
to create a per-component-luminance value for the fonthost to use. Only supported
on Mac at the moment (but still disabled by default)
git-svn-id: http://skia.googlecode.com/svn/trunk@3180 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPaint.cpp | 17 | ||||
-rw-r--r-- | src/ports/SkFontHost_mac_coretext.cpp | 25 |
2 files changed, 36 insertions, 6 deletions
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 4026acbae4..86bc49ed54 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1301,6 +1301,14 @@ static SkColor computeLuminanceColor(const SkPaint& paint) { } return c; } + +static U8CPU reduce_lumbits(U8CPU x) { + static const uint8_t gReduceBits[] = { + 0x0, 0x55, 0xAA, 0xFF + }; + return gReduceBits[x >> 6]; +} + #else // returns 0..kLuminance_Max static unsigned computeLuminance(const SkPaint& paint) { @@ -1476,6 +1484,15 @@ void SkScalerContext::MakeRec(const SkPaint& paint, #else rec->setLuminanceBits(0); #endif + } else { +#ifdef SK_USE_COLOR_LUMINANCE + // filter down the luminance color to a finite number of bits + SkColor c = rec->getLuminanceColor(); + c = SkColorSetRGB(reduce_lumbits(SkColorGetR(c)), + reduce_lumbits(SkColorGetG(c)), + reduce_lumbits(SkColorGetB(c))); + rec->setLuminanceColor(c); +#endif } } diff --git a/src/ports/SkFontHost_mac_coretext.cpp b/src/ports/SkFontHost_mac_coretext.cpp index 0500508383..19b91ad298 100644 --- a/src/ports/SkFontHost_mac_coretext.cpp +++ b/src/ports/SkFontHost_mac_coretext.cpp @@ -31,6 +31,7 @@ class SkScalerContext_Mac; + // inline versions of these rect helpers static bool CGRectIsEmpty_inline(const CGRect& rect) { @@ -464,6 +465,12 @@ static SkTypeface* GetDefaultFace() { /////////////////////////////////////////////////////////////////////////////// +extern CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face); +CTFontRef SkTypeface_GetCTFontRef(const SkTypeface* face) { + const SkTypeface_Mac* macface = (const SkTypeface_Mac*)face; + return macface ? macface->fFontRef : NULL; +} + /* This function is visible on the outside. It first searches the cache, and if * not found, returns a new entry (after adding it to the cache). */ @@ -1230,13 +1237,13 @@ void SkScalerContext_Mac::generateImage(const SkGlyph& glyph) { CGRGBPixel* bkPixels = NULL; bool needBlack = true; bool needWhite = true; - + if (!isLCD || (SK_ColorWHITE == lumBits)) { needBlack = false; } else if (SK_ColorBLACK == lumBits) { needWhite = false; } - + if (needBlack) { bkPixels = fBlackScreen.getCG(*this, glyph, false, cgGlyph, &cgRowBytes); cgPixels = bkPixels; @@ -1793,10 +1800,16 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec) { } rec->setHinting(h); - // for compatibility at the moment, discretize luminance to 3 settings - // black, white, gray. This helps with fontcache utilization, since we - // won't create multiple entries that in the end map to the same results. -#ifndef SK_USE_COLOR_LUMINANCE +#ifdef SK_USE_COLOR_LUMINANCE + { + SkColor c = rec->getLuminanceColor(); + // apply our chosen scaling between Black and White cg output + int r = SkColorGetR(c)*2/3; + int g = SkColorGetG(c)*2/3; + int b = SkColorGetB(c)*2/3; + rec->setLuminanceColor(SkColorSetRGB(r, g, b)); + } +#else { unsigned lum = rec->getLuminanceByte(); if (lum <= BLACK_LUMINANCE_LIMIT) { |