diff --git a/tests/alpha-blending-test.c b/tests/alpha-blending-test.c index 3f7317f3..2ec2b255 100644 --- a/tests/alpha-blending-test.c +++ b/tests/alpha-blending-test.c @@ -94,20 +94,6 @@ premult_color(uint32_t a, uint32_t r, uint32_t g, uint32_t b) return c; } -static void -unpremult_float(struct color_float *cf) -{ - int i; - - if (cf->a == 0.0f) { - for (i = 0; i < COLOR_CHAN_NUM; i++) - cf->rgb[i] = 0.0f; - } else { - for (i = 0; i < COLOR_CHAN_NUM; i++) - cf->rgb[i] /= cf->a; - } -} - static void fill_alpha_pattern(struct buffer *buf) { @@ -205,9 +191,9 @@ verify_sRGB_blend_a8r8g8b8(uint32_t bg32, uint32_t fg32, uint32_t dst32, bool ok = true; int i; - unpremult_float(&bg); - unpremult_float(&fg); - unpremult_float(&dst); + bg = color_float_unpremult(bg); + fg = color_float_unpremult(fg); + dst = color_float_unpremult(dst); if (space == BLEND_LINEAR) { sRGB_linearize(&bg); diff --git a/tests/color_util.c b/tests/color_util.c index 4bbd4071..c1bf622d 100644 --- a/tests/color_util.c +++ b/tests/color_util.c @@ -280,6 +280,24 @@ sRGB_delinearize(struct color_float *cf) *cf = color_float_apply_curve(TRANSFER_FN_SRGB_EOTF_INVERSE, *cf); } +struct color_float +color_float_unpremult(struct color_float in) +{ + static const struct color_float transparent = { + .r = 0.0f, .g = 0.0f, .b = 0.0f, .a = 0.0f, + }; + struct color_float out; + int i; + + if (in.a == 0.0f) + return transparent; + + for (i = 0; i < COLOR_CHAN_NUM; i++) + out.rgb[i] = in.rgb[i] / in.a; + out.a = in.a; + return out; +} + /* * Returns the result of the matrix-vector multiplication mat * c. */ diff --git a/tests/color_util.h b/tests/color_util.h index e9d931cd..ffcbd7a8 100644 --- a/tests/color_util.h +++ b/tests/color_util.h @@ -107,6 +107,9 @@ process_pixel_using_pipeline(enum transfer_fn pre_curve, const struct color_float *in, struct color_float *out); +struct color_float +color_float_unpremult(struct color_float in); + struct color_float color_float_apply_matrix(const struct lcmsMAT3 *mat, struct color_float c);