SkBlendMode Reference

Blend Mode

Overview

Member Function

SkBlendMode member functions read and modify the structure properties.

Constant

SkBlendMode related constants are defined by enum, enum class, #define, const, and constexpr.

Describes how destination pixel is replaced with a combination of itself and source pixel. Blend Mode may use source, destination, or both. Blend Mode may operate on each Color component independently, or may allow all source pixel components to contribute to one destination pixel component.

Blend Mode does not use adjacent pixels to determine the outcome.

Blend Mode uses source and read destination Alpha to determine written destination Alpha; both source and destination Alpha may also affect written destination Color components.

Regardless of how Alpha is encoded in source and destination pixel, nearly all Color Types treat it as ranging from zero to one. And, nearly all Blend Mode algorithms limit the output so that all results are also zero to one.

Two exceptions are SkBlendMode::kPlus and kRGBA_F16_SkColorType.

SkBlendMode::kPlus permits computing Alpha and Color component values larger than one. For Color Types other than kRGBA_F16_SkColorType, resulting Alpha and component values are clamped to one.

kRGBA_F16_SkColorType permits values outside the zero to one range. It is up to the client to ensure that the result is within the range of zero to one, and therefore well-defined.

Porter Duff

Compositing Digital Images describes Porter Duff modes SkBlendMode::kClear through SkBlendMode::kXor.

Drawing a bitmap with transparency using Porter Duff compositing is free to clear the destination.

Porter_Duff

Draw geometry with transparency using Porter Duff compositing does not combine transparent source pixels, leaving the destination outside the geometry untouched.

Porter_Duff

Lighten Darken

Modes SkBlendMode::kPlus and SkBlendMode::kScreen use simple arithmetic to lighten or darken the destination. Modes SkBlendMode::kOverlay through SkBlendMode::kMultiply use more complicated algorithms to lighten or darken; sometimes one mode does both, as described by Blend Modes .

Lighten_Darken

Modulate Blend

SkBlendMode::kModulate is a mashup of SkBlendMode::kSrcATop and SkBlendMode::kMultiply. It multiplies all components, including Alpha; unlike SkBlendMode::kMultiply, if either source or destination is transparent, result is transparent. SkBlendMode::kModulate uses Premultiplied values to compute the product; SkBlendMode::kMultiply uses Unpremultiplied values to compute the product.

Modulate_Blend

Color Blends

Modes SkBlendMode::kHue, SkBlendMode::kSaturation, SkBlendMode::kColor, and SkBlendMode::kLuminosity convert source and destination pixels using all components color information, using non-separable blend modes .

Color_Blends

Enum SkBlendMode

Constants

See Also

SkCanvas::drawColor SkCanvas::drawVertices[2][3][4] SkPaint SkShader::MakeCompose SkXfermodeImageFilter

Clear

SkBlendMode::kClear sets destination to: [0, 0] . Use SkBlendMode::kClear to initialize a buffer to fully transparent pixels when creating a mask with irregular edges.

Example

See Also

SkCanvas::clear

Src

Given: Sa as source Alpha, Sc as source Color component; SkBlendMode::kSrc sets destination to: [Sa, Sc] . Use SkBlendMode::kSrc to copy one buffer to another. All pixels are copied, regardless of source and destination Alpha values. As a parameter to SkCanvas::drawAtlas, selects sprites and ignores colors.

Example

See Also

SkSurface::draw[2] SkSurface::readPixels[2][3]

Dst

Given: Da as destination Alpha, Dc as destination Color component; SkBlendMode::kDst preserves destination set to: [Da, Dc] . Setting Paint Blend Mode to SkBlendMode::kDst causes drawing with Paint to have no effect. As a parameter to SkCanvas::drawAtlas, selects colors and ignores sprites.

Example

Src Over

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kSrcOver replaces destination with: [Sa + Da * (1 - Sa), Sc + Dc * (1 - Sa)] , drawing source over destination. SkBlendMode::kSrcOver is the default for Paint.

SkBlendMode::kSrcOver cannot make destination more transparent; the result will be at least as opaque as the less transparent of source and original destination.

Example

Dst Over

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kDstOver replaces destination with: [Da + Sa * (1 - Da), Dc + Sc * (1 - Da)] , drawing destination over source. Has no effect destination if is opaque.

Example

Src In

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha; SkBlendMode::kSrcIn replaces destination with: [Sa * Da, Sc * Da] , drawing source with destination opacity.

Example

Dst In

Given: Sa as source Alpha, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kDstIn replaces destination with: [Da * Sa, Dc * Sa] , scaling destination Alpha by source Alpha. Resulting destination is visible where source is visible.

Example

Src Out

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha; SkBlendMode::kSrcOut replaces destination with: [Sa * (1 - Da), Sc * (1 - Da)] , drawing source fully where destination Alpha is zero. Is destination is opaque, has no effect.

Example

Dst Out

Given: Sa as source Alpha, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kDstOut replaces destination with: [Da * (1 - Sa), Dc * (1 - Sa)] , scaling destination Alpha by source transparency. Resulting destination is visible where source is transparent. If source is transparent, has no effect.

Example

Src Atop

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kSrcATop replaces destination with: [Da, Sc * Da + Dc * (1 - Sa)] , replacing opaque destination with opaque source. If source or destination is transparent, has no effect.

Example

Dst Atop

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kDstATop replaces destination with: [Sa, Dc * Sa + Sc * (1 - Da)] , making destination transparent where source is transparent.

Example

Xor

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kXor replaces destination with: [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + Dc * (1 - Sa)] , exchanging the transparency of the source and destination.

Example

Plus

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kPlus replaces destination with: [Sa + Da, Sc + Dc] , summing the Alpha and Color components.

Example

Modulate

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kModulate replaces destination with: [Sa * Da, Sc * Dc] , scaling Alpha and Color components by the lesser of the values. SkBlendMode::kModulate differs from SkBlendMode::kMultiply in two ways. SkBlendMode::kModulate like SkBlendMode::kSrcATop alters the destination inside the destination area, as if the destination Alpha defined the boundaries of a soft clip. SkBlendMode::kMultiply like SkBlendMode::kSrcOver can alter the destination where the destination is transparent. SkBlendMode::kModulate computes the product of the source and destination using Premultiplied component values. SkBlendMode::kMultiply the product of the source and destination using Unpremultiplied component values.

Example

Screen

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kScreen replaces destination with: [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] .

Example

Overlay

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kOverlay replaces destination with: [Sa + Da - Sa * Da, Sc * (1 - Da) + Dc * (1 - Sa) + (2 * Dc <= Da ? 2 * Sc * Dc : Sa * Da - 2 * (Da - Dc) * (Sa - Sc))] .

Example

Darken

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kDarken replaces destination with: [Sa + Da - Sa * Da, Sc + Dc - max(Sc * Da, Dc * Sa)] . SkBlendMode::kDarken does not make an image darker; it replaces the destination component with source if source is darker.

Example

Lighten

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kLighten replaces destination with: [Sa + Da - Sa * Da, Sc + Dc - min(Sc * Da, Dc * Sa)] . SkBlendMode::kDarken does not make an image lighter; it replaces the destination component with source if source is lighter.

Example

Color Dodge

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kColorDodge replaces destination with: [Sa + Da - Sa * Da, Dc == 0 ? Sc * (1 - Da) : Sc == Sa ? Sc + Da * (1 - Sa) : Sa * min(Da, Dc * Sa / (Sa - Sc)) + Sc * (1 - Da) + Da * (1 - Sa)] , making destination brighter to reflect source.

Example

Color Burn

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kColorBurn replaces destination with: [Sa + Da - Sa * Da, Dc == Da ? Dc + Sc * (1 - Da) : Sc == 0 ? Da * (1 - Sa) : Sa * (Da - min(Da, (Da - Dc) * Sa / Sc)) + Sc * (1 - Da) + Da * (1 - Sa)] , making destination darker to reflect source.

Example

Hard Light

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kHardLight replaces destination with: [Sa + Da - Sa * Da, Sc * (1 - Da) + Dc * (1 - Sa) + 2 * Sc <= Sa ? 2 * Sc * Dc : Sa * Da - 2 * (Da - Dc) * (Sa - Sc)] , making destination lighter or darker, depending on source.

Example

Soft Light

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component where m = Da > 0 ? Dc / Da : 0; SkBlendMode::kSoftLight replaces destination with: [Sa + Da - Sa * Da, Sc / Da + Dc / Sa + (2 * Sc <= Sa ? Dc * (Sa + (2 * Sc - Sa) * (1 - m)) : Dc * Sa + Da * (2 * Sc - Sa) * (4 * Dc <= Da ? (16 * m * m + 4 * m) * (m - 1) + 7 * m : sqrt(m) - m))]
, making destination lighter or darker, depending on source.

Example

Difference

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kDifference replaces destination with: [Sa + Da - Sa * Da, Sc + Dc - 2 * min(Sc * Da, Dc * Sa)] , replacing destination with lighter less darker.

Example

Exclusion

Given: Sa as source Alpha, Sc as source Color, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kExclusion replaces destination with: [Sa + Da - Sa * Da, Sc + Dc - 2 * Sc * Dc] , replacing destination with lighter less darker, ignoring Alpha.

Example

Multiply

Given: Sa as source Alpha, Sc as source Color component, Da as destination Alpha, Dc as destination Color component; SkBlendMode::kMultiply replaces destination with: [Sa + Da - Sa * Da, Sc * (1 - Da) + Dc * (1 - Sa) + Sc * Dc] , the product of Unpremultiplied source and destination. SkBlendMode::kMultiply makes the image darker.

Example

Hue

Given: Sa as source Alpha, S as source Color, Da as destination Alpha, D as destination Color; SkBlendMode::kHue replaces destination with: [Sa + Da - Sa * Da, SetLuminosity(SetSaturation(S, Saturation(D)), Luminosity(D))] , source hue, leaving destination luminosity and saturation unchanged.

Example

Saturation

Given: Sa as source Alpha, S as source Color, Da as destination Alpha, D as destination Color; SkBlendMode::kHue replaces destination with: [Sa + Da - Sa * Da, SetLuminosity(SetSaturation(D, Saturation(S)), Luminosity(D))] , source hue, leaving destination luminosity and saturation unchanged.

Example

Color

Given: Sa as source Alpha, S as source Color, Da as destination Alpha, D as destination Color; SkBlendMode::kColor replaces destination with: [Sa + Da - Sa * Da, SetLuminosity(S, Luminosity(D))] , source hue and saturation, leaving destination luminosity unchanged.

Example

Luminosity

Given: Sa as source Alpha, S as source Color, Da as destination Alpha, D as destination Color; SkBlendMode::kLuminosity replaces destination with: [Sa + Da - Sa * Da, SetLuminosity(D, Luminosity(S))] , source luminosity, leaving destination hue and saturation unchanged.

Example

SkBlendMode_Name

Returns name of blendMode as null-terminated C string.

Parameters

Return Value

C string

Example

Example Output

default blend: SkBlendMode::kSrcOver

See Also

SkBlendMode