+ da += dst->linesize[3];
+ sa += src->linesize[3];
+ }
+}
+
+static av_always_inline void blend_image_yuv(AVFilterContext *ctx,
+ AVFrame *dst, const AVFrame *src,
+ int hsub, int vsub,
+ int main_has_alpha,
+ int x, int y)
+{
+ const int src_w = src->width;
+ const int src_h = src->height;
+ const int dst_w = dst->width;
+ const int dst_h = dst->height;
+
+ if (main_has_alpha)
+ alpha_composite(src, dst, src_w, src_h, dst_w, dst_h, x, y);
+
+ blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 0, 0, 0, x, y, main_has_alpha);
+ blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 1, hsub, vsub, x, y, main_has_alpha);
+ blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 2, hsub, vsub, x, y, main_has_alpha);
+}
+
+static void blend_image_yuv420(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int x, int y)
+{
+ OverlayContext *s = ctx->priv;
+
+ blend_image_yuv(ctx, dst, src, 1, 1, s->main_has_alpha, x, y);
+}
+
+static void blend_image_yuv422(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int x, int y)
+{
+ OverlayContext *s = ctx->priv;
+
+ blend_image_yuv(ctx, dst, src, 1, 0, s->main_has_alpha, x, y);
+}
+
+static void blend_image_yuv444(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int x, int y)
+{
+ OverlayContext *s = ctx->priv;
+
+ blend_image_yuv(ctx, dst, src, 0, 0, s->main_has_alpha, x, y);
+}
+
+static int config_input_main(AVFilterLink *inlink)
+{
+ OverlayContext *s = inlink->dst->priv;
+ const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
+
+ av_image_fill_max_pixsteps(s->main_pix_step, NULL, pix_desc);
+
+ s->hsub = pix_desc->log2_chroma_w;
+ s->vsub = pix_desc->log2_chroma_h;
+
+ s->main_is_packed_rgb =
+ ff_fill_rgba_map(s->main_rgba_map, inlink->format) >= 0;
+ s->main_has_alpha = ff_fmt_is_in(inlink->format, alpha_pix_fmts);
+ switch (s->format) {
+ case OVERLAY_FORMAT_YUV420:
+ s->blend_image = blend_image_yuv420;
+ break;
+ case OVERLAY_FORMAT_YUV422:
+ s->blend_image = blend_image_yuv422;
+ break;
+ case OVERLAY_FORMAT_YUV444:
+ s->blend_image = blend_image_yuv444;
+ break;
+ case OVERLAY_FORMAT_RGB:
+ s->blend_image = blend_image_packed_rgb;
+ break;