tests: use color_float rgb[] alias more

Iterate over rgb[] array instead of repeating the code for .r, .g and
.b.

Also in process_pipeline_comparison() f_max_err variable is dropped
since it was not used much.

This should make the code easier to read.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 3 years ago committed by Pekka Paalanen
parent 4012062228
commit 29d4472e13
  1. 26
      tests/alpha-blending-test.c
  2. 43
      tests/color-shaper-matrix-test.c
  3. 23
      tests/color_util.c

@ -109,14 +109,14 @@ premult_color(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
static void static void
unpremult_float(struct color_float *cf) unpremult_float(struct color_float *cf)
{ {
int i;
if (cf->a == 0.0f) { if (cf->a == 0.0f) {
cf->r = 0.0f; for (i = 0; i < COLOR_CHAN_NUM; i++)
cf->g = 0.0f; cf->rgb[i] = 0.0f;
cf->b = 0.0f;
} else { } else {
cf->r /= cf->a; for (i = 0; i < COLOR_CHAN_NUM; i++)
cf->g /= cf->a; cf->rgb[i] /= cf->a;
cf->b /= cf->a;
} }
} }
@ -218,11 +218,13 @@ verify_sRGB_blend_a8r8g8b8(uint32_t bg32, uint32_t fg32, uint32_t dst32,
int x, struct color_float *max_diff, int x, struct color_float *max_diff,
enum blend_space space) enum blend_space space)
{ {
const char *const chan_name[COLOR_CHAN_NUM] = { "r", "g", "b" };
struct color_float bg = a8r8g8b8_to_float(bg32); struct color_float bg = a8r8g8b8_to_float(bg32);
struct color_float fg = a8r8g8b8_to_float(fg32); struct color_float fg = a8r8g8b8_to_float(fg32);
struct color_float dst = a8r8g8b8_to_float(dst32); struct color_float dst = a8r8g8b8_to_float(dst32);
struct color_float ref; struct color_float ref;
bool ok = true; bool ok = true;
int i;
unpremult_float(&bg); unpremult_float(&bg);
unpremult_float(&fg); unpremult_float(&fg);
@ -233,16 +235,16 @@ verify_sRGB_blend_a8r8g8b8(uint32_t bg32, uint32_t fg32, uint32_t dst32,
sRGB_linearize(&fg); sRGB_linearize(&fg);
} }
ref.r = (1.0f - fg.a) * bg.r + fg.a * fg.r; for (i = 0; i < COLOR_CHAN_NUM; i++)
ref.g = (1.0f - fg.a) * bg.g + fg.a * fg.g; ref.rgb[i] = (1.0f - fg.a) * bg.rgb[i] + fg.a * fg.rgb[i];
ref.b = (1.0f - fg.a) * bg.b + fg.a * fg.b;
if (space == BLEND_LINEAR) if (space == BLEND_LINEAR)
sRGB_delinearize(&ref); sRGB_delinearize(&ref);
ok = compare_float(ref.r, dst.r, x, "r", &max_diff->r) && ok; for (i = 0; i < COLOR_CHAN_NUM; i++) {
ok = compare_float(ref.g, dst.g, x, "g", &max_diff->g) && ok; ok = compare_float(ref.rgb[i], dst.rgb[i], x,
ok = compare_float(ref.b, dst.b, x, "b", &max_diff->b) && ok; chan_name[i], &max_diff->rgb[i]) && ok;
}
return ok; return ok;
} }

@ -166,7 +166,7 @@ get_image_prop(struct buffer *buf, struct image_header *header)
static void static void
gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar) gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar)
{ {
static const int hue[][3] = { static const int hue[][COLOR_CHAN_NUM] = {
{ 1, 1, 1 }, /* White */ { 1, 1, 1 }, /* White */
{ 1, 1, 0 }, /* Yellow */ { 1, 1, 0 }, /* Yellow */
{ 0, 1, 1 }, /* Cyan */ { 0, 1, 1 }, /* Cyan */
@ -180,6 +180,7 @@ gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar)
float val_max; float val_max;
int x, y; int x, y;
int hue_index; int hue_index;
int chan;
float value; float value;
unsigned char r, g, b; unsigned char r, g, b;
uint32_t *pixel; uint32_t *pixel;
@ -200,12 +201,10 @@ gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar)
if (width_bar > 1) if (width_bar > 1)
value = floor(value * n_steps) / n_steps; value = floor(value * n_steps) / n_steps;
if (hue[hue_index][0]) for (chan = 0; chan < COLOR_CHAN_NUM; chan++) {
rgb.r = value; if (hue[hue_index][chan])
if (hue[hue_index][1]) rgb.rgb[chan] = value;
rgb.g = value; }
if (hue[hue_index][2])
rgb.b = value;
sRGB_delinearize(&rgb); sRGB_delinearize(&rgb);
@ -359,14 +358,15 @@ process_pipeline_comparison(const struct image_header *src,
const struct image_header *shot, const struct image_header *shot,
const struct setup_args * arg) const struct setup_args * arg)
{ {
const char *const chan_name[COLOR_CHAN_NUM] = { "r", "g", "b" };
const float max_pixel_value = 255.0; const float max_pixel_value = 255.0;
struct color_float max_diff_pipeline = { .rgb = { 0.0f, 0.0f, 0.0f } }; struct color_float max_diff_pipeline = { .rgb = { 0.0f, 0.0f, 0.0f } };
float max_allow_diff = arg->pipeline.tolerance / max_pixel_value; float max_allow_diff = arg->pipeline.tolerance / max_pixel_value;
float max_err = 0; float max_err = 0.0f;
float f_max_err = 0;
bool ok = true; bool ok = true;
uint32_t *row_ptr, *row_ptr_shot; uint32_t *row_ptr, *row_ptr_shot;
int y, x; int y, x;
int chan;
struct color_float pix_src; struct color_float pix_src;
struct color_float pix_src_pipeline; struct color_float pix_src_pipeline;
struct color_float pix_shot; struct color_float pix_shot;
@ -383,26 +383,25 @@ process_pipeline_comparison(const struct image_header *src,
&arg->pipeline.mat, &arg->pipeline.mat,
arg->pipeline.post_fn, arg->pipeline.post_fn,
&pix_src, &pix_src_pipeline); &pix_src, &pix_src_pipeline);
/* check if pipeline matches to shader variant */ /* check if pipeline matches to shader variant */
ok &= compare_float(pix_src_pipeline.r, pix_shot.r, x,"r", for (chan = 0; chan < COLOR_CHAN_NUM; chan++) {
&max_diff_pipeline.r, max_allow_diff); ok &= compare_float(pix_src_pipeline.rgb[chan],
ok &= compare_float(pix_src_pipeline.g, pix_shot.g, x, "g", pix_shot.rgb[chan],
&max_diff_pipeline.g, max_allow_diff); x, chan_name[chan],
ok &= compare_float(pix_src_pipeline.b, pix_shot.b, x, "b", &max_diff_pipeline.rgb[chan],
&max_diff_pipeline.b, max_allow_diff); max_allow_diff);
}
} }
} }
max_err = max_diff_pipeline.r;
if (max_err < max_diff_pipeline.g)
max_err = max_diff_pipeline.g;
if (max_err < max_diff_pipeline.b)
max_err = max_diff_pipeline.b;
f_max_err = max_pixel_value * max_err; for (chan = 0; chan < COLOR_CHAN_NUM; chan++)
max_err = MAX(max_err, max_diff_pipeline.rgb[chan]);
testlog("%s %s %s tol_req %d, tol_cal %f, max diff: r=%f, g=%f, b=%f\n", testlog("%s %s %s tol_req %d, tol_cal %f, max diff: r=%f, g=%f, b=%f\n",
__func__, ok == true? "SUCCESS":"FAILURE", __func__, ok == true? "SUCCESS":"FAILURE",
arg->meta.name, arg->pipeline.tolerance, f_max_err, arg->meta.name, arg->pipeline.tolerance,
max_err * max_pixel_value,
max_diff_pipeline.r, max_diff_pipeline.g, max_diff_pipeline.b); max_diff_pipeline.r, max_diff_pipeline.g, max_diff_pipeline.b);
return ok; return ok;

@ -229,28 +229,19 @@ process_pixel_using_pipeline(enum transfer_fn pre_curve,
struct color_float *out) struct color_float *out)
{ {
int i, j; int i, j;
float rgb_in[3]; struct color_float cf;
float out_blend[3];
float tmp; float tmp;
rgb_in[0] = in->r; for (i = 0; i < COLOR_CHAN_NUM; i++)
rgb_in[1] = in->g; cf.rgb[i] = apply_tone_curve(pre_curve, in->rgb[i]);
rgb_in[2] = in->b;
for (i = 0; i < 3; i++)
rgb_in[i] = apply_tone_curve(pre_curve, rgb_in[i]);
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
tmp = 0.0f; tmp = 0.0f;
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
tmp += rgb_in[j] * mat->v[j].n[i]; tmp += cf.rgb[j] * mat->v[j].n[i];
out_blend[i] = tmp; out->rgb[i] = tmp;
} }
for (i = 0; i < 3; i++) for (i = 0; i < COLOR_CHAN_NUM; i++)
out_blend[i] = apply_tone_curve(post_curve, out_blend[i]); out->rgb[i] = apply_tone_curve(post_curve, out->rgb[i]);
out->r = out_blend[0];
out->g = out_blend[1];
out->b = out_blend[2];
} }

Loading…
Cancel
Save