From 92ea3b13f5c207598ada6c8e92dbe8d36a573f99 Mon Sep 17 00:00:00 2001 From: Chris Darroch Date: Sat, 11 Jan 2020 20:42:53 -0800 Subject: fix image plane copying in nlmeans prefilter setup When nlmeans_prefilter() is preparing to apply a pre-filter to an image plane, it first attempts to make a copy of the mem image plane into the mem_pre plane which will hold the pre-filter's output. However, the existing logic, which mirrors the loop over all pixel rows in nlmeans_alloc(), improperly leaves the bottom 2*border rows of the mem_pre plane uninitialized. Where nlmeans_alloc() correctly copies the source image's rows into its plane, by adding the correct offset to the memcpy(3) destination to locate the image pixel data between the horizontal and vertical borders, in nlmeans_prefilter() the intention is to copy both the image and the borders. However, the current loop only iterates h times, i.e., the size of the image itself, and skips the last (bh - h) = 2*border rows. Instead, we replace the loop with a single memcpy(3) call which just duplicates the entire mem image plane, including the border data. --- libhb/nlmeans.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libhb/nlmeans.c b/libhb/nlmeans.c index 153043659..9770fe0f4 100644 --- a/libhb/nlmeans.c +++ b/libhb/nlmeans.c @@ -616,10 +616,7 @@ static void nlmeans_prefilter(BorderedPlane *src, // Duplicate plane uint8_t *mem_pre = malloc(bw * bh * sizeof(uint8_t)); uint8_t *image_pre = mem_pre + border + bw * border; - for (int y = 0; y < h; y++) - { - memcpy(mem_pre + y * bw, mem + y * bw, bw); - } + memcpy(mem_pre, mem, bw * bh * sizeof(uint8_t)); // Filter plane; should already have at least 2px extra border on each side if (filter_type & NLMEANS_PREFILTER_MODE_CSM5X5) -- cgit v1.2.3