Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tests/BlendTest.cpp

Issue 181503003: BlendTest: implicit casts -> explicit casts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: static Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "Test.h" 1 #include "Test.h"
2 #include "SkColor.h" 2 #include "SkColor.h"
3 3
4 #define ASSERT(x) REPORTER_ASSERT(r, x) 4 #define ASSERT(x) REPORTER_ASSERT(r, x)
5 5
6 static uint8_t double_to_u8(double d) {
7 SkASSERT(d >= 0);
8 SkASSERT(d < 256);
9 return uint8_t(d);
10 }
11
6 // All algorithms we're testing have this interface. 12 // All algorithms we're testing have this interface.
7 // We want a single channel blend, src over dst, assuming src is premultiplied b y srcAlpha. 13 // We want a single channel blend, src over dst, assuming src is premultiplied b y srcAlpha.
8 typedef uint8_t(*Blend)(uint8_t dst, uint8_t src, uint8_t srcAlpha); 14 typedef uint8_t(*Blend)(uint8_t dst, uint8_t src, uint8_t srcAlpha);
9 15
10 // This is our golden algorithm. 16 // This is our golden algorithm.
11 static uint8_t blend_double_round(uint8_t dst, uint8_t src, uint8_t srcAlpha) { 17 static uint8_t blend_double_round(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
12 SkASSERT(src <= srcAlpha); 18 SkASSERT(src <= srcAlpha);
13 return SkToU8(0.5 + src + dst * (255.0 - srcAlpha) / 255.0); 19 return double_to_u8(0.5 + src + dst * (255.0 - srcAlpha) / 255.0);
14 } 20 }
15 21
16 static uint8_t abs_diff(uint8_t a, uint8_t b) { 22 static uint8_t abs_diff(uint8_t a, uint8_t b) {
17 const int diff = a - b; 23 const int diff = a - b;
18 return diff > 0 ? diff : -diff; 24 return diff > 0 ? diff : -diff;
19 } 25 }
20 26
21 static void test(skiatest::Reporter* r, int maxDiff, Blend algorithm, 27 static void test(skiatest::Reporter* r, int maxDiff, Blend algorithm,
22 uint8_t dst, uint8_t src, uint8_t alpha) { 28 uint8_t dst, uint8_t src, uint8_t alpha) {
23 const uint8_t golden = blend_double_round(dst, src, alpha); 29 const uint8_t golden = blend_double_round(dst, src, alpha);
(...skipping 21 matching lines...) Expand all
45 SkASSERT(maxDiff >= 0); 51 SkASSERT(maxDiff >= 0);
46 52
47 for (unsigned alpha = 0; alpha < 256; alpha++) { 53 for (unsigned alpha = 0; alpha < 256; alpha++) {
48 for (unsigned src = 0; src <= alpha; src++) { 54 for (unsigned src = 0; src <= alpha; src++) {
49 test(r, maxDiff, algorithm, dst, src, alpha); 55 test(r, maxDiff, algorithm, dst, src, alpha);
50 } 56 }
51 } 57 }
52 } 58 }
53 59
54 static uint8_t blend_double_trunc(uint8_t dst, uint8_t src, uint8_t srcAlpha) { 60 static uint8_t blend_double_trunc(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
55 return SkToU8(src + dst * (255.0 - srcAlpha) / 255.0); 61 return double_to_u8(src + dst * (255.0 - srcAlpha) / 255.0);
56 } 62 }
57 63
58 static uint8_t blend_float_trunc(uint8_t dst, uint8_t src, uint8_t srcAlpha) { 64 static uint8_t blend_float_trunc(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
59 return SkToU8(src + dst * (255.0f - srcAlpha) / 255.0f); 65 return double_to_u8(src + dst * (255.0f - srcAlpha) / 255.0f);
60 } 66 }
61 67
62 static uint8_t blend_float_round(uint8_t dst, uint8_t src, uint8_t srcAlpha) { 68 static uint8_t blend_float_round(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
63 return SkToU8(0.5f + src + dst * (255.0f - srcAlpha) / 255.0f); 69 return double_to_u8(0.5f + src + dst * (255.0f - srcAlpha) / 255.0f);
64 } 70 }
65 71
66 static uint8_t blend_255_trunc(uint8_t dst, uint8_t src, uint8_t srcAlpha) { 72 static uint8_t blend_255_trunc(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
67 const uint16_t invAlpha = 255 - srcAlpha; 73 const uint16_t invAlpha = 255 - srcAlpha;
68 const uint16_t product = dst * invAlpha; 74 const uint16_t product = dst * invAlpha;
69 return src + (product >> 8); 75 return src + (product >> 8);
70 } 76 }
71 77
72 static uint8_t blend_255_round(uint8_t dst, uint8_t src, uint8_t srcAlpha) { 78 static uint8_t blend_255_round(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
73 const uint16_t invAlpha = 255 - srcAlpha; 79 const uint16_t invAlpha = 255 - srcAlpha;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 // blend_perfect 249 // blend_perfect
244 // GOOD ENOUGH 250 // GOOD ENOUGH
245 // blend_double_trunc 251 // blend_double_trunc
246 // blend_float_trunc 252 // blend_float_trunc
247 // blend_256_round 253 // blend_256_round
248 // blend_256_round_alt 254 // blend_256_round_alt
249 // NOT GOOD ENOUGH 255 // NOT GOOD ENOUGH
250 // all others 256 // all others
251 // 257 //
252 // Algorithms that make sense to use in Skia: blend_256_round, blend_256_round_ alt, blend_perfect 258 // Algorithms that make sense to use in Skia: blend_256_round, blend_256_round_ alt, blend_perfect
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698