diff --git a/tests/color-icc-output-test.c b/tests/color-icc-output-test.c index 429a7ce0..2f2de05e 100644 --- a/tests/color-icc-output-test.c +++ b/tests/color-icc-output-test.c @@ -189,8 +189,6 @@ test_roundtrip(uint8_t r, uint8_t g, uint8_t b, cmsPipeline *pip, static void roundtrip_verification(cmsPipeline *DToB, cmsPipeline *BToD, float tolerance) { - const char *const chan_name[COLOR_CHAN_NUM] = { "r", "g", "b" }; - unsigned i; unsigned r, g, b; struct rgb_diff_stat stat = {}; cmsPipeline *pip; @@ -211,15 +209,7 @@ roundtrip_verification(cmsPipeline *DToB, cmsPipeline *BToD, float tolerance) cmsPipelineFree(pip); - testlog("DToB->BToD roundtrip error statistics (%u samples):\n", - stat.two_norm.count); - for (i = 0; i < COLOR_CHAN_NUM; i++) { - testlog(" ch %s error:\n", chan_name[i]); - scalar_stat_print_rgb8bit(&stat.rgb[i]); - } - testlog(" Two-norm error:\n"); - scalar_stat_print_rgb8bit(&stat.two_norm); - + rgb_diff_stat_print(&stat, "DToB->BToD roundtrip", 8); assert(stat.two_norm.max < tolerance); } diff --git a/tests/color_util.c b/tests/color_util.c index c1bf622d..acbd040a 100644 --- a/tests/color_util.c +++ b/tests/color_util.c @@ -396,17 +396,6 @@ scalar_stat_avg(const struct scalar_stat *stat) return stat->sum / stat->count; } -#define RGB888_FMT "(%3u, %3u, %3u)" -#define RGB888_VAL(cf) (unsigned)round((cf).r * 255.0), (unsigned)round((cf).g * 255.0), (unsigned)round((cf).b * 255.0) - -void -scalar_stat_print_rgb8bit(const struct scalar_stat *stat) -{ - testlog(" min %8.5f at " RGB888_FMT "\n", stat->min, RGB888_VAL(stat->min_pos)); - testlog(" max %8.5f at " RGB888_FMT "\n", stat->max, RGB888_VAL(stat->max_pos)); - testlog(" avg %8.5f\n", scalar_stat_avg(stat)); -} - void scalar_stat_print_float(const struct scalar_stat *stat) { @@ -415,6 +404,41 @@ scalar_stat_print_float(const struct scalar_stat *stat) testlog(" avg %11.5g\n", scalar_stat_avg(stat)); } +static void +print_stat_at_pos(const char *lim, double val, struct color_float pos, double scale) +{ + testlog(" %s %8.5f at rgb(%7.2f, %7.2f, %7.2f)\n", + lim, val * scale, pos.r * scale, pos.g * scale, pos.b * scale); +} + +static void +print_rgb_at_pos(const struct scalar_stat *stat, double scale) +{ + print_stat_at_pos("min", stat->min, stat->min_pos, scale); + print_stat_at_pos("max", stat->max, stat->max_pos, scale); + testlog(" avg %8.5f\n", scalar_stat_avg(stat) * scale); +} + +void +rgb_diff_stat_print(const struct rgb_diff_stat *stat, + const char *title, unsigned scaling_bits) +{ + const char *const chan_name[COLOR_CHAN_NUM] = { "r", "g", "b" }; + float scale = exp2f(scaling_bits) - 1.0f; + unsigned i; + + assert(scaling_bits > 0); + + testlog("%s error statistics, %u samples, value range 0.0 - %.1f:\n", + title, stat->two_norm.count, scale); + for (i = 0; i < COLOR_CHAN_NUM; i++) { + testlog(" ch %s (signed):\n", chan_name[i]); + print_rgb_at_pos(&stat->rgb[i], scale); + } + testlog(" rgb two-norm:\n"); + print_rgb_at_pos(&stat->two_norm, scale); +} + void rgb_diff_stat_update(struct rgb_diff_stat *stat, struct color_float *ref, struct color_float *val) diff --git a/tests/color_util.h b/tests/color_util.h index ffcbd7a8..2278c874 100644 --- a/tests/color_util.h +++ b/tests/color_util.h @@ -144,12 +144,13 @@ scalar_stat_update(struct scalar_stat *stat, double val, struct color_float *pos float scalar_stat_avg(const struct scalar_stat *stat); -void -scalar_stat_print_rgb8bit(const struct scalar_stat *stat); - void scalar_stat_print_float(const struct scalar_stat *stat); void rgb_diff_stat_update(struct rgb_diff_stat *stat, struct color_float *ref, struct color_float *val); + +void +rgb_diff_stat_print(const struct rgb_diff_stat *stat, + const char *title, unsigned scaling_bits);