avfilter/vf_nlmeans: refactor line processing in preparation for x86 SIMD assembly
This commit is contained in:
parent
38c86e7a02
commit
eaca36d495
@ -38,11 +38,6 @@
|
|||||||
#include "vf_nlmeans.h"
|
#include "vf_nlmeans.h"
|
||||||
#include "video.h"
|
#include "video.h"
|
||||||
|
|
||||||
struct weighted_avg {
|
|
||||||
float total_weight;
|
|
||||||
float sum;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct NLMeansContext {
|
typedef struct NLMeansContext {
|
||||||
const AVClass *class;
|
const AVClass *class;
|
||||||
int nb_planes;
|
int nb_planes;
|
||||||
@ -329,28 +324,17 @@ struct thread_data {
|
|||||||
int p;
|
int p;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
static void compute_weights_line_c(const uint32_t *const iia,
|
||||||
|
const uint32_t *const iib,
|
||||||
|
const uint32_t *const iid,
|
||||||
|
const uint32_t *const iie,
|
||||||
|
const uint8_t *const src,
|
||||||
|
struct weighted_avg *wa,
|
||||||
|
const float *const weight_lut,
|
||||||
|
int max_meaningful_diff,
|
||||||
|
int startx, int endx)
|
||||||
{
|
{
|
||||||
NLMeansContext *s = ctx->priv;
|
for (int x = startx; x < endx; x++) {
|
||||||
const uint32_t max_meaningful_diff = s->max_meaningful_diff;
|
|
||||||
const struct thread_data *td = arg;
|
|
||||||
const ptrdiff_t src_linesize = td->src_linesize;
|
|
||||||
const int process_h = td->endy - td->starty;
|
|
||||||
const int slice_start = (process_h * jobnr ) / nb_jobs;
|
|
||||||
const int slice_end = (process_h * (jobnr+1)) / nb_jobs;
|
|
||||||
const int starty = td->starty + slice_start;
|
|
||||||
const int endy = td->starty + slice_end;
|
|
||||||
const int p = td->p;
|
|
||||||
const uint32_t *ii = td->ii_start + (starty - p - 1) * s->ii_lz_32 - p - 1;
|
|
||||||
const int dist_b = 2*p + 1;
|
|
||||||
const int dist_d = dist_b * s->ii_lz_32;
|
|
||||||
const int dist_e = dist_d + dist_b;
|
|
||||||
const float *const weight_lut = s->weight_lut;
|
|
||||||
|
|
||||||
for (int y = starty; y < endy; y++) {
|
|
||||||
const uint8_t *src = td->src + y*src_linesize;
|
|
||||||
struct weighted_avg *wa = s->wa + y*s->wa_linesize;
|
|
||||||
for (int x = td->startx; x < td->endx; x++) {
|
|
||||||
/*
|
/*
|
||||||
* M is a discrete map where every entry contains the sum of all the entries
|
* M is a discrete map where every entry contains the sum of all the entries
|
||||||
* in the rectangle from the top-left origin of M to its coordinate. In the
|
* in the rectangle from the top-left origin of M to its coordinate. In the
|
||||||
@ -380,16 +364,48 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs
|
|||||||
* contains the sum of the squared difference of every corresponding pixels of
|
* contains the sum of the squared difference of every corresponding pixels of
|
||||||
* two input planes of the same size as M.
|
* two input planes of the same size as M.
|
||||||
*/
|
*/
|
||||||
const uint32_t a = ii[x];
|
const uint32_t a = iia[x];
|
||||||
const uint32_t b = ii[x + dist_b];
|
const uint32_t b = iib[x];
|
||||||
const uint32_t d = ii[x + dist_d];
|
const uint32_t d = iid[x];
|
||||||
const uint32_t e = ii[x + dist_e];
|
const uint32_t e = iie[x];
|
||||||
const uint32_t patch_diff_sq = FFMIN(e - d - b + a, max_meaningful_diff);
|
const uint32_t patch_diff_sq = FFMIN(e - d - b + a, max_meaningful_diff);
|
||||||
const float weight = weight_lut[patch_diff_sq]; // exp(-patch_diff_sq * s->pdiff_scale)
|
const float weight = weight_lut[patch_diff_sq]; // exp(-patch_diff_sq * s->pdiff_scale)
|
||||||
|
|
||||||
wa[x].total_weight += weight;
|
wa[x].total_weight += weight;
|
||||||
wa[x].sum += weight * src[x];
|
wa[x].sum += weight * src[x];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||||
|
{
|
||||||
|
NLMeansContext *s = ctx->priv;
|
||||||
|
const uint32_t max_meaningful_diff = s->max_meaningful_diff;
|
||||||
|
const struct thread_data *td = arg;
|
||||||
|
const ptrdiff_t src_linesize = td->src_linesize;
|
||||||
|
const int process_h = td->endy - td->starty;
|
||||||
|
const int slice_start = (process_h * jobnr ) / nb_jobs;
|
||||||
|
const int slice_end = (process_h * (jobnr+1)) / nb_jobs;
|
||||||
|
const int starty = td->starty + slice_start;
|
||||||
|
const int endy = td->starty + slice_end;
|
||||||
|
const int p = td->p;
|
||||||
|
const uint32_t *ii = td->ii_start + (starty - p - 1) * s->ii_lz_32 - p - 1;
|
||||||
|
const int dist_b = 2*p + 1;
|
||||||
|
const int dist_d = dist_b * s->ii_lz_32;
|
||||||
|
const int dist_e = dist_d + dist_b;
|
||||||
|
const float *const weight_lut = s->weight_lut;
|
||||||
|
NLMeansDSPContext *dsp = &s->dsp;
|
||||||
|
|
||||||
|
for (int y = starty; y < endy; y++) {
|
||||||
|
const uint8_t *const src = td->src + y*src_linesize;
|
||||||
|
struct weighted_avg *wa = s->wa + y*s->wa_linesize;
|
||||||
|
const uint32_t *const iia = ii;
|
||||||
|
const uint32_t *const iib = ii + dist_b;
|
||||||
|
const uint32_t *const iid = ii + dist_d;
|
||||||
|
const uint32_t *const iie = ii + dist_e;
|
||||||
|
|
||||||
|
dsp->compute_weights_line(iia, iib, iid, iie, src, wa,
|
||||||
|
weight_lut, max_meaningful_diff,
|
||||||
|
td->startx, td->endx);
|
||||||
ii += s->ii_lz_32;
|
ii += s->ii_lz_32;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -493,6 +509,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
|||||||
void ff_nlmeans_init(NLMeansDSPContext *dsp)
|
void ff_nlmeans_init(NLMeansDSPContext *dsp)
|
||||||
{
|
{
|
||||||
dsp->compute_safe_ssd_integral_image = compute_safe_ssd_integral_image_c;
|
dsp->compute_safe_ssd_integral_image = compute_safe_ssd_integral_image_c;
|
||||||
|
dsp->compute_weights_line = compute_weights_line_c;
|
||||||
|
|
||||||
if (ARCH_AARCH64)
|
if (ARCH_AARCH64)
|
||||||
ff_nlmeans_init_aarch64(dsp);
|
ff_nlmeans_init_aarch64(dsp);
|
||||||
|
@ -22,11 +22,25 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct weighted_avg {
|
||||||
|
float total_weight;
|
||||||
|
float sum;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct NLMeansDSPContext {
|
typedef struct NLMeansDSPContext {
|
||||||
void (*compute_safe_ssd_integral_image)(uint32_t *dst, ptrdiff_t dst_linesize_32,
|
void (*compute_safe_ssd_integral_image)(uint32_t *dst, ptrdiff_t dst_linesize_32,
|
||||||
const uint8_t *s1, ptrdiff_t linesize1,
|
const uint8_t *s1, ptrdiff_t linesize1,
|
||||||
const uint8_t *s2, ptrdiff_t linesize2,
|
const uint8_t *s2, ptrdiff_t linesize2,
|
||||||
int w, int h);
|
int w, int h);
|
||||||
|
void (*compute_weights_line)(const uint32_t *const iia,
|
||||||
|
const uint32_t *const iib,
|
||||||
|
const uint32_t *const iid,
|
||||||
|
const uint32_t *const iie,
|
||||||
|
const uint8_t *const src,
|
||||||
|
struct weighted_avg *wa,
|
||||||
|
const float *const weight_lut,
|
||||||
|
int max_meaningful_diff,
|
||||||
|
int startx, int endx);
|
||||||
} NLMeansDSPContext;
|
} NLMeansDSPContext;
|
||||||
|
|
||||||
void ff_nlmeans_init(NLMeansDSPContext *dsp);
|
void ff_nlmeans_init(NLMeansDSPContext *dsp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user