Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
SkHighContrastFilter Struct Reference

#include <SkHighContrastFilter.h>

Static Public Member Functions

static sk_sp< SkColorFilterMake (const SkHighContrastConfig &config)
 

Detailed Description

Color filter that provides transformations to improve contrast for users with low vision.

Applies the following transformations in this order. Each of these can be configured using SkHighContrastConfig.

Calling SkHighContrastFilter::Make will return nullptr if the config is not valid, e.g. if you try to call it with a contrast outside the range of -1.0 to 1.0.

Definition at line 79 of file SkHighContrastFilter.h.

Member Function Documentation

◆ Make()

sk_sp< SkColorFilter > SkHighContrastFilter::Make ( const SkHighContrastConfig config)
static

Definition at line 24 of file SkHighContrastFilter.cpp.

24 {
25 if (!config.isValid()) {
26 return nullptr;
27 }
28
29 struct Uniforms { float grayscale, invertStyle, contrast; };
30
31 // A contrast setting of exactly +1 would divide by zero (1+c)/(1-c), so pull in to +1-ε.
32 // I'm not exactly sure why we've historically pinned -1 up to -1+ε, maybe just symmetry?
33 float c = SkTPin(config.fContrast,
34 -1.0f + FLT_EPSILON,
35 +1.0f - FLT_EPSILON);
36
37 Uniforms uniforms = {
38 config.fGrayscale ? 1.0f : 0.0f,
39 (float)config.fInvertStyle, // 0.0f for none, 1.0f for brightness, 2.0f for lightness
40 (1+c)/(1-c),
41 };
42
43 const SkRuntimeEffect* highContrastEffect =
44 GetKnownRuntimeEffect(SkKnownRuntimeEffects::StableKey::kHighContrast);
45
49 highContrastEffect->makeColorFilter(SkData::MakeWithCopy(&uniforms,sizeof(uniforms))),
50 &linear, nullptr/*use dst gamut*/, &unpremul);
51}
kUnpremul_SkAlphaType
SkAlphaType
Definition SkAlphaType.h:26
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition SkTPin.h:19
static sk_sp< SkColorFilter > WithWorkingFormat(sk_sp< SkColorFilter > child, const skcms_TransferFunction *tf, const skcms_Matrix3x3 *gamut, const SkAlphaType *at)
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition SkData.cpp:111
sk_sp< SkColorFilter > makeColorFilter(sk_sp< const SkData > uniforms) const
const SkRuntimeEffect * GetKnownRuntimeEffect(StableKey stableKey)
static constexpr skcms_TransferFunction kLinear
static sk_sp< SkShader > linear(sk_sp< SkShader > shader)

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