Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
18#include "modules/skcms/skcms.h"
21
22#include <cfloat>
23
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
static constexpr skcms_TransferFunction kLinear
static sk_sp< SkColorFilter > Make(const SkHighContrastConfig &config)
static sk_sp< SkShader > linear(sk_sp< SkShader > shader)