Flutter Engine
The Flutter Engine
SkHighContrastFilter.cpp
Go to the documentation of this file.
1/*
2* Copyright 2017 Google Inc.
3*
4* Use of this source code is governed by a BSD-style license that can be
5* found in the LICENSE file.
6*/
7
9
13#include "include/core/SkData.h"
20
21#include <cfloat>
22
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
static sk_sp< SkColorFilter > Make(const SkHighContrastConfig &config)
Definition: types.h:8