From 3c75500cd4960f32438adff8dae15a24239df6d7 Mon Sep 17 00:00:00 2001 From: Marko Viitanen Date: Fri, 26 Feb 2021 19:38:15 +0200 Subject: [PATCH] Fix PSNR calculation, broken after the introduction of frame padding --- src/encmain.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/encmain.c b/src/encmain.c index 7cd84d3d..c9203a78 100644 --- a/src/encmain.c +++ b/src/encmain.c @@ -110,13 +110,26 @@ static void compute_psnr(const kvz_picture *const src, double sse[3] = { 0.0 }; for (int32_t c = 0; c < colors; ++c) { + + kvz_pixel* src_ptr = src->data[c]; + kvz_pixel* rec_ptr = rec->data[c]; + int32_t width = src->width; + int32_t height = src->height; + int32_t stride = src->stride; int32_t num_pixels = pixels; if (c != COLOR_Y) { + width >>= 1; + height >>= 1; + stride >>= 1; num_pixels >>= 2; } - for (int32_t i = 0; i < num_pixels; ++i) { - const int32_t error = src->data[c][i] - rec->data[c][i]; - sse[c] += error * error; + for (int32_t y = 0; y < height; ++y) { + for (int32_t x = 0; x < width; ++x) { + const int32_t error = src_ptr[x] - rec_ptr[x]; + sse[c] += error * error; + } + src_ptr += stride; + rec_ptr += stride; } // Avoid division by zero