101 enum OverlayFormat { OVERLAY_FORMAT_YUV420, OVERLAY_FORMAT_YUV444, OVERLAY_FORMAT_RGB, OVERLAY_FORMAT_NB} format;
102 enum EvalMode { EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB } eval_mode;
108 int main_pix_step[4];
109 int overlay_pix_step[4];
125 "The rgb option is deprecated and is overriding the format option, use format instead\n");
126 s->
format = OVERLAY_FORMAT_RGB;
146 return (
int)d & ~((1 << chroma_sub) - 1);
171 "Error when evaluating the expression '%s' for %s\n",
187 if (!strcmp(cmd,
"x"))
189 else if (!strcmp(cmd,
"y"))
214 static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = {
221 static const enum AVPixelFormat overlay_pix_fmts_yuv444[] = {
241 case OVERLAY_FORMAT_YUV420:
245 case OVERLAY_FORMAT_YUV444:
249 case OVERLAY_FORMAT_RGB:
325 "main w:%d h:%d fmt:%s overlay w:%d h:%d fmt:%s\n",
346 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
352 #define UNPREMULTIPLY_ALPHA(x, y) ((((x) << 16) - ((x) << 9) + (x)) / ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)))
362 int i, imax, j, jmax, k, kmax;
363 const int src_w = src->
width;
364 const int src_h = src->
height;
365 const int dst_w = dst->
width;
366 const int dst_h = dst->
height;
368 if (x >= dst_w || x+dst_w < 0 ||
369 y >= dst_h || y+dst_h < 0)
391 for (imax =
FFMIN(-y + dst_h, src_h); i < imax; i++) {
394 d = dp + (x+j) * dstep;
396 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
401 if (main_has_alpha && alpha != 0 && alpha != 255) {
417 d[dr] =
FAST_DIV255(d[dr] * (255 - alpha) + s[sr] * alpha);
418 d[dg] =
FAST_DIV255(d[dg] * (255 - alpha) + s[sg] * alpha);
419 d[db] =
FAST_DIV255(d[db] * (255 - alpha) + s[sb] * alpha);
421 if (main_has_alpha) {
441 if (main_has_alpha) {
449 for (imax =
FFMIN(-y + dst_h, src_h); i < imax; i++) {
454 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
456 if (alpha != 0 && alpha != 255) {
477 for (i = 0; i < 3; i++) {
478 int hsub = i ? s->
hsub : 0;
479 int vsub = i ? s->
vsub : 0;
493 for (jmax =
FFMIN(-yp + dst_hp, src_hp); j < jmax; j++) {
499 for (kmax =
FFMIN(-xp + dst_wp, src_wp); k < kmax; k++) {
500 int alpha_v, alpha_h,
alpha;
503 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
504 alpha = (a[0] + a[src->
linesize[3]] +
506 }
else if (hsub || vsub) {
507 alpha_h = hsub && k+1 < src_wp ?
508 (a[0] + a[1]) >> 1 : a[0];
509 alpha_v = vsub && j+1 < src_hp ?
510 (a[0] + a[src->
linesize[3]]) >> 1 : a[0];
511 alpha = (alpha_v + alpha_h) >> 1;
516 if (main_has_alpha && alpha != 0 && alpha != 255) {
519 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
520 alpha_d = (d[0] + d[src->
linesize[3]] +
522 }
else if (hsub || vsub) {
523 alpha_h = hsub && k+1 < src_wp ?
524 (d[0] + d[1]) >> 1 : d[0];
525 alpha_v = vsub && j+1 < src_hp ?
526 (d[0] + d[src->
linesize[3]]) >> 1 : d[0];
527 alpha_d = (alpha_v + alpha_h) >> 1;
539 ap += (1 << vsub) * src->
linesize[3];
577 av_dlog(ctx,
"main_pts:%s main_pts_time:%s",
580 av_dlog(ctx,
" over_pts:%s over_pts_time:%s",
695 #define OFFSET(x) offsetof(OverlayContext, x)
696 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
701 {
"eval",
"specify when to evaluate expressions",
OFFSET(eval_mode),
AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_FRAME}, 0, EVAL_MODE_NB-1,
FLAGS,
"eval" },
702 {
"init",
"eval expressions once during initialization", 0,
AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags =
FLAGS, .unit =
"eval" },
703 {
"frame",
"eval expressions per-frame", 0,
AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags =
FLAGS, .unit =
"eval" },
704 {
"rgb",
"force packed RGB in input and output (deprecated)",
OFFSET(allow_packed_rgb),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1,
FLAGS },
705 {
"shortest",
"force termination when the shortest input terminates",
OFFSET(shortest),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
FLAGS },
706 {
"format",
"set output format",
OFFSET(format),
AV_OPT_TYPE_INT, {.i64=OVERLAY_FORMAT_YUV420}, 0, OVERLAY_FORMAT_NB-1,
FLAGS,
"format" },
752 .priv_class = &overlay_class,
757 .
inputs = avfilter_vf_overlay_inputs,
758 .
outputs = avfilter_vf_overlay_outputs,