Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -332,6 +332,7 @@ struct thread_data { · 331 unmodified lines | ||
| 332 | 332 | static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
| 333 | 333 | { |
| 334 | 334 | NLMeansContext *s = ctx->priv; |
| 335 | + const uint32_t max_meaningful_diff = s->max_meaningful_diff; | |
| 335 | 336 | const struct thread_data *td = arg; |
| 336 | 337 | const ptrdiff_t src_linesize = td->src_linesize; |
| 337 | 338 | const int process_h = td->endy - td->starty; |
| @@ -383,13 +384,11 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs · 45 unmodified lines | ||
| 383 | 384 | const uint32_t b = ii[x + dist_b]; |
| 384 | 385 | const uint32_t d = ii[x + dist_d]; |
| 385 | 386 | const uint32_t e = ii[x + dist_e]; |
| 386 | − const uint32_t patch_diff_sq = e - d - b + a; | |
| 387 | + const uint32_t patch_diff_sq = FFMIN(e - d - b + a, max_meaningful_diff); | |
| 388 | + const float weight = weight_lut[patch_diff_sq]; // exp(-patch_diff_sq * s->pdiff_scale) | |
| 387 | 389 | |
| 388 | − if (patch_diff_sq < s->max_meaningful_diff) { | |
| 389 | − const float weight = weight_lut[patch_diff_sq]; // exp(-patch_diff_sq * s->pdiff_scale) | |
| 390 | − wa[x].total_weight += weight; | |
| 391 | − wa[x].sum += weight * src[x]; | |
| 392 | − } | |
| 390 | + wa[x].total_weight += weight; | |
| 391 | + wa[x].sum += weight * src[x]; | |
| 393 | 392 | } |
| 394 | 393 | ii += s->ii_lz_32; |
| 395 | 394 | } |
| @@ -506,7 +505,7 @@ static av_cold int init(AVFilterContext *ctx) · 110 unmodified lines | ||
| 506 | 505 | |
| 507 | 506 | s->pdiff_scale = 1. / (h * h); |
| 508 | 507 | s->max_meaningful_diff = log(255.) / s->pdiff_scale; |
| 509 | − s->weight_lut = av_calloc(s->max_meaningful_diff, sizeof(*s->weight_lut)); | |
| 508 | + s->weight_lut = av_calloc(s->max_meaningful_diff + 1, sizeof(*s->weight_lut)); | |
| 510 | 509 | if (!s->weight_lut) |
| 511 | 510 | return AVERROR(ENOMEM); |
| 512 | 511 | for (int i = 0; i < s->max_meaningful_diff; i++) |