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
This commit is contained in:
parent
d6e2c7cf08
commit
813d38b7a0
@ -17,7 +17,6 @@
|
||||
#include "SkPoint.h"
|
||||
|
||||
//#define SK_USE_COLOR_LUMINANCE
|
||||
//#define USE_FULL_LUMI
|
||||
|
||||
class SkDescriptor;
|
||||
class SkMaskFilter;
|
||||
@ -236,34 +235,12 @@ public:
|
||||
}
|
||||
|
||||
#ifdef SK_USE_COLOR_LUMINANCE
|
||||
static unsigned ColorToLumBits(U8CPU x) {
|
||||
SkASSERT(x <= 0xFF);
|
||||
return x >> 7;
|
||||
}
|
||||
static U8CPU LumBitsToColor(unsigned x) {
|
||||
SkASSERT(x <= 1);
|
||||
return x * 0xFF;
|
||||
}
|
||||
|
||||
SkColor getLuminanceColor() const {
|
||||
#ifdef USE_FULL_LUMI
|
||||
return fLumBits;
|
||||
#else
|
||||
unsigned bits = fLumBits;
|
||||
return SkColorSetRGB(LumBitsToColor((bits >> 2) & 1),
|
||||
LumBitsToColor((bits >> 1) & 1),
|
||||
LumBitsToColor((bits >> 0) & 1));
|
||||
#endif
|
||||
}
|
||||
|
||||
void setLuminanceColor(SkColor c) {
|
||||
#ifdef USE_FULL_LUMI
|
||||
fLumBits = c;
|
||||
#else
|
||||
fLumBits = (ColorToLumBits(SkColorGetR(c)) << 2) |
|
||||
(ColorToLumBits(SkColorGetG(c)) << 1) |
|
||||
(ColorToLumBits(SkColorGetB(c)) << 0);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
unsigned getLuminanceBits() const {
|
||||
|
@ -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) {
|
||||
@ -1475,6 +1483,15 @@ void SkScalerContext::MakeRec(const SkPaint& paint,
|
||||
rec->setLuminanceColor(0);
|
||||
#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
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user