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

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: Unref gamma texture 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()) {
reed1 2014/06/03 19:46:44 What is the expected lifespan of this TEMP flag?
jvanverth1 2014/06/05 18:18:23 I don't know. Though I just realized a problem wit
jvanverth1 2014/06/06 15:34:44 Done. I was not able to use the DeviceProperties b
1817 rec->ignorePreBlend();
1818
1819 rec->fFlags |= SkScalerContext::kSubpixelPositioning_Flag;
1820 rec->fFlags &= ~SkScalerContext::kForceAutohinting_Flag;
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 size_t SkScalerContext::getGammaLUTSize(SkScalar contrast, SkScalar paintGamma,
1995 SkScalar deviceGamma, int* width, int* h eight) {
1996 SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
1997 const SkMaskGamma& maskGamma = cachedMaskGamma(contrast,
1998 paintGamma,
1999 deviceGamma);
2000
2001 maskGamma.getGammaTableDimensions(width, height);
2002 size_t size = (*width)*(*height)*sizeof(uint8_t);
2003
2004 return size;
2005 }
2006
2007 void SkScalerContext::getGammaLUTData(SkScalar contrast, SkScalar paintGamma, Sk Scalar deviceGamma,
2008 void* data) {
2009 SkAutoMutexAcquire ama(gMaskGammaCacheMutex);
2010 const SkMaskGamma& maskGamma = cachedMaskGamma(contrast,
2011 paintGamma,
2012 deviceGamma);
2013 int width, height;
2014 maskGamma.getGammaTableDimensions(&width, &height);
2015 size_t size = width*height*sizeof(uint8_t);
2016 const uint8_t* gammaTables = maskGamma.getGammaTables();
2017 memcpy(data, gammaTables, size);
2018 }
2019
2020
1977 /////////////////////////////////////////////////////////////////////////////// 2021 ///////////////////////////////////////////////////////////////////////////////
1978 2022
1979 #include "SkStream.h" 2023 #include "SkStream.h"
1980 2024
1981 static uintptr_t asint(const void* p) { 2025 static uintptr_t asint(const void* p) {
1982 return reinterpret_cast<uintptr_t>(p); 2026 return reinterpret_cast<uintptr_t>(p);
1983 } 2027 }
1984 2028
1985 union Scalar32 { 2029 union Scalar32 {
1986 SkScalar fScalar; 2030 SkScalar fScalar;
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2734 } 2778 }
2735 #ifdef SK_BUILD_FOR_ANDROID 2779 #ifdef SK_BUILD_FOR_ANDROID
2736 if (dirty & kPaintOptionsAndroid_DirtyBit) { 2780 if (dirty & kPaintOptionsAndroid_DirtyBit) {
2737 SkPaintOptionsAndroid options; 2781 SkPaintOptionsAndroid options;
2738 options.unflatten(buffer); 2782 options.unflatten(buffer);
2739 paint->setPaintOptionsAndroid(options); 2783 paint->setPaintOptionsAndroid(options);
2740 } 2784 }
2741 #endif 2785 #endif
2742 SkASSERT(dirty == paint->fDirtyBits); 2786 SkASSERT(dirty == paint->fDirtyBits);
2743 } 2787 }
OLDNEW
« no previous file with comments | « src/core/SkMaskGamma.h ('k') | src/core/SkScalerContext.h » ('j') | src/core/SkScalerContext.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698