michael@0: #ifndef SkDeviceProperties_DEFINED michael@0: #define SkDeviceProperties_DEFINED michael@0: michael@0: #ifndef SK_GAMMA_EXPONENT michael@0: #define SK_GAMMA_EXPONENT (2.2f) michael@0: #endif michael@0: michael@0: #ifdef SK_GAMMA_SRGB michael@0: #undef SK_GAMMA_EXPONENT michael@0: #define SK_GAMMA_EXPONENT (0.0f) michael@0: #endif michael@0: michael@0: //TODO: get everyone to stop using SkFontLCDConfig::SetSubpixel* and remove this import. michael@0: #include "SkFontLCDConfig.h" michael@0: michael@0: struct SkDeviceProperties { michael@0: struct Geometry { michael@0: /** The orientation of the pixel specifies the interpretation of the michael@0: * layout. If the orientation is horizontal, the layout is interpreted as michael@0: * left to right. It the orientation is vertical, the layout is michael@0: * interpreted top to bottom (rotated 90deg cw from horizontal). michael@0: */ michael@0: enum Orientation { michael@0: kUnknown_Orientation = 0x0, michael@0: kKnown_Orientation = 0x2, michael@0: michael@0: kHorizontal_Orientation = 0x2, //!< this is the default michael@0: kVertical_Orientation = 0x3, michael@0: michael@0: kOrientationMask = 0x3, michael@0: }; michael@0: michael@0: /** The layout of the pixel specifies its subpixel geometry. michael@0: * michael@0: * kUnknown_Layout means that the subpixel elements are not spatially michael@0: * separated in any known or usable fashion. michael@0: */ michael@0: enum Layout { michael@0: kUnknown_Layout = 0x0, michael@0: kKnown_Layout = 0x8, michael@0: michael@0: kRGB_Layout = 0x8, //!< this is the default michael@0: kBGR_Layout = 0xC, michael@0: michael@0: kLayoutMask = 0xC, michael@0: }; michael@0: michael@0: Orientation getOrientation() { michael@0: return static_cast(fGeometry & kOrientationMask); michael@0: } michael@0: Layout getLayout() { michael@0: return static_cast(fGeometry & kLayoutMask); michael@0: } michael@0: michael@0: bool isOrientationKnown() { michael@0: return SkToBool(fGeometry & kKnown_Orientation); michael@0: } michael@0: bool isLayoutKnown() { michael@0: return SkToBool(fGeometry & kKnown_Layout); michael@0: } michael@0: michael@0: private: michael@0: //TODO: get everyone to stop using SkFontLCDConfig::SetSubpixel* and replace these calls with constants. michael@0: static Orientation fromOldOrientation(SkFontLCDConfig::LCDOrientation orientation) { michael@0: switch (orientation) { michael@0: case SkFontLCDConfig::kHorizontal_LCDOrientation: return kHorizontal_Orientation; michael@0: case SkFontLCDConfig::kVertical_LCDOrientation: return kVertical_Orientation; michael@0: default: return kUnknown_Orientation; michael@0: } michael@0: } michael@0: static Layout fromOldLayout(SkFontLCDConfig::LCDOrder order) { michael@0: switch (order) { michael@0: case SkFontLCDConfig::kRGB_LCDOrder: return kRGB_Layout; michael@0: case SkFontLCDConfig::kBGR_LCDOrder: return kBGR_Layout; michael@0: default: return kUnknown_Layout; michael@0: } michael@0: } michael@0: public: michael@0: static Geometry MakeDefault() { michael@0: Orientation orientation = fromOldOrientation(SkFontLCDConfig::GetSubpixelOrientation()); //kHorizontal_Orientation michael@0: Layout layout = fromOldLayout(SkFontLCDConfig::GetSubpixelOrder()); //kRGB_Layout michael@0: Geometry ret = { SkToU8(orientation | layout) }; michael@0: return ret; michael@0: } michael@0: michael@0: static Geometry Make(Orientation orientation, Layout layout) { michael@0: Geometry ret = { SkToU8(orientation | layout) }; michael@0: return ret; michael@0: } michael@0: michael@0: uint8_t fGeometry; michael@0: }; michael@0: michael@0: static SkDeviceProperties MakeDefault() { michael@0: SkDeviceProperties ret = { Geometry::MakeDefault(), SK_GAMMA_EXPONENT }; michael@0: return ret; michael@0: } michael@0: michael@0: static SkDeviceProperties Make(Geometry geometry, SkScalar gamma) { michael@0: SkDeviceProperties ret = { geometry, gamma }; michael@0: return ret; michael@0: } michael@0: michael@0: /** Each pixel of an image will have some number of channels. michael@0: * Can the layout of those channels be exploited? */ michael@0: Geometry fGeometry; michael@0: michael@0: /** Represents the color space of the image. This is a woefully inadequate beginning. */ michael@0: SkScalar fGamma; michael@0: }; michael@0: michael@0: #endif