From patchwork Sat Sep 21 14:49:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 15208 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 E6BFB448C32 for ; Sat, 21 Sep 2019 17:49:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D254868A846; Sat, 21 Sep 2019 17:49:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6604568A87F for ; Sat, 21 Sep 2019 17:49:44 +0300 (EEST) Received: by mail-pl1-f196.google.com with SMTP id d22so3237520pls.0 for ; Sat, 21 Sep 2019 07:49:44 -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=eZWVqfr/rvGTLlEK9SpHTxjGIJ3JG7ekMswgQ5hHFPQ=; b=gD4TDBzdSfWo9r1seJVRyTr93PGsaKim5FPTEyMKq8peNJa/UTgH0n3L2zpIRoKFmS OTpZ6HFmXiIj/JkjUNiIJO/F484IHfgx/OSyhKHyup7mjERvBJU3h0fgQ4xny0x5Ge78 gYTLwmEtVu9WXFlEwm3Xut9S9X7SS91JvAzqcnu8PPfZ38uPcfILuF5ocNI9+fa8IfhA YFA8WLDFuu3dbz8xrRlvW3sRVUr84Wn6u4Z11oLAl9YVGU8JPO9UBle5Zn19e0kJqqWz 4tLRTYzMnzed1yERITUkFM9977QDL4FtKp+U9ItvOPD26AGxQvIwGVDZOCxdB0BAQKP+ MqEA== 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=eZWVqfr/rvGTLlEK9SpHTxjGIJ3JG7ekMswgQ5hHFPQ=; b=KbiUDgHyC8vALwZeGaHzTWA8YOsNBIkSH8Oliiv0Mw3gheokkdQTRY4VlqgAYDwyqc NJ3XR/l1KgBAU99H5h0HHBO+yRTUH83rUNQKsdbC3TxcNArKpALy4yLwzgYJkoSQd5/K IkIHSFwyu1pLSNpdjUnkSt5O2dIhXSyeMm7O30MQe9QLe6tyHpKUwMuAKSdk3H8EogoQ tiBz5PkWCUAgEGJuMSYY3m1OTAp/cpd+0ecjmgEfbCigZmmxN6Ocet0getFm2HiCtp50 ui6bdXFsvBpS+n88unQCtWT2JWDfWDV/qM9aXxgk4j9uc+9fNk+PQsHdIF3Cy/8jJ6A6 +bjQ== X-Gm-Message-State: APjAAAW5SY0RRPGaVoJ09zp8Ye4+hZ2BzxJPDqrWlyskqlRICeZCa6TW tSLCdqpQGmggHI43zxDxJM25GFxW X-Google-Smtp-Source: APXvYqzKUy50CRf9qbxpWNJffpPkdqHVP6DQDF/6V0BCoh1YEAHGhQlYHwFq8aMXv7uUbkROoz+FAA== X-Received: by 2002:a17:902:67:: with SMTP id 94mr23132576pla.121.1569077382668; Sat, 21 Sep 2019 07:49:42 -0700 (PDT) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id u31sm18682829pgn.93.2019.09.21.07.49.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Sep 2019 07:49:42 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sat, 21 Sep 2019 22:49:31 +0800 Message-Id: <20190921144932.32241-3-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20190921144932.32241-1-lance.lmwang@gmail.com> References: <20190921144932.32241-1-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v1 3/4] 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 3d8200b..887f173 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 1254da8..6383f69 100644 --- a/libavfilter/vf_framerate.c +++ b/libavfilter/vf_framerate.c @@ -236,44 +236,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)