summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Darroch <[email protected]>2020-01-11 20:42:53 -0800
committerBradley Sepos <[email protected]>2020-01-23 02:48:12 -0500
commit92ea3b13f5c207598ada6c8e92dbe8d36a573f99 (patch)
tree88900a4202c0cb3316ea27891b7769d88afd92bc
parent8966caad127cc10ff8c840ae3bcc665c2625755c (diff)
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.
-rw-r--r--libhb/nlmeans.c5
1 files changed, 1 insertions, 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)