Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
SkRGBA4f< kAT > Struct Template Reference

#include <SkColor.h>

Public Member Functions

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 ()
 
std::array< float, 4 > array () const
 
float operator[] (int index) const
 
float & operator[] (int index)
 
bool isOpaque () const
 
bool fitsInBytes () const
 
SkColor toSkColor () const
 
SkRGBA4f< kPremul_SkAlphaTypepremul () const
 
SkRGBA4f< kUnpremul_SkAlphaTypeunpremul () const
 
uint32_t toBytes_RGBA () const
 
SkRGBA4f makeOpaque () const
 

Static Public Member Functions

static SkRGBA4f FromColor (SkColor color)
 
static SkRGBA4f FromPMColor (SkPMColor)
 
static SkRGBA4f FromBytes_RGBA (uint32_t color)
 

Public Attributes

float fR
 red component More...
 
float fG
 green component More...
 
float fB
 blue component More...
 
float fA
 alpha component More...
 

Detailed Description

template<SkAlphaType kAT>
struct SkRGBA4f< kAT >

RGBA color value, holding four floating point components. Color components are always in a known order. kAT determines if the SkRGBA4f's R, G, and B components are premultiplied by alpha or not.

Skia's public API always uses unpremultiplied colors, which can be stored as SkRGBA4f<kUnpremul_SkAlphaType>. For convenience, this type can also be referred to as SkColor4f.

Definition at line 262 of file SkColor.h.

Member Function Documentation

◆ array()

template<SkAlphaType kAT>
std::array< float, 4 > SkRGBA4f< kAT >::array ( ) const
inline

As a std::array<float, 4>

Definition at line 317 of file SkColor.h.

317{ return {fR, fG, fB, fA}; }
float fB
blue component
Definition: SkColor.h:265
float fR
red component
Definition: SkColor.h:263
float fG
green component
Definition: SkColor.h:264
float fA
alpha component
Definition: SkColor.h:266

◆ fitsInBytes()

template<SkAlphaType kAT>
bool SkRGBA4f< kAT >::fitsInBytes ( ) const
inline

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

Definition at line 350 of file SkColor.h.

350 {
351 SkASSERT(fA >= 0.0f && fA <= 1.0f);
352 return fR >= 0.0f && fR <= 1.0f &&
353 fG >= 0.0f && fG <= 1.0f &&
354 fB >= 0.0f && fB <= 1.0f;
355 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ FromBytes_RGBA()

template<SkAlphaType kAT>
static SkRGBA4f SkRGBA4f< kAT >::FromBytes_RGBA ( uint32_t  color)
static

◆ FromColor()

template<SkAlphaType kAT>
static SkRGBA4f SkRGBA4f< kAT >::FromColor ( SkColor  color)
static

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

Parameters
colorColor with Alpha, red, blue, and green components
Returns
SkColor as SkRGBA4f

example: https://fiddle.skia.org/c/@RGBA4f_FromColor

◆ FromPMColor()

template<SkAlphaType kAT>
static SkRGBA4f SkRGBA4f< kAT >::FromPMColor ( SkPMColor  )
static

Returns closest SkRGBA4f to SkPMColor. Only allowed if SkRGBA4f is premultiplied.

Returns
SkPMColor as SkRGBA4f

◆ isOpaque()

template<SkAlphaType kAT>
bool SkRGBA4f< kAT >::isOpaque ( ) const
inline

Returns true if SkRGBA4f is an opaque color. Asserts if fA is out of range and SK_DEBUG is defined.

Returns
true if SkRGBA4f is opaque

Definition at line 344 of file SkColor.h.

344 {
345 SkASSERT(fA <= 1.0f && fA >= 0.0f);
346 return fA == 1.0f;
347 }

◆ makeOpaque()

template<SkAlphaType kAT>
SkRGBA4f SkRGBA4f< kAT >::makeOpaque ( ) const
inline

Returns a copy of the SkRGBA4f but with alpha component set to 1.0f.

Returns
opaque color

Definition at line 415 of file SkColor.h.

415 {
416 return { fR, fG, fB, 1.0f };
417 }

◆ operator!=()

template<SkAlphaType kAT>
bool SkRGBA4f< kAT >::operator!= ( const SkRGBA4f< kAT > &  other) const
inline

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

Parameters
otherSkRGBA4f to compare
Returns
true if SkRGBA4f is not equal to other

Definition at line 282 of file SkColor.h.

282 {
283 return !(*this == other);
284 }

◆ operator*() [1/2]

template<SkAlphaType kAT>
SkRGBA4f SkRGBA4f< kAT >::operator* ( const SkRGBA4f< kAT > &  scale) const
inline

Returns SkRGBA4f multiplied component-wise by scale.

Parameters
scaleSkRGBA4f to multiply by
Returns
SkRGBA4f as (fR * scale.fR, fG * scale.fG, fB * scale.fB, fA * scale.fA)

Definition at line 300 of file SkColor.h.

300 {
301 return { fR * scale.fR, fG * scale.fG, fB * scale.fB, fA * scale.fA };
302 }
const Scalar scale

◆ operator*() [2/2]

template<SkAlphaType kAT>
SkRGBA4f SkRGBA4f< kAT >::operator* ( float  scale) const
inline

Returns SkRGBA4f multiplied by scale.

Parameters
scalevalue to multiply by
Returns
SkRGBA4f as (fR * scale, fG * scale, fB * scale, fA * scale)

Definition at line 291 of file SkColor.h.

291 {
292 return { fR * scale, fG * scale, fB * scale, fA * scale };
293 }

◆ operator==()

template<SkAlphaType kAT>
bool SkRGBA4f< kAT >::operator== ( const SkRGBA4f< kAT > &  other) const
inline

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

Parameters
otherSkRGBA4f to compare
Returns
true if SkRGBA4f equals other

Definition at line 273 of file SkColor.h.

273 {
274 return fA == other.fA && fR == other.fR && fG == other.fG && fB == other.fB;
275 }

◆ operator[]() [1/2]

template<SkAlphaType kAT>
float & SkRGBA4f< kAT >::operator[] ( int  index)
inline

Returns one component. Asserts if index is out of range and SK_DEBUG is defined.

Parameters
indexone of: 0 (fR), 1 (fG), 2 (fB), 3 (fA)
Returns
value corresponding to index

Definition at line 334 of file SkColor.h.

334 {
335 SkASSERT(index >= 0 && index < 4);
336 return this->vec()[index];
337 }
const float * vec() const
Definition: SkColor.h:308

◆ operator[]() [2/2]

template<SkAlphaType kAT>
float SkRGBA4f< kAT >::operator[] ( int  index) const
inline

Returns one component. Asserts if index is out of range and SK_DEBUG is defined.

Parameters
indexone of: 0 (fR), 1 (fG), 2 (fB), 3 (fA)
Returns
value corresponding to index

Definition at line 324 of file SkColor.h.

324 {
325 SkASSERT(index >= 0 && index < 4);
326 return this->vec()[index];
327 }

◆ premul()

template<SkAlphaType kAT>
SkRGBA4f< kPremul_SkAlphaType > SkRGBA4f< kAT >::premul ( ) const
inline

Returns SkRGBA4f premultiplied by alpha. Asserts at compile time if SkRGBA4f is already premultiplied.

Returns
premultiplied color

Definition at line 385 of file SkColor.h.

385 {
386 static_assert(kAT == kUnpremul_SkAlphaType, "");
387 return { fR * fA, fG * fA, fB * fA, fA };
388 }
kUnpremul_SkAlphaType

◆ toBytes_RGBA()

template<SkAlphaType kAT>
uint32_t SkRGBA4f< kAT >::toBytes_RGBA ( ) const

◆ toSkColor()

template<SkAlphaType kAT>
SkColor SkRGBA4f< kAT >::toSkColor ( ) const

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

Returns
color as SkColor

example: https://fiddle.skia.org/c/@RGBA4f_toSkColor

◆ unpremul()

template<SkAlphaType kAT>
SkRGBA4f< kUnpremul_SkAlphaType > SkRGBA4f< kAT >::unpremul ( ) const
inline

Returns SkRGBA4f unpremultiplied by alpha. Asserts at compile time if SkRGBA4f is already unpremultiplied.

Returns
unpremultiplied color

Definition at line 395 of file SkColor.h.

395 {
396 static_assert(kAT == kPremul_SkAlphaType, "");
397
398 if (fA == 0.0f) {
399 return { 0, 0, 0, 0 };
400 } else {
401 float invAlpha = 1 / fA;
402 return { fR * invAlpha, fG * invAlpha, fB * invAlpha, fA };
403 }
404 }
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29

◆ vec() [1/2]

template<SkAlphaType kAT>
float * SkRGBA4f< kAT >::vec ( )
inline

Returns a pointer to components of SkRGBA4f, for array access.

Returns
pointer to array [fR, fG, fB, fA]

Definition at line 314 of file SkColor.h.

314{ return &fR; }

◆ vec() [2/2]

template<SkAlphaType kAT>
const float * SkRGBA4f< kAT >::vec ( ) const
inline

Returns a pointer to components of SkRGBA4f, for array access.

Returns
pointer to array [fR, fG, fB, fA]

Definition at line 308 of file SkColor.h.

308{ return &fR; }

Member Data Documentation

◆ fA

template<SkAlphaType kAT>
float SkRGBA4f< kAT >::fA

alpha component

Definition at line 266 of file SkColor.h.

◆ fB

template<SkAlphaType kAT>
float SkRGBA4f< kAT >::fB

blue component

Definition at line 265 of file SkColor.h.

◆ fG

template<SkAlphaType kAT>
float SkRGBA4f< kAT >::fG

green component

Definition at line 264 of file SkColor.h.

◆ fR

template<SkAlphaType kAT>
float SkRGBA4f< kAT >::fR

red component

Definition at line 263 of file SkColor.h.


The documentation for this struct was generated from the following file: