From patchwork Wed Oct 26 02:58:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 1176 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp262406vsd; Tue, 25 Oct 2016 20:11:49 -0700 (PDT) X-Received: by 10.28.12.77 with SMTP id 74mr923136wmm.115.1477451508925; Tue, 25 Oct 2016 20:11:48 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o7si26377680wjy.107.2016.10.25.20.11.48; Tue, 25 Oct 2016 20:11:48 -0700 (PDT) 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 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 D6E1B689DED; Wed, 26 Oct 2016 06:11:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f66.google.com (mail-it0-f66.google.com [209.85.214.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AA64689D8C for ; Wed, 26 Oct 2016 06:11:37 +0300 (EEST) Received: by mail-it0-f66.google.com with SMTP id k64so190125itb.1 for ; Tue, 25 Oct 2016 20:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=QHWmkf5vTALJs0YF0B9YWzVBol678xQPCJR7ujD7rpY=; b=Lbac7I2gBT/Tq9LowPqcHvQC4rpfrudcG/KM/AZKVhsLWftTk+lntQSKwANyiV+yqr nJWBoTwhPQ+E0rWb1dTekRg1y64B9MKq1wkho1QQ7okvpuAkzxi0s3P7mcLyuqBcPpSt aL2sXZSF2CZbXE0twLT3E8V46uuFamBuBXn3OhcjzDCw3yYXi3Q0f/NWlAyQ31+ddzIX luHv57yC+JR7F3p91JBnX/NER5Tb07XqPTlXNflYtTQecWlA5yWoeDrDU2ZjCg6ElVN5 dQMROW/XAup5GDx9ooj3xlS83zK/MzogjP9+XO2Qp4EuyOYq9erhOV1lRl9EgOogKttc CpVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=QHWmkf5vTALJs0YF0B9YWzVBol678xQPCJR7ujD7rpY=; b=HCQEtnzOfJoI2IkyhaOiWu7H/ZcpByFZDUTKYVAb5+zcco5a2exQWtJHEECqq8UYxe BADfwMOGkRH6Rc6ep6XZhUSOLn8qQvURikaXxQb2sdGdQcwcByHrXcY3zCJtiG9mYrWE Divo8YTrtzGlf8udpbRNOdonmg+TKCE6aFDsmihp3wv7Cd1Nhq9fhK3yxP475ZSWJnO6 7DcAbHCvAqwQ5Jf3slPGMZWkkqWzq9slnO+dWVfsGZxQj8Z7WuNWhbn2G7QyyVmEr1q7 iZiMSl7kfzZwAdUaolSI2WKVSOFtkSU6J7DtHOj9VmtQiKKn02BR82cMSHV6Ik0ci3lj ecOA== X-Gm-Message-State: ABUngvedzZ4aheBzrkZ1FVBciuy7rGcvF/gX2SBLFTfJABN7Bm+Gjeahuh2Mxdajo96IRA== X-Received: by 10.107.40.205 with SMTP id o196mr279834ioo.137.1477450727317; Tue, 25 Oct 2016 19:58:47 -0700 (PDT) Received: from Rodgers-MacBook-Pro.local.net (c-73-209-137-129.hsd1.il.comcast.net. [73.209.137.129]) by smtp.gmail.com with ESMTPSA id x5sm2460136itd.18.2016.10.25.19.58.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 25 Oct 2016 19:58:46 -0700 (PDT) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Tue, 25 Oct 2016 21:58:43 -0500 Message-Id: <20161026025843.13135-1-rodger.combs@gmail.com> X-Mailer: git-send-email 2.10.0 Subject: [FFmpeg-devel] [PATCH] lavfi/vf_overlay: support NV12 and NV21 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" --- libavfilter/vf_overlay.c | 22 +++++++++++++++++----- tests/fate/filter-video.mak | 10 ++++++++++ tests/filtergraphs/overlay_nv12 | 5 +++++ tests/filtergraphs/overlay_nv21 | 5 +++++ 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 tests/filtergraphs/overlay_nv12 create mode 100644 tests/filtergraphs/overlay_nv21 Tested-by: Michael on x86-32/64 linux, mingw, mips/arm qemu linux diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c index c592dca..b249ad7 100644 --- a/libavfilter/vf_overlay.c +++ b/libavfilter/vf_overlay.c @@ -125,6 +125,7 @@ typedef struct OverlayContext { int main_pix_step[4]; ///< steps per pixel for each plane of the main output int overlay_pix_step[4]; ///< steps per pixel for each plane of the overlay int hsub, vsub; ///< chroma subsampling values + const AVPixFmtDescriptor *main_desc; ///< format descriptor for main input double var_values[VAR_VARS_NB]; char *x_expr, *y_expr; @@ -215,7 +216,9 @@ static int query_formats(AVFilterContext *ctx) /* overlay formats contains alpha, for avoiding conversion with alpha information loss */ static const enum AVPixelFormat main_pix_fmts_yuv420[] = { - AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE + AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVA420P, + AV_PIX_FMT_NV12, AV_PIX_FMT_NV21, + AV_PIX_FMT_NONE }; static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = { AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE @@ -470,6 +473,7 @@ static av_always_inline void blend_plane(AVFilterContext *ctx, int x, int y, int main_has_alpha) { + 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); @@ -479,14 +483,20 @@ 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[i] + (yp+j) * dst->linesize[i]; + dp = dst->data[dst_plane] + + (yp+j) * dst->linesize[dst_plane] + + dst_offset; ap = src->data[3] + (j<linesize[3]; for (jmax = FFMIN(-yp + dst_hp, src_hp); j < jmax; j++) { k = FFMAX(-xp, 0); - d = dp + xp+k; + d = dp + (xp+k) * dst_step; s = sp + k; a = ap + (k<linesize[i]; + dp += dst->linesize[dst_plane]; sp += src->linesize[i]; ap += (1 << vsub) * src->linesize[3]; } @@ -626,6 +636,8 @@ static int config_input_main(AVFilterLink *inlink) s->hsub = pix_desc->log2_chroma_w; s->vsub = pix_desc->log2_chroma_h; + s->main_desc = pix_desc; + 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); diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index e2513f5..ec22d25 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -172,6 +172,16 @@ FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER OVERLAY_F fate-filter-overlay_yuv420: tests/data/filtergraphs/overlay_yuv420 fate-filter-overlay_yuv420: CMD = framecrc -c:v pgmyuv -i $(SRC) -filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_yuv420 +FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER OVERLAY_FILTER) += fate-filter-overlay_nv12 +fate-filter-overlay_nv12: tests/data/filtergraphs/overlay_nv12 +fate-filter-overlay_nv12: CMD = framecrc -c:v pgmyuv -i $(SRC) -filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_nv12 +fate-filter-overlay_nv12: REF = $(SRC_PATH)/tests/ref/fate/filter-overlay_yuv420 + +FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER OVERLAY_FILTER) += fate-filter-overlay_nv21 +fate-filter-overlay_nv21: tests/data/filtergraphs/overlay_nv21 +fate-filter-overlay_nv21: CMD = framecrc -c:v pgmyuv -i $(SRC) -filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_nv21 +fate-filter-overlay_nv21: REF = $(SRC_PATH)/tests/ref/fate/filter-overlay_yuv420 + FATE_FILTER_VSYNTH-$(call ALLYES, SPLIT_FILTER SCALE_FILTER PAD_FILTER OVERLAY_FILTER) += fate-filter-overlay_yuv422 fate-filter-overlay_yuv422: tests/data/filtergraphs/overlay_yuv422 fate-filter-overlay_yuv422: CMD = framecrc -c:v pgmyuv -i $(SRC) -filter_complex_script $(TARGET_PATH)/tests/data/filtergraphs/overlay_yuv422 diff --git a/tests/filtergraphs/overlay_nv12 b/tests/filtergraphs/overlay_nv12 new file mode 100644 index 0000000..ec82cbe --- /dev/null +++ b/tests/filtergraphs/overlay_nv12 @@ -0,0 +1,5 @@ +sws_flags=+accurate_rnd+bitexact; +split [main][over]; +[over] scale=88:72, pad=96:80:4:4 [overf]; +[main] format=nv12 [mainf]; +[mainf][overf] overlay=240:16:format=yuv420, format=yuv420p diff --git a/tests/filtergraphs/overlay_nv21 b/tests/filtergraphs/overlay_nv21 new file mode 100644 index 0000000..9c30d07 --- /dev/null +++ b/tests/filtergraphs/overlay_nv21 @@ -0,0 +1,5 @@ +sws_flags=+accurate_rnd+bitexact; +split [main][over]; +[over] scale=88:72, pad=96:80:4:4 [overf]; +[main] format=nv21 [mainf]; +[mainf][overf] overlay=240:16:format=yuv420, format=yuv420p