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 "include/core/SkColorFilter.h" 12 13 /** 14 * Configuration struct for SkHighContrastFilter. 15 * 16 * Provides transformations to improve contrast for users with low vision. 17 */ 18 struct SkHighContrastConfig { 19 enum class InvertStyle { 20 kNoInvert, 21 kInvertBrightness, 22 kInvertLightness, 23 24 kLast = kInvertLightness 25 }; 26 SkHighContrastConfigSkHighContrastConfig27 SkHighContrastConfig() { 28 fGrayscale = false; 29 fInvertStyle = InvertStyle::kNoInvert; 30 fContrast = 0.0f; 31 } 32 SkHighContrastConfigSkHighContrastConfig33 SkHighContrastConfig(bool grayscale, 34 InvertStyle invertStyle, 35 SkScalar contrast) 36 : fGrayscale(grayscale), 37 fInvertStyle(invertStyle), 38 fContrast(contrast) {} 39 40 // Returns true if all of the fields are set within the valid range. isValidSkHighContrastConfig41 bool isValid() const { 42 return fInvertStyle >= InvertStyle::kNoInvert && 43 fInvertStyle <= InvertStyle::kInvertLightness && 44 fContrast >= -1.0 && 45 fContrast <= 1.0; 46 } 47 48 // If true, the color will be converted to grayscale. 49 bool fGrayscale; 50 51 // Whether to invert brightness, lightness, or neither. 52 InvertStyle fInvertStyle; 53 54 // After grayscale and inverting, the contrast can be adjusted linearly. 55 // The valid range is -1.0 through 1.0, where 0.0 is no adjustment. 56 SkScalar fContrast; 57 }; 58 59 /** 60 * Color filter that provides transformations to improve contrast 61 * for users with low vision. 62 * 63 * Applies the following transformations in this order. Each of these 64 * can be configured using SkHighContrastConfig. 65 * 66 * - Conversion to grayscale 67 * - Color inversion (either in RGB or HSL space) 68 * - Increasing the resulting contrast. 69 * 70 * Calling SkHighContrastFilter::Make will return nullptr if the config is 71 * not valid, e.g. if you try to call it with a contrast outside the range of 72 * -1.0 to 1.0. 73 */ 74 75 struct SK_API SkHighContrastFilter { 76 // Returns the filter, or nullptr if the config is invalid. 77 static sk_sp<SkColorFilter> Make(const SkHighContrastConfig& config); 78 }; 79 80 #endif 81