SkColor4f Reference

Color4f

Struct SkColor4f

Member

SkColor4f members may be read and written directly without using a member function.

Topic Description
fA alpha component
fB blue component
fG green component
fR red component

Each component is stored as a 32-bit single precision floating point float value. All values are allowed, but only the range from zero to one is meaningful.

Each component is independent of the others; fA Alpha is not Premultiplied with fG green, fB blue, or fR red.

Values smaller than zero or larger than one are allowed. Values out of range may be used with Blend Mode so that the final component is in range.

Overview

Topic Description
Functions global and class member functions
Members member values
Operators operator overloading methods

Operator

SkColor4f operators inline class member functions with arithmetic equivalents.

Topic Description
operator!=(const SkColor4f& other) const compares colors for inequality
operator==(const SkColor4f& other) const compares Color4f for equality

Member Function

SkColor4f member functions read and modify the structure properties.

Topic Description
FromColor sets components from Color
Pin sets components to valid range
pin sets components to valid range
premul returns Premultiplied color; internal use only
toSkColor returns closest Color
vec returns array of components

Members

Type Name Description
float fR Single precision float for red ranges from no red (0.0) to full red (1.0).
float fG Single precision float for green ranges from no green (0.0) to full green (1.0).
float fB Single precision float for blue ranges from no blue (0.0) to full blue (1.0).
float fA Single precision float for Alpha ranges from no Alpha (0.0) to full Alpha (1.0).

operator==

bool operator==(const SkColor4f& other) _const

Compares Color4f with other, and returns true if all components are equivalent.

Parameters

other Color4f to compare

Return Value

true if Color4f equals other

Example

#### Example Output ~~~~ colorRed == colorNamedRed ~~~~

See Also

operator!=(const SkColor4f& other) const


operator!=

bool operator!=(const SkColor4f& other) _const

Compares Color4f with other, and returns true if all components are not equivalent.

Parameters

other Color4f to compare

Return Value

true if Color4f is not equal to other

Example

#### Example Output ~~~~ colorGray != colorNamedGray ~~~~

See Also

operator==(const SkColor4f& other) const


vec

const float* vec() const

Returns Color4f components as a read-only array.

Return Value

components as read-only array

Example

#### Example Output ~~~~ red=0.0578054 green=0.246201 blue=0.603827 alpha=0.533333 [0]=0.0578054 [1]=0.246201 [2]=0.603827 [3]=0.533333 ~~~~

See Also

SkColor4f


float* vec()

Returns Color4f components as a writable array.

Return Value

components as writable array

Example

#### Example Output ~~~~ red=0.0578054 green=0.246201 blue=0.603827 alpha=0.533333 [0]=0.0578054 [1]=0.246201 [2]=0.603827 [3]=1 ~~~~

See Also

SkColor4f


Pin

static SkColor4f Pin(float r, float g, float b, float a)

Constructs and returns Color4f with each component pinned from zero to one.

Parameters

r red component
g green component
b blue component
a Alpha component

Return Value

Color4f with valid components

Example

See Also

pin FromColor


FromColor

static SkColor4f FromColor(SkColor)

Converts to closest Color4f.

Parameters

SkColor Color with Alpha, red, blue, and green components

Return Value

Color4f equivalent

Example

#### Example Output ~~~~ red=0.0742136 green=0.130136 blue=0.318547 alpha=0.168627 red=77 green=101 blue=153 alpha=43 ~~~~

See Also

toSkColor


toSkColor

SkColor toSkColor() const

Converts to closest SkColor.

Return Value

closest Color

Example

#### Example Output ~~~~ red=75 green=101 blue=153 alpha=43 red=0.0703601 green=0.130136 blue=0.318547 alpha=0.168627 ~~~~

See Also

FromColor


pin

SkColor4f pin() const

Returns Color4f with all components in the range from zero to one.

Return Value

Color4f with valid components

Example

See Also

Pin


premul

SkPM4f premul() const

Return Value

Premultiplied color


Struct SkPM4f