diff mbox

[FFmpeg-devel] avfilter/vf_nlmeans: round values toward nearest integer

Message ID 20191020195416.29732-1-onemda@gmail.com
State Accepted
Commit a174e5f8da77d17dc16227f94eb14db7fd0365a4
Headers show

Commit Message

Paul B Mahol Oct. 20, 2019, 7:54 p.m. UTC
Instead of rounding toward zero and thus producing
darker output.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavfilter/vf_nlmeans.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Clément Bœsch Oct. 21, 2019, 5:56 a.m. UTC | #1
On Sun, Oct 20, 2019 at 09:54:16PM +0200, Paul B Mahol wrote:
> Instead of rounding toward zero and thus producing
> darker output.
> 
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavfilter/vf_nlmeans.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
> index dcb5a03953..06233b0dd4 100644
> --- a/libavfilter/vf_nlmeans.c
> +++ b/libavfilter/vf_nlmeans.c
> @@ -419,7 +419,7 @@ static void weight_averages(uint8_t *dst, ptrdiff_t dst_linesize,
>              // Also weight the centered pixel
>              wa[x].total_weight += 1.f;
>              wa[x].sum += 1.f * src[x];
> -            dst[x] = av_clip_uint8(wa[x].sum / wa[x].total_weight);
> +            dst[x] = av_clip_uint8(wa[x].sum / wa[x].total_weight + 0.5f);
>          }
>          dst += dst_linesize;
>          src += src_linesize;

LGTM
diff mbox

Patch

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index dcb5a03953..06233b0dd4 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -419,7 +419,7 @@  static void weight_averages(uint8_t *dst, ptrdiff_t dst_linesize,
             // Also weight the centered pixel
             wa[x].total_weight += 1.f;
             wa[x].sum += 1.f * src[x];
-            dst[x] = av_clip_uint8(wa[x].sum / wa[x].total_weight);
+            dst[x] = av_clip_uint8(wa[x].sum / wa[x].total_weight + 0.5f);
         }
         dst += dst_linesize;
         src += src_linesize;