Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: src/core/SkPaint.cpp

Issue 258883002: Gamma correction for distance field text. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comments for the magic bold factor Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPaint.h" 8 #include "SkPaint.h"
9 #include "SkAnnotation.h" 9 #include "SkAnnotation.h"
10 #include "SkAutoKern.h" 10 #include "SkAutoKern.h"
(...skipping 1755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 SkSafeUnref(gMaskGamma); 1766 SkSafeUnref(gMaskGamma);
1767 gMaskGamma = NULL; 1767 gMaskGamma = NULL;
1768 SkDEBUGCODE(gContrast = SK_ScalarMin;) 1768 SkDEBUGCODE(gContrast = SK_ScalarMin;)
1769 SkDEBUGCODE(gPaintGamma = SK_ScalarMin;) 1769 SkDEBUGCODE(gPaintGamma = SK_ScalarMin;)
1770 SkDEBUGCODE(gDeviceGamma = SK_ScalarMin;) 1770 SkDEBUGCODE(gDeviceGamma = SK_ScalarMin;)
1771 } 1771 }
1772 1772
1773 /** 1773 /**
1774 * We ensure that the rec is self-consistent and efficient (where possible) 1774 * We ensure that the rec is self-consistent and efficient (where possible)
1775 */ 1775 */
1776 void SkScalerContext::PostMakeRec(const SkPaint&, SkScalerContext::Rec* rec) { 1776 void SkScalerContext::PostMakeRec(const SkPaint& paint, SkScalerContext::Rec* re c) {
1777 /** 1777 /**
1778 * If we're asking for A8, we force the colorlum to be gray, since that 1778 * If we're asking for A8, we force the colorlum to be gray, since that
1779 * limits the number of unique entries, and the scaler will only look at 1779 * limits the number of unique entries, and the scaler will only look at
1780 * the lum of one of them. 1780 * the lum of one of them.
1781 */ 1781 */
1782 switch (rec->fMaskFormat) { 1782 switch (rec->fMaskFormat) {
1783 case SkMask::kLCD16_Format: 1783 case SkMask::kLCD16_Format:
1784 case SkMask::kLCD32_Format: { 1784 case SkMask::kLCD32_Format: {
1785 // filter down the luminance color to a finite number of bits 1785 // filter down the luminance color to a finite number of bits
1786 SkColor color = rec->getLuminanceColor(); 1786 SkColor color = rec->getLuminanceColor();
(...skipping 15 matching lines...) Expand all
1802 // reduce to our finite number of bits 1802 // reduce to our finite number of bits
1803 color = SkColorSetRGB(lum, lum, lum); 1803 color = SkColorSetRGB(lum, lum, lum);
1804 rec->setLuminanceColor(SkMaskGamma::CanonicalColor(color)); 1804 rec->setLuminanceColor(SkMaskGamma::CanonicalColor(color));
1805 break; 1805 break;
1806 } 1806 }
1807 case SkMask::kBW_Format: 1807 case SkMask::kBW_Format:
1808 // No need to differentiate gamma if we're BW 1808 // No need to differentiate gamma if we're BW
1809 rec->ignorePreBlend(); 1809 rec->ignorePreBlend();
1810 break; 1810 break;
1811 } 1811 }
1812
1813 /**
1814 * If we're using distance fields we need to reset the rec to default value s
1815 */
1816 if (paint.isDistanceFieldTextTEMP()) {
1817 rec->ignorePreBlend();
1818
1819 rec->fFlags |= SkScalerContext::kSubpixelPositioning_Flag;
1820 rec->fFlags &= ~SkScalerContext::kForceAutohinting_Flag;
reed1 2014/05/28 19:45:17 other than preblend, this rest of this change seem
jvanverth1 2014/05/29 18:53:49 This was done in GrDistanceFieldTextContext::init(
1821
1822 if (SkMask::kLCD16_Format == rec->fMaskFormat ||
1823 SkMask::kLCD32_Format == rec->fMaskFormat) {
1824 rec->fMaskFormat = SkMask::kA8_Format;
1825 }
1826 rec->setHinting(SkPaint::kNo_Hinting);
1827 }
1828
1812 } 1829 }
1813 1830
1814 #define MIN_SIZE_FOR_EFFECT_BUFFER 1024 1831 #define MIN_SIZE_FOR_EFFECT_BUFFER 1024
1815 1832
1816 #ifdef SK_DEBUG 1833 #ifdef SK_DEBUG
1817 #define TEST_DESC 1834 #define TEST_DESC
1818 #endif 1835 #endif
1819 1836
1820 /* 1837 /*
1821 * ignoreGamma tells us that the caller just wants metrics that are unaffected 1838 * ignoreGamma tells us that the caller just wants metrics that are unaffected
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 */ 1984 */
1968 //static 1985 //static
1969 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re c& rec) { 1986 SkMaskGamma::PreBlend SkScalerContext::GetMaskPreBlend(const SkScalerContext::Re c& rec) {
1970 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); 1987 SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
1971 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(), 1988 const SkMaskGamma& maskGamma = cachedMaskGamma(rec.getContrast(),
1972 rec.getPaintGamma(), 1989 rec.getPaintGamma(),
1973 rec.getDeviceGamma()); 1990 rec.getDeviceGamma());
1974 return maskGamma.preBlend(rec.getLuminanceColor()); 1991 return maskGamma.preBlend(rec.getLuminanceColor());
1975 } 1992 }
1976 1993
1994 void* SkScalerContext::getGammaLUTData(int& width, int& height, SkScalar contras t,
reed1 2014/05/28 19:45:17 style again: use pointers for out-params
jvanverth1 2014/05/29 18:53:49 Done.
1995 SkScalar paintGamma, SkScalar deviceGamma ) {
1996 SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
1997 const SkMaskGamma& maskGamma = cachedMaskGamma(contrast,
1998 paintGamma,
1999 deviceGamma);
2000 const uint8_t* gammaTables = maskGamma.getGammaTables(width, height);
2001 size_t size = width*height*sizeof(uint8_t);
2002 void* data = SkNEW_ARRAY(uint8_t, size);
2003 memcpy(data, gammaTables, size);
2004
2005 return data;
2006 }
2007
2008
1977 /////////////////////////////////////////////////////////////////////////////// 2009 ///////////////////////////////////////////////////////////////////////////////
1978 2010
1979 #include "SkStream.h" 2011 #include "SkStream.h"
1980 2012
1981 static uintptr_t asint(const void* p) { 2013 static uintptr_t asint(const void* p) {
1982 return reinterpret_cast<uintptr_t>(p); 2014 return reinterpret_cast<uintptr_t>(p);
1983 } 2015 }
1984 2016
1985 union Scalar32 { 2017 union Scalar32 {
1986 SkScalar fScalar; 2018 SkScalar fScalar;
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2734 } 2766 }
2735 #ifdef SK_BUILD_FOR_ANDROID 2767 #ifdef SK_BUILD_FOR_ANDROID
2736 if (dirty & kPaintOptionsAndroid_DirtyBit) { 2768 if (dirty & kPaintOptionsAndroid_DirtyBit) {
2737 SkPaintOptionsAndroid options; 2769 SkPaintOptionsAndroid options;
2738 options.unflatten(buffer); 2770 options.unflatten(buffer);
2739 paint->setPaintOptionsAndroid(options); 2771 paint->setPaintOptionsAndroid(options);
2740 } 2772 }
2741 #endif 2773 #endif
2742 SkASSERT(dirty == paint->fDirtyBits); 2774 SkASSERT(dirty == paint->fDirtyBits);
2743 } 2775 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698