You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avfilter/vf_maskedclamp: add slice threading
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
@@ -30,6 +30,10 @@
|
|||||||
#define OFFSET(x) offsetof(MaskedClampContext, x)
|
#define OFFSET(x) offsetof(MaskedClampContext, x)
|
||||||
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
||||||
|
|
||||||
|
typedef struct ThreadData {
|
||||||
|
AVFrame *b, *o, *m, *d;
|
||||||
|
} ThreadData;
|
||||||
|
|
||||||
typedef struct MaskedClampContext {
|
typedef struct MaskedClampContext {
|
||||||
const AVClass *class;
|
const AVClass *class;
|
||||||
|
|
||||||
@@ -43,11 +47,7 @@ typedef struct MaskedClampContext {
|
|||||||
int depth;
|
int depth;
|
||||||
FFFrameSync fs;
|
FFFrameSync fs;
|
||||||
|
|
||||||
void (*maskedclamp)(const uint8_t *bsrc, const uint8_t *osrc,
|
int (*maskedclamp)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
|
||||||
const uint8_t *msrc, uint8_t *dst,
|
|
||||||
ptrdiff_t blinesize, ptrdiff_t darklinesize,
|
|
||||||
ptrdiff_t brightlinesize, ptrdiff_t destlinesize,
|
|
||||||
int w, int h, int undershoot, int overshoot);
|
|
||||||
} MaskedClampContext;
|
} MaskedClampContext;
|
||||||
|
|
||||||
static const AVOption maskedclamp_options[] = {
|
static const AVOption maskedclamp_options[] = {
|
||||||
@@ -103,43 +103,56 @@ static int process_frame(FFFrameSync *fs)
|
|||||||
if (!out)
|
if (!out)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
} else {
|
} else {
|
||||||
int p;
|
ThreadData td;
|
||||||
|
|
||||||
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
||||||
if (!out)
|
if (!out)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
av_frame_copy_props(out, base);
|
av_frame_copy_props(out, base);
|
||||||
|
|
||||||
for (p = 0; p < s->nb_planes; p++) {
|
td.b = base;
|
||||||
if (!((1 << p) & s->planes)) {
|
td.o = dark;
|
||||||
av_image_copy_plane(out->data[p], out->linesize[p], base->data[p], base->linesize[p],
|
td.m = bright;
|
||||||
s->linesize[p], s->height[p]);
|
td.d = out;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
s->maskedclamp(base->data[p], dark->data[p],
|
ctx->internal->execute(ctx, s->maskedclamp, &td, NULL, FFMIN(s->height[0],
|
||||||
bright->data[p], out->data[p],
|
ff_filter_get_nb_threads(ctx)));
|
||||||
base->linesize[p], dark->linesize[p],
|
|
||||||
bright->linesize[p], out->linesize[p],
|
|
||||||
s->width[p], s->height[p],
|
|
||||||
s->undershoot, s->overshoot);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
|
out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
|
||||||
|
|
||||||
return ff_filter_frame(outlink, out);
|
return ff_filter_frame(outlink, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void maskedclamp8(const uint8_t *bsrc, const uint8_t *darksrc,
|
static int maskedclamp8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||||
const uint8_t *brightsrc, uint8_t *dst,
|
|
||||||
ptrdiff_t blinesize, ptrdiff_t darklinesize,
|
|
||||||
ptrdiff_t brightlinesize, ptrdiff_t dlinesize,
|
|
||||||
int w, int h,
|
|
||||||
int undershoot, int overshoot)
|
|
||||||
{
|
{
|
||||||
|
MaskedClampContext *s = ctx->priv;
|
||||||
|
ThreadData *td = arg;
|
||||||
|
int p;
|
||||||
|
|
||||||
|
for (p = 0; p < s->nb_planes; p++) {
|
||||||
|
const ptrdiff_t blinesize = td->b->linesize[p];
|
||||||
|
const ptrdiff_t brightlinesize = td->m->linesize[p];
|
||||||
|
const ptrdiff_t darklinesize = td->o->linesize[p];
|
||||||
|
const ptrdiff_t dlinesize = td->d->linesize[p];
|
||||||
|
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 uint8_t *bsrc = td->b->data[p] + slice_start * blinesize;
|
||||||
|
const uint8_t *darksrc = td->o->data[p] + slice_start * darklinesize;
|
||||||
|
const uint8_t *brightsrc = td->m->data[p] + slice_start * brightlinesize;
|
||||||
|
uint8_t *dst = td->d->data[p] + slice_start * dlinesize;
|
||||||
|
const int undershoot = s->undershoot;
|
||||||
|
const int overshoot = s->overshoot;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
for (y = 0; y < h; y++) {
|
if (!((1 << p) & s->planes)) {
|
||||||
|
av_image_copy_plane(dst, dlinesize, bsrc, blinesize,
|
||||||
|
s->linesize[p], slice_end - slice_start);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (y = slice_start; y < slice_end; y++) {
|
||||||
for (x = 0; x < w; x++) {
|
for (x = 0; x < w; x++) {
|
||||||
if (bsrc[x] < darksrc[x] - undershoot)
|
if (bsrc[x] < darksrc[x] - undershoot)
|
||||||
dst[x] = darksrc[x] - undershoot;
|
dst[x] = darksrc[x] - undershoot;
|
||||||
@@ -154,27 +167,41 @@ static void maskedclamp8(const uint8_t *bsrc, const uint8_t *darksrc,
|
|||||||
darksrc += darklinesize;
|
darksrc += darklinesize;
|
||||||
brightsrc += brightlinesize;
|
brightsrc += brightlinesize;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void maskedclamp16(const uint8_t *bbsrc, const uint8_t *oosrc,
|
static int maskedclamp16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
|
||||||
const uint8_t *mmsrc, uint8_t *ddst,
|
|
||||||
ptrdiff_t blinesize, ptrdiff_t darklinesize,
|
|
||||||
ptrdiff_t brightlinesize, ptrdiff_t dlinesize,
|
|
||||||
int w, int h,
|
|
||||||
int undershoot, int overshoot)
|
|
||||||
{
|
{
|
||||||
const uint16_t *bsrc = (const uint16_t *)bbsrc;
|
MaskedClampContext *s = ctx->priv;
|
||||||
const uint16_t *darksrc = (const uint16_t *)oosrc;
|
ThreadData *td = arg;
|
||||||
const uint16_t *brightsrc = (const uint16_t *)mmsrc;
|
int p;
|
||||||
uint16_t *dst = (uint16_t *)ddst;
|
|
||||||
|
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;
|
int x, y;
|
||||||
|
|
||||||
dlinesize /= 2;
|
if (!((1 << p) & s->planes)) {
|
||||||
blinesize /= 2;
|
av_image_copy_plane(dst, dlinesize, bsrc, blinesize,
|
||||||
darklinesize /= 2;
|
s->linesize[p], slice_end - slice_start);
|
||||||
brightlinesize /= 2;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (y = 0; y < h; y++) {
|
for (y = slice_start; y < slice_end; y++) {
|
||||||
for (x = 0; x < w; x++) {
|
for (x = 0; x < w; x++) {
|
||||||
if (bsrc[x] < darksrc[x] - undershoot)
|
if (bsrc[x] < darksrc[x] - undershoot)
|
||||||
dst[x] = darksrc[x] - undershoot;
|
dst[x] = darksrc[x] - undershoot;
|
||||||
@@ -189,6 +216,9 @@ static void maskedclamp16(const uint8_t *bbsrc, const uint8_t *oosrc,
|
|||||||
darksrc += darklinesize;
|
darksrc += darklinesize;
|
||||||
brightsrc += brightlinesize;
|
brightsrc += brightlinesize;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_input(AVFilterLink *inlink)
|
static int config_input(AVFilterLink *inlink)
|
||||||
@@ -324,5 +354,5 @@ AVFilter ff_vf_maskedclamp = {
|
|||||||
.inputs = maskedclamp_inputs,
|
.inputs = maskedclamp_inputs,
|
||||||
.outputs = maskedclamp_outputs,
|
.outputs = maskedclamp_outputs,
|
||||||
.priv_class = &maskedclamp_class,
|
.priv_class = &maskedclamp_class,
|
||||||
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
|
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user