skia

Python Skia binding module.

Functions

AlphaTypeIsOpaque

Returns true if AlphaType equals kOpaque_AlphaType.

AsWinding

Set the result with fill type winding to area equivalent to path.

BlendMode_AsCoeff

Returns true if 'mode' is a coefficient-based blend mode (<= kLastCoeffMode).

BlendMode_Name

Returns name of blendMode as null-terminated C string.

Color

Returns color value from 8-bit component values.

ColorGetA

Returns alpha byte from color value.

ColorGetB

Returns blue component of color, from zero to 255.

ColorGetG

Returns green component of color, from zero to 255.

ColorGetR

Returns red component of color, from zero to 255.

ColorSetA

Returns unpremultiplied color with red, blue, and green set from c; and alpha set from a.

ColorSetARGB

Returns color value from 8-bit component values.

ColorSetRGB

Returns color value from 8-bit component values, with alpha set fully opaque to 255.

ColorToHSV

Converts ARGB to its HSV components.

ColorTypeBytesPerPixel

Returns the number of bytes required to store a pixel, including unused padding.

ColorTypeIsAlwaysOpaque

Returns true if ColorType always decodes alpha to 1.0, making the pixel fully opaque.

ColorTypeValidateAlphaType

Returns true if canonical can be set to a valid AlphaType for colorType.

ComputeIsOpaque

Returns true if all pixels are opaque.

EncodedOriginToMatrix

Given an encoded origin and the width and height of the source data, returns a matrix that transforms the source rectangle with upper left corner at [0, 0] and origin to a correctly oriented destination rectangle of [0, 0, w, h].

HSVToColor

Converts HSV components to an ARGB color.

MakeNullCanvas

Op

Set this path to the result of applying the Op to this path and the specified path: this = (this op operand).

PathFillType_ConvertToNonInverse

PathFillType_IsEvenOdd

PathFillType_IsInverse

PreMultiplyARGB

Returns a SkPMColor value from unpremultiplied 8-bit component values.

PreMultiplyColor

Returns pmcolor closest to color c.

RGBToHSV

Converts RGB to its HSV components.

Simplify

Set this path to a set of non-overlapping contours that describe the same area as the original path.

TightBounds

Set the resulting rectangle to the tight bounds of the path.

Classes

AlphaType

Members:

ApplyPerspectiveClip

Members:

AutoCanvasRestore

Stack helper class calls Canvas.restoreToCount() when AutoCanvasRestore goes out of scope.

BBHFactory

BBoxHierarchy

Bitmap

Bitmap describes a two-dimensional raster pixel array.

BlendMode

Members:

BlendModeCoeff

For Porter-Duff SkBlendModes (those <= kLastCoeffMode), these coefficients

BlurMaskFilter

BlurStyle

Members:

Budgeted

Indicates whether an allocation should count against a cache budget.

Canvas

Canvas provides an interface for drawing, and how the drawing is clipped and transformed.

ClipOp

Members:

Codec

Codec Abstraction layer directly on top of an image codec.

Color4f

RGBA color value, holding four floating point components.

ColorChannel

Describes different color channels one can manipulate.

ColorChannelFlag

Used to represent the channels available in a color type or texture format

ColorFilter

ColorFilters are optional objects in the drawing pipeline.

ColorFilters

ColorInfo

Describes pixel and encoding.

ColorMatrix

ColorMatrixFilter

ColorSpace

ColorType

Members:

ConvergeMode

Describes geometric operations (ala Region.Op) that can be

CornerPathEffect

CornerPathEffect is a subclass of PathEffect that can turn sharp corners into various treatments (e.g.

CubicResampler

DashPathEffect

Data

Data holds an immutable data buffer.

DiscretePathEffect

Document

High-level API for creating a document-based canvas.

Drawable

Base-class for objects that draw into Canvas.

DynamicMemoryWStream

EncodedImageFormat

Enum describing format of encoded data.

EncodedOrigin

Image orientation values from their encoded EXIF data

FILEStream

FILEWStream

FilterMode

Members:

Flattanable

Flattenable is the base class for objects that need to be flattened into a data stream for either transport or as part of the key to the font cache.

Font

Font controls options applied when drawing and measuring text.

FontArguments

Represents a set of actual arguments for a font.

FontHinting

Members:

FontMetrics

The metrics of an Font.

FontMgr

Font manager that knows system fonts.

FontParameters

FontStyle

FontStyleSet

GrBackendApi

Possible 3D APIs that may be used by Ganesh.

GrBackendFormat

GrBackendRenderTarget

GrBackendRenderTargets

alias of GrBackendRenderTarget

GrBackendSemaphore

GrBackendTexture

GrColorType

Members:

GrContext

alias of GrDirectContext

GrContextOptions

GrContext_Base

GrDirectContext

GrDirectContexts

alias of GrDirectContext

GrFlushInfo

Struct to supply options to flush calls.

GrGLBackendState

A GrContext's cache of backend context state can be partially invalidated.

GrGLFormat

Members:

GrGLFramebufferInfo

GrGLInterface

GrGLTextureInfo

GrImageContext

GrMipmapped

Used to say whether a texture has mip levels allocated or not.

GrMockOptions

GrMockRenderTargetInfo

GrMockTextureInfo

GrProtected

Members:

GrPurgeResourceOptions

Members:

GrRecordingContext

GrRenderable

Members:

GrSemaphoresSubmitted

Members:

GrSurfaceOrigin

GPU Image and Surfaces can be stored such that

GrSyncCpu

Members:

GrTextureType

Members:

GrVkAlloc

GrVkBackendContext

The BackendContext contains all of the base Vulkan objects needed by the GrVkGpu.

GrVkDrawableInfo

GrVkImageInfo

When wrapping a GrBackendTexture or GrBackendRendenderTarget, the fCurrentQueueFamily should either be VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_EXTERNAL, or VK_QUEUE_FAMILY_FOREIGN_EXT.

GrVkYcbcrConversionInfo

GradientShader

HighContrastConfig

Configuration struct for HighContrastFilter.

HighContrastFilter

Color filter that provides transformations to improve contrast for users with low vision.

IPoint

IPoint holds two 32-bit integer coordinates.

IRect

IRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.

ISize

Image

Image describes a two dimensional array of pixels to draw.

ImageFilter

Base class for image filters.

ImageFilters

ImageInfo

Describes pixel dimensions and encoding.

Line2DPathEffect

LumaColorFilter

LumaColorFilter multiplies the luma of its input into the alpha channel, and sets the red, green, and blue channels to zero.

M44

4x4 matrix used by Canvas and other parts of Skia.

MaskFilter

MaskFilter is the base class for object that perform transformations on the mask before drawing it.

Matrix

Matrix holds a 3x3 matrix for transforming coordinates.

MemoryStream

MipmapBuilder

MipmapMode

Members:

NullWStream

OpBuilder

Perform a series of path operations, optimized for unioning many paths together.

OverdrawColorFilter

Uses the value in the src alpha channel to set the dst pixel.

PDF

Paint

Paint controls options applied when drawing.

Path

Path contain geometry.

Path1DPathEffect

Path2DPathEffect

PathBuilder

PathDirection

Members:

PathEffect

PathEffect is the base class for objects in the Paint that affect the geometry of a drawing primitive before it is transformed by the canvas' matrix and drawn.

PathFillType

Members:

PathMeasure

PathMeasure

PathOp

The logical operations that can be performed when combining two paths.

PathSegmentMask

Members:

PathVerb

Members:

PerlinNoiseShader

PerlinNoiseShader creates an image using the Perlin turbulence function.

Picture

Picture records drawing commands made to Canvas.

PictureRecorder

PixelGeometry

Description of how the LCD strips are arranged for each pixel.

PixelRef

This class is the smart container for pixel memory, and is used with Bitmap.

Pixmap

Pixmap provides a utility to pair ImageInfo with pixels and row bytes.

Point

Point holds two 32-bit floating point coordinates.

Point3

Point holds three 32-bit floating point coordinates.

RRect

RRect describes a rounded rectangle with a bounds and a pair of radii for each corner.

RSXform

A compressed form of a rotation+scale matrix.

RTreeFactory

Rect

Rect holds four float coordinates describing the upper and lower bounds of a rectangle.

RefCnt

RefCntBase

RefCntBase is the base class for objects that may be shared by multiple objects.

Region

Region describes the set of pixels used to clip Canvas.

RuntimeBlendBuilder

alias of RuntimeEffectBuilder

RuntimeColorFilterBuilder

alias of RuntimeEffectBuilder

RuntimeEffect

RuntimeEffectBuilder

RuntimeEffectBuilderChild

RuntimeEffectBuilderUniform

RuntimeEffectChildPtr

RuntimeEffectResult

RuntimeShaderBuilder

alias of RuntimeEffectBuilder

SVGCanvas

SVGDOM

SamplingOptions

Shader

Shaders specify the source color(s) for what is being drawn.

ShaderMaskFilter

Shaders

Size

SpanRuntimeEffectChildPtr

Stream

Stream – abstraction for a source of bytes.

StreamAsset

StreamMemory

StreamRewindable

StreamSeekable

String

StrokeRec

Surface

Surface is responsible for managing the pixels that a canvas draws into.

SurfaceCharacterization

SurfaceProps

Describes properties and constraints of a given Surface.

Surfaces

alias of Surface

TableColorFilter

TableMaskFilter

Applies a table lookup on each of the alpha values in the mask.

TextBlob

TextBlob combines multiple text runs into an immutable container.

TextBlobBuilder

Helper class for constructing TextBlob.

TextEncoding

Members:

TileMode

Members:

TrimPathEffect

Typeface

The Typeface class specifies the typeface and intrinsic style of a font.

Unicode

V3

V4

VectorRuntimeEffectChildPtr

Vertices

An immutable set of vertex data that can be used with Canvas.drawVertices().

VkFormat

Members:

VkImageLayout

Members:

WStream

Subclasses

YUVAInfo

Specifies the structure of planes for a YUV image with optional alpha.

YUVAPixmapInfo

YUVAInfo combined with per-plane ColorType and row bytes.

YUVAPixmaps

Helper to store Pixmap planes as described by a YUVAPixmapInfo.

YUVColorSpace

Members:

gpuBackendApi

Possible 3D APIs that may be used by Graphite.

textlayout_FontCollection

textlayout_Paragraph

textlayout_ParagraphBuilder

textlayout_ParagraphStyle

textlayout_TextAlign

Members:

textlayout_TextDecoration

Members:

textlayout_TextDecorationMode

Members:

textlayout_TextDecorationStyle

Members:

textlayout_TextStyle

Functions

AlphaTypeIsOpaque(at: skia.AlphaType) bool

Returns true if AlphaType equals kOpaque_AlphaType.

kOpaque_AlphaType is a hint that the ColorType is opaque, or that all alpha values are set to their 1.0 equivalent. If AlphaType is kOpaque_AlphaType, and ColorType is not opaque, then the result of drawing any pixel with a alpha value less than 1.0 is undefined.

AsWinding(path: skia.Path) skia.Path

Set the result with fill type winding to area equivalent to path.

Returns true if successful. Does not detect if path contains contours which contain self-crossings or cross other contours; in these cases, may return true even though result does not fill same area as path.

Returns if operation was able to produce a result; otherwise, throws a runtime error. The result may be the input.

Parameters:

path – The path typically with fill type set to even odd.

Returns:

The equivalent path with fill type set to winding.

BlendMode_AsCoeff(mode: skia.BlendMode, src: skia.BlendModeCoeff, dst: skia.BlendModeCoeff) bool

Returns true if ‘mode’ is a coefficient-based blend mode (<= kLastCoeffMode).

If true is returned, the mode’s src and dst coefficient functions are set in ‘src’ and ‘dst’.

BlendMode_Name(blendMode: skia.BlendMode) str

Returns name of blendMode as null-terminated C string.

Color(r: int, g: int, b: int, a: int = 255) int

Returns color value from 8-bit component values.

In Skia, colors are represented as 32-bit ARGB word, where each component has 8-bit. Colors can be specified by Python literal or constructed from the functions.

Floating point representation is available via Color4f.

Example:

c = 0xFFFF0000  # ARGB
c = skia.Color(255, 0, 0)  # RGB
c = skia.Color(255, 0, 0, 255)  # RGBA
c = skia.ColorSetRGB(255, 255, 0, 0)  # RGB
c = skia.ColorSetARGB(255, 255, 0, 0)  # ARGB

Asserts if SK_DEBUG is defined if a, r, g, or b exceed 255. Since color is unpremultiplied, a may be smaller than the largest of r, g, and b.

Parameters:
  • r (int) – amount of red, from no red (0) to full red (255)

  • g (int) – amount of green, from no green (0) to full green (255)

  • b (int) – amount of blue, from no blue (0) to full blue (255)

  • a (int) – amount of alpha, from fully transparent (0) to fully opaque (255)

Returns:

color and alpha, unpremultiplied

ColorGetA(color: int) int

Returns alpha byte from color value.

ColorGetB(color: int) int

Returns blue component of color, from zero to 255.

ColorGetG(color: int) int

Returns green component of color, from zero to 255.

ColorGetR(color: int) int

Returns red component of color, from zero to 255.

ColorSetA(c: int, a: int) int

Returns unpremultiplied color with red, blue, and green set from c; and alpha set from a.

Alpha component of c is ignored and is replaced by a in result.

Parameters:
  • c (int) – packed RGB, eight bits per component

  • a (int) – alpha: transparent at zero, fully opaque at 255

Returns:

color with transparency

ColorSetARGB(a: int, r: int, g: int, b: int) int

Returns color value from 8-bit component values.

Asserts if SK_DEBUG is defined if a, r, g, or b exceed 255. Since color is unpremultiplied, a may be smaller than the largest of r, g, and b.

Parameters:
  • a (int) – amount of alpha, from fully transparent (0) to fully opaque (255)

  • r (int) – amount of red, from no red (0) to full red (255)

  • g (int) – amount of green, from no green (0) to full green (255)

  • b (int) – amount of blue, from no blue (0) to full blue (255)

Returns:

color and alpha, unpremultiplied

ColorSetRGB(r: int, g: int, b: int) int

Returns color value from 8-bit component values, with alpha set fully opaque to 255.

ColorToHSV(color: int) list[float]

Converts ARGB to its HSV components.

Alpha in ARGB is ignored. hsv[0] contains hsv hue, and is assigned a value from zero to less than 360. hsv[1] contains hsv saturation, a value from zero to one. hsv[2] contains hsv value, a value from zero to one.

Parameters:

color (int) – ARGB color to convert

Returns:

three element array which holds the resulting HSV components

ColorTypeBytesPerPixel(ct: skia.ColorType) int

Returns the number of bytes required to store a pixel, including unused padding.

Returns zero if ct is kUnknown_ColorType or invalid.

Returns:

bytes per pixel

ColorTypeIsAlwaysOpaque(ct: skia.ColorType) bool

Returns true if ColorType always decodes alpha to 1.0, making the pixel fully opaque.

If true, ColorType does not reserve bits to encode alpha.

Returns:

true if alpha is always set to 1.0

ColorTypeValidateAlphaType(colorType: skia.ColorType, alphaType: skia.AlphaType, canonical: skia.AlphaType = None) bool

Returns true if canonical can be set to a valid AlphaType for colorType.

If there is more than one valid canonical AlphaType, set to alphaType, if valid. If true is returned and canonical is not nullptr, store valid AlphaType.

Returns false only if alphaType is kUnknown_AlphaType, color type is not kUnknown_ColorType, and ColorType is not always opaque. If false is returned, canonical is ignored.

Parameters:
  • colorType – color type

  • alphaType – alpha type

  • canonical – output storage for AlphaType

Returns:

true if valid AlphaType can be associated with colorType

ComputeIsOpaque(bm: skia.Bitmap) bool

Returns true if all pixels are opaque.

ColorType determines how pixels are encoded, and whether pixel describes alpha. Returns true for ColorType without alpha in each pixel; for other ColorType, returns true if all pixels have alpha values equivalent to 1.0 or greater.

For ColorType kRGB_565_ColorType or kGray_8_ColorType: always returns true. For ColorType kAlpha_8_ColorType, kBGRA_8888_ColorType, kRGBA_8888_ColorType: returns true if all pixel alpha values are 255. For ColorType kARGB_4444_ColorType: returns true if all pixel alpha values are 15. For kRGBA_F16_ColorType: returns true if all pixel alpha values are 1.0 or greater.

Returns false for kUnknown_ColorType.

Parameters:

bm (skia.Bitmap) – Bitmap to check

Returns:

true if all pixels have opaque values or ColorType is opaque

EncodedOriginToMatrix(origin: skia.EncodedOrigin, w: int, h: int) skia.Matrix

Given an encoded origin and the width and height of the source data, returns a matrix that transforms the source rectangle with upper left corner at [0, 0] and origin to a correctly oriented destination rectangle of [0, 0, w, h].

HSVToColor(hsv: list[float], alpha: int = 255) int

Converts HSV components to an ARGB color.

Alpha is passed through unchanged. hsv[0] represents hsv hue, an angle from zero to less than 360. hsv[1] represents hsv saturation, and varies from zero to one. hsv[2] represents hsv value, and varies from zero to one.

Out of range hsv values are pinned.

Parameters:
  • hsv – three element array which holds the input HSV components

  • alpha – alpha component of the returned ARGB color

Returns:

ARGB equivalent to HSV

MakeNullCanvas() skia.Canvas
Op(one: skia.Path, two: skia.Path, op: skia.PathOp) skia.Path

Set this path to the result of applying the Op to this path and the specified path: this = (this op operand).

The resulting path will be constructed from non-overlapping contours. The curve order is reduced where possible so that cubics may be turned into quadratics, and quadratics maybe turned into lines.

Returns if operation was able to produce a result; otherwise, throws a runtime error.

Parameters:
  • one – The first operand (for difference, the minuend)

  • two – The second operand (for difference, the subtrahend)

  • op – The operator to apply.

Returns:

The product of the operands. The result may be one of the inputs.

PathFillType_ConvertToNonInverse(ft: skia.PathFillType) skia.PathFillType
PathFillType_IsEvenOdd(ft: skia.PathFillType) bool
PathFillType_IsInverse(ft: skia.PathFillType) bool
PreMultiplyARGB(a: int, r: int, g: int, b: int) int

Returns a SkPMColor value from unpremultiplied 8-bit component values.

Parameters:
  • a – amount of alpha, from fully transparent (0) to fully opaque (255)

  • r – amount of red, from no red (0) to full red (255)

  • g – amount of green, from no green (0) to full green (255)

  • b – amount of blue, from no blue (0) to full blue (255)

Returns:

premultiplied color

PreMultiplyColor(c: int) int

Returns pmcolor closest to color c.

Multiplies c RGB components by the c alpha, and arranges the bytes to match the format of kN32_ColorType.

Parameters:

c – unpremultiplied ARGB color

Returns:

premultiplied color

RGBToHSV(red: int, green: int, blue: int) list[float]

Converts RGB to its HSV components.

hsv[0] contains hsv hue, a value from zero to less than 360. hsv[1] contains hsv saturation, a value from zero to one. hsv[2] contains hsv value, a value from zero to one.

Parameters:
  • red (int) – red component value from zero to 255

  • green (int) – green component value from zero to 255

  • blue (int) – blue component value from zero to 255

Returns:

three element array which holds the resulting HSV components

Simplify(path: skia.Path) skia.Path

Set this path to a set of non-overlapping contours that describe the same area as the original path.

The curve order is reduced where possible so that cubics may be turned into quadratics, and quadratics maybe turned into lines.

Returns if operation was able to produce a result; otherwise, throws a runtime error.

Parameters:

path – The path to simplify.

Returns:

The simplified path. The result may be the input.

TightBounds(path: skia.Path) skia.Rect

Set the resulting rectangle to the tight bounds of the path.

Parameters:

path – The path measured.

Returns:

The tight bounds of the path.