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>
This commit is contained in:
Pekka Paalanen 2022-02-15 14:51:26 +02:00 committed by Pekka Paalanen
parent 4012062228
commit 29d4472e13
3 changed files with 42 additions and 50 deletions

View File

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

View File

@ -166,7 +166,7 @@ get_image_prop(struct buffer *buf, struct image_header *header)
static void
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, 0 }, /* Yellow */
{ 0, 1, 1 }, /* Cyan */
@ -180,6 +180,7 @@ gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar)
float val_max;
int x, y;
int hue_index;
int chan;
float value;
unsigned char r, g, b;
uint32_t *pixel;
@ -200,12 +201,10 @@ gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar)
if (width_bar > 1)
value = floor(value * n_steps) / n_steps;
if (hue[hue_index][0])
rgb.r = value;
if (hue[hue_index][1])
rgb.g = value;
if (hue[hue_index][2])
rgb.b = value;
for (chan = 0; chan < COLOR_CHAN_NUM; chan++) {
if (hue[hue_index][chan])
rgb.rgb[chan] = value;
}
sRGB_delinearize(&rgb);
@ -359,14 +358,15 @@ process_pipeline_comparison(const struct image_header *src,
const struct image_header *shot,
const struct setup_args * arg)
{
const char *const chan_name[COLOR_CHAN_NUM] = { "r", "g", "b" };
const float max_pixel_value = 255.0;
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_err = 0;
float f_max_err = 0;
float max_err = 0.0f;
bool ok = true;
uint32_t *row_ptr, *row_ptr_shot;
int y, x;
int chan;
struct color_float pix_src;
struct color_float pix_src_pipeline;
struct color_float pix_shot;
@ -383,26 +383,25 @@ process_pipeline_comparison(const struct image_header *src,
&arg->pipeline.mat,
arg->pipeline.post_fn,
&pix_src, &pix_src_pipeline);
/* check if pipeline matches to shader variant */
ok &= compare_float(pix_src_pipeline.r, pix_shot.r, x,"r",
&max_diff_pipeline.r, max_allow_diff);
ok &= compare_float(pix_src_pipeline.g, pix_shot.g, x, "g",
&max_diff_pipeline.g, max_allow_diff);
ok &= compare_float(pix_src_pipeline.b, pix_shot.b, x, "b",
&max_diff_pipeline.b, max_allow_diff);
for (chan = 0; chan < COLOR_CHAN_NUM; chan++) {
ok &= compare_float(pix_src_pipeline.rgb[chan],
pix_shot.rgb[chan],
x, chan_name[chan],
&max_diff_pipeline.rgb[chan],
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",
__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);
return ok;

View File

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