You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avfilter/vf_maskedmerge: rewrite and remove some duplicated code
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
@@ -35,8 +35,11 @@ typedef struct MaskedMergeContext {
|
|||||||
int max, half, depth;
|
int max, half, depth;
|
||||||
FFFrameSync fs;
|
FFFrameSync fs;
|
||||||
|
|
||||||
void (*maskedmerge)(struct MaskedMergeContext *s, const AVFrame *base,
|
void (*maskedmerge)(struct MaskedMergeContext *s,
|
||||||
const AVFrame *overlay, const AVFrame *mask, AVFrame *out);
|
const uint8_t *bsrc, int blinesize,
|
||||||
|
const uint8_t *osrc, int olinesize,
|
||||||
|
const uint8_t *msrc, int mlinesize,
|
||||||
|
uint8_t *dst, int dlinesize, int w, int h);
|
||||||
} MaskedMergeContext;
|
} MaskedMergeContext;
|
||||||
|
|
||||||
#define OFFSET(x) offsetof(MaskedMergeContext, x)
|
#define OFFSET(x) offsetof(MaskedMergeContext, x)
|
||||||
@@ -92,78 +95,76 @@ static int process_frame(FFFrameSync *fs)
|
|||||||
if (!out)
|
if (!out)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
} else {
|
} else {
|
||||||
|
int p;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
s->maskedmerge(s, base, overlay, mask, out);
|
for (p = 0; p < s->nb_planes; p++) {
|
||||||
|
if (!((1 << p) & s->planes)) {
|
||||||
|
av_image_copy_plane(out->data[p], out->linesize[p], base->data[p], base->linesize[p],
|
||||||
|
s->width[p], s->height[p]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
s->maskedmerge(s, base->data[p], base->linesize[p],
|
||||||
|
overlay->data[p], overlay->linesize[p],
|
||||||
|
mask->data[p], mask->linesize[p],
|
||||||
|
out->data[p], out->linesize[p],
|
||||||
|
s->width[p], s->height[p]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out->pts = av_rescale_q(base->pts, s->fs.time_base, outlink->time_base);
|
out->pts = av_rescale_q(base->pts, s->fs.time_base, outlink->time_base);
|
||||||
|
|
||||||
return ff_filter_frame(outlink, out);
|
return ff_filter_frame(outlink, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void maskedmerge8(MaskedMergeContext *s, const AVFrame *base,
|
static void maskedmerge8(MaskedMergeContext *s,
|
||||||
const AVFrame *overlay, const AVFrame *mask, AVFrame *out)
|
const uint8_t *bsrc, int blinesize,
|
||||||
|
const uint8_t *osrc, int olinesize,
|
||||||
|
const uint8_t *msrc, int mlinesize,
|
||||||
|
uint8_t *dst, int dlinesize, int w, int h)
|
||||||
{
|
{
|
||||||
int p, x, y;
|
int x, y;
|
||||||
|
|
||||||
for (p = 0; p < s->nb_planes; p++) {
|
for (y = 0; y < h; y++) {
|
||||||
const uint8_t *bsrc = base->data[p];
|
for (x = 0; x < w; x++) {
|
||||||
const uint8_t *osrc = overlay->data[p];
|
dst[x] = ((256 - msrc[x]) * bsrc[x] + msrc[x] * osrc[x] + 128) >> 8;
|
||||||
const uint8_t *msrc = mask->data[p];
|
|
||||||
uint8_t *dst = out->data[p];
|
|
||||||
|
|
||||||
if (!((1 << p) & s->planes)) {
|
|
||||||
av_image_copy_plane(dst, out->linesize[p], bsrc, base->linesize[p],
|
|
||||||
s->width[p], s->height[p]);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (y = 0; y < s->height[p]; y++) {
|
dst += dlinesize;
|
||||||
for (x = 0; x < s->width[p]; x++) {
|
bsrc += blinesize;
|
||||||
dst[x] = ((256 - msrc[x]) * bsrc[x] + msrc[x] * osrc[x] + 128) >> 8;
|
osrc += olinesize;
|
||||||
}
|
msrc += mlinesize;
|
||||||
|
|
||||||
dst += out->linesize[p];
|
|
||||||
bsrc += base->linesize[p];
|
|
||||||
osrc += overlay->linesize[p];
|
|
||||||
msrc += mask->linesize[p];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void maskedmerge16(MaskedMergeContext *s, const AVFrame *base,
|
static void maskedmerge16(MaskedMergeContext *s,
|
||||||
const AVFrame *overlay, const AVFrame *mask, AVFrame *out)
|
const uint8_t *bbsrc, int blinesize,
|
||||||
|
const uint8_t *oosrc, int olinesize,
|
||||||
|
const uint8_t *mmsrc, int mlinesize,
|
||||||
|
uint8_t *ddst, int dlinesize, int w, int h)
|
||||||
{
|
{
|
||||||
const int max = s->max;
|
const int max = s->max;
|
||||||
const int half = s->half;
|
const int half = s->half;
|
||||||
const int shift = s->depth;
|
const int shift = s->depth;
|
||||||
int p, x, y;
|
const uint16_t *bsrc = (const uint16_t *)bbsrc;
|
||||||
|
const uint16_t *osrc = (const uint16_t *)oosrc;
|
||||||
|
const uint16_t *msrc = (const uint16_t *)mmsrc;
|
||||||
|
uint16_t *dst = (uint16_t *)ddst;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
for (p = 0; p < s->nb_planes; p++) {
|
for (y = 0; y < h; y++) {
|
||||||
const uint16_t *bsrc = (const uint16_t *)base->data[p];
|
for (x = 0; x < w; x++) {
|
||||||
const uint16_t *osrc = (const uint16_t *)overlay->data[p];
|
dst[x] = ((max - msrc[x]) * bsrc[x] + msrc[x] * osrc[x] + half) >> shift;
|
||||||
const uint16_t *msrc = (const uint16_t *)mask->data[p];
|
|
||||||
uint16_t *dst = (uint16_t *)out->data[p];
|
|
||||||
|
|
||||||
if (!((1 << p) & s->planes)) {
|
|
||||||
av_image_copy_plane(out->data[p], out->linesize[p], base->data[p], base->linesize[p],
|
|
||||||
s->width[p], s->height[p]);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (y = 0; y < s->height[p]; y++) {
|
dst += dlinesize / 2;
|
||||||
for (x = 0; x < s->width[p]; x++) {
|
bsrc += blinesize / 2;
|
||||||
dst[x] = ((max - msrc[x]) * bsrc[x] + msrc[x] * osrc[x] + half) >> shift;
|
osrc += olinesize / 2;
|
||||||
}
|
msrc += mlinesize / 2;
|
||||||
|
|
||||||
dst += out->linesize[p] / 2;
|
|
||||||
bsrc += base->linesize[p] / 2;
|
|
||||||
osrc += overlay->linesize[p] / 2;
|
|
||||||
msrc += mask->linesize[p] / 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user