ImageFilters

class ImageFilters

Methods

Arithmetic

Create a filter that implements a custom blend mode.

Blur

Create a filter that blurs its input by the separate X and Y sigmas.

ColorFilter

Create a filter that applies the color filter to the input filter results.

Compose

Create a filter that composes 'inner' with 'outer', such that the results of 'inner' are treated as the source bitmap passed to 'outer', i.e. result = outer(inner(source)).

Dilate

Create a filter that dilates each input pixel's channel values to the max value within the given radii along the x and y axes.

DisplacementMap

Create a filter that moves each pixel in its color input based on an (x,y) vector encoded in its displacement input filter.

DistantLitDiffuse

Create a filter that calculates the diffuse illumination from a distant light source, interpreting the alpha channel of the input as the height profile of the surface (to approximate normal vectors).

DistantLitSpecular

Create a filter that calculates the specular illumination from a distant light source, interpreting the alpha channel of the input as the height profile of the surface (to approximate normal vectors).

DropShadow

Create a filter that draws a drop shadow under the input content.

DropShadowOnly

Create a filter that renders a drop shadow, in exactly the same manner as DropShadow(), except that the resulting image does not include the input content.

Erode

Create a filter that erodes each input pixel's channel values to the minimum channel value within the given radii along the x and y axes.

Image

Overloaded function.

Magnifier

Create a filter that mimics a zoom/magnifying lens effect.

MatrixConvolution

Create a filter that applies an NxM image processing kernel to the input image.

MatrixTransform

Create a filter that transforms the input image by 'matrix'.

Merge

Create a filter that merges the 'count' filters together by drawing their results in order with src-over blending.

Offset

Create a filter that offsets the input filter by the given vector.

Picture

Create a filter that produces the SkPicture as its output, drawn into targetRect.

PointLitDiffuse

Create a filter that calculates the diffuse illumination from a point light source, using alpha channel of the input as the height profile of the surface (to approximate normal vectors).

PointLitSpecular

Create a filter that calculates the specular illumination from a point light source, using alpha channel of the input as the height profile of the surface (to approximate normal vectors).

SpotLitDiffuse

Create a filter that calculates the diffuse illumination from a spot light source, using alpha channel of the input as the height profile of the surface (to approximate normal vectors).

SpotLitSpecular

Create a filter that calculates the diffuse illumination from a spot light source, using alpha channel of the input as the height profile of the surface (to approximate normal vectors).

Tile

Create a tile image filter.

Xfermode

This filter takes an BlendMode and uses it to composite the two filters together.

__init__

Methods

static ImageFilters.Arithmetic(k1: float, k2: float, k3: float, k4: float, enforcePMColor: bool, background: skia.ImageFilter, foreground: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that implements a custom blend mode.

Each output pixel is the result of combining the corresponding background and foreground pixels using the 4 coefficients:

k1 * foreground * background + k2 * foreground + \
k3 * background + k4
Parameters:
  • k1 (float) – The first coefficients used to combine the foreground and background.

  • k2 (float) – The second coefficients used to combine the foreground and background.

  • k3 (float) – The third coefficients used to combine the foreground and background.

  • k4 (float) – The fourth coefficients used to combine the foreground and background.

  • enforcePMColor (bool) – If true, the RGB channels will be clamped to the calculated alpha.

  • background (skia.ImageFilter) – The background content, using the source bitmap when this is null.

  • foreground (skia.ImageFilter) – The foreground content, using the source bitmap when this is null.

  • cropRect (skia.Rect) – Optional rectangle that crops the inputs and output.

static ImageFilters.Blur(sigmaX: float, sigmaY: float, tileMode: skia.TileMode = <TileMode.kDecal: 3>, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that blurs its input by the separate X and Y sigmas.

The provided tile mode is used when the blur kernel goes outside the input image.

Parameters:
  • sigmaX (float) – The Gaussian sigma value for blurring along the X axis.

  • sigmaY (float) – The Gaussian sigma value for blurring along the Y axis.

  • tileMode (skia.TileMode) – The tile mode applied at edges. TODO (michaelludwig) - kMirror is not supported yet

  • input (skia.ImageFilter) – The input filter that is blurred, uses source bitmap if this is null.

  • cropRect (skia.Rect) – Optional rectangle that crops the input and output.

static ImageFilters.ColorFilter(cf: skia.ColorFilter, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that applies the color filter to the input filter results.

Parameters:
  • cf (skia.ColorFilter) – The color filter that transforms the input image.

  • input (skia.ImageFilter) – The input filter, or uses the source bitmap if this is null.

  • cropRect (skia.Rect) – Optional rectangle that crops the input and output.

static ImageFilters.Compose(outer: skia.ImageFilter, inner: skia.ImageFilter) skia.ImageFilter

Create a filter that composes ‘inner’ with ‘outer’, such that the results of ‘inner’ are treated as the source bitmap passed to ‘outer’, i.e. result = outer(inner(source)).

Parameters:
  • outer (skia.ImageFilter) – The outer filter that evaluates the results of inner.

  • inner (skia.ImageFilter) – The inner filter that produces the input to outer.

static ImageFilters.Dilate(radiusX: float, radiusY: float, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that dilates each input pixel’s channel values to the max value within the given radii along the x and y axes.

Parameters:
  • radiusX (float) – The distance to dilate along the x axis to either side of each pixel.

  • radiusY (float) – The distance to dilate along the y axis to either side of each pixel.

  • input (skia.ImageFilter) – The image filter that is dilated, using source bitmap if this is null.

  • cropRect (skia.Rect) – Optional rectangle that crops the input and output.

static ImageFilters.DisplacementMap(xChannelSelector: skia.ColorChannel, yChannelSelector: skia.ColorChannel, scale: float, displacement: skia.ImageFilter, color: skia.ImageFilter, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that moves each pixel in its color input based on an (x,y) vector encoded in its displacement input filter.

Two color components of the displacement image are mapped into a vector as scale * (color[xChannel], color[yChannel]), where the channel selectors are one of R, G, B, or A.

Parameters:
  • xChannelSelector (skia.ColorChannel) – RGBA channel that encodes the x displacement per pixel.

  • yChannelSelector (skia.ColorChannel) – RGBA channel that encodes the y displacement per pixel.

  • scale (float) – Scale applied to displacement extracted from image.

  • displacement (skia.ImageFilter) – The filter defining the displacement image, or null to use source.

  • color (skia.ImageFilter) – The filter providing the color pixels to be displaced.

  • cropRect (skia.Rect) – Optional rectangle that crops the color input and output.

static ImageFilters.DistantLitDiffuse(direction: skia.Point3, lightColor: int, surfaceScale: float, kd: float, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that calculates the diffuse illumination from a distant light source, interpreting the alpha channel of the input as the height profile of the surface (to approximate normal vectors).

Parameters:
  • direction (skia.Point3) – The direction to the distance light.

  • lightColor (int) – The color of the diffuse light source.

  • surfaceScale (float) – Scale factor to transform from alpha values to physical height.

  • kd (float) – Diffuse reflectance coefficient.

  • input (skia.ImageFilter) – The input filter that defines surface normals (as alpha), or uses the source bitmap when null.

  • cropRect (skia.Rect) – Optional rectangle that crops the input and output.

static ImageFilters.DistantLitSpecular(direction: skia.Point3, lightColor: int, surfaceScale: float, ks: float, shininess: float, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that calculates the specular illumination from a distant light source, interpreting the alpha channel of the input as the height profile of the surface (to approximate normal vectors).

Parameters:
  • direction (skia.Point3) – The direction to the distance light.

  • lightColor (int) – The color of the diffuse light source.

  • surfaceScale (float) – Scale factor to transform from alpha values to physical height.

  • ks (float) – Specular reflectance coefficient.

  • shininess (float) – The specular exponent determining how shiny the surface is.

  • input (skia.ImageFilter) – The input filter that defines surface normals (as alpha), or uses the source bitmap when null.

  • cropRect (skia.Rect) – Optional rectangle that crops the input and output.

static ImageFilters.DropShadow(dx: float, dy: float, sigmaX: float, sigmaY: float, color: int, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that draws a drop shadow under the input content.

This filter produces an image that includes the inputs’ content.

Parameters:
  • dx (float) – The X offset of the shadow.

  • dy (float) – The Y offset of the shadow.

  • sigmaX (float) – The blur radius for the shadow, along the X axis.

  • sigmaY (float) – The blur radius for the shadow, along the Y axis.

  • color (int) – The color of the drop shadow.

  • input (skia.ImageFilter) – The input filter, or will use the source bitmap if this is null.

  • cropRect (skia.Rect) – Optional rectangle that crops the input and output.

static ImageFilters.DropShadowOnly(dx: float, dy: float, sigmaX: float, sigmaY: float, color: int, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that renders a drop shadow, in exactly the same manner as DropShadow(), except that the resulting image does not include the input content.

This allows the shadow and input to be composed by a filter DAG in a more flexible manner.

Parameters:
  • dx (float) – The X offset of the shadow.

  • dy (float) – The Y offset of the shadow.

  • sigmaX (float) – The blur radius for the shadow, along the X axis.

  • sigmaY (float) – The blur radius for the shadow, along the Y axis.

  • color (int) – The color of the drop shadow.

  • input (skia.ImageFilter) – The input filter, or will use the source bitmap if this is null.

  • cropRect (skia.Rect) – Optional rectangle that crops the input and output.

static ImageFilters.Erode(radiusX: float, radiusY: float, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that erodes each input pixel’s channel values to the minimum channel value within the given radii along the x and y axes.

Parameters:
  • radiusX (float) – The distance to erode along the x axis to either side of each pixel.

  • radiusY (float) – The distance to erode along the y axis to either side of each pixel.

  • input (skia.ImageFilter) – The image filter that is eroded, using source bitmap if this is null.

  • cropRect (skia.Rect) – Optional rectangle that crops the input and output.

static ImageFilters.Image(*args, **kwargs)

Overloaded function.

  1. Image(image: skia.Image, srcRect: skia.Rect, dstRect: skia.Rect, options: skia.SamplingOptions = <skia.SamplingOptions object at 0x7f87ad7befb0>) -> skia.ImageFilter

    Create a filter that draws the ‘srcRect’ portion of image into ‘dstRect’ using the given filter quality.

    Similar to Canvas.drawImageRect(). Returns null if ‘image’ is null.

    image:

    The image that is output by the filter, subset by ‘srcRect’.

    srcRect:

    The source pixels sampled into ‘dstRect’

    dstRect:

    The local rectangle to draw the image into.

    filterQuality:

    The filter quality that is used when sampling the image.

  2. Image(image: skia.Image, options: skia.SamplingOptions = <skia.SamplingOptions object at 0x7f87ad1cb6f0>) -> skia.ImageFilter

    Create a filter that produces the image contents.

    image:

    The image that is output by the filter.

static ImageFilters.Magnifier(srcRect: skia.Rect, zoomAmount: float, inset: float, sampling: skia.SamplingOptions, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that mimics a zoom/magnifying lens effect.

Parameters:
  • srcRect (skia.Rect) – Source rect.

  • inset (float) – Inset.

  • input (skia.ImageFilter) – The input filter that is magnified, if null the source bitmap is used.

  • cropRect (skia.Rect) – Optional rectangle that crops the input and output.

static ImageFilters.MatrixConvolution(kernelSize: skia.ISize, kernel: List[float], gain: float, bias: float, kernelOffset: skia.IPoint, tileMode: skia.TileMode, convolveAlpha: bool, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that applies an NxM image processing kernel to the input image.

This can be used to produce effects such as sharpening, blurring, edge detection, etc.

Parameters:
  • kernelSize (skia.ISize) – The kernel size in pixels, in each dimension (N by M).

  • kernel (List[float]) – The image processing kernel. Must contain N * M elements, in row order.

  • gain (float) – A scale factor applied to each pixel after convolution. This can be used to normalize the kernel, if it does not already sum to 1.

  • bias (float) – A bias factor added to each pixel after convolution.

  • kernelOffset (skia.IPoint) – An offset applied to each pixel coordinate before convolution. This can be used to center the kernel over the image (e.g., a 3x3 kernel should have an offset of {1, 1}).

  • tileMode (skia.TileMode) – How accesses outside the image are treated. TODO (michaelludwig) - kMirror is not supported yet

  • convolveAlpha (bool) – If true, all channels are convolved. If false, only the RGB channels are convolved, and alpha is copied from the source image.

  • input (skia.ImageFilter) – The input image filter, if null the source bitmap is used instead.

  • cropRect (skia.Rect) – Optional rectangle to which the output processing will be limited.

static ImageFilters.MatrixTransform(matrix: skia.Matrix, sampling: skia.SamplingOptions, input: skia.ImageFilter = None) skia.ImageFilter

Create a filter that transforms the input image by ‘matrix’.

This matrix transforms the local space, which means it effectively happens prior to any transformation coming from the SkCanvas initiating the filtering.

Parameters:
  • matrix (skia.Matrix) – The matrix to apply to the original content.

  • sampling (skia.SamplingOptions) – How the image will be sampled when it is transformed

  • input (skia.ImageFilter) – The image filter to transform, or null to use the source image.

static ImageFilters.Merge(filters: list, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that merges the ‘count’ filters together by drawing their results in order with src-over blending.

Parameters:
  • filters (List[skia.ImageFilter]) – The input filter array to merge, which must have ‘count’ elements. Any null filter pointers will use the source bitmap instead.

  • cropRect (skia.Rect) – Optional rectangle that crops all input filters and the output.

static ImageFilters.Offset(dx: float, dy: float, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that offsets the input filter by the given vector.

Parameters:
  • dx (float) – The x offset in local space that the image is shifted.

  • dy (float) – The y offset in local space that the image is shifted.

  • input (skia.ImageFilter) – The input that will be moved, if null the source bitmap is used instead.

  • cropRect (skia.Rect) – Optional rectangle to crop the input and output.

static ImageFilters.Picture(pic: SkPicture, targetRect: skia.Rect = None) skia.ImageFilter

Create a filter that produces the SkPicture as its output, drawn into targetRect.

Note that the targetRect is not the same as the SkIRect cropRect that many filters accept. Returns null if ‘pic’ is null.

Parameters:
  • pic (skia.Picture) – The picture that is drawn for the filter output.

  • targetRect (skia.Rect) – The drawing region for the picture.

static ImageFilters.PointLitDiffuse(location: skia.Point3, lightColor: int, surfaceScale: float, kd: float, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that calculates the diffuse illumination from a point light source, using alpha channel of the input as the height profile of the surface (to approximate normal vectors).

Parameters:
  • location (skia.Point3) – The location of the point light.

  • lightColor (int) – The color of the diffuse light source.

  • surfaceScale (float) – Scale factor to transform from alpha values to physical height.

  • kd (float) – Diffuse reflectance coefficient.

  • input (skia.ImageFilter) – The input filter that defines surface normals (as alpha), or uses the source bitmap when null.

  • cropRect (skia.IRect) – Optional rectangle that crops the input and output.

static ImageFilters.PointLitSpecular(location: skia.Point3, lightColor: int, surfaceScale: float, ks: float, shininess: float, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that calculates the specular illumination from a point light source, using alpha channel of the input as the height profile of the surface (to approximate normal vectors).

Parameters:
  • location (skia.Point3) – The location of the point light.

  • lightColor (int) – The color of the diffuse light source.

  • surfaceScale (float) – Scale factor to transform from alpha values to physical height.

  • ks (float) – Specular reflectance coefficient.

  • shininess (float) – The specular exponent determining how shiny the surface is.

  • input (skia.ImageFilter) – The input filter that defines surface normals (as alpha), or uses the source bitmap when null.

  • cropRect (skia.IRect) – Optional rectangle that crops the input and output.

static ImageFilters.SpotLitDiffuse(location: skia.Point3, target: skia.Point3, falloffExponent: float, cutoffAngle: float, lightColor: int, surfaceScale: float, kd: float, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that calculates the diffuse illumination from a spot light source, using alpha channel of the input as the height profile of the surface (to approximate normal vectors).

The spot light is restricted to be within ‘cutoffAngle’ of the vector between the location and target.

Parameters:
  • location (skia.Point3) – The location of the spot light.

  • target (skia.Point3) – The location that the spot light is point towards

  • falloffExponent (float) – Exponential falloff parameter for illumination outside of cutoffAngle

  • cutoffAngle (float) – Maximum angle from lighting direction that receives full light

  • lightColor (int) – The color of the diffuse light source.

  • surfaceScale (float) – Scale factor to transform from alpha values to physical height.

  • kd (float) – Diffuse reflectance coefficient.

  • input (skia.ImageFilter) – The input filter that defines surface normals (as alpha), or uses the source bitmap when null.

  • cropRect (skia.IRect) – Optional rectangle that crops the input and output.

static ImageFilters.SpotLitSpecular(location: skia.Point3, target: skia.Point3, falloffExponent: float, cutoffAngle: float, lightColor: int, surfaceScale: float, ks: float, shininess: float, input: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

Create a filter that calculates the diffuse illumination from a spot light source, using alpha channel of the input as the height profile of the surface (to approximate normal vectors).

The spot light is restricted to be within ‘cutoffAngle’ of the vector between the location and target.

Parameters:
  • location (skia.Point3) – The location of the spot light.

  • target (skia.Point3) – The location that the spot light is point towards

  • falloffExponent (float) – Exponential falloff parameter for illumination outside of cutoffAngle

  • cutoffAngle (float) – Maximum angle from lighting direction that receives full light

  • lightColor (int) – The color of the diffuse light source.

  • surfaceScale (float) – Scale factor to transform from alpha values to physical height.

  • ks (float) – Specular reflectance coefficient.

  • shininess (float) – The specular exponent determining how shiny the surface is.

  • input (skia.ImageFilter) – The input filter that defines surface normals (as alpha), or uses the source bitmap when null.

  • cropRect (skia.IRect) – Optional rectangle that crops the input and output.

static ImageFilters.Tile(src: skia.Rect, dst: skia.Rect, input: skia.ImageFilter = None) skia.ImageFilter

Create a tile image filter.

Parameters:
  • src (skia.Rect) – Defines the pixels to tile

  • dst (skia.Rect) – Defines the pixel region that the tiles will be drawn to

  • input (skia.ImageFilter) – The input that will be tiled, if null the source bitmap is used instead.

static ImageFilters.Xfermode(mode: skia.BlendMode, background: skia.ImageFilter = None, foreground: skia.ImageFilter = None, cropRect: skia.IRect = None) skia.ImageFilter

This filter takes an BlendMode and uses it to composite the two filters together.

Parameters:
  • background (skia.ImageFilter) – The Dst pixels used in blending, if null the source bitmap is used.

  • foreground (skia.ImageFilter) – The Src pixels used in blending, if null the source bitmap is used. Optional rectangle to crop input and output.

ImageFilters.__init__(*args, **kwargs)