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 #include "include/core/SkColor.h"
9 #include "include/core/SkColorFilter.h"
10 #include "include/core/SkPaint.h"
11 #include "include/core/SkRefCnt.h"
12 #include "include/effects/SkHighContrastFilter.h"
13 #include "tests/Test.h"
14
15 #include <initializer_list>
16
DEF_TEST(HighContrastFilter_SmokeTest,reporter)17 DEF_TEST(HighContrastFilter_SmokeTest, reporter) {
18 SkHighContrastConfig config;
19 config.fInvertStyle = SkHighContrastConfig::InvertStyle::kInvertLightness;
20 sk_sp<SkColorFilter> filter = SkHighContrastFilter::Make(config);
21 REPORTER_ASSERT(reporter, filter->isAlphaUnchanged());
22
23 SkColorSpace* cs = nullptr;
24 SkColor4f white_inverted = filter->filterColor4f(SkColors::kWhite, cs, cs);
25 REPORTER_ASSERT(reporter, white_inverted == SkColors::kBlack);
26
27 SkColor4f black_inverted = filter->filterColor4f(SkColors::kBlack, cs, cs);
28 REPORTER_ASSERT(reporter, black_inverted == SkColors::kWhite);
29 }
30
DEF_TEST(HighContrastFilter_InvalidInputs,reporter)31 DEF_TEST(HighContrastFilter_InvalidInputs, reporter) {
32 SkHighContrastConfig config;
33 REPORTER_ASSERT(reporter, config.isValid());
34
35 // Valid invert style
36 config.fInvertStyle = SkHighContrastConfig::InvertStyle::kInvertBrightness;
37 REPORTER_ASSERT(reporter, config.isValid());
38 config.fInvertStyle = SkHighContrastConfig::InvertStyle::kInvertLightness;
39 REPORTER_ASSERT(reporter, config.isValid());
40 sk_sp<SkColorFilter> filter = SkHighContrastFilter::Make(config);
41 REPORTER_ASSERT(reporter, filter);
42
43 // Invalid invert style
44 config.fInvertStyle = static_cast<SkHighContrastConfig::InvertStyle>(999);
45 REPORTER_ASSERT(reporter, !config.isValid());
46 filter = SkHighContrastFilter::Make(config);
47 REPORTER_ASSERT(reporter, !filter);
48
49 // Valid contrast
50 for (float contrast : {0.5f, +1.0f, -1.0f}) {
51 config.fInvertStyle = SkHighContrastConfig::InvertStyle::kInvertBrightness;
52 config.fContrast = contrast;
53 REPORTER_ASSERT(reporter, config.isValid());
54 filter = SkHighContrastFilter::Make(config);
55 REPORTER_ASSERT(reporter, filter);
56 }
57
58 // Invalid contrast
59 config.fContrast = 1.1f;
60 REPORTER_ASSERT(reporter, !config.isValid());
61 filter = SkHighContrastFilter::Make(config);
62 REPORTER_ASSERT(reporter, !filter);
63 }
64