From patchwork Tue Sep 24 10:18:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 15249 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C94E644921B for ; Tue, 24 Sep 2019 13:18:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AC1AE68994B; Tue, 24 Sep 2019 13:18:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D2DA68836F for ; Tue, 24 Sep 2019 13:18:23 +0300 (EEST) Received: by mail-pg1-f177.google.com with SMTP id c17so1065712pgg.4 for ; Tue, 24 Sep 2019 03:18:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ahi3VDZ6mgfWoSjEgYfqjcndYFA+EDcbSu8FTApXMOs=; b=mFDfSKZWOqnwuh7xiay/MGolyOipt3l3un9ArC7Q/0hFbq5ceaOsaehRJAzFwtXj4t h+KnO2WuWyi313i5kT9oIRB49KJlS/FV+a00z4BRQdJhx//8zQkLjzHLsNaqAcP+0cHl dTNXcMEkwJzngaA4Lop/aQE7DnakqhWRJ5tjEkeckmyrYbpjz6TaU67/1tuemjKbAGni 7ZkUh7tHgFmC9Rwc0f0tvzhYcD6GRMBMLHr2sq/pCAzsOCGcrIRik1xdj6XYgRyC2yn2 616wlZkRNgFhCw4YB8aStXwAHgNORIKx3PR6ITbH9Ik0aeqwNqAF5dCuSVrFmWX4x5fb j59A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ahi3VDZ6mgfWoSjEgYfqjcndYFA+EDcbSu8FTApXMOs=; b=TQAlOvu/577LlikC4w0TNp5ymw2xXQG5hLOF6IRvUIzfqhvCYDTVNHSltJOrxFg+jv FHRQ90XevVMOZaIJ1fxfw9jMz5rxH0L8e2XufI8dpbMNJQy0jpNtCzcwcNZvehhOcfIh qEDqtCMLzmgrSvXWMwOAgpw91sXlO6JgrjjN5EOo5G8ag1iiaBYSxNBt6bNV4YigvR8g bk4P2vsUzJ5GmDeY5TbOf1+vJ+XBr0a0W1fnN3H2CtH5hq86AnvB7+18VIHt5tv8H8oR KJON8yh6JjNrL1PBNaNFGitG6Twyo+5vkUF0mc5MI3CzUOc8FCtDjWrVUQOZDWynv71E sjew== X-Gm-Message-State: APjAAAWRy6/TsNRDsfQw57TUlbiZOLwykpERUTO3p0id0RHLTFUPrq2f voyuhkBTJjWD29VMTb2mSrmjJNJ+ X-Google-Smtp-Source: APXvYqxmsRmkbYXSm8w+inq1wCAehmtj8KpnHaPvpsTJmXhai/9i+xi7oNpcF3cOkNpx5nd4s8ejmw== X-Received: by 2002:a65:4844:: with SMTP id i4mr2367680pgs.113.1569320301254; Tue, 24 Sep 2019 03:18:21 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id r1sm1469324pgv.70.2019.09.24.03.18.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Sep 2019 03:18:20 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 24 Sep 2019 18:18:09 +0800 Message-Id: <20190924101809.13656-3-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20190924101809.13656-1-lance.lmwang@gmail.com> References: <20190921144932.32241-1-lance.lmwang@gmail.com> <20190924101809.13656-1-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 3/3] avfilter/vf_framerate: remove duplicate code with macro-based function 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 Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavfilter/framerate.h | 3 +- libavfilter/vf_framerate.c | 58 +++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/libavfilter/framerate.h b/libavfilter/framerate.h index 3d8200b2fe..887f173210 100644 --- a/libavfilter/framerate.h +++ b/libavfilter/framerate.h @@ -28,8 +28,7 @@ ptrdiff_t width, ptrdiff_t height, \ int factor1, int factor2, int half -#define BLEND_FACTOR_DEPTH8 7 -#define BLEND_FACTOR_DEPTH16 15 +#define BLEND_FACTOR_DEPTH(n) (n-1) typedef void (*blend_func)(BLEND_FUNC_PARAMS); diff --git a/libavfilter/vf_framerate.c b/libavfilter/vf_framerate.c index f16400e8ff..a3c1befd4a 100644 --- a/libavfilter/vf_framerate.c +++ b/libavfilter/vf_framerate.c @@ -233,44 +233,38 @@ static int query_formats(AVFilterContext *ctx) return ff_set_common_formats(ctx, fmts_list); } -static void blend_frames_c(BLEND_FUNC_PARAMS) -{ - int line, pixel; - for (line = 0; line < height; line++) { - for (pixel = 0; pixel < width; pixel++) - dst[pixel] = ((src1[pixel] * factor1) + (src2[pixel] * factor2) + half) >> BLEND_FACTOR_DEPTH8; - src1 += src1_linesize; - src2 += src2_linesize; - dst += dst_linesize; - } -} - -static void blend_frames16_c(BLEND_FUNC_PARAMS) -{ - int line, pixel; - uint16_t *dstw = (uint16_t *)dst; - uint16_t *src1w = (uint16_t *)src1; - uint16_t *src2w = (uint16_t *)src2; - width /= 2; - src1_linesize /= 2; - src2_linesize /= 2; - dst_linesize /= 2; - for (line = 0; line < height; line++) { - for (pixel = 0; pixel < width; pixel++) - dstw[pixel] = ((src1w[pixel] * factor1) + (src2w[pixel] * factor2) + half) >> BLEND_FACTOR_DEPTH16; - src1w += src1_linesize; - src2w += src2_linesize; - dstw += dst_linesize; - } +#define BLEND_FRAME_FUNC(nbits) \ +static void blend_frames##nbits##_c(BLEND_FUNC_PARAMS) \ +{ \ + int line, pixel; \ + uint##nbits##_t *dstw = (uint##nbits##_t *)dst; \ + uint##nbits##_t *src1w = (uint##nbits##_t *)src1; \ + uint##nbits##_t *src2w = (uint##nbits##_t *)src2; \ + int bytes = nbits / 8; \ + width /= bytes; \ + src1_linesize /= bytes; \ + src2_linesize /= bytes; \ + dst_linesize /= bytes; \ + for (line = 0; line < height; line++) { \ + for (pixel = 0; pixel < width; pixel++) \ + dstw[pixel] = ((src1w[pixel] * factor1) + \ + (src2w[pixel] * factor2) + half) \ + >> BLEND_FACTOR_DEPTH(nbits); \ + src1w += src1_linesize; \ + src2w += src2_linesize; \ + dstw += dst_linesize; \ + } \ } +BLEND_FRAME_FUNC(8) +BLEND_FRAME_FUNC(16) void ff_framerate_init(FrameRateContext *s) { if (s->bitdepth == 8) { - s->blend_factor_max = 1 << BLEND_FACTOR_DEPTH8; - s->blend = blend_frames_c; + s->blend_factor_max = 1 << BLEND_FACTOR_DEPTH(8); + s->blend = blend_frames8_c; } else { - s->blend_factor_max = 1 << BLEND_FACTOR_DEPTH16; + s->blend_factor_max = 1 << BLEND_FACTOR_DEPTH(16); s->blend = blend_frames16_c; } if (ARCH_X86)