Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ColorTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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
13#include "src/base/SkMathPriv.h"
14#include "src/base/SkRandom.h"
15#include "tests/Test.h"
16
17DEF_TEST(ColorPremul, reporter) {
18 for (int a = 0; a <= 255; a++) {
19 for (int x = 0; x <= 255; x++) {
20 SkColor c0 = SkColorSetARGB(a, x, x, x);
22
25
26 // we can't promise that c0 == c1, since c0 -> p0 is a many to one
27 // function, however, we can promise that p0 -> c1 -> p1 : p0 == p1
28 REPORTER_ASSERT(reporter, p0 == p1);
29
30 {
31 int ax = SkMulDiv255Ceiling(x, a);
33 }
34 }
35 }
36}
37
38/**
39 This test fails: SkFourByteInterp does *not* preserve opaque destinations.
40 SkAlpha255To256 implemented as (alpha + 1) is faster than
41 (alpha + (alpha >> 7)), but inaccurate, and Skia intends to phase it out.
42*/
43DEF_TEST(ColorInterp, reporter) {
44 SkRandom r;
45
46 U8CPU a0 = 0;
47 U8CPU a255 = 255;
48 for (int i = 0; i < 200; i++) {
49 SkColor colorSrc = r.nextU();
50 SkColor colorDst = r.nextU();
51 SkPMColor src = SkPreMultiplyColor(colorSrc);
52 SkPMColor dst = SkPreMultiplyColor(colorDst);
53
54 if ((false)) {
55 REPORTER_ASSERT(reporter, SkFourByteInterp(src, dst, a0) == dst);
56 REPORTER_ASSERT(reporter, SkFourByteInterp(src, dst, a255) == src);
57 }
58 }
59}
60
61DEF_TEST(ColorFastIterp, reporter) {
62 SkRandom r;
63
64 U8CPU a0 = 0;
65 U8CPU a255 = 255;
66 for (int i = 0; i < 200; i++) {
67 SkColor colorSrc = r.nextU();
68 SkColor colorDst = r.nextU();
69 SkPMColor src = SkPreMultiplyColor(colorSrc);
70 SkPMColor dst = SkPreMultiplyColor(colorDst);
71
72 REPORTER_ASSERT(reporter, SkFastFourByteInterp(src, dst, a0) == dst);
73 REPORTER_ASSERT(reporter, SkFastFourByteInterp(src, dst, a255) == src);
74 }
75}
reporter
unsigned U8CPU
Definition SkCPUTypes.h:18
static SkPMColor SkFastFourByteInterp(SkPMColor src, SkPMColor dst, U8CPU srcWeight)
static SkPMColor SkFourByteInterp(SkPMColor src, SkPMColor dst, U8CPU srcWeight)
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition SkColor.cpp:21
uint32_t SkColor
Definition SkColor.h:37
uint32_t SkPMColor
Definition SkColor.h:205
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49
static U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b)
Definition SkMathPriv.h:102
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
uint32_t nextU()
Definition SkRandom.h:42
static SkColor PMColorToColor(SkPMColor c)
struct MyStruct a[10]
double x