92 int overlay_pix_step[4];
98 #define OFFSET(x) offsetof(OverlayContext, x)
99 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
113 static const char *shorthand[] = {
"x",
"y",
NULL };
115 over->
class = &overlay_class;
227 "main w:%d h:%d fmt:%s overlay x:%d y:%d w:%d h:%d fmt:%s\n",
234 if (over->
x < 0 || over->
y < 0 ||
238 "Overlay area (%d,%d)<->(%d,%d) not within the main area (0,0)<->(%d,%d) or zero-sized\n",
242 (
int)var_values[
VAR_MAIN_W], (
int)var_values[VAR_MAIN_H]);
249 "Error when evaluating the expression '%s'\n", expr);
266 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
272 #define UNPREMULTIPLY_ALPHA(x, y) ((((x) << 16) - ((x) << 9) + (x)) / ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)))
305 for (i = 0; i <
height; i++) {
307 for (j = 0; j <
width; j++) {
312 if (main_has_alpha && alpha != 0 && alpha != 255) {
328 d[dr] =
FAST_DIV255(d[dr] * (255 - alpha) + s[sr] * alpha);
329 d[dg] =
FAST_DIV255(d[dg] * (255 - alpha) + s[sg] * alpha);
330 d[db] =
FAST_DIV255(d[db] * (255 - alpha) + s[sb] * alpha);
332 if (main_has_alpha) {
352 if (main_has_alpha) {
357 for (i = 0; i <
height; i++) {
359 for (j = 0; j <
width; j++) {
361 if (alpha != 0 && alpha != 255) {
382 for (i = 0; i < 3; i++) {
383 int hsub = i ? over->
hsub : 0;
384 int vsub = i ? over->
vsub : 0;
389 int wp =
FFALIGN(width, 1<<hsub) >> hsub;
390 int hp =
FFALIGN(height, 1<<vsub) >> vsub;
391 for (j = 0; j < hp; j++) {
393 for (k = 0; k < wp; k++) {
395 int alpha_v, alpha_h, alpha;
396 if (hsub && vsub && j+1 < hp && k+1 < wp) {
397 alpha = (a[0] + a[src->
linesize[3]] +
399 }
else if (hsub || vsub) {
400 alpha_h = hsub && k+1 < wp ?
401 (a[0] + a[1]) >> 1 : a[0];
402 alpha_v = vsub && j+1 < hp ?
403 (a[0] + a[src->
linesize[3]]) >> 1 : a[0];
404 alpha = (alpha_v + alpha_h) >> 1;
409 if (main_has_alpha && alpha != 0 && alpha != 255) {
412 if (hsub && vsub && j+1 < hp && k+1 < wp) {
413 alpha_d = (d[0] + d[src->
linesize[3]] +
415 }
else if (hsub || vsub) {
416 alpha_h = hsub && k+1 < wp ?
417 (d[0] + d[1]) >> 1 : d[0];
418 alpha_v = vsub && j+1 < hp ?
419 (d[0] + d[src->
linesize[3]]) >> 1 : d[0];
420 alpha_d = (alpha_v + alpha_h) >> 1;
432 ap += (1 << vsub) * src->
linesize[3];
466 av_dlog(ctx,
"main_pts:%s main_pts_time:%s",
469 av_dlog(ctx,
" over_pts:%s over_pts_time:%s",
499 return ret ==
AVERROR(EAGAIN) ? 0 : ret;
533 return ret ==
AVERROR(EAGAIN) ? 0 : ret;
605 .
inputs = avfilter_vf_overlay_inputs,
606 .
outputs = avfilter_vf_overlay_outputs,
607 .priv_class = &overlay_class,