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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/BlendTest.cpp
diff --git a/tests/BlendTest.cpp b/tests/BlendTest.cpp
index b72d8d5c752fc92a6d6ce38f540006d2581c94d1..a0a84d7a7b0a69a1a6dba496ba5e1166f3bf9de5 100644
--- a/tests/BlendTest.cpp
+++ b/tests/BlendTest.cpp
@@ -3,6 +3,12 @@
#define ASSERT(x) REPORTER_ASSERT(r, x)
+static uint8_t double_to_u8(double d) {
+ SkASSERT(d >= 0);
+ SkASSERT(d < 256);
+ return uint8_t(d);
+}
+
// All algorithms we're testing have this interface.
// We want a single channel blend, src over dst, assuming src is premultiplied by srcAlpha.
typedef uint8_t(*Blend)(uint8_t dst, uint8_t src, uint8_t srcAlpha);
@@ -10,7 +16,7 @@ typedef uint8_t(*Blend)(uint8_t dst, uint8_t src, uint8_t srcAlpha);
// This is our golden algorithm.
static uint8_t blend_double_round(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
SkASSERT(src <= srcAlpha);
- return SkToU8(0.5 + src + dst * (255.0 - srcAlpha) / 255.0);
+ return double_to_u8(0.5 + src + dst * (255.0 - srcAlpha) / 255.0);
}
static uint8_t abs_diff(uint8_t a, uint8_t b) {
@@ -52,15 +58,15 @@ static void test_dst(skiatest::Reporter* r, uint8_t dst, int maxDiff, Blend algo
}
static uint8_t blend_double_trunc(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
- return SkToU8(src + dst * (255.0 - srcAlpha) / 255.0);
+ return double_to_u8(src + dst * (255.0 - srcAlpha) / 255.0);
}
static uint8_t blend_float_trunc(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
- return SkToU8(src + dst * (255.0f - srcAlpha) / 255.0f);
+ return double_to_u8(src + dst * (255.0f - srcAlpha) / 255.0f);
}
static uint8_t blend_float_round(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
- return SkToU8(0.5f + src + dst * (255.0f - srcAlpha) / 255.0f);
+ return double_to_u8(0.5f + src + dst * (255.0f - srcAlpha) / 255.0f);
}
static uint8_t blend_255_trunc(uint8_t dst, uint8_t src, uint8_t srcAlpha) {
« 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