From ffac29061fc920b7c985f05c6a0d649bc4f27c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Fri, 19 May 2017 13:08:36 +0300 Subject: [PATCH] Fix extrapolated inter SATD --- src/image.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/image.c b/src/image.c index 2528b3c4..8a1fe36f 100644 --- a/src/image.c +++ b/src/image.c @@ -23,6 +23,7 @@ #include #include +#include "strategies/strategies-ipol.h" #include "strategies/strategies-picture.h" #include "threads.h" @@ -519,17 +520,36 @@ unsigned kvz_image_calc_satd(const kvz_picture *pic, ref_data, ref->stride) >> (KVZ_BIT_DEPTH - 8); } else { - // Call a routine that knows how to interpolate pixels outside the frame. - // TODO: write interpolated SATD - unsigned sad = image_interpolated_sad(pic, - ref, - pic_x, - pic_y, - ref_x, - ref_y, - block_width, - block_height) >> (KVZ_BIT_DEPTH - 8); - return 2.4 * sad; + // Extrapolate pixels from outside the frame. + kvz_extended_block block; + kvz_get_extended_block(pic_x, + pic_y, + ref_x - pic_x, + ref_y - pic_y, + 0, + 0, + ref->y, + ref->width, + ref->height, + 0, + block_width, + block_height, + &block); + + const kvz_pixel *pic_data = &pic->y[pic_y * pic->stride + pic_x]; + + unsigned satd = kvz_satd_any_size(block_width, + block_height, + pic_data, + pic->stride, + block.buffer, + block.stride) >> (KVZ_BIT_DEPTH - 8); + + if (block.malloc_used) { + FREE_POINTER(block.buffer); + } + + return satd; } }