History

avfilter/vf_nlmeans: avoid if () to help paralellization

Paul B Mahol committed 5 years ago

Commit 38c86e71 parent 64d19411 file · +6 −7Browse files

Unified · Split

libavfilter/vf_nlmeans.c+6−7
@@ -332,6 +332,7 @@ struct thread_data { · 331 unmodified lines
332332 static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
333333 {
334334 NLMeansContext *s = ctx->priv;
335+ const uint32_t max_meaningful_diff = s->max_meaningful_diff;
335336 const struct thread_data *td = arg;
336337 const ptrdiff_t src_linesize = td->src_linesize;
337338 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
383384 const uint32_t b = ii[x + dist_b];
384385 const uint32_t d = ii[x + dist_d];
385386 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)
387389
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];
393392 }
394393 ii += s->ii_lz_32;
395394 }
@@ -506,7 +505,7 @@ static av_cold int init(AVFilterContext *ctx) · 110 unmodified lines
506505
507506 s->pdiff_scale = 1. / (h * h);
508507 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));
510509 if (!s->weight_lut)
511510 return AVERROR(ENOMEM);
512511 for (int i = 0; i < s->max_meaningful_diff; i++)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t