ImageInfo

class ImageInfo

Describes pixel dimensions and encoding.

Bitmap, Image, Pixmap, and Surface can be created from ImageInfo. ImageInfo can be retrieved from Bitmap and Pixmap, but not from Image and Surface. For example, Image and Surface implementations may defer pixel depth, so may not completely specify ImageInfo.

ImageInfo contains dimensions, the pixel integral width and height. It encodes how pixel bits describe alpha, transparency; color components red, blue, and green; and ColorSpace, the range and linearity of colors.

Methods

ByteSizeOverflowed

Returns true if byteSize equals SIZE_MAX.

Make

Overloaded function.

MakeA8

Overloaded function.

MakeN32

Creates ImageInfo from integral dimensions width and height, kN32_ColorType, AlphaType at, and optionally ColorSpace cs.

MakeN32Premul

Overloaded function.

MakeS32

Creates ImageInfo from integral dimensions width and height, kN32_ColorType, AlphaType at, with sRGB ColorSpace.

MakeUnknown

Overloaded function.

__init__

Creates an empty ImageInfo with kUnknown_ColorType, kUnknown_AlphaType, a width and height of zero, and no ColorSpace.

alphaType

bounds

Returns IRect (0, 0, width(), height()).

bytesPerPixel

Returns number of bytes per pixel required by ColorType.

colorInfo

Returns the dimensionless ColorInfo that represents the same color type, alpha type, and color space as this ImageInfo.

colorSpace

Returns ColorSpace, the range of colors.

colorType

computeByteSize

Returns storage required by pixel array, given ImageInfo dimensions, ColorType, and rowBytes.

computeMinByteSize

Returns storage required by pixel array, given ImageInfo dimensions, and ColorType.

computeOffset

Returns byte offset of pixel from pixel base address.

dimensions

Returns ISize (width(), height()).

gammaCloseToSRGB

Returns true if associated ColorSpace is not nullptr, and ColorSpace gamma is approximately the same as sRGB.

height

Returns pixel row count.

isEmpty

Returns if ImageInfo describes an empty area of pixels by checking if either width or height is zero or smaller.

isOpaque

Returns true if AlphaType is set to hint that all pixels are opaque; their alpha value is implicitly or explicitly 1.0.

makeAlphaType

Creates ImageInfo with same ColorType, ColorSpace, width, and height, with AlphaType set to newAlphaType.

makeColorSpace

Creates ImageInfo with same AlphaType, ColorType, width, and height, with ColorSpace set to cs.

makeColorType

Creates ImageInfo with same AlphaType, ColorSpace, width, and height, with ColorType set to newColorType.

makeDimensions

Creates ImageInfo with the same ColorType, ColorSpace, and AlphaType, with dimensions set to newDimensions.

makeWH

Creates ImageInfo with the same ColorType, ColorSpace, and AlphaType, with dimensions set to width and height.

minRowBytes

Returns minimum bytes per row, computed from pixel width() and ColorType, which specifies bytesPerPixel().

minRowBytes64

Returns minimum bytes per row, computed from pixel width() and ColorType, which specifies bytesPerPixel().

refColorSpace

Returns smart pointer to ColorSpace, the range of colors.

reset

Creates an empty ImageInfo with kUnknown_ColorType, kUnknown_AlphaType, a width and height of zero, and no ColorSpace.

shiftPerPixel

Returns bit shift converting row bytes to row pixels.

validRowBytes

Returns true if rowBytes is valid for this ImageInfo.

width

Returns pixel count in each row.

Methods

static ImageInfo.ByteSizeOverflowed(byteSize: int) bool

Returns true if byteSize equals SIZE_MAX.

computeByteSize() and computeMinByteSize() return SIZE_MAX if size_t can not hold buffer size.

Parameters:

byteSize (int) – result of computeByteSize() or computeMinByteSize()

Returns:

true if computeByteSize() or computeMinByteSize() result exceeds size_t

static ImageInfo.Make(*args, **kwargs)

Overloaded function.

  1. Make(width: int, height: int, ct: skia.ColorType, at: skia.AlphaType, cs: skia.ColorSpace = None) -> skia.ImageInfo

    Creates ImageInfo from integral dimensions width and height, ColorType ct, AlphaType at, and optionally ColorSpace cs.

    If ColorSpace cs is nullptr and ImageInfo is part of drawing source: ColorSpace defaults to sRGB, mapping into Surface ColorSpace.

    Parameters are not validated to see if their values are legal, or that the combination is supported.

    width:

    pixel column count; must be zero or greater

    height:

    pixel row count; must be zero or greater

    cs:

    range of colors; may be nullptr

    return:

    created ImageInfo

  2. Make(dimensions: skia.ISize, ct: skia.ColorType, at: skia.AlphaType, cs: skia.ColorSpace = None) -> skia.ImageInfo

  3. Make(dimensions: skia.ISize, colorInfo: skia.ColorInfo) -> skia.ImageInfo

    Creates ImageInfo from integral dimensions and ColorInfo colorInfo,.

    Parameters are not validated to see if their values are legal, or that the combination is supported.

    param skia.ISize dimensions:

    pixel column and row count; must be zeros or greater

    param skia.ColorInfo colorInfo:

    ColorInfo the pixel encoding consisting of ColorType, AlphaType, and ColorSpace (which may be nullptr)

    return:

    created ImageInfo

static ImageInfo.MakeA8(*args, **kwargs)

Overloaded function.

  1. MakeA8(width: int, height: int) -> skia.ImageInfo

    Creates ImageInfo from integral dimensions width and height, kAlpha_8_ColorType, kPremul_AlphaType, with ColorSpace set to nullptr.

    width:

    pixel column count; must be zero or greater

    height:

    pixel row count; must be zero or greater

  2. MakeA8(dimensions: skia.ISize) -> skia.ImageInfo

    Creates ImageInfo from integral dimensions, kAlpha_8_ColorType, kPremul_AlphaType, with ColorSpace set to nullptr.

    dimensions:

    pixel row and column count; must be zero or greater

static ImageInfo.MakeN32(width: int, height: int, at: skia.AlphaType, cs: skia.ColorSpace = None) skia.ImageInfo

Creates ImageInfo from integral dimensions width and height, kN32_ColorType, AlphaType at, and optionally ColorSpace cs.

kN32_ColorType will equal either kBGRA_8888_ColorType or kRGBA_8888_ColorType, whichever is optimal.

If ColorSpace cs is nullptr and ImageInfo is part of drawing source: ColorSpace defaults to sRGB, mapping into Surface ColorSpace.

Parameters are not validated to see if their values are legal, or that the combination is supported.

Parameters:
  • width (int) – pixel column count; must be zero or greater

  • height (int) – pixel row count; must be zero or greater

  • cs (skia.ColorSpace) – range of colors; may be nullptr

Returns:

created ImageInfo

static ImageInfo.MakeN32Premul(*args, **kwargs)

Overloaded function.

  1. MakeN32Premul(width: int, height: int, cs: skia.ColorSpace = None) -> skia.ImageInfo

    Creates ImageInfo from integral dimensions width and height, kN32_ColorType, kPremul_AlphaType, with optional ColorSpace.

    If ColorSpace cs is nullptr and ImageInfo is part of drawing source: ColorSpace defaults to sRGB, mapping into Surface ColorSpace.

    Parameters are not validated to see if their values are legal, or that the combination is supported.

    width:

    pixel column count; must be zero or greater

    height:

    pixel row count; must be zero or greater

    cs:

    range of colors; may be nullptr

    return:

    created ImageInfo

  2. MakeN32Premul(dimensions: skia.ISize, cs: skia.ColorSpace = None) -> skia.ImageInfo

    Creates ImageInfo from integral dimensions width and height, kN32_ColorType, kPremul_AlphaType, with optional ColorSpace.

    If ColorSpace cs is nullptr and ImageInfo is part of drawing source: ColorSpace defaults to sRGB, mapping into Surface ColorSpace.

    Parameters are not validated to see if their values are legal, or that the combination is supported.

    dimensions:

    width and height, each must be zero or greater

    cs:

    range of colors; may be nullptr

    return:

    created ImageInfo

static ImageInfo.MakeS32(width: int, height: int, at: skia.AlphaType) skia.ImageInfo

Creates ImageInfo from integral dimensions width and height, kN32_ColorType, AlphaType at, with sRGB ColorSpace.

Parameters are not validated to see if their values are legal, or that the combination is supported.

Parameters:
  • width (int) – pixel column count; must be zero or greater

  • height (int) – pixel row count; must be zero or greater

Returns:

created ImageInfo

static ImageInfo.MakeUnknown(*args, **kwargs)

Overloaded function.

  1. MakeUnknown(width: int, height: int) -> skia.ImageInfo

    Creates ImageInfo from integral dimensions width and height, kUnknown_ColorType, kUnknown_AlphaType, with ColorSpace set to nullptr.

    Returned ImageInfo as part of source does not draw, and as part of destination can not be drawn to.

    width:

    pixel column count; must be zero or greater

    height:

    pixel row count; must be zero or greater

    return:

    created ImageInfo

  2. MakeUnknown() -> skia.ImageInfo

    Creates ImageInfo from integral dimensions width and height set to zero, kUnknown_ColorType, kUnknown_AlphaType, with ColorSpace set to nullptr.

    Returned ImageInfo as part of source does not draw, and as part of destination can not be drawn to.

    return:

    created ImageInfo

ImageInfo.__init__(self: skia.ImageInfo) None

Creates an empty ImageInfo with kUnknown_ColorType, kUnknown_AlphaType, a width and height of zero, and no ColorSpace.

ImageInfo.alphaType(self: skia.ImageInfo) skia.AlphaType
ImageInfo.bounds(self: skia.ImageInfo) skia.IRect

Returns IRect (0, 0, width(), height()).

Returns:

integral rectangle from origin to width() and height()

ImageInfo.bytesPerPixel(self: skia.ImageInfo) int

Returns number of bytes per pixel required by ColorType.

Returns zero if colorType() is kUnknown_ColorType.

Returns:

bytes in pixel

ImageInfo.colorInfo(self: skia.ImageInfo) skia.ColorInfo

Returns the dimensionless ColorInfo that represents the same color type, alpha type, and color space as this ImageInfo.

ImageInfo.colorSpace(self: skia.ImageInfo) skia.ColorSpace

Returns ColorSpace, the range of colors.

The reference count of ColorSpace is unchanged. The returned ColorSpace is immutable.

Returns:

ColorSpace, or nullptr

ImageInfo.colorType(self: skia.ImageInfo) skia.ColorType
ImageInfo.computeByteSize(self: skia.ImageInfo, rowBytes: int) int

Returns storage required by pixel array, given ImageInfo dimensions, ColorType, and rowBytes.

rowBytes is assumed to be at least as large as minRowBytes().

Returns zero if height is zero. Returns SIZE_MAX if answer exceeds the range of size_t.

Parameters:

rowBytes (int) – size of pixel row or larger

Returns:

memory required by pixel buffer

ImageInfo.computeMinByteSize(self: skia.ImageInfo) int

Returns storage required by pixel array, given ImageInfo dimensions, and ColorType.

Uses minRowBytes() to compute bytes for pixel row.

Returns zero if height is zero. Returns SIZE_MAX if answer exceeds the range of size_t.

Returns:

least memory required by pixel buffer

ImageInfo.computeOffset(self: skia.ImageInfo, x: int, y: int, rowBytes: int) int

Returns byte offset of pixel from pixel base address.

Asserts in debug build if x or y is outside of bounds. Does not assert if rowBytes is smaller than minRowBytes(), even though result may be incorrect.

Parameters:
  • x (int) – column index, zero or greater, and less than width()

  • y (int) – row index, zero or greater, and less than height()

  • rowBytes (int) – size of pixel row or larger

Returns:

offset within pixel array

ImageInfo.dimensions(self: skia.ImageInfo) skia.ISize

Returns ISize (width(), height()).

Returns:

integral size of width() and height()

ImageInfo.gammaCloseToSRGB(self: skia.ImageInfo) bool

Returns true if associated ColorSpace is not nullptr, and ColorSpace gamma is approximately the same as sRGB.

Returns:

true if ColorSpace gamma is approximately the same as sRGB

ImageInfo.height(self: skia.ImageInfo) int

Returns pixel row count.

Returns:

pixel height

ImageInfo.isEmpty(self: skia.ImageInfo) bool

Returns if ImageInfo describes an empty area of pixels by checking if either width or height is zero or smaller.

Returns:

true if either dimension is zero or smaller

ImageInfo.isOpaque(self: skia.ImageInfo) bool

Returns true if AlphaType is set to hint that all pixels are opaque; their alpha value is implicitly or explicitly 1.0.

If true, and all pixels are not opaque, Skia may draw incorrectly.

Does not check if ColorType allows alpha, or if any pixel value has transparency.

Returns:

true if AlphaType is kOpaque_AlphaType

ImageInfo.makeAlphaType(self: skia.ImageInfo, newAlphaType: skia.AlphaType) skia.ImageInfo

Creates ImageInfo with same ColorType, ColorSpace, width, and height, with AlphaType set to newAlphaType.

Created ImageInfo contains newAlphaType even if it is incompatible with ColorType, in which case AlphaType in ImageInfo is ignored.

Parameters:

newAlphaType (skia.AlphaType) – new alpha type

Returns:

created ImageInfo

ImageInfo.makeColorSpace(self: skia.ImageInfo, cs: skia.ColorSpace) skia.ImageInfo

Creates ImageInfo with same AlphaType, ColorType, width, and height, with ColorSpace set to cs.

Parameters:

cs (skia.ColorSpace) – range of colors; may be nullptr

Returns:

created ImageInfo

ImageInfo.makeColorType(self: skia.ImageInfo, newColorType: skia.ColorType) skia.ImageInfo

Creates ImageInfo with same AlphaType, ColorSpace, width, and height, with ColorType set to newColorType.

Parameters:

newColorType (skia.ColorType) – new color type

Returns:

created ImageInfo

ImageInfo.makeDimensions(self: skia.ImageInfo, newSize: skia.ISize) skia.ImageInfo

Creates ImageInfo with the same ColorType, ColorSpace, and AlphaType, with dimensions set to newDimensions.

Parameters:

newSize (skia.ISize) – pixel column and row count; must be zero or greater

Returns:

created ImageInfo

ImageInfo.makeWH(self: skia.ImageInfo, newWidth: int, newHeight: int) skia.ImageInfo

Creates ImageInfo with the same ColorType, ColorSpace, and AlphaType, with dimensions set to width and height.

Parameters:
  • newWidth (int) – pixel column count; must be zero or greater

  • newHeight (int) – pixel row count; must be zero or greater

Returns:

created ImageInfo

ImageInfo.minRowBytes(self: skia.ImageInfo) int

Returns minimum bytes per row, computed from pixel width() and ColorType, which specifies bytesPerPixel().

Bitmap maximum value for row bytes must fit in 31 bits.

Returns:

width() times bytesPerPixel() as signed 32-bit integer

ImageInfo.minRowBytes64(self: skia.ImageInfo) int

Returns minimum bytes per row, computed from pixel width() and ColorType, which specifies bytesPerPixel().

Bitmap maximum value for row bytes must fit in 31 bits.

Returns:

width() times bytesPerPixel() as unsigned 64-bit integer

ImageInfo.refColorSpace(self: skia.ImageInfo) skia.ColorSpace

Returns smart pointer to ColorSpace, the range of colors.

The smart pointer tracks the number of objects sharing this ColorSpace reference so the memory is released when the owners destruct.

The returned ColorSpace is immutable.

Returns:

ColorSpace wrapped in a smart pointer

ImageInfo.reset(self: skia.ImageInfo) None

Creates an empty ImageInfo with kUnknown_ColorType, kUnknown_AlphaType, a width and height of zero, and no ColorSpace.

ImageInfo.shiftPerPixel(self: skia.ImageInfo) int

Returns bit shift converting row bytes to row pixels.

Returns zero for skia.ColorType.kUnknown_ColorType.

Returns:

one of: 0, 1, 2, 3; left shift to convert pixels to bytes

ImageInfo.validRowBytes(self: skia.ImageInfo, rowBytes: int) bool

Returns true if rowBytes is valid for this ImageInfo.

Parameters:

rowBytes (int) – size of pixel row including padding

Returns:

true if rowBytes is large enough to contain pixel row and is properly aligned

ImageInfo.width(self: skia.ImageInfo) int

Returns pixel count in each row.

Returns:

pixel width