SkColor4f_Reference.md 19 KB

SkColor4f Reference



struct SkRGBA4f {

    float fR;
    float fG;
    float fB;
    float fA;

    bool operator==(const SkRGBA4f& other) const;
    bool operator!=(const SkRGBA4f& other) const;
    SkRGBA4f operator*(float scale) const;
    SkRGBA4f operator*(const SkRGBA4f& scale) const;
    const float* vec() const;
    float* vec();
    float operator[](int index) const;
    float& operator[](int index);
    bool isOpaque() const;
    static SkRGBA4f FromColor(SkColor color);
    SkColor toSkColor() const;
    static SkRGBA4f FromPMColor(SkPMColor);
    SkRGBA4f<kPremul_SkAlphaType> premul() const;
    SkRGBA4f<kUnpremul_SkAlphaType> unpremul() const;
    uint32_t toBytes_RGBA() const;
    static SkRGBA4f FromBytes_RGBA(uint32_t color);
    SkRGBA4f makeOpaque() const;
};

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.

Components are independent of the others if defined with kUnpremul_SkAlphaType; fA Alpha is may be greater or smaller than fG green, fB blue, or fR red. SkColor4f is shorthand for Unpremultiplied SkRGBA4f.

Components are connected if defined with kPremul_SkAlphaType; fA Alpha is equal to or larger than fG green, fB blue, and fR red. The values stored in fG, fB, and fR combine the color component with the Alpha component.

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.

Type Member Description

<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '>float</td>
<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '><a name='SkRGBA4f_fR'><code>fR</code></a></td>
<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '>

Single precision float for red ranges from no red (0.0) to full red (1.0).

<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '>float</td>
<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '><a name='SkRGBA4f_fG'><code>fG</code></a></td>
<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '>

Single precision float for green ranges from no green (0.0) to full green (1.0).

<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '>float</td>
<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '><a name='SkRGBA4f_fB'><code>fB</code></a></td>
<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '>

Single precision float for blue ranges from no blue (0.0) to full blue (1.0).

<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '>float</td>
<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '><a name='SkRGBA4f_fA'><code>fA</code></a></td>
<td style='text-align: left; border: 2px solid #dddddd; padding: 8px; '>

Single precision float for Alpha ranges from no Alpha (0.0) to full Alpha (1.0).


bool operator==(const SkRGBA4f& other)const

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

Parameters

other SkRGBA4f to compare

Return Value

true if SkRGBA4f equals other

Example

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

See Also

operator!=(const SkRGBA4f& other) const


bool operator!=(const SkRGBA4f& other)const

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

Parameters

other SkRGBA4f to compare

Return Value

true if SkRGBA4f is not equal to other

Example

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

See Also

operator==(const SkRGBA4f& other) const


SkRGBA4f operator*(float scale)const

Multiplies each component by scale. Does not pin the result.

Parameters

scale component multiplier

Return Value

scaled color

See Also

SkBlendMode::kMultiply


SkRGBA4f operator*(const SkRGBA4f& scale)const

Multiplies each component by scale component. Does not pin the result.

Parameters

scale SkRGBA4f component multipliers

Return Value

scaled color

See Also

SkBlendMode::kMultiply


const float* vec()const

Returns SkRGBA4f components as a read-only array.

Return Value

components as read-only array

Example

#### Example Output ~~~~ red=0.266667 green=0.533333 blue=0.8 alpha=0.533333 [0]=0.266667 [1]=0.533333 [2]=0.8 [3]=0.533333 ~~~~

See Also

SkColor4f


float* vec()

Returns SkRGBA4f components as a writable array.

Return Value

components as writable array

Example

#### Example Output ~~~~ red=0.266667 green=0.533333 blue=0.8 alpha=0.533333 [0]=0.266667 [1]=0.533333 [2]=0.8 [3]=1 ~~~~

See Also

SkColor4f


float operator[](int index)const

Returns SkRGBA4f component by index, zero through three. index out of range triggers an assert in debug builds.

Parameters

index component, zero through three

Return Value

component by index

See Also

vec


float& operator[](int index)

Returns writable component reference by index, zero through three. index out of range triggers an assert in debug builds.

Parameters

index component, zero through three

Return Value

writable component reference by index

See Also

vec


bool isOpaque()const

Returns true if Alpha component is one. Color has no transparency regardless of whether color is Premultiplied or Unpremultiplied. Triggers a debugging assert if Alpha not valid.

Return Value

true if Alpha is one

See Also

vec SkColorGetA


static SkRGBA4f FromColor(SkColor color)

Returns closest SkRGBA4f to SkColor. Only allowed if SkRGBA4f is unpremultiplied.

Parameters

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

Return Value

SkColor as SkRGBA4f

Example

#### Example Output ~~~~ red=0.301961 green=0.396078 blue=0.6 alpha=0.168627 red=77 green=101 blue=153 alpha=43 ~~~~

See Also

toSkColor


SkColor toSkColor()const

Converts to closest SkColor.

Return Value

closest Color

Example

#### Example Output ~~~~ red=18 green=33 blue=82 alpha=43 red=0.0705882 green=0.129412 blue=0.321569 alpha=0.168627 ~~~~

See Also

FromColor


static SkRGBA4f FromPMColor(SkPMColor)

Converts from Premultiplied integer components to Unpremultiplied float components.

Parameters

SkPMColor Premultiplied color

Return Value

Unpremultiplied color

See Also

FromColor


SkRGBA4f<kPremul_SkAlphaType> premul()const

Returns SkColor4f with all components premultiplied by Alpha.

Return Value

Premultiplied color

See Also

unpremul


SkRGBA4f<kUnpremul_SkAlphaType> unpremul()const

Returns SkRGBA4f with all components independent of Alpha.

Return Value

Unpremultiplied color

See Also

premul


uint32_t toBytes_RGBA()const

Produces bytes in RGBA order. Component values are not affected by color Alpha.

Return Value

color


static SkRGBA4f FromBytes_RGBA(uint32_t color)

Returns from color kRGBA_8888_SkColorType order. Component values are not affected by color Alpha.

Parameters

color Premultiplied or Unpremultiplied

Return Value

color


SkRGBA4f makeOpaque()const

Returns color with Alpha set to one.

Return Value

color


using SkColor4f = SkRGBA4f<kUnpremul_SkAlphaType>;