180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc. 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkDeviceProfile_DEFINED 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkDeviceProfile_DEFINED 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkRefCnt.h" 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkDeviceProfile : public SkRefCnt { 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_DECLARE_INST_COUNT(SkDeviceProfile) 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru enum LCDConfig { 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kNone_LCDConfig, // disables LCD text rendering, uses A8 instead 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kRGB_Horizontal_LCDConfig, 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kBGR_Horizontal_LCDConfig, 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kRGB_Vertical_LCDConfig, 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kBGR_Vertical_LCDConfig 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru enum FontHintLevel { 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kNone_FontHintLevel, 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kSlight_FontHintLevel, 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kNormal_FontHintLevel, 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFull_FontHintLevel, 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kAuto_FontHintLevel 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * gammaExp is typically between 1.0 and 2.2. For no gamma adjustment, 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * specify 1.0 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * contrastScale will be pinned between 0.0 and 1.0. For no contrast 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * adjustment, specify 0.0 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param config Describes the LCD layout for this device. If this is set 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * to kNone, then all requests for LCD text will be 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * devolved to A8 antialiasing. 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param level The hinting level to be used, IF the paint specifies 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * "default". Otherwise the paint's hinting level will be 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * respected. 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static SkDeviceProfile* Create(float gammaExp, 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru float contrastScale, 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru LCDConfig, 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru FontHintLevel); 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Returns the global default profile, that is used if no global profile is 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * specified with SetGlobal(), or if NULL is specified to SetGlobal(). 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * The references count is *not* incremented, and the caller should not 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * call unref(). 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static SkDeviceProfile* GetDefault(); 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Return the current global profile (or the default if no global had yet 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * been set) and increment its reference count. The call *must* call unref() 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * when it is done using it. 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static SkDeviceProfile* RefGlobal(); 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Make the specified profile be the global value for all subsequently 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * instantiated devices. Does not affect any existing devices. 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Increments the reference count on the profile. 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Specify NULL for the "identity" profile (where there is no gamma or 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * contrast correction). 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static void SetGlobal(SkDeviceProfile*); 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru float getFontGammaExponent() const { return fGammaExponent; } 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru float getFontContrastScale() const { return fContrastScale; } 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Given a luminance byte (0 for black, 0xFF for white), generate a table 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * that applies the gamma/contrast settings to linear coverage values. 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void generateTableForLuminanceByte(U8CPU lumByte, uint8_t table[256]) const; 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate: 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDeviceProfile(float gammaExp, float contrastScale, LCDConfig, 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru FontHintLevel); 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru float fGammaExponent; 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru float fContrastScale; 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru LCDConfig fLCDConfig; 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru FontHintLevel fFontHintLevel; 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef SkRefCnt INHERITED; 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 99