From patchwork Thu Nov 28 01:34:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 16464 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 C0CC9449E0E for ; Thu, 28 Nov 2019 03:34:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AC1C168B19E; Thu, 28 Nov 2019 03:34:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 06BCB68AD24 for ; Thu, 28 Nov 2019 03:34:31 +0200 (EET) Received: by mail-pf1-f195.google.com with SMTP id b19so12258052pfd.3 for ; Wed, 27 Nov 2019 17:34:30 -0800 (PST) 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=4JkIodsPf/osoDHhsdSACLaZ9xxd2w4+N4TCXPgkH/k=; b=q6eJMLleomExVI7SVp/x+F+mAUZI0dYzsrKDT8cGwI+iAVeYIzcNN02IeA4khGdR4q EuQG9lNLqmc4/wEIxROJ5nxpllW1wIZ8VXxf69X0u9m6Vl8LFPCLacL1LAzlKmI5/s0m KFEGVsauOsSdc3OOHTdP1/1xQmQzMbtfdObdtoVBGL6ZcbLZMcQNsO1OoODqYJLFBweT mD24JZ/7Q54SYlYtuCkjO3yLm8urk5U7+64FhKkBuMCLuGisFtPUYvP5J1Hxt/0lzXWp TntuoQDgL4dw5jbm5Guxc0uY7iO0OJ1RLSc+QHDx2CJdwmICRw21Hxq8Un/EZsf6WOHg x3Vw== 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=4JkIodsPf/osoDHhsdSACLaZ9xxd2w4+N4TCXPgkH/k=; b=DPvM+fqn94wjvg/phovYTXKcJYJDMcZ3QOT/sqfSW7kUJHUCGzrDt8Y+7sL5n1s/Fo 2UXxn05duTIPEY8Bqwswv4h2U2cwAN7BI9nE8FzxH+e5T4lvf5RjbDMec4mE2t02Y0fI BkyvXqM94P2I5solaAKNsUDMYw4nFtXr+CwvxgpDoFIwKbyHjnDNvfFpcLT4Ey9MkJM0 GOR5IGv1btwAg9LvGqkZkTslrNieOBJdxN0sk3veg3guvjNp+8orCuLW2Ov8kmKnaJRS HbZ53GjjJ2urSMEDHj6H7541noOjXc1G1I5QpWt8tMO3zut8QacpYxrgOr5mWnANF+KZ 8lLQ== X-Gm-Message-State: APjAAAWOhG4FEPQ4t4uDehu5UHW2Y8WEg2yiFHtCq/5HWNjzMoGRbEkE 09h6+8VxAFD2MShyuk1NhIm3jigl X-Google-Smtp-Source: APXvYqyp8YrQPqpuazJErBIvnlX33lV3prxZWXQ6hc7TOWyZq4m0ifu+Fgns9dk+MqvBoVf6ynrf2A== X-Received: by 2002:a63:2783:: with SMTP id n125mr8381669pgn.431.1574904868763; Wed, 27 Nov 2019 17:34:28 -0800 (PST) Received: from vpn.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id d139sm19577360pfd.162.2019.11.27.17.34.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2019 17:34:28 -0800 (PST) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Nov 2019 09:34:18 +0800 Message-Id: <20191128013418.10908-3-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20191128013418.10908-1-lance.lmwang@gmail.com> References: <20191128013418.10908-1-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v1 3/3] avfilter/vf_yadif: 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/vf_yadif.c | 147 +++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 93 deletions(-) diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index f53bb77008..15d8c47b0b 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -91,101 +91,62 @@ typedef struct ThreadData { next2++; \ } -static void filter_line_c(void *dst1, - void *prev1, void *cur1, void *next1, - int w, int prefs, int mrefs, int parity, int mode) -{ - uint8_t *dst = dst1; - uint8_t *prev = prev1; - uint8_t *cur = cur1; - uint8_t *next = next1; - int x; - uint8_t *prev2 = parity ? prev : cur ; - uint8_t *next2 = parity ? cur : next; - - /* The function is called with the pointers already pointing to data[3] and - * with 6 subtracted from the width. This allows the FILTER macro to be - * called so that it processes all the pixels normally. A constant value of - * true for is_not_edge lets the compiler ignore the if statement. */ - FILTER(0, w, 1) +#define FILTER_LINE_FUNC(type, depth, bps) \ +static void filter_line_c_##depth##bit(void *dst1, \ + void *prev1, void *cur1, void *next1, \ + int w, int prefs, int mrefs, int parity, int mode) \ +{ \ + type *dst = dst1; \ + type *prev = prev1; \ + type *cur = cur1; \ + type *next = next1; \ + int x; \ + type *prev2 = parity ? prev : cur ; \ + type *next2 = parity ? cur : next; \ + mrefs /= bps; \ + prefs /= bps; \ + \ + /* The function is called with the pointers already pointing to data[3] and */ \ + /* with 6 subtracted from the width. This allows the FILTER macro to be */ \ + /* called so that it processes all the pixels normally. A constant value of */ \ + /* true for is_not_edge lets the compiler ignore the if statement. */ \ + FILTER(0, w, 1) \ } +FILTER_LINE_FUNC(uint16_t, 16, 2); +FILTER_LINE_FUNC(uint8_t, 8, 1); #define MAX_ALIGN 8 -static void filter_edges(void *dst1, void *prev1, void *cur1, void *next1, - int w, int prefs, int mrefs, int parity, int mode) -{ - uint8_t *dst = dst1; - uint8_t *prev = prev1; - uint8_t *cur = cur1; - uint8_t *next = next1; - int x; - uint8_t *prev2 = parity ? prev : cur ; - uint8_t *next2 = parity ? cur : next; - - const int edge = MAX_ALIGN - 1; - - /* Only edge pixels need to be processed here. A constant value of false - * for is_not_edge should let the compiler ignore the whole branch. */ - FILTER(0, 3, 0) - - dst = (uint8_t*)dst1 + w - edge; - prev = (uint8_t*)prev1 + w - edge; - cur = (uint8_t*)cur1 + w - edge; - next = (uint8_t*)next1 + w - edge; - prev2 = (uint8_t*)(parity ? prev : cur); - next2 = (uint8_t*)(parity ? cur : next); - - FILTER(w - edge, w - 3, 1) - FILTER(w - 3, w, 0) -} - - -static void filter_line_c_16bit(void *dst1, - void *prev1, void *cur1, void *next1, - int w, int prefs, int mrefs, int parity, - int mode) -{ - uint16_t *dst = dst1; - uint16_t *prev = prev1; - uint16_t *cur = cur1; - uint16_t *next = next1; - int x; - uint16_t *prev2 = parity ? prev : cur ; - uint16_t *next2 = parity ? cur : next; - mrefs /= 2; - prefs /= 2; - - FILTER(0, w, 1) -} - -static void filter_edges_16bit(void *dst1, void *prev1, void *cur1, void *next1, - int w, int prefs, int mrefs, int parity, int mode) -{ - uint16_t *dst = dst1; - uint16_t *prev = prev1; - uint16_t *cur = cur1; - uint16_t *next = next1; - int x; - uint16_t *prev2 = parity ? prev : cur ; - uint16_t *next2 = parity ? cur : next; - - const int edge = MAX_ALIGN / 2 - 1; - - mrefs /= 2; - prefs /= 2; - - FILTER(0, 3, 0) - - dst = (uint16_t*)dst1 + w - edge; - prev = (uint16_t*)prev1 + w - edge; - cur = (uint16_t*)cur1 + w - edge; - next = (uint16_t*)next1 + w - edge; - prev2 = (uint16_t*)(parity ? prev : cur); - next2 = (uint16_t*)(parity ? cur : next); - - FILTER(w - edge, w - 3, 1) - FILTER(w - 3, w, 0) +#define EDGES_FUNC(type, depth, bps) \ +static void filter_edges_##depth##bit(void *dst1, void *prev1, void *cur1, \ + void *next1, int w, int prefs, int mrefs, int parity, int mode) \ +{ \ + type *dst = dst1; \ + type *prev = prev1; \ + type *cur = cur1; \ + type *next = next1; \ + int x; \ + type *prev2 = parity ? prev : cur ; \ + type *next2 = parity ? cur : next; \ + \ + const int edge = MAX_ALIGN / bps - 1; \ + \ + mrefs /= bps; \ + prefs /= bps; \ + \ + FILTER(0, 3, 0) \ + \ + dst = (type*)dst1 + w - edge; \ + prev = (type*)prev1 + w - edge; \ + cur = (type*)cur1 + w - edge; \ + next = (type*)next1 + w - edge; \ + prev2 = (type*)(parity ? prev : cur); \ + next2 = (type*)(parity ? cur : next); \ + \ + FILTER(w - edge, w - 3, 1) \ + FILTER(w - 3, w, 0) \ } +EDGES_FUNC(uint16_t, 16, 2); +EDGES_FUNC(uint8_t, 8, 1); static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { @@ -313,8 +274,8 @@ static int config_output(AVFilterLink *outlink) s->filter_line = filter_line_c_16bit; s->filter_edges = filter_edges_16bit; } else { - s->filter_line = filter_line_c; - s->filter_edges = filter_edges; + s->filter_line = filter_line_c_8bit; + s->filter_edges = filter_edges_8bit; } if (ARCH_X86)