Flutter Engine
The Flutter Engine
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 23 of file SkHighContrastFilter.cpp.

23 {
24 if (!config.isValid()) {
25 return nullptr;
26 }
27
28 struct Uniforms { float grayscale, invertStyle, contrast; };
29
30 // A contrast setting of exactly +1 would divide by zero (1+c)/(1-c), so pull in to +1-ε.
31 // I'm not exactly sure why we've historically pinned -1 up to -1+ε, maybe just symmetry?
32 float c = SkTPin(config.fContrast,
33 -1.0f + FLT_EPSILON,
34 +1.0f - FLT_EPSILON);
35
36 Uniforms uniforms = {
37 config.fGrayscale ? 1.0f : 0.0f,
38 (float)config.fInvertStyle, // 0.0f for none, 1.0f for brightness, 2.0f for lightness
39 (1+c)/(1-c),
40 };
41
42 const SkRuntimeEffect* highContrastEffect =
44
47 highContrastEffect->makeColorFilter(SkData::MakeWithCopy(&uniforms,sizeof(uniforms))),
49 /* gamut= */ nullptr, // use the dst gamut
50 &kUnpremul);
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
@ kUnpremul
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
static const FlSetting kHighContrast
const SkRuntimeEffect * GetKnownRuntimeEffect(StableKey stableKey)
static constexpr skcms_TransferFunction kLinear
Definition: SkColorSpace.h:51
Definition: types.h:8

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