diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-02-15 14:50:29 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-02-15 14:50:29 +0000 |
commit | dd43df99b16b67f7b00457b7fff4b2539da40702 (patch) | |
tree | bc210e0358321164526da231735b5115ebe31c20 /src/core | |
parent | 178964b6f6957762f00b0cfa12734f980fd97ca9 (diff) |
suport A8 grayscale text with COLOR_LUMINANCE build option
git-svn-id: http://skia.googlecode.com/svn/trunk@3197 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkPaint.cpp | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 86bc49ed54..3b9714e304 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1302,13 +1302,29 @@ static SkColor computeLuminanceColor(const SkPaint& paint) { return c; } +#define assert_byte(x) SkASSERT(0 == ((x) >> 8)) + static U8CPU reduce_lumbits(U8CPU x) { static const uint8_t gReduceBits[] = { 0x0, 0x55, 0xAA, 0xFF }; + assert_byte(x); return gReduceBits[x >> 6]; } +static unsigned computeLuminance(SkColor c) { + int r = SkColorGetR(c); + int g = SkColorGetG(c); + int b = SkColorGetB(c); + // compute luminance + // R=0.2126 G=0.7152 B=0.0722 + // scaling by 127 yields 27, 92, 9 + int luminance = r * 27 + g * 92 + b * 9; + luminance >>= 7; + assert_byte(luminance); + return luminance; +} + #else // returns 0..kLuminance_Max static unsigned computeLuminance(const SkPaint& paint) { @@ -1477,22 +1493,38 @@ void SkScalerContext::MakeRec(const SkPaint& paint, */ SkFontHost::FilterRec(rec); - // No need to differentiate gamma if we're BW - if (SkMask::kBW_Format == rec->fMaskFormat) { + switch (rec->fMaskFormat) { + case SkMask::kLCD16_Format: + case SkMask::kLCD32_Format: { #ifdef SK_USE_COLOR_LUMINANCE - rec->setLuminanceColor(0); -#else - rec->setLuminanceBits(0); + // 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 - } else { + break; + } + case SkMask::kA8_Format: { #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); + // filter down the luminance to a single component, since A8 can't + // use per-component information + unsigned lum = computeLuminance(rec->getLuminanceColor()); + // reduce to our finite number of bits + lum = reduce_lumbits(lum); + rec->setLuminanceColor(SkColorSetRGB(lum, lum, lum)); #endif + break; + } + case SkMask::kBW_Format: + // No need to differentiate gamma if we're BW +#ifdef SK_USE_COLOR_LUMINANCE + rec->setLuminanceColor(0); +#else + rec->setLuminanceBits(0); +#endif + break; } } |