Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkHighContrastFilter.h
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 
8 #ifndef SkHighContrastFilter_DEFINED
9 #define SkHighContrastFilter_DEFINED
10 
11 #include "SkColorFilter.h"
12 #include "SkPaint.h"
13 
20  enum class InvertStyle {
21  kNoInvert,
22  kInvertBrightness,
23  kInvertLightness,
24  };
25 
27  fGrayscale = false;
28  fInvertStyle = InvertStyle::kNoInvert;
29  fContrast = 0.0f;
30  }
31 
32  SkHighContrastConfig(bool grayscale,
33  InvertStyle invertStyle,
34  SkScalar contrast)
35  : fGrayscale(grayscale),
36  fInvertStyle(invertStyle),
37  fContrast(contrast) {}
38 
39  // Returns true if all of the fields are set within the valid range.
40  bool isValid() const {
41  return fInvertStyle >= InvertStyle::kNoInvert &&
42  fInvertStyle <= InvertStyle::kInvertLightness &&
43  fContrast >= -1.0 &&
44  fContrast <= 1.0;
45  }
46 
47  // If true, the color will be converted to grayscale.
48  bool fGrayscale;
49 
50  // Whether to invert brightness, lightness, or neither.
51  InvertStyle fInvertStyle;
52 
53  // After grayscale and inverting, the contrast can be adjusted linearly.
54  // The valid range is -1.0 through 1.0, where 0.0 is no adjustment.
55  SkScalar fContrast;
56 };
57 
73 class SK_API SkHighContrastFilter {
74 public:
75  // Returns the filter, or nullptr if the config is invalid.
76  static sk_sp<SkColorFilter> Make(const SkHighContrastConfig& config);
77 
78  SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
79 };
80 
81 #endif
Color filter that provides transformations to improve contrast for users with low vision...
Definition: SkHighContrastFilter.h:73
Configuration struct for SkHighContrastFilter.
Definition: SkHighContrastFilter.h:19