Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 &srcConvert, SkScalar srcGamma, 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 229 of file SkMaskGamma.h.

229 {
230 return component;
231}

◆ sk_apply_lut_if< true >()

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

Definition at line 232 of file SkMaskGamma.h.

232 {
233 return lut[component];
234}

◆ 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 srcConvert,
SkScalar  srcGamma,
const SkColorSpaceLuminance dstConvert,
SkScalar  dstGamma 
)

Definition at line 78 of file SkMaskGamma.cpp.

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