tests/alpha-blending: move unpremult to color_util

More tests are going to need this.

The API is changed to work by copy in and copy out to match the other
color_util API. Hopefully this makes the caller code easier to read.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 2 years ago committed by Pekka Paalanen
parent 213195c4db
commit 0d385ffacb
  1. 20
      tests/alpha-blending-test.c
  2. 18
      tests/color_util.c
  3. 3
      tests/color_util.h

@ -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);

@ -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.
*/

@ -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);

Loading…
Cancel
Save