Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
ColorTest.cpp File Reference
#include "include/core/SkColor.h"
#include "include/core/SkTypes.h"
#include "include/core/SkUnPreMultiply.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkCPUTypes.h"
#include "src/base/SkMathPriv.h"
#include "src/base/SkRandom.h"
#include "tests/Test.h"

Go to the source code of this file.

Functions

 DEF_TEST (ColorPremul, reporter)
 
 DEF_TEST (ColorInterp, reporter)
 
 DEF_TEST (ColorFastIterp, reporter)
 

Function Documentation

◆ DEF_TEST() [1/3]

DEF_TEST ( ColorFastIterp  ,
reporter   
)

Definition at line 61 of file ColorTest.cpp.

61 {
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();
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)
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition SkColor.cpp:21
uint32_t SkColor
Definition SkColor.h:37
uint32_t SkPMColor
Definition SkColor.h:205
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
uint32_t nextU()
Definition SkRandom.h:42
dst
Definition cp.py:12

◆ DEF_TEST() [2/3]

DEF_TEST ( ColorInterp  ,
reporter   
)

This test fails: SkFourByteInterp does not preserve opaque destinations. SkAlpha255To256 implemented as (alpha + 1) is faster than (alpha + (alpha >> 7)), but inaccurate, and Skia intends to phase it out.

Definition at line 43 of file ColorTest.cpp.

43 {
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();
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}
static SkPMColor SkFourByteInterp(SkPMColor src, SkPMColor dst, U8CPU srcWeight)

◆ DEF_TEST() [3/3]

DEF_TEST ( ColorPremul  ,
reporter   
)

Definition at line 17 of file ColorTest.cpp.

17 {
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}
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
static SkColor PMColorToColor(SkPMColor c)
struct MyStruct a[10]
double x