1SkBlendMode Overview 2=== 3Describes how destination <a href='undocumented#Pixel'>pixel</a> is replaced with a combination of itself and 4source <a href='undocumented#Pixel'>pixel</a>. <a href='#Blend_Mode'>Blend_Mode</a> may use source, destination, or both. <a href='#Blend_Mode'>Blend_Mode</a> may 5operate on each <a href='SkColor_Reference#Color'>Color</a> component independently, or may allow all source <a href='undocumented#Pixel'>pixel</a> 6components to contribute to one destination <a href='undocumented#Pixel'>pixel</a> component. 7 8<a href='#Blend_Mode'>Blend_Mode</a> does not use adjacent pixels to determine the outcome. 9 10<a href='#Blend_Mode'>Blend_Mode</a> uses source and read destination <a href='SkColor_Reference#Alpha'>Alpha</a> to determine written 11destination <a href='SkColor_Reference#Alpha'>Alpha</a>; both source and destination <a href='SkColor_Reference#Alpha'>Alpha</a> may also affect written 12destination <a href='SkColor_Reference#Color'>Color</a> components. 13 14Regardless of how <a href='SkColor_Reference#Alpha'>Alpha</a> is encoded in source and destination <a href='undocumented#Pixel'>pixel</a>, nearly all 15<a href='#Image_Info_Color_Type'>Color_Types</a> treat it as ranging from zero to one. And, nearly all <a href='#Blend_Mode'>Blend_Mode</a> 16algorithms limit the output so that all results are also zero to one. 17 18Two exceptions are <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kPlus'>kPlus</a> and <a href='SkImageInfo_Reference#kRGBA_F16_SkColorType'>kRGBA_F16_SkColorType</a>. 19 20<a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kPlus'>kPlus</a> permits computing <a href='SkColor_Reference#Alpha'>Alpha</a> and <a href='SkColor_Reference#Color'>Color</a> component values larger 21than one. For <a href='#Image_Info_Color_Type'>Color_Types</a> other than <a href='SkImageInfo_Reference#kRGBA_F16_SkColorType'>kRGBA_F16_SkColorType</a>, resulting <a href='SkColor_Reference#Alpha'>Alpha</a> 22and component values are clamped to one. 23 24<a href='SkImageInfo_Reference#kRGBA_F16_SkColorType'>kRGBA_F16_SkColorType</a> permits values outside the zero to one range. It is up 25to the client to ensure that the result is within the range of zero to one, 26and therefore well-defined. 27 28<a name='Porter_Duff'></a> 29 30<a href='https://graphics.pixar.com/library/Compositing/paper.pdf'>Compositing Digital Images</a></a> describes <a href='#Blend_Mode_Overview_Porter_Duff'>Porter_Duff</a> modes <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kClear'>kClear</a> through <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kXor'>kXor</a>. 31 32Drawing a <a href='SkBitmap_Reference#Bitmap'>bitmap</a> with transparency using <a href='#Blend_Mode_Overview_Porter_Duff'>Porter_Duff</a> compositing is free to clear 33the destination. 34 35![Porter_Duff](https://fiddle.skia.org/i/819903e0bb125385269948474b6c8a84_raster.png "") 36 37Draw geometry with transparency using <a href='#Blend_Mode_Overview_Porter_Duff'>Porter_Duff</a> compositing does not combine 38transparent source pixels, leaving the destination outside the geometry untouched. 39 40![Porter_Duff](https://fiddle.skia.org/i/8f320c1e94e77046e00f7e9e843caa27_raster.png "") 41 42<a name='Lighten_Darken'></a> 43 44Modes <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kPlus'>kPlus</a> and <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kScreen'>kScreen</a> use 45simple arithmetic to lighten or darken the destination. Modes 46<a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kOverlay'>kOverlay</a> through <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kMultiply'>kMultiply</a> use more complicated 47algorithms to lighten or darken; sometimes one mode does both, as described by 48<a href='https://en.wikipedia.org/wiki/Blend_modes'>Blend Modes</a></a> . 49 50![Lighten_Darken](https://fiddle.skia.org/i/23a33fa04cdd0204b2490d05e340f87c_raster.png "") 51 52<a name='Modulate_Blend'></a> 53 54<a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kModulate'>kModulate</a> is a mashup of <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kSrcATop'>kSrcATop</a> and <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kMultiply'>kMultiply</a>. 55It multiplies all components, including <a href='SkColor_Reference#Alpha'>Alpha</a>; unlike <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kMultiply'>kMultiply</a>, if either 56source or destination is transparent, result is transparent. <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kModulate'>kModulate</a> 57uses <a href='undocumented#Premultiply'>Premultiplied</a> values to compute the product; <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kMultiply'>kMultiply</a> uses <a href='undocumented#Unpremultiply'>Unpremultiplied</a> 58values to compute the product. 59 60![Modulate_Blend](https://fiddle.skia.org/i/877f96610ab7638a310432674b04f837_raster.png "") 61 62<a name='Color_Blends'></a> 63 64Modes <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kHue'>kHue</a>, <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kSaturation'>kSaturation</a>, <a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kColor'>kColor</a>, and 65<a href='SkBlendMode_Reference#SkBlendMode'>SkBlendMode</a>::<a href='#SkBlendMode_kLuminosity'>kLuminosity</a> convert source and destination pixels using all 66components <a href='SkColor_Reference#Color'>color</a> information, using 67<a href='https://www.w3.org/TR/compositing-1/#blendingnonseparable'>non-separable blend modes</a></a> . 68 69![Color_Blends](https://fiddle.skia.org/i/630fe21aea8369b307231f5bcf8b2d50_raster.png "") 70 71