#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);
// 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) {
}
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) {