1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkBlendMode_DEFINED 9 #define SkBlendMode_DEFINED 10 11 #include "include/core/SkTypes.h" 12 13 /** 14 * Blends are operators that take in two colors (source, destination) and return a new color. 15 * Many of these operate the same on all 4 components: red, green, blue, alpha. For these, 16 * we just document what happens to one component, rather than naming each one separately. 17 * 18 * Different SkColorTypes have different representations for color components: 19 * 8-bit: 0..255 20 * 6-bit: 0..63 21 * 5-bit: 0..31 22 * 4-bit: 0..15 23 * floats: 0...1 24 * 25 * The documentation is expressed as if the component values are always 0..1 (floats). 26 * 27 * For brevity, the documentation uses the following abbreviations 28 * s : source 29 * d : destination 30 * sa : source alpha 31 * da : destination alpha 32 * 33 * Results are abbreviated 34 * r : if all 4 components are computed in the same manner 35 * ra : result alpha component 36 * rc : result "color": red, green, blue components 37 */ 38 enum class SkBlendMode { 39 kClear, //!< r = 0 40 kSrc, //!< r = s 41 kDst, //!< r = d 42 kSrcOver, //!< r = s + (1-sa)*d 43 kDstOver, //!< r = d + (1-da)*s 44 kSrcIn, //!< r = s * da 45 kDstIn, //!< r = d * sa 46 kSrcOut, //!< r = s * (1-da) 47 kDstOut, //!< r = d * (1-sa) 48 kSrcATop, //!< r = s*da + d*(1-sa) 49 kDstATop, //!< r = d*sa + s*(1-da) 50 kXor, //!< r = s*(1-da) + d*(1-sa) 51 kPlus, //!< r = min(s + d, 1) 52 kModulate, //!< r = s*d 53 kScreen, //!< r = s + d - s*d 54 55 kOverlay, //!< multiply or screen, depending on destination 56 kDarken, //!< rc = s + d - max(s*da, d*sa), ra = kSrcOver 57 kLighten, //!< rc = s + d - min(s*da, d*sa), ra = kSrcOver 58 kColorDodge, //!< brighten destination to reflect source 59 kColorBurn, //!< darken destination to reflect source 60 kHardLight, //!< multiply or screen, depending on source 61 kSoftLight, //!< lighten or darken, depending on source 62 kDifference, //!< rc = s + d - 2*(min(s*da, d*sa)), ra = kSrcOver 63 kExclusion, //!< rc = s + d - two(s*d), ra = kSrcOver 64 kMultiply, //!< r = s*(1-da) + d*(1-sa) + s*d 65 66 kHue, //!< hue of source with saturation and luminosity of destination 67 kSaturation, //!< saturation of source with hue and luminosity of destination 68 kColor, //!< hue and saturation of source with luminosity of destination 69 kLuminosity, //!< luminosity of source with hue and saturation of destination 70 71 kLastCoeffMode = kScreen, //!< last porter duff blend mode 72 kLastSeparableMode = kMultiply, //!< last blend mode operating separately on components 73 kLastMode = kLuminosity, //!< last valid value 74 }; 75 76 /** 77 * For Porter-Duff SkBlendModes (those <= kLastCoeffMode), these coefficients describe the blend 78 * equation used. Coefficient-based blend modes specify an equation: 79 * ('dstCoeff' * dst + 'srcCoeff' * src), where the coefficient values are constants, functions of 80 * the src or dst alpha, or functions of the src or dst color. 81 */ 82 enum class SkBlendModeCoeff { 83 kZero, /** 0 */ 84 kOne, /** 1 */ 85 kSC, /** src color */ 86 kISC, /** inverse src color (i.e. 1 - sc) */ 87 kDC, /** dst color */ 88 kIDC, /** inverse dst color (i.e. 1 - dc) */ 89 kSA, /** src alpha */ 90 kISA, /** inverse src alpha (i.e. 1 - sa) */ 91 kDA, /** dst alpha */ 92 kIDA, /** inverse dst alpha (i.e. 1 - da) */ 93 94 kCoeffCount 95 }; 96 97 /** 98 * Returns true if 'mode' is a coefficient-based blend mode (<= kLastCoeffMode). If true is 99 * returned, the mode's src and dst coefficient functions are set in 'src' and 'dst'. 100 */ 101 SK_API bool SkBlendMode_AsCoeff(SkBlendMode mode, SkBlendModeCoeff* src, SkBlendModeCoeff* dst); 102 103 104 /** Returns name of blendMode as null-terminated C string. 105 106 @return C string 107 */ 108 SK_API const char* SkBlendMode_Name(SkBlendMode blendMode); 109 110 #endif 111