Flutter Engine
The Flutter Engine
Classes | Functions
SkMaskGamma.h File Reference
#include "include/core/SkColor.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkCPUTypes.h"
#include "include/private/base/SkNoncopyable.h"
#include "include/private/base/SkTo.h"
#include <cstdint>

Go to the source code of this file.

Classes

class  SkColorSpaceLuminance
 
class  SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >
 
class  SkTMaskPreBlend< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS >
 

Functions

void SkTMaskGamma_build_correcting_lut (uint8_t table[256], U8CPU srcI, SkScalar contrast, const SkColorSpaceLuminance &dstConvert, SkScalar dstGamma)
 
template<U8CPU N>
static U8CPU sk_t_scale255 (U8CPU base)
 
template<>
U8CPU sk_t_scale255< 1 > (U8CPU base)
 
template<>
U8CPU sk_t_scale255< 2 > (U8CPU base)
 
template<>
U8CPU sk_t_scale255< 4 > (U8CPU base)
 
template<>
U8CPU sk_t_scale255< 8 > (U8CPU base)
 
template<bool APPLY_LUT>
static U8CPU sk_apply_lut_if (U8CPU component, const uint8_t *)
 
template<>
U8CPU sk_apply_lut_if< true > (U8CPU component, const uint8_t *lut)
 

Function Documentation

◆ sk_apply_lut_if()

template<bool APPLY_LUT>
static U8CPU sk_apply_lut_if ( U8CPU  component,
const uint8_t *   
)
inlinestatic

If APPLY_LUT is false, returns component unchanged. If APPLY_LUT is true, returns lut[component].

Parameters
APPLY_LUTwhether or not the look-up table should be applied to component. @component the initial component. @lut a look-up table which transforms the component.

Definition at line 225 of file SkMaskGamma.h.

225 {
226 return component;
227}

◆ sk_apply_lut_if< true >()

template<>
U8CPU sk_apply_lut_if< true > ( U8CPU  component,
const uint8_t *  lut 
)
inline

Definition at line 228 of file SkMaskGamma.h.

228 {
229 return lut[component];
230}

◆ sk_t_scale255()

template<U8CPU N>
static U8CPU sk_t_scale255 ( U8CPU  base)
inlinestatic

Scales base <= 2^N-1 to 2^8-1

Parameters
N[1, 8] the number of bits used by base.
basethe number to be scaled to [0, 255].

Definition at line 61 of file SkMaskGamma.h.

61 {
62 base <<= (8 - N);
63 U8CPU lum = base;
64 for (unsigned int i = N; i < 8; i += N) {
65 lum |= base >> i;
66 }
67 return lum;
68}
unsigned U8CPU
Definition: SkCPUTypes.h:18
#define N
Definition: beziers.cpp:19
static float lum(float r, float g, float b)
Definition: hsl.cpp:52

◆ sk_t_scale255< 1 >()

template<>
U8CPU sk_t_scale255< 1 > ( U8CPU  base)
inline

Definition at line 69 of file SkMaskGamma.h.

69 {
70 return base * 0xFF;
71}

◆ sk_t_scale255< 2 >()

template<>
U8CPU sk_t_scale255< 2 > ( U8CPU  base)
inline

Definition at line 72 of file SkMaskGamma.h.

72 {
73 return base * 0x55;
74}

◆ sk_t_scale255< 4 >()

template<>
U8CPU sk_t_scale255< 4 > ( U8CPU  base)
inline

Definition at line 75 of file SkMaskGamma.h.

75 {
76 return base * 0x11;
77}

◆ sk_t_scale255< 8 >()

template<>
U8CPU sk_t_scale255< 8 > ( U8CPU  base)
inline

Definition at line 78 of file SkMaskGamma.h.

78 {
79 return base;
80}

◆ SkTMaskGamma_build_correcting_lut()

void SkTMaskGamma_build_correcting_lut ( uint8_t  table[256],
U8CPU  srcI,
SkScalar  contrast,
const SkColorSpaceLuminance dstConvert,
SkScalar  dstGamma 
)

Definition at line 78 of file SkMaskGamma.cpp.

79 {
80 const SkColorSpaceLuminance& srcConvert = dstConvert;
81 const SkScalar srcGamma = dstGamma;
82 const float src = (float)srcI / 255.0f;
83 const float linSrc = srcConvert.toLuma(srcGamma, src);
84 //Guess at the dst. The perceptual inverse provides smaller visual
85 //discontinuities when slight changes to desaturated colors cause a channel
86 //to map to a different correcting lut with neighboring srcI.
87 //See https://code.google.com/p/chromium/issues/detail?id=141425#c59 .
88 const float dst = 1.0f - src;
89 const float linDst = dstConvert.toLuma(dstGamma, dst);
90
91 //Contrast value tapers off to 0 as the src luminance becomes white
92 const float adjustedContrast = contrast * linDst;
93
94 //Remove discontinuity and instability when src is close to dst.
95 //The value 1/256 is arbitrary and appears to contain the instability.
96 if (fabs(src - dst) < (1.0f / 256.0f)) {
97 float ii = 0.0f;
98 for (int i = 0; i < 256; ++i, ii += 1.0f) {
99 float rawSrca = ii / 255.0f;
100 float srca = apply_contrast(rawSrca, adjustedContrast);
101 table[i] = SkToU8(sk_float_round2int(255.0f * srca));
102 }
103 } else {
104 // Avoid slow int to float conversion.
105 float ii = 0.0f;
106 for (int i = 0; i < 256; ++i, ii += 1.0f) {
107 // 'rawSrca += 1.0f / 255.0f' and even
108 // 'rawSrca = i * (1.0f / 255.0f)' can add up to more than 1.0f.
109 // When this happens the table[255] == 0x0 instead of 0xff.
110 // See http://code.google.com/p/chromium/issues/detail?id=146466
111 float rawSrca = ii / 255.0f;
112 float srca = apply_contrast(rawSrca, adjustedContrast);
113 SkASSERT(srca <= 1.0f);
114 float dsta = 1.0f - srca;
115
116 //Calculate the output we want.
117 float linOut = (linSrc * srca + dsta * linDst);
118 SkASSERT(linOut <= 1.0f);
119 float out = dstConvert.fromLuma(dstGamma, linOut);
120
121 //Undo what the blit blend will do.
122 float result = (out - dst) / (src - dst);
123 SkASSERT(sk_float_round2int(255.0f * result) <= 255);
124
125 table[i] = SkToU8(sk_float_round2int(255.0f * result));
126 }
127 }
128}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define sk_float_round2int(x)
static float apply_contrast(float srca, float contrast)
Definition: SkMaskGamma.cpp:74
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22
SI F table(const skcms_Curve *curve, F v)
virtual SkScalar fromLuma(SkScalar gamma, SkScalar luma) const =0
virtual SkScalar toLuma(SkScalar gamma, SkScalar luminance) const =0
float SkScalar
Definition: extension.cpp:12
GAsyncResult * result
dst
Definition: cp.py:12