96 enum OverlayFormat { OVERLAY_FORMAT_YUV420, OVERLAY_FORMAT_YUV444, OVERLAY_FORMAT_RGB, OVERLAY_FORMAT_NB} format;
97 enum EvalMode { EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB } eval_mode;
101 int main_pix_step[4];
102 int overlay_pix_step[4];
123 return (
int)d & ~((1 << chroma_sub) - 1);
145 NULL, NULL, NULL, NULL, 0, log_ctx);
148 "Error when evaluating the expression '%s' for %s\n",
164 if (!strcmp(cmd,
"x"))
166 else if (!strcmp(cmd,
"y"))
191 static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = {
198 static const enum AVPixelFormat overlay_pix_fmts_yuv444[] = {
218 case OVERLAY_FORMAT_YUV420:
222 case OVERLAY_FORMAT_YUV444:
226 case OVERLAY_FORMAT_RGB:
302 "main w:%d h:%d fmt:%s overlay w:%d h:%d fmt:%s\n",
323 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
329 #define UNPREMULTIPLY_ALPHA(x, y) ((((x) << 16) - ((x) << 9) + (x)) / ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)))
339 int i, imax, j, jmax, k, kmax;
340 const int src_w = src->
width;
341 const int src_h = src->
height;
342 const int dst_w = dst->
width;
343 const int dst_h = dst->
height;
345 if (x >= dst_w || x+dst_w < 0 ||
346 y >= dst_h || y+dst_h < 0)
368 for (imax =
FFMIN(-y + dst_h, src_h); i < imax; i++) {
371 d = dp + (x+j) * dstep;
373 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
378 if (main_has_alpha && alpha != 0 && alpha != 255) {
394 d[dr] =
FAST_DIV255(d[dr] * (255 - alpha) + s[sr] * alpha);
395 d[dg] =
FAST_DIV255(d[dg] * (255 - alpha) + s[sg] * alpha);
396 d[db] =
FAST_DIV255(d[db] * (255 - alpha) + s[sb] * alpha);
398 if (main_has_alpha) {
418 if (main_has_alpha) {
426 for (imax =
FFMIN(-y + dst_h, src_h); i < imax; i++) {
431 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
433 if (alpha != 0 && alpha != 255) {
454 for (i = 0; i < 3; i++) {
455 int hsub = i ? s->
hsub : 0;
456 int vsub = i ? s->
vsub : 0;
470 for (jmax =
FFMIN(-yp + dst_hp, src_hp); j < jmax; j++) {
476 for (kmax =
FFMIN(-xp + dst_wp, src_wp); k < kmax; k++) {
477 int alpha_v, alpha_h,
alpha;
480 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
481 alpha = (a[0] + a[src->
linesize[3]] +
483 }
else if (hsub || vsub) {
484 alpha_h = hsub && k+1 < src_wp ?
485 (a[0] + a[1]) >> 1 : a[0];
486 alpha_v = vsub && j+1 < src_hp ?
487 (a[0] + a[src->
linesize[3]]) >> 1 : a[0];
488 alpha = (alpha_v + alpha_h) >> 1;
493 if (main_has_alpha && alpha != 0 && alpha != 255) {
496 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
497 alpha_d = (d[0] + d[src->
linesize[3]] +
499 }
else if (hsub || vsub) {
500 alpha_h = hsub && k+1 < src_wp ?
501 (d[0] + d[1]) >> 1 : d[0];
502 alpha_v = vsub && j+1 < src_hp ?
503 (d[0] + d[src->
linesize[3]]) >> 1 : d[0];
504 alpha_d = (alpha_v + alpha_h) >> 1;
516 ap += (1 << vsub) * src->
linesize[3];
572 "The rgb option is deprecated and is overriding the format option, use format instead\n");
573 s->
format = OVERLAY_FORMAT_RGB;
579 #define OFFSET(x) offsetof(OverlayContext, x)
580 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
585 {
"eval",
"specify when to evaluate expressions",
OFFSET(eval_mode),
AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_FRAME}, 0, EVAL_MODE_NB-1,
FLAGS,
"eval" },
586 {
"init",
"eval expressions once during initialization", 0,
AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags =
FLAGS, .unit =
"eval" },
587 {
"frame",
"eval expressions per-frame", 0,
AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags =
FLAGS, .unit =
"eval" },
588 {
"rgb",
"force packed RGB in input and output (deprecated)",
OFFSET(allow_packed_rgb),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1,
FLAGS },
589 {
"shortest",
"force termination when the shortest input terminates",
OFFSET(dinput.shortest),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
FLAGS },
590 {
"format",
"set output format",
OFFSET(format),
AV_OPT_TYPE_INT, {.i64=OVERLAY_FORMAT_YUV420}, 0, OVERLAY_FORMAT_NB-1,
FLAGS,
"format" },
594 {
"repeatlast",
"repeat overlay of the last overlay frame",
OFFSET(dinput.repeatlast),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1,
FLAGS },
636 .priv_class = &overlay_class,
641 .
inputs = avfilter_vf_overlay_inputs,
642 .
outputs = avfilter_vf_overlay_outputs,