diff options
author | jvanverth <jvanverth@google.com> | 2014-06-09 12:04:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-06-09 12:04:55 -0700 |
commit | 4d517fdbb145cb95e5e935470df331e1b6667cfc (patch) | |
tree | 277a6a4f0296f9a0c49eb6e4f3397bc1ff0d70c1 /src/core/SkPaint.cpp | |
parent | 8405ef9854858b2527bf03b7e7abb1c0da59411d (diff) |
Gamma correction for distance field text.
Handles both non-LCD and LCD text. Uses a texture to look up the gamma correction values for a given text color or luminance.
BUG=skia:
R=reed@google.com, bungeman@google.com, robertphillips@google.com, bsalomon@google.com
Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/258883002
Diffstat (limited to 'src/core/SkPaint.cpp')
-rw-r--r-- | src/core/SkPaint.cpp | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 78d947020b..b08b2c6da7 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1814,10 +1814,8 @@ void SkScalerContext::PostMakeRec(const SkPaint&, SkScalerContext::Rec* rec) { /* * ignoreGamma tells us that the caller just wants metrics that are unaffected - * by gamma correction, so we jam the luminance field to 0 (most common value - * for black text) in hopes that we get a cache hit easier. A better solution - * would be for the fontcache lookup to know to ignore the luminance field - * entirely, but not sure how to do that and keep it fast. + * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1, + * contrast = 0, luminanceColor = transparent black. */ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, const SkMatrix* deviceMatrix, @@ -1827,7 +1825,7 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, SkScalerContext::MakeRec(*this, deviceProperties, deviceMatrix, &rec); if (ignoreGamma) { - rec.setLuminanceColor(0); + rec.ignorePreBlend(); } size_t descSize = sizeof(rec); @@ -1951,9 +1949,10 @@ void SkPaint::descriptorProc(const SkDeviceProperties* deviceProperties, } SkGlyphCache* SkPaint::detachCache(const SkDeviceProperties* deviceProperties, - const SkMatrix* deviceMatrix) const { + const SkMatrix* deviceMatrix, + bool ignoreGamma) const { SkGlyphCache* cache; - this->descriptorProc(deviceProperties, deviceMatrix, DetachDescProc, &cache, false); + this->descriptorProc(deviceProperties, deviceMatrix, DetachDescProc, &cache, ignoreGamma); return cache; } @@ -1969,6 +1968,33 @@ SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re return maskGamma.preBlend(rec.getLuminanceColor()); } +size_t SkScalerContext::GetGammaLUTSize(SkScalar contrast, SkScalar paintGamma, + SkScalar deviceGamma, int* width, int* height) { + SkAutoMutexAcquire ama(gMaskGammaCacheMutex); + const SkMaskGamma& maskGamma = cachedMaskGamma(contrast, + paintGamma, + deviceGamma); + + maskGamma.getGammaTableDimensions(width, height); + size_t size = (*width)*(*height)*sizeof(uint8_t); + + return size; +} + +void SkScalerContext::GetGammaLUTData(SkScalar contrast, SkScalar paintGamma, SkScalar deviceGamma, + void* data) { + SkAutoMutexAcquire ama(gMaskGammaCacheMutex); + const SkMaskGamma& maskGamma = cachedMaskGamma(contrast, + paintGamma, + deviceGamma); + int width, height; + maskGamma.getGammaTableDimensions(&width, &height); + size_t size = width*height*sizeof(uint8_t); + const uint8_t* gammaTables = maskGamma.getGammaTables(); + memcpy(data, gammaTables, size); +} + + /////////////////////////////////////////////////////////////////////////////// #include "SkStream.h" @@ -2557,7 +2583,7 @@ SkTextToPathIter::SkTextToPathIter( const char text[], size_t length, fPaint.setPathEffect(NULL); } - fCache = fPaint.detachCache(NULL, NULL); + fCache = fPaint.detachCache(NULL, NULL, false); SkPaint::Style style = SkPaint::kFill_Style; SkPathEffect* pe = NULL; |