Flutter Engine
The Flutter Engine
Functions
SrcOverTest.cpp File Reference
#include "include/core/SkColorPriv.h"
#include "include/private/base/SkMath.h"
#include "tests/Test.h"
#include <algorithm>

Go to the source code of this file.

Functions

static int test_srcover0 (unsigned dst, unsigned alpha)
 
static int test_srcover1 (unsigned dst, unsigned alpha)
 
static int test_srcover2 (unsigned dst, unsigned alpha)
 
 DEF_TEST (SrcOver, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( SrcOver  ,
reporter   
)

Definition at line 29 of file SrcOverTest.cpp.

29 {
30 /* Here's the idea. Can we ensure that when we blend on top of an opaque
31 dst, that the result always stay's opaque (i.e. exactly 255)?
32 */
33
34 unsigned i;
35 int opaqueCounter0 = 0;
36 int opaqueCounter1 = 0;
37 int opaqueCounter2 = 0;
38 for (i = 0; i <= 255; i++) {
39 unsigned result0 = test_srcover0(0xFF, i);
40 unsigned result1 = test_srcover1(0xFF, i);
41 unsigned result2 = test_srcover2(0xFF, i);
42 opaqueCounter0 += (result0 == 0xFF);
43 opaqueCounter1 += (result1 == 0xFF);
44 opaqueCounter2 += (result2 == 0xFF);
45 }
46#if 0
47 INFOF(reporter, "---- opaque test: [%d %d %d]\n",
48 opaqueCounter0, opaqueCounter1, opaqueCounter2);
49#endif
50 // we acknowledge that technique0 does not always return opaque
51 REPORTER_ASSERT(reporter, opaqueCounter0 == 256);
52 REPORTER_ASSERT(reporter, opaqueCounter1 == 256);
53 REPORTER_ASSERT(reporter, opaqueCounter2 == 256);
54
55 // Now ensure that we never over/underflow a byte
56 for (i = 0; i <= 255; i++) {
57 for (unsigned dst = 0; dst <= 255; dst++) {
58 unsigned r0 = test_srcover0(dst, i);
59 unsigned r1 = test_srcover1(dst, i);
60 unsigned r2 = test_srcover2(dst, i);
61 unsigned max = std::max(dst, i);
62 // ignore the known failure
63 if (dst != 255) {
64 REPORTER_ASSERT(reporter, r0 <= 255 && r0 >= max);
65 }
66 REPORTER_ASSERT(reporter, r1 <= 255 && r1 >= max);
67 REPORTER_ASSERT(reporter, r2 <= 255 && r2 >= max);
68
69#if 0
70 // this shows where r1 (faster) differs from r2 (more exact)
71 if (r1 != r2) {
72 INFOF(reporter, "--- dst=%d i=%d r1=%d r2=%d exact=%g\n",
73 dst, i, r1, r2, i + dst - dst*i/255.0f);
74 }
75#endif
76 }
77 }
78}
reporter
Definition: FontMgrTest.cpp:39
static int test_srcover2(unsigned dst, unsigned alpha)
Definition: SrcOverTest.cpp:25
static int test_srcover0(unsigned dst, unsigned alpha)
Definition: SrcOverTest.cpp:15
static int test_srcover1(unsigned dst, unsigned alpha)
Definition: SrcOverTest.cpp:20
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define INFOF(REPORTER,...)
Definition: Test.h:298
static float max(float r, float g, float b)
Definition: hsl.cpp:49
dst
Definition: cp.py:12

◆ test_srcover0()

static int test_srcover0 ( unsigned  dst,
unsigned  alpha 
)
static

Definition at line 15 of file SrcOverTest.cpp.

15 {
16 return alpha + SkAlphaMul(dst, SkAlpha255To256(255 - alpha));
17}
#define SkAlphaMul(value, alpha256)
Definition: SkColorPriv.h:34
static unsigned SkAlpha255To256(U8CPU alpha)
Definition: SkColorPriv.h:24

◆ test_srcover1()

static int test_srcover1 ( unsigned  dst,
unsigned  alpha 
)
static

Definition at line 20 of file SrcOverTest.cpp.

20 {
21 return alpha + SkAlphaMul(dst, 256 - alpha);
22}

◆ test_srcover2()

static int test_srcover2 ( unsigned  dst,
unsigned  alpha 
)
static

Definition at line 25 of file SrcOverTest.cpp.

25 {
26 return alpha + SkMulDiv255Round(dst, 255 - alpha);
27}
static U8CPU SkMulDiv255Round(U16CPU a, U16CPU b)
Definition: SkMath.h:73