Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | List of all members
SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS > Class Template Reference

#include <SkMaskGamma.h>

Inheritance diagram for SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >:
SkRefCnt SkRefCntBase

Public Types

typedef SkTMaskPreBlend< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS > PreBlend
 

Public Member Functions

 SkTMaskGamma ()
 
 SkTMaskGamma (SkScalar contrast, SkScalar deviceGamma)
 
PreBlend preBlend (SkColor color) const
 
void getGammaTableDimensions (int *tableWidth, int *numTables) const
 
const uint8_t * getGammaTables () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static SkColor CanonicalColor (SkColor color)
 

Detailed Description

template<int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS>
class SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >

A regular mask contains linear alpha values. A gamma correcting mask contains non-linear alpha values in an attempt to create gamma correct blits in the presence of a gamma incorrect (linear) blend in the blitter.

SkMaskGamma creates and maintains tables which convert linear alpha values to gamma correcting alpha values.

Parameters
RThe number of luminance bits to use [1, 8] from the red channel.
GThe number of luminance bits to use [1, 8] from the green channel.
BThe number of luminance bits to use [1, 8] from the blue channel.

Definition at line 99 of file SkMaskGamma.h.

Member Typedef Documentation

◆ PreBlend

template<int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS>
typedef SkTMaskPreBlend<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS> SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >::PreBlend

The type of the mask pre-blend which will be returned from preBlend(SkColor).

Definition at line 132 of file SkMaskGamma.h.

Constructor & Destructor Documentation

◆ SkTMaskGamma() [1/2]

template<int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS>
SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >::SkTMaskGamma ( )
inline

Creates a linear SkTMaskGamma.

Definition at line 104 of file SkMaskGamma.h.

104: fIsLinear(true) { }

◆ SkTMaskGamma() [2/2]

template<int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS>
SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >::SkTMaskGamma ( SkScalar  contrast,
SkScalar  deviceGamma 
)
inline

Creates tables to convert linear alpha values to gamma correcting alpha values.

Parameters
contrastA value in the range [0.0, 1.0] which indicates the amount of artificial contrast to add.
deviceThe color space of the target device.

Definition at line 114 of file SkMaskGamma.h.

114 : fIsLinear(false) {
115 const SkColorSpaceLuminance& deviceConvert = SkColorSpaceLuminance::Fetch(deviceGamma);
116 for (U8CPU i = 0; i < (1 << MAX_LUM_BITS); ++i) {
117 U8CPU lum = sk_t_scale255<MAX_LUM_BITS>(i);
118 SkTMaskGamma_build_correcting_lut(fGammaTables[i], lum, contrast,
119 deviceConvert, deviceGamma);
120 }
121 }
unsigned U8CPU
Definition: SkCPUTypes.h:18
void SkTMaskGamma_build_correcting_lut(uint8_t table[256], U8CPU srcI, SkScalar contrast, const SkColorSpaceLuminance &dstConvert, SkScalar dstGamma)
Definition: SkMaskGamma.cpp:78
static const SkColorSpaceLuminance & Fetch(SkScalar gamma)
Definition: SkMaskGamma.cpp:60
static float lum(float r, float g, float b)
Definition: hsl.cpp:52

Member Function Documentation

◆ CanonicalColor()

template<int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS>
static SkColor SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >::CanonicalColor ( SkColor  color)
inlinestatic

Given a color, returns the closest canonical color.

Definition at line 124 of file SkMaskGamma.h.

124 {
125 return SkColorSetRGB(
126 sk_t_scale255<R_LUM_BITS>(SkColorGetR(color) >> (8 - R_LUM_BITS)),
127 sk_t_scale255<G_LUM_BITS>(SkColorGetG(color) >> (8 - G_LUM_BITS)),
128 sk_t_scale255<B_LUM_BITS>(SkColorGetB(color) >> (8 - B_LUM_BITS)));
129 }
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
#define SkColorSetRGB(r, g, b)
Definition: SkColor.h:57
#define SkColorGetB(color)
Definition: SkColor.h:73
DlColor color

◆ getGammaTableDimensions()

template<int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS>
void SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >::getGammaTableDimensions ( int tableWidth,
int numTables 
) const
inline

Get dimensions for the full table set, so it can be allocated as a block.

Definition at line 144 of file SkMaskGamma.h.

144 {
145 *tableWidth = 256;
146 *numTables = (1 << MAX_LUM_BITS);
147 }

◆ getGammaTables()

template<int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS>
const uint8_t * SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >::getGammaTables ( ) const
inline

Provides direct access to the full table set, so it can be uploaded into a texture or analyzed in other ways. Returns nullptr if fGammaTables hasn't been initialized.

Definition at line 154 of file SkMaskGamma.h.

154 {
155 return fIsLinear ? nullptr : (const uint8_t*) fGammaTables;
156 }

◆ preBlend()

template<int R_LUM_BITS, int G_LUM_BITS, int B_LUM_BITS>
SkTMaskPreBlend< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS > SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >::preBlend ( SkColor  color) const

Provides access to the tables appropriate for converting linear alpha values into gamma correcting alpha values when drawing the given color through the mask. The destination color will be approximated.

Definition at line 209 of file SkMaskGamma.h.

209 {
211 : SkTMaskPreBlend<R_LUM_BITS, G_LUM_BITS, B_LUM_BITS>(sk_ref_sp(this),
212 fGammaTables[SkColorGetR(color) >> (8 - MAX_LUM_BITS)],
213 fGammaTables[SkColorGetG(color) >> (8 - MAX_LUM_BITS)],
214 fGammaTables[SkColorGetB(color) >> (8 - MAX_LUM_BITS)]);
215}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381

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