From patchwork Mon Jan 30 15:04:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 2371 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp1495671vsb; Mon, 30 Jan 2017 07:05:49 -0800 (PST) X-Received: by 10.223.131.34 with SMTP id 31mr23186200wrd.119.1485788749633; Mon, 30 Jan 2017 07:05:49 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i201si13740280wmf.9.2017.01.30.07.05.48; Mon, 30 Jan 2017 07:05:49 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F123868A520; Mon, 30 Jan 2017 17:05:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B5B9468A4D5 for ; Mon, 30 Jan 2017 17:05:37 +0200 (EET) Received: by mail-wm0-f65.google.com with SMTP id v77so16672578wmv.0 for ; Mon, 30 Jan 2017 07:05:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=I44VbJ4IoGwhbQofumHtMXduBue2DZMFJO3Uy51aoB8=; b=TjpXsadsKolja4zIGasugY5wwWrpbye3RMWQauJBKg3IpPFP8ohb0zQPmoR0DtK/WD /fPVOyfBVjCPHD47sbEasyCNkR6zApDenWUY+Z9VJfxludNdeLWYIa72aVS2oybYPTpl amXAwU96TRA9rAabiUZxwujEGm43QosO93HiblOv2Ie+FDUQGJgsOQ4TggqsudN2eWWO 1F9ya39VpmM/MqRz/AiIP66ZdCD1PKz1nTw8w35NatQNvwoS8XKFlrBteGJxjxyPnUE/ tu4u2+n52HGIQ3HUNj/yZ2lRo9/PdjafxwuVM8ZtlkcW1Fair9l4LxT1t6js13JAdqMN n9YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=I44VbJ4IoGwhbQofumHtMXduBue2DZMFJO3Uy51aoB8=; b=YBk860GDOAUrrRor2eLzkBQUwEEDMbTI7pwbz+1k10W4b2lSw0OKIfQA9rmo4Q0JPD uPj9xt/m/cXX6GXQ7td/CSz8QV0+ELas4bzmunvKLlkW1eMfcyZh8UpdRZidG7OAGuni nb/rwJ1xYe2ZfMMw+NbZ7C1gJORGjqNHO7kNtHuJIlXeKvxdcqdr5PQWzNgFbunFh0ar uqS0URMuSdWzFHobyAx+kUN48GknSVp4bCIbYRH/vP+6AnwvUCwVjN5X85n/iVPrF9us FMXiER7wRoENnRws0SZiqd3E9/97Xj5r/cjI9t8HCU2F/whIrgjl6bAjdltFbSiUiVuI 5nWA== X-Gm-Message-State: AIkVDXJVd9e770Zw5F9jr3ASaSOFrVJqiYuENlUMJKxP+elmj5uy4JhgY4mlS6A7r9pIGg== X-Received: by 10.28.207.7 with SMTP id f7mr14900630wmg.112.1485788739305; Mon, 30 Jan 2017 07:05:39 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id l67sm19129235wmf.1.2017.01.30.07.05.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 07:05:38 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Jan 2017 16:04:59 +0100 Message-Id: <20170130150459.20430-1-onemda@gmail.com> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH] avfilter/overlay: add gbrp output format X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- doc/filters.texi | 5 +++- libavfilter/vf_overlay.c | 71 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 21a5bf5..14cd026 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10201,7 +10201,10 @@ force YUV422 output force YUV444 output @item rgb -force RGB output +force packed RGB output + +@item gbrp +force planar RGB output @end table Default value is @samp{yuv420}. diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c index 108a6fc..bbcd6b5 100644 --- a/libavfilter/vf_overlay.c +++ b/libavfilter/vf_overlay.c @@ -103,6 +103,7 @@ enum OverlayFormat { OVERLAY_FORMAT_YUV422, OVERLAY_FORMAT_YUV444, OVERLAY_FORMAT_RGB, + OVERLAY_FORMAT_GBRP, OVERLAY_FORMAT_NB }; @@ -238,6 +239,13 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE }; + static const enum AVPixelFormat main_pix_fmts_gbrp[] = { + AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE + }; + static const enum AVPixelFormat overlay_pix_fmts_gbrp[] = { + AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE + }; + static const enum AVPixelFormat main_pix_fmts_rgb[] = { AV_PIX_FMT_ARGB, AV_PIX_FMT_RGBA, AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA, @@ -283,6 +291,13 @@ static int query_formats(AVFilterContext *ctx) goto fail; } break; + case OVERLAY_FORMAT_GBRP: + if (!(main_formats = ff_make_format_list(main_pix_fmts_gbrp)) || + !(overlay_formats = ff_make_format_list(overlay_pix_fmts_gbrp))) { + ret = AVERROR(ENOMEM); + goto fail; + } + break; default: av_assert0(0); } @@ -306,7 +321,7 @@ fail: static const enum AVPixelFormat alpha_pix_fmts[] = { AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_RGBA, - AV_PIX_FMT_BGRA, AV_PIX_FMT_NONE + AV_PIX_FMT_BGRA, AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE }; static int config_input_overlay(AVFilterLink *inlink) @@ -471,9 +486,11 @@ static av_always_inline void blend_plane(AVFilterContext *ctx, int dst_w, int dst_h, int i, int hsub, int vsub, int x, int y, - int main_has_alpha) + int main_has_alpha, + int dst_plane, + int dst_offset, + int dst_step) { - OverlayContext *ol = ctx->priv; int src_wp = AV_CEIL_RSHIFT(src_w, hsub); int src_hp = AV_CEIL_RSHIFT(src_h, vsub); int dst_wp = AV_CEIL_RSHIFT(dst_w, hsub); @@ -483,10 +500,6 @@ static av_always_inline void blend_plane(AVFilterContext *ctx, uint8_t *s, *sp, *d, *dp, *a, *ap; int jmax, j, k, kmax; - int dst_plane = ol->main_desc->comp[i].plane; - int dst_offset = ol->main_desc->comp[i].offset; - int dst_step = ol->main_desc->comp[i].step; - j = FFMAX(-yp, 0); sp = src->data[i] + j * src->linesize[i]; dp = dst->data[dst_plane] @@ -592,6 +605,7 @@ static av_always_inline void blend_image_yuv(AVFilterContext *ctx, int main_has_alpha, int x, int y) { + OverlayContext *s = ctx->priv; const int src_w = src->width; const int src_h = src->height; const int dst_w = dst->width; @@ -600,9 +614,35 @@ static av_always_inline void blend_image_yuv(AVFilterContext *ctx, 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); + blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 0, 0, 0, x, y, main_has_alpha, + s->main_desc->comp[0].plane, s->main_desc->comp[0].offset, s->main_desc->comp[0].step); + blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 1, hsub, vsub, x, y, main_has_alpha, + s->main_desc->comp[1].plane, s->main_desc->comp[1].offset, s->main_desc->comp[1].step); + blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 2, hsub, vsub, x, y, main_has_alpha, + s->main_desc->comp[2].plane, s->main_desc->comp[2].offset, s->main_desc->comp[2].step); +} + +static av_always_inline void blend_image_rgb(AVFilterContext *ctx, + AVFrame *dst, const AVFrame *src, + int hsub, int vsub, + int main_has_alpha, + int x, int y) +{ + OverlayContext *s = ctx->priv; + 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, + s->main_desc->comp[1].plane, s->main_desc->comp[1].offset, s->main_desc->comp[1].step); + blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 1, hsub, vsub, x, y, main_has_alpha, + s->main_desc->comp[2].plane, s->main_desc->comp[2].offset, s->main_desc->comp[2].step); + blend_plane(ctx, dst, src, src_w, src_h, dst_w, dst_h, 2, hsub, vsub, x, y, main_has_alpha, + s->main_desc->comp[0].plane, s->main_desc->comp[0].offset, s->main_desc->comp[0].step); } static void blend_image_yuv420(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int x, int y) @@ -626,6 +666,13 @@ static void blend_image_yuv444(AVFilterContext *ctx, AVFrame *dst, const AVFrame blend_image_yuv(ctx, dst, src, 0, 0, s->main_has_alpha, x, y); } +static void blend_image_gbrp(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int x, int y) +{ + OverlayContext *s = ctx->priv; + + blend_image_rgb(ctx, dst, src, 0, 0, s->main_has_alpha, x, y); +} + static int config_input_main(AVFilterLink *inlink) { OverlayContext *s = inlink->dst->priv; @@ -654,6 +701,9 @@ static int config_input_main(AVFilterLink *inlink) case OVERLAY_FORMAT_RGB: s->blend_image = blend_image_packed_rgb; break; + case OVERLAY_FORMAT_GBRP: + s->blend_image = blend_image_gbrp; + break; } return 0; } @@ -747,6 +797,7 @@ static const AVOption overlay_options[] = { { "yuv422", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV422}, .flags = FLAGS, .unit = "format" }, { "yuv444", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV444}, .flags = FLAGS, .unit = "format" }, { "rgb", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_RGB}, .flags = FLAGS, .unit = "format" }, + { "gbrp", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_GBRP}, .flags = FLAGS, .unit = "format" }, { "repeatlast", "repeat overlay of the last overlay frame", OFFSET(dinput.repeatlast), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS }, { NULL } };