Skip to content

Commit

Permalink
fix image plane copying in nlmeans prefilter setup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrisd8088 authored and bradleysepos committed Jan 23, 2020
1 parent 8966caa commit 92ea3b1
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions libhb/nlmeans.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 92ea3b1

Please sign in to comment.