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
This commit is contained in:
parent
897e66cb0b
commit
1f6b4ae0f7
@ -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]);
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,3 @@ void SkFontHost::GetGammaTables(const uint8_t* tables[2])
|
||||
tables[1] = NULL;
|
||||
}
|
||||
|
||||
int SkFontHost::ComputeGammaFlag(const SkPaint& paint)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user