86 enum OverlayFormat { OVERLAY_FORMAT_YUV420, OVERLAY_FORMAT_YUV444, OVERLAY_FORMAT_RGB, OVERLAY_FORMAT_NB} format;
93 int overlay_pix_step[4];
100 #define OFFSET(x) offsetof(OverlayContext, x)
101 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
106 {
"rgb",
"force packed RGB in input and output (deprecated)",
OFFSET(allow_packed_rgb),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1,
FLAGS },
107 {
"shortest",
"force termination when the shortest input terminates",
OFFSET(shortest),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
FLAGS },
109 {
"format",
"set output format",
OFFSET(format),
AV_OPT_TYPE_INT, {.i64=OVERLAY_FORMAT_YUV420}, 0, OVERLAY_FORMAT_NB-1,
FLAGS,
"format" },
122 static const char *shorthand[] = {
"x",
"y",
NULL };
125 over->
class = &overlay_class;
134 "The rgb option is deprecated and is overriding the format option, use format instead\n");
135 over->
format = OVERLAY_FORMAT_RGB;
159 static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = {
166 static const enum AVPixelFormat overlay_pix_fmts_yuv444[] = {
186 case OVERLAY_FORMAT_YUV420:
190 case OVERLAY_FORMAT_YUV444:
194 case OVERLAY_FORMAT_RGB:
268 "main w:%d h:%d fmt:%s overlay x:%d y:%d w:%d h:%d fmt:%s\n",
275 if (over->
x < 0 || over->
y < 0 ||
279 "Overlay area with coordinates x1:%d y1:%d x2:%d y2:%d "
280 "is not completely contained within the output with size %dx%d\n",
284 (
int)var_values[
VAR_MAIN_W], (
int)var_values[VAR_MAIN_H]);
290 "Error when evaluating the expression '%s'\n", expr);
307 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
313 #define UNPREMULTIPLY_ALPHA(x, y) ((((x) << 16) - ((x) << 9) + (x)) / ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)))
323 int i, imax, j, jmax, k, kmax;
324 const int src_w = src->
video->
w;
325 const int src_h = src->
video->
h;
326 const int dst_w = dst->
video->
w;
327 const int dst_h = dst->
video->
h;
329 if (x >= dst_w || x+dst_w < 0 ||
330 y >= dst_h || y+dst_h < 0)
352 for (imax =
FFMIN(-y + dst_h, src_h); i < imax; i++) {
355 d = dp + (x+j) * dstep;
357 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
362 if (main_has_alpha && alpha != 0 && alpha != 255) {
378 d[dr] =
FAST_DIV255(d[dr] * (255 - alpha) + s[sr] * alpha);
379 d[dg] =
FAST_DIV255(d[dg] * (255 - alpha) + s[sg] * alpha);
380 d[db] =
FAST_DIV255(d[db] * (255 - alpha) + s[sb] * alpha);
382 if (main_has_alpha) {
402 if (main_has_alpha) {
410 for (imax =
FFMIN(-y + dst_h, src_h); i < imax; i++) {
415 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
417 if (alpha != 0 && alpha != 255) {
438 for (i = 0; i < 3; i++) {
439 int hsub = i ? over->
hsub : 0;
440 int vsub = i ? over->
vsub : 0;
441 int src_wp =
FFALIGN(src_w, 1<<hsub) >> hsub;
442 int src_hp =
FFALIGN(src_h, 1<<vsub) >> vsub;
443 int dst_wp =
FFALIGN(dst_w, 1<<hsub) >> hsub;
444 int dst_hp =
FFALIGN(dst_h, 1<<vsub) >> vsub;
454 for (jmax =
FFMIN(-yp + dst_hp, src_hp); j < jmax; j++) {
460 for (kmax =
FFMIN(-xp + dst_wp, src_wp); k < kmax; k++) {
461 int alpha_v, alpha_h,
alpha;
464 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
465 alpha = (a[0] + a[src->
linesize[3]] +
467 }
else if (hsub || vsub) {
468 alpha_h = hsub && k+1 < src_wp ?
469 (a[0] + a[1]) >> 1 : a[0];
470 alpha_v = vsub && j+1 < src_hp ?
471 (a[0] + a[src->
linesize[3]]) >> 1 : a[0];
472 alpha = (alpha_v + alpha_h) >> 1;
477 if (main_has_alpha && alpha != 0 && alpha != 255) {
480 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
481 alpha_d = (d[0] + d[src->
linesize[3]] +
483 }
else if (hsub || vsub) {
484 alpha_h = hsub && k+1 < src_wp ?
485 (d[0] + d[1]) >> 1 : d[0];
486 alpha_v = vsub && j+1 < src_hp ?
487 (d[0] + d[src->
linesize[3]]) >> 1 : d[0];
488 alpha_d = (alpha_v + alpha_h) >> 1;
500 ap += (1 << vsub) * src->
linesize[3];
534 av_dlog(ctx,
"main_pts:%s main_pts_time:%s",
537 av_dlog(ctx,
" over_pts:%s over_pts_time:%s",
568 return ret ==
AVERROR(EAGAIN) ? 0 : ret;
602 return ret ==
AVERROR(EAGAIN) ? 0 : ret;
676 .
inputs = avfilter_vf_overlay_inputs,
677 .
outputs = avfilter_vf_overlay_outputs,
678 .priv_class = &overlay_class,