From patchwork Mon May 7 17:24:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 8843 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp3103213jad; Mon, 7 May 2018 10:25:21 -0700 (PDT) X-Google-Smtp-Source: AB8JxZruFNBdtBgTY3R7PlXV1YXCIkSsr4fBwnEZ1InxqtzoCvljmUA31EAmVkt9aAaZds96h5UE X-Received: by 10.28.0.206 with SMTP id 197mr1272457wma.118.1525713921676; Mon, 07 May 2018 10:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525713921; cv=none; d=google.com; s=arc-20160816; b=k8K3h06D/Xne62y02y0iQN2ec8jTyBsi7TphmjrSGj2MLtULfh7rHj0+WDguggZmTC DPlviV1xWGYXZ9YcbQ3D/H3LLc7UevOSqVPrOxPJTBh0P6zBdQn2O6Ov57NIpE6RcxwX BFYEHsTfyyCMJyHiqu/FVYVyCdKWwkfGVhVh2x4HEaIz9ol0b07JrfH3Z2QYWDVXgEe2 V9NanVXvFyQHhXmD3rMKV6hnrZOWesHO4csrxQQiWPjh8cDIzwDfCilYZdaPmP7pu8Lu 8LJ3f8VdNakHSuy5fszw6mMqdfkmcos+xkh9bpEBclGt/jP/qZucqrcalABtw73YVp8o pF+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:domainkey-signature:dkim-signature :delivered-to:arc-authentication-results; bh=TtrvvaBQ+PSqGiZY23Jx2M9YrUJxQ3RTCOkmgCXTrNo=; b=TuI4ZjDFnUZ5Oh5od6EZd3rMYzsxauPpoGqyRywqK0Gn52vNWvwHgeYIQr028qm8Y9 NaQOqN4j7brgwJTiFCfNHmbKroZ1PzLSp/1+/a0hG9sIYAjwDMrT0WjBRqWA2+TT8XNO X5JfhyGxVcHCTugVqOm5raDSYHa2ZDmpZ2RZJl4NAxXPgVZhkvKsOMu3SVE/plxFEtgw pnUlY7m8whUEkDMLw0Oi7bx5+8sCtGwIAl4wh6ZMfJ4/PpEqt1X4FTEM5pOQycg3Hm5l lRRYd0qJ4LTJZWxx3zQuMRIcwuBCT4kEkEFA4Fv2mJxrOHhqR5vazGrmFPaz8ex0Nxxj jBYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=UsT/EZ3d; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c1-v6si5878384wrf.71.2018.05.07.10.25.21; Mon, 07 May 2018 10:25:21 -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=@pkh.me header.s=selector1 header.b=UsT/EZ3d; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CB68068A668; Mon, 7 May 2018 20:24:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from golem.pkh.me (LStLambert-657-1-117-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CE34C68A658 for ; Mon, 7 May 2018 20:24:00 +0300 (EEST) Received: from golem.pkh.me (localhost.localdomain [127.0.0.1]) by golem.pkh.me (OpenSMTPD) with ESMTP id 4160fc26 for ; Mon, 7 May 2018 17:24:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pkh.me; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=selector1; bh=q3MP72o obDC8hvBnlsJyoEx6gKA=; b=UsT/EZ3d16P03IzQ4mVn+JMBWC4iRrwHnv1fdyl fQXvBl3tLtTotPKRsRZbV2XIG5cLUPiesb0U46fFze0VBtTiVjJX+2PIFs/BV5oU zvFpq84++pjUHP9uMpa8JQK0o1qd8uINvV/EBGCxKFfn2QXtrPUQQ4/TrZMEne0y 1PgX5c4qJXnFLhj6SOTcMMMuxdmuCkWJ9Q8KOHuEU01C8Ma+YBYqBXCY81yj8Slp myBHscvMjV4xwl5ImaACVgzLN/c9eiGx0U255AvVc5JIz6wNXJrbKduKZ7r3M+T6 R1uMPnFd4mlzcVIsWuDetwr7FC0iqazxU1ksIvZ2cueCohg== DomainKey-Signature: a=rsa-sha1; c=nofws; d=pkh.me; h=from:to:cc:subject :date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; q=dns; s=selector1; b=V 2rxUVtfc3tKwy14X5zA1lq0UAyyk4EmhjkfaJRsK479nuGvaav3UdRfRrzNT2ra1 9CuE0eKRvczRSz31bcUOAkxN/MwoXkxThuoSQZR1tj4/xBDksuDFMmo+/raE+6KF tqdoa3HACbfC+H3Jr63aG29WpcQsxD6VQsXPtEPO8ACYbpPjiWicXGTvK4nZ730B 9guFjm/funmYkSuq26eoWXzTxV5+ea3+NhvCNkotctWX9DBCO/Dlj95O3rDB9T2k 2bRaow6dPxoXkIsQmV75r5RO5cJC45Qf5rfrTm69KHQ7ZSDfWa5H3z6sutkwsXLQ ikHPSVIxf+wrN9Xh1uRcA== Received: from localhost (golem.pkh.me [local]) by golem.pkh.me (OpenSMTPD) with ESMTPA id 4bcf1b4c; Mon, 7 May 2018 17:24:24 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 May 2018 19:24:17 +0200 Message-Id: <20180507172422.11003-6-u@pkh.me> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180507172422.11003-1-u@pkh.me> References: <20180507172422.11003-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 05/10] checkasm: add vf_nlmeans test for ssd_integral_image 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: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- tests/checkasm/Makefile | 1 + tests/checkasm/checkasm.c | 3 + tests/checkasm/checkasm.h | 1 + tests/checkasm/vf_nlmeans.c | 113 ++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 tests/checkasm/vf_nlmeans.c diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile index 0233d2f989..9484acbbd7 100644 --- a/tests/checkasm/Makefile +++ b/tests/checkasm/Makefile @@ -35,6 +35,7 @@ AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o AVFILTEROBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o AVFILTEROBJS-$(CONFIG_THRESHOLD_FILTER) += vf_threshold.o +AVFILTEROBJS-$(CONFIG_NLMEANS_FILTER) += vf_nlmeans.o CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index ba1d1d0253..721a0912fb 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -159,6 +159,9 @@ static const struct { #if CONFIG_HFLIP_FILTER { "vf_hflip", checkasm_check_vf_hflip }, #endif + #if CONFIG_NLMEANS_FILTER + { "vf_nlmeans", checkasm_check_nlmeans }, + #endif #if CONFIG_THRESHOLD_FILTER { "vf_threshold", checkasm_check_vf_threshold }, #endif diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index dcab74de06..c45cfb46f8 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -62,6 +62,7 @@ void checkasm_check_huffyuvdsp(void); void checkasm_check_jpeg2000dsp(void); void checkasm_check_llviddsp(void); void checkasm_check_llviddspenc(void); +void checkasm_check_nlmeans(void); void checkasm_check_pixblockdsp(void); void checkasm_check_sbrdsp(void); void checkasm_check_synth_filter(void); diff --git a/tests/checkasm/vf_nlmeans.c b/tests/checkasm/vf_nlmeans.c new file mode 100644 index 0000000000..5e2c934226 --- /dev/null +++ b/tests/checkasm/vf_nlmeans.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018 Clément Bœsch + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "checkasm.h" +#include "libavfilter/vf_nlmeans.h" +#include "libavutil/avassert.h" + +#define randomize_buffer(buf, size) do { \ + int i; \ + for (i = 0; i < size / 4; i++) \ + ((uint32_t *)buf)[i] = rnd(); \ +} while (0) + +void checkasm_check_nlmeans(void) +{ + NLMeansDSPContext dsp = {0}; + + const int w = 123; // source width + const int h = 45; // source height + const int p = 3; // patch half size + const int r = 2; // research window half size + + ff_nlmeans_init(&dsp); + + /* See the filter's code for the explanations on the variables */ + if (check_func(dsp.compute_safe_ssd_integral_image, "ssd_integral_image")) { + int offx, offy; + const int e = p + r; + const int ii_w = w + e*2; + const int ii_h = h + e*2; + const int ii_lz_32 = FFALIGN(ii_w + 1, 4); + uint32_t *ii_orig_ref = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_ref)); + uint32_t *ii_ref = ii_orig_ref + ii_lz_32 + 1; + uint32_t *ii_orig_new = av_mallocz_array(ii_h + 1, ii_lz_32 * sizeof(*ii_orig_new)); + uint32_t *ii_new = ii_orig_new + ii_lz_32 + 1; + const int src_lz = FFALIGN(w, 16); + uint8_t *src = av_mallocz_array(h, src_lz); + + declare_func(void, uint32_t *dst, ptrdiff_t dst_linesize_32, + const uint8_t *s1, ptrdiff_t linesize1, + const uint8_t *s2, ptrdiff_t linesize2, + int w, int h); + + randomize_buffer(src, h * src_lz); + + for (offy = -r; offy <= r; offy++) { + for (offx = -r; offx <= r; offx++) { + if (offx || offy) { + const int s1x = e; + const int s1y = e; + const int s2x = e + offx; + const int s2y = e + offy; + const int startx_safe = FFMAX(s1x, s2x); + const int starty_safe = FFMAX(s1y, s2y); + const int u_endx_safe = FFMIN(s1x + w, s2x + w); + const int endy_safe = FFMIN(s1y + h, s2y + h); + const int safe_pw = (u_endx_safe - startx_safe) & ~0xf; + const int safe_ph = endy_safe - starty_safe; + + av_assert0(safe_pw && safe_ph); + av_assert0(startx_safe - s1x >= 0); av_assert0(startx_safe - s1x < w); + av_assert0(starty_safe - s1y >= 0); av_assert0(starty_safe - s1y < h); + av_assert0(startx_safe - s2x >= 0); av_assert0(startx_safe - s2x < w); + av_assert0(starty_safe - s2y >= 0); av_assert0(starty_safe - s2y < h); + + memset(ii_ref, 0, ii_lz_32 * ii_h * sizeof(*ii_ref)); + memset(ii_new, 0, ii_lz_32 * ii_h * sizeof(*ii_new)); + + call_ref(ii_ref + starty_safe*ii_lz_32 + startx_safe, ii_lz_32, + src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz, + src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz, + safe_pw, safe_ph); + call_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32, + src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz, + src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz, + safe_pw, safe_ph); + + if (memcmp(ii_ref, ii_new, ii_h * ii_lz_32 * 4)) + fail(); + + memset(ii_new, 0, ii_lz_32 * ii_h * sizeof(*ii_new)); + bench_new(ii_new + starty_safe*ii_lz_32 + startx_safe, ii_lz_32, + src + (starty_safe - s1y) * src_lz + (startx_safe - s1x), src_lz, + src + (starty_safe - s2y) * src_lz + (startx_safe - s2x), src_lz, + safe_pw, safe_ph); + } + } + } + + av_freep(&ii_orig_ref); + av_freep(&ii_orig_new); + av_freep(&src); + } + + report("dsp"); +}