From e103ef4d0d695218509d53cac9b7ff9143f6f0bb Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Mon, 20 Jun 2022 13:32:25 +0300 Subject: [PATCH] tests: add rgb_diff_stat dumps This is a special case of scalar_stat dumps to record all of two-norm and RGB differences on the same line in the dump file. This makes the dump file easier to handle when you want full RGB errors recorded. Signed-off-by: Pekka Paalanen --- tests/color_util.c | 18 ++++++++++++++---- tests/color_util.h | 12 ++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/color_util.c b/tests/color_util.c index 9267aefe..1f0928b6 100644 --- a/tests/color_util.c +++ b/tests/color_util.c @@ -454,13 +454,23 @@ rgb_diff_stat_update(struct rgb_diff_stat *stat, { unsigned i; double ssd = 0.0; + double diff[COLOR_CHAN_NUM]; + double two_norm; for (i = 0; i < COLOR_CHAN_NUM; i++) { - double diff = val->rgb[i] - ref->rgb[i]; + diff[i] = val->rgb[i] - ref->rgb[i]; - scalar_stat_update(&stat->rgb[i], diff, pos); - ssd += diff * diff; + scalar_stat_update(&stat->rgb[i], diff[i], pos); + ssd += diff[i] * diff[i]; } + two_norm = sqrt(ssd); - scalar_stat_update(&stat->two_norm, sqrt(ssd), pos); + scalar_stat_update(&stat->two_norm, two_norm, pos); + + if (stat->dump) { + fprintf(stat->dump, "%.8g %.8g %.8g %.8g %.5g %.5g %.5g %.5g\n", + two_norm, + diff[COLOR_CHAN_R], diff[COLOR_CHAN_G], diff[COLOR_CHAN_B], + pos->r, pos->g, pos->b, pos->a); + } } diff --git a/tests/color_util.h b/tests/color_util.h index 9ad09588..7a361a6b 100644 --- a/tests/color_util.h +++ b/tests/color_util.h @@ -148,6 +148,18 @@ struct scalar_stat { struct rgb_diff_stat { struct scalar_stat rgb[COLOR_CHAN_NUM]; struct scalar_stat two_norm; + + /** Debug dump into file + * + * Initialize this to a writable file to get a record of all values + * ever fed through this statistics accumulator. The file shall be + * text with the two-norm error, the rgb difference, and their position + * per line: + * norm diff.r diff.g diff.b pos.r pos.g pos.b pos.a + * + * Set to NULL to not record. + */ + FILE *dump; }; void