avfilter/vf_maskedclamp: rewrite using macro

pull/324/head
Paul B Mahol 5 years ago
parent a34d06222f
commit 2a75006ddc
  1. 147
      libavfilter/vf_maskedclamp.c

@ -47,7 +47,9 @@ typedef struct MaskedClampContext {
int depth;
FFFrameSync fs;
int (*maskedclamp)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
void (*maskedclamp)(const uint8_t *bsrc, uint8_t *dst,
const uint8_t *darksrc, const uint8_t *brightsrc,
int w, int undershoot, int overshoot);
} MaskedClampContext;
static const AVOption maskedclamp_options[] = {
@ -85,45 +87,7 @@ static int query_formats(AVFilterContext *ctx)
return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
}
static int process_frame(FFFrameSync *fs)
{
AVFilterContext *ctx = fs->parent;
MaskedClampContext *s = fs->opaque;
AVFilterLink *outlink = ctx->outputs[0];
AVFrame *out, *base, *dark, *bright;
int ret;
if ((ret = ff_framesync_get_frame(&s->fs, 0, &base, 0)) < 0 ||
(ret = ff_framesync_get_frame(&s->fs, 1, &dark, 0)) < 0 ||
(ret = ff_framesync_get_frame(&s->fs, 2, &bright, 0)) < 0)
return ret;
if (ctx->is_disabled) {
out = av_frame_clone(base);
if (!out)
return AVERROR(ENOMEM);
} else {
ThreadData td;
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
if (!out)
return AVERROR(ENOMEM);
av_frame_copy_props(out, base);
td.b = base;
td.o = dark;
td.m = bright;
td.d = out;
ctx->internal->execute(ctx, s->maskedclamp, &td, NULL, FFMIN(s->height[0],
ff_filter_get_nb_threads(ctx)));
}
out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
return ff_filter_frame(outlink, out);
}
static int maskedclamp8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int maskedclamp_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
{
MaskedClampContext *s = ctx->priv;
ThreadData *td = arg;
@ -144,7 +108,7 @@ static int maskedclamp8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
uint8_t *dst = td->d->data[p] + slice_start * dlinesize;
const int undershoot = s->undershoot;
const int overshoot = s->overshoot;
int x, y;
int y;
if (!((1 << p) & s->planes)) {
av_image_copy_plane(dst, dlinesize, bsrc, blinesize,
@ -153,14 +117,7 @@ static int maskedclamp8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
}
for (y = slice_start; y < slice_end; y++) {
for (x = 0; x < w; x++) {
if (bsrc[x] < darksrc[x] - undershoot)
dst[x] = darksrc[x] - undershoot;
else if (bsrc[x] > brightsrc[x] + overshoot)
dst[x] = brightsrc[x] + overshoot;
else
dst[x] = bsrc[x];
}
s->maskedclamp(bsrc, dst, darksrc, brightsrc, w, undershoot, overshoot);
dst += dlinesize;
bsrc += blinesize;
@ -172,55 +129,67 @@ static int maskedclamp8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
return 0;
}
static int maskedclamp16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int process_frame(FFFrameSync *fs)
{
MaskedClampContext *s = ctx->priv;
ThreadData *td = arg;
int p;
AVFilterContext *ctx = fs->parent;
MaskedClampContext *s = fs->opaque;
AVFilterLink *outlink = ctx->outputs[0];
AVFrame *out, *base, *dark, *bright;
int ret;
for (p = 0; p < s->nb_planes; p++) {
const ptrdiff_t blinesize = td->b->linesize[p] / 2;
const ptrdiff_t brightlinesize = td->m->linesize[p] / 2;
const ptrdiff_t darklinesize = td->o->linesize[p] / 2;
const ptrdiff_t dlinesize = td->d->linesize[p] / 2;
const int w = s->width[p];
const int h = s->height[p];
const int slice_start = (h * jobnr) / nb_jobs;
const int slice_end = (h * (jobnr+1)) / nb_jobs;
const uint16_t *bsrc = (const uint16_t *)td->b->data[p] + slice_start * blinesize;
const uint16_t *darksrc = (const uint16_t *)td->o->data[p] + slice_start * darklinesize;
const uint16_t *brightsrc = (const uint16_t *)td->m->data[p] + slice_start * brightlinesize;
uint16_t *dst = (uint16_t *)td->d->data[p] + slice_start * dlinesize;
const int undershoot = s->undershoot;
const int overshoot = s->overshoot;
int x, y;
if ((ret = ff_framesync_get_frame(&s->fs, 0, &base, 0)) < 0 ||
(ret = ff_framesync_get_frame(&s->fs, 1, &dark, 0)) < 0 ||
(ret = ff_framesync_get_frame(&s->fs, 2, &bright, 0)) < 0)
return ret;
if (!((1 << p) & s->planes)) {
av_image_copy_plane((uint8_t *)dst, dlinesize, (const uint8_t *)bsrc, blinesize,
s->linesize[p], slice_end - slice_start);
continue;
}
if (ctx->is_disabled) {
out = av_frame_clone(base);
if (!out)
return AVERROR(ENOMEM);
} else {
ThreadData td;
for (y = slice_start; y < slice_end; y++) {
for (x = 0; x < w; x++) {
if (bsrc[x] < darksrc[x] - undershoot)
dst[x] = darksrc[x] - undershoot;
else if (bsrc[x] > brightsrc[x] + overshoot)
dst[x] = brightsrc[x] + overshoot;
else
dst[x] = bsrc[x];
}
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
if (!out)
return AVERROR(ENOMEM);
av_frame_copy_props(out, base);
dst += dlinesize;
bsrc += blinesize;
darksrc += darklinesize;
brightsrc += brightlinesize;
}
td.b = base;
td.o = dark;
td.m = bright;
td.d = out;
ctx->internal->execute(ctx, maskedclamp_slice, &td, NULL, FFMIN(s->height[0],
ff_filter_get_nb_threads(ctx)));
}
out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
return 0;
return ff_filter_frame(outlink, out);
}
#define MASKEDCLAMP(type, name) \
static void maskedclamp##name(const uint8_t *bbsrc, uint8_t *ddst, \
const uint8_t *ddarksrc, const uint8_t *bbrightsrc, \
int w, int undershoot, int overshoot) \
{ \
const type *bsrc = (const type *)bbsrc; \
const type *darksrc = (const type *)ddarksrc; \
const type *brightsrc = (const type *)bbrightsrc; \
type *dst = (type *)ddst; \
\
for (int x = 0; x < w; x++) { \
if (bsrc[x] < darksrc[x] - undershoot) \
dst[x] = darksrc[x] - undershoot; \
else if (bsrc[x] > brightsrc[x] + overshoot) \
dst[x] = brightsrc[x] + overshoot; \
else \
dst[x] = bsrc[x]; \
} \
}
MASKEDCLAMP(uint8_t, 8)
MASKEDCLAMP(uint16_t, 16)
static int config_input(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;

Loading…
Cancel
Save