Color4f

class Color4f

RGBA color value, holding four floating point components.

Color components are always in a known order, and are unpremultiplied.

Skia’s public API always uses unpremultiplied colors.

Example:

color4f = skia.Color4f(0xFFFFFFFF)            # From int format
color4f = skia.Color4f(1.0, 0.0, 0.0, 1.0)    # From elements
color4f = skia.Color4f((1.0, 0.0, 0.0, 1.0))  # From tuple
color = color4f.toColor()                     # Convert to int format
color = int(color4f)                          # Convert to int format
r, g, b, a = tuple(color4f)                   # Convert to tuple

Methods

FromBytes_RGBA

FromColor

Returns closest Color4f to Color int.

__init__

__init__(*args, **kwargs) Overloaded function.

fitsInBytes

Returns true if all channels are in [0, 1].

isOpaque

Returns true if Color4f is an opaque color.

makeOpaque

toBytes_RGBA

toColor

Returns closest Color to Color4f.

vec

Returns a memoryview to components of Color4f, for array access.

Attributes

fA

alpha component

fB

blue component

fG

green component

fR

red component

kBlack

kBlue

kCyan

kDkGray

kGray

kGreen

kLtGray

kMagenta

kRed

kTransparent

kWhite

kYellow

Methods

static Color4f.FromBytes_RGBA(rgba: int) skia.Color4f
static Color4f.FromColor(color: int) skia.Color4f

Returns closest Color4f to Color int.

Parameters

color (int) – Color with Alpha, red, blue, and green components (e.g., 0xFFFFFFFF)

Returns

Color int as Color4f

Color4f.__init__(*args, **kwargs)

__init__(*args, **kwargs) Overloaded function.

  1. __init__(self: skia.Color4f, color: int) -> None

    Returns closest Color4f to ARGB Color. See FromColor().

  2. __init__(self: skia.Color4f, red: float, green: float, blue: float, alpha: float = 1.0) -> None

    Returns a new Color4f instance initialized with the given values.

    red

    red components

    green

    green components

    blue

    blue components

    alpha

    alpha components

  3. __init__(self: skia.Color4f, t: tuple) -> None

    Returns a new Color4f instance given (R, G, B) or (R, G, B, A) tuple.

Color4f.fitsInBytes(self: skia.Color4f) bool

Returns true if all channels are in [0, 1].

Color4f.isOpaque(self: skia.Color4f) bool

Returns true if Color4f is an opaque color.

Asserts if fA is out of range and SK_DEBUG is defined.

Returns

true if Color4f is opaque

Color4f.makeOpaque(self: skia.Color4f) skia.Color4f
Color4f.toBytes_RGBA(self: skia.Color4f) int
Color4f.toColor(self: skia.Color4f) int

Returns closest Color to Color4f.

Returns

color as Color int

Color4f.vec(self: skia.Color4f) memoryview

Returns a memoryview to components of Color4f, for array access.

Attributes

Color4f.fA

alpha component

Color4f.fB

blue component

Color4f.fG

green component

Color4f.fR

red component

Color4f.kBlack = Color4f(0, 0, 0, 1)
Color4f.kBlue = Color4f(0, 0, 1, 1)
Color4f.kCyan = Color4f(0, 1, 1, 1)
Color4f.kDkGray = Color4f(0.25, 0.25, 0.25, 1)
Color4f.kGray = Color4f(0.5, 0.5, 0.5, 1)
Color4f.kGreen = Color4f(0, 1, 0, 1)
Color4f.kLtGray = Color4f(0.75, 0.75, 0.75, 1)
Color4f.kMagenta = Color4f(1, 0, 1, 1)
Color4f.kRed = Color4f(1, 0, 0, 1)
Color4f.kTransparent = Color4f(0, 0, 0, 0)
Color4f.kWhite = Color4f(1, 1, 1, 1)
Color4f.kYellow = Color4f(1, 1, 0, 1)