95 enum OverlayFormat { OVERLAY_FORMAT_YUV420, OVERLAY_FORMAT_YUV444, OVERLAY_FORMAT_RGB, OVERLAY_FORMAT_NB} format;
96 enum EvalMode { EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB } eval_mode;
100 int main_pix_step[4];
101 int overlay_pix_step[4];
122 return (
int)d & ~((1 << chroma_sub) - 1);
144 NULL, NULL, NULL, NULL, 0, log_ctx);
147 "Error when evaluating the expression '%s' for %s\n",
163 if (!strcmp(cmd,
"x"))
165 else if (!strcmp(cmd,
"y"))
190 static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = {
197 static const enum AVPixelFormat overlay_pix_fmts_yuv444[] = {
217 case OVERLAY_FORMAT_YUV420:
221 case OVERLAY_FORMAT_YUV444:
225 case OVERLAY_FORMAT_RGB:
301 "main w:%d h:%d fmt:%s overlay w:%d h:%d fmt:%s\n",
327 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
333 #define UNPREMULTIPLY_ALPHA(x, y) ((((x) << 16) - ((x) << 9) + (x)) / ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)))
343 int i, imax, j, jmax, k, kmax;
344 const int src_w = src->
width;
345 const int src_h = src->
height;
346 const int dst_w = dst->
width;
347 const int dst_h = dst->
height;
349 if (x >= dst_w || x+src_w < 0 ||
350 y >= dst_h || y+src_h < 0)
372 for (imax =
FFMIN(-y + dst_h, src_h); i < imax; i++) {
375 d = dp + (x+j) * dstep;
377 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
382 if (main_has_alpha && alpha != 0 && alpha != 255) {
398 d[dr] =
FAST_DIV255(d[dr] * (255 - alpha) + s[sr] * alpha);
399 d[dg] =
FAST_DIV255(d[dg] * (255 - alpha) + s[sg] * alpha);
400 d[db] =
FAST_DIV255(d[db] * (255 - alpha) + s[sb] * alpha);
402 if (main_has_alpha) {
422 if (main_has_alpha) {
430 for (imax =
FFMIN(-y + dst_h, src_h); i < imax; i++) {
435 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
437 if (alpha != 0 && alpha != 255) {
458 for (i = 0; i < 3; i++) {
459 int hsub = i ? s->
hsub : 0;
460 int vsub = i ? s->
vsub : 0;
474 for (jmax =
FFMIN(-yp + dst_hp, src_hp); j < jmax; j++) {
480 for (kmax =
FFMIN(-xp + dst_wp, src_wp); k < kmax; k++) {
481 int alpha_v, alpha_h,
alpha;
484 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
485 alpha = (a[0] + a[src->
linesize[3]] +
487 }
else if (hsub || vsub) {
488 alpha_h = hsub && k+1 < src_wp ?
489 (a[0] + a[1]) >> 1 : a[0];
490 alpha_v = vsub && j+1 < src_hp ?
491 (a[0] + a[src->
linesize[3]]) >> 1 : a[0];
492 alpha = (alpha_v + alpha_h) >> 1;
497 if (main_has_alpha && alpha != 0 && alpha != 255) {
500 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
501 alpha_d = (d[0] + d[src->
linesize[3]] +
503 }
else if (hsub || vsub) {
504 alpha_h = hsub && k+1 < src_wp ?
505 (d[0] + d[1]) >> 1 : d[0];
506 alpha_v = vsub && j+1 < src_hp ?
507 (d[0] + d[src->
linesize[3]]) >> 1 : d[0];
508 alpha_d = (alpha_v + alpha_h) >> 1;
520 ap += (1 << vsub) * src->
linesize[3];
570 "The rgb option is deprecated and is overriding the format option, use format instead\n");
571 s->
format = OVERLAY_FORMAT_RGB;
577 #define OFFSET(x) offsetof(OverlayContext, x)
578 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
583 {
"eval",
"specify when to evaluate expressions",
OFFSET(eval_mode),
AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_FRAME}, 0, EVAL_MODE_NB-1,
FLAGS,
"eval" },
584 {
"init",
"eval expressions once during initialization", 0,
AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags =
FLAGS, .unit =
"eval" },
585 {
"frame",
"eval expressions per-frame", 0,
AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags =
FLAGS, .unit =
"eval" },
586 {
"rgb",
"force packed RGB in input and output (deprecated)",
OFFSET(allow_packed_rgb),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1,
FLAGS },
587 {
"shortest",
"force termination when the shortest input terminates",
OFFSET(dinput.shortest),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
FLAGS },
588 {
"format",
"set output format",
OFFSET(format),
AV_OPT_TYPE_INT, {.i64=OVERLAY_FORMAT_YUV420}, 0, OVERLAY_FORMAT_NB-1,
FLAGS,
"format" },
592 {
"repeatlast",
"repeat overlay of the last overlay frame",
OFFSET(dinput.repeatlast),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1,
FLAGS },
631 .priv_class = &overlay_class,
634 .
inputs = avfilter_vf_overlay_inputs,
635 .
outputs = avfilter_vf_overlay_outputs,