From patchwork Sun Oct 24 20:24:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 31226 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp4158206ioa; Sun, 24 Oct 2021 13:25:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtUiQPPcNQ1DL4ipg8d7QFwOhnz4iw/pdI7zScamm5ccunO32bJoru96y4Xwc94iEu1zud X-Received: by 2002:a05:6402:40d2:: with SMTP id z18mr20396194edb.362.1635107116711; Sun, 24 Oct 2021 13:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635107116; cv=none; d=google.com; s=arc-20160816; b=ku5Zmyu96vIGlHBJpjMQW0LPWiMpm+F473M5dWt8+Wy3hgSiaepv5/tSugq5m3b9nE zNAIHbZpB7ylIhUDWolsnRZ4f9neeyI5lCL/2KtL1iIiUWI30e12pwlaxsVW6bMDSFRb 3EMP3eTm50vDNKfvodiV4NDb6IEY7jt0OcZczB0pJvamHeQz4Yzf1W87WwL5ygZfmpli YqIgPIr2l8+cRHDjDPojqNrAfH/2mAYWDsTOHxn/axrS20fGETFTrg2NeEEME1qIUJcg iyFcViUBhZQNOp9eYH2nqbjnQMcj/o+naBHvpTfamCTAxRPE6V6GX6v0gz/NND27n/J5 61wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=ftq+Ngri4elMI/14XifkB610ggVsKXVlfr42pRBRwnE=; b=gUdWPrWR/cSgZEPCUjj7CZ4uyTgO5Oe/Qj1FTWzWkrHmfWfR6j0U26qCvTIxNIi3lv aUcGja27SJkKNWAKimRJAXjnMhGrgIEe/tLYH0nvidaE0I9LbiwO2Mr/MFortpcpO7Uu bP0twtZVsRzjSRZ40+qCfjP9+QTkU0Yf0D/rKSO9P8Kfia5mRvWXr7o/Hc280lgEm3/k qlH+/P3bLSARQrd09wtlBlUt1hhZP5F6bgkIK5ojwiTOQHYPHhlorl+RKBQJIdjaGr6S PFR25svWSce4COWAZJ7/kR2+qfmiZZEKqY1tCmM2SS9D/98rVq4pM1MxUYVTbiJBBpyk E79Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=IkW7Szyi; 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 sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b18si24503392ede.158.2021.10.24.13.25.12; Sun, 24 Oct 2021 13:25:16 -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 header.s=20210112 header.b=IkW7Szyi; 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 sp=QUARANTINE 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 072B768A305; Sun, 24 Oct 2021 23:25:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 597B3680986 for ; Sun, 24 Oct 2021 23:24:59 +0300 (EEST) Received: by mail-ed1-f51.google.com with SMTP id g8so2238663edb.2 for ; Sun, 24 Oct 2021 13:24:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zzO0lxpSHVCmw6WQztEDBV6PYfWdTDsSQyD2FKbi6mk=; b=IkW7SzyiJ+Zi5nB317XE1FcBrIznNJqbfcpxIrW9qCcHK7gIiGTHrqGb69l/PC/ic8 bVE/utgtBbfwB+K/o5huXpqspzL35p4phCT3gRYAxp/MtsqdxyL7LVBs/Vi/I7v0VeMe F7/qMkbh/syVeoT92UuUFNXXYW5IAHByyNhvtNrsWXMH78nNcb9Wm5RRJi+V0sS8ceSi tq0Azo7Vzo10rG0bI8ph/GMT+/fstBhi+FsxRvYFegUbMiey+SsXxmM9nfogdQ3f21qY 6HP+NvO9t6dCZU4dtTQylxzqt/HWJCnjrEWZdNZObTZSjJDiwL2I38ZELILGZBZrFyh+ tIJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=zzO0lxpSHVCmw6WQztEDBV6PYfWdTDsSQyD2FKbi6mk=; b=KdnqK64QmDToIHRwL/U0gVCmuDRPU7EMSvomx+78QvITbVveQkmdwxhJRnze/PZAPw PmJ+Zo1eT+0fbS2wFJ0werC8f4J5pgWgWrYV8rV4fLh7r43X8W91zR6ddeK4itbqPGJ0 Y1WyyCI4R69pz4oVsZZxQrnI0hA6sMbNluTz44UbKwkTwk10TmB10781hpeRI0kQP/cu RAF+3PnkUfeLMhTk6dD48yYKBvP8Vd6NttX/YvzRLy5IDk5sgWMT60+wzHxmjiAIUpwX Rcidj6Pf6Ok0dM2tR9vkE3pxYCBEHRi4bMhqxlZx9hj8MXAUAXrPfhzmiExksKoHzQ3Z BkNw== X-Gm-Message-State: AOAM53300vCNw32tJumhQskXTGayLK8T0V1rAqearQrR6YU0opnTN0cx NWEpghu1PamUz4hHMgTZCIOrtfM5Qdc= X-Received: by 2002:a17:907:8a06:: with SMTP id sc6mr6990628ejc.372.1635107098670; Sun, 24 Oct 2021 13:24:58 -0700 (PDT) Received: from localhost.localdomain ([95.168.118.28]) by smtp.gmail.com with ESMTPSA id ga42sm6416697ejc.105.2021.10.24.13.24.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Oct 2021 13:24:58 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sun, 24 Oct 2021 22:24:57 +0200 Message-Id: <20211024202502.945133-1-onemda@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6] avfilter/vf_nlmeans: use more friendlier 'for (int ...' X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /oCxt582amrU Signed-off-by: Paul B Mahol --- libavfilter/vf_nlmeans.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c index 74fc3923b3..b8d8bb2ec0 100644 --- a/libavfilter/vf_nlmeans.c +++ b/libavfilter/vf_nlmeans.c @@ -101,14 +101,13 @@ static void compute_safe_ssd_integral_image_c(uint32_t *dst, ptrdiff_t dst_lines const uint8_t *s2, ptrdiff_t linesize2, int w, int h) { - int x, y; const uint32_t *dst_top = dst - dst_linesize_32; /* SIMD-friendly assumptions allowed here */ av_assert2(!(w & 0xf) && w >= 16 && h >= 1); - for (y = 0; y < h; y++) { - for (x = 0; x < w; x += 4) { + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x += 4) { const int d0 = s1[x ] - s2[x ]; const int d1 = s1[x + 1] - s2[x + 1]; const int d2 = s1[x + 2] - s2[x + 2]; @@ -161,14 +160,12 @@ static inline void compute_unsafe_ssd_integral_image(uint32_t *dst, ptrdiff_t ds int offx, int offy, int r, int sw, int sh, int w, int h) { - int x, y; - - for (y = starty; y < starty + h; y++) { + for (int y = starty; y < starty + h; y++) { uint32_t acc = dst[y*dst_linesize_32 + startx - 1] - dst[(y-1)*dst_linesize_32 + startx - 1]; const int s1y = av_clip(y - r, 0, sh - 1); const int s2y = av_clip(y - (r + offy), 0, sh - 1); - for (x = startx; x < startx + w; x++) { + for (int x = startx; x < startx + w; x++) { const int s1x = av_clip(x - r, 0, sw - 1); const int s2x = av_clip(x - (r + offx), 0, sw - 1); const uint8_t v1 = src[s1y*linesize + s1x]; @@ -334,7 +331,6 @@ struct thread_data { static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { - int x, y; NLMeansContext *s = ctx->priv; const struct thread_data *td = arg; const ptrdiff_t src_linesize = td->src_linesize; @@ -349,10 +345,10 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs const int dist_d = dist_b * s->ii_lz_32; const int dist_e = dist_d + dist_b; - for (y = starty; y < endy; y++) { + for (int y = starty; y < endy; y++) { const uint8_t *src = td->src + y*src_linesize; struct weighted_avg *wa = s->wa + y*s->wa_linesize; - for (x = td->startx; x < td->endx; x++) { + for (int x = td->startx; x < td->endx; x++) { /* * M is a discrete map where every entry contains the sum of all the entries * in the rectangle from the top-left origin of M to its coordinate. In the @@ -404,10 +400,8 @@ static void weight_averages(uint8_t *dst, ptrdiff_t dst_linesize, struct weighted_avg *wa, ptrdiff_t wa_linesize, int w, int h) { - int x, y; - - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { // Also weight the centered pixel wa[x].total_weight += 1.f; wa[x].sum += 1.f * src[x]; @@ -423,7 +417,6 @@ static int nlmeans_plane(AVFilterContext *ctx, int w, int h, int p, int r, uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize) { - int offx, offy; NLMeansContext *s = ctx->priv; /* patches center points cover the whole research window so the patches * themselves overflow the research window */ @@ -433,8 +426,8 @@ static int nlmeans_plane(AVFilterContext *ctx, int w, int h, int p, int r, memset(s->wa, 0, s->wa_linesize * h * sizeof(*s->wa)); - for (offy = -r; offy <= r; offy++) { - for (offx = -r; offx <= r; offx++) { + for (int offy = -r; offy <= r; offy++) { + for (int offx = -r; offx <= r; offx++) { if (offx || offy) { struct thread_data td = { .src = src + offy*src_linesize + offx, @@ -464,7 +457,6 @@ static int nlmeans_plane(AVFilterContext *ctx, int w, int h, int p, int r, static int filter_frame(AVFilterLink *inlink, AVFrame *in) { - int i; AVFilterContext *ctx = inlink->dst; NLMeansContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; @@ -476,7 +468,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } av_frame_copy_props(out, in); - for (i = 0; i < s->nb_planes; i++) { + for (int i = 0; i < s->nb_planes; i++) { const int w = i ? s->chroma_w : inlink->w; const int h = i ? s->chroma_h : inlink->h; const int p = i ? s->patch_hsize_uv : s->patch_hsize; @@ -508,7 +500,6 @@ void ff_nlmeans_init(NLMeansDSPContext *dsp) static av_cold int init(AVFilterContext *ctx) { - int i; NLMeansContext *s = ctx->priv; const double h = s->sigma * 10.; @@ -517,7 +508,7 @@ static av_cold int init(AVFilterContext *ctx) s->weight_lut = av_calloc(s->max_meaningful_diff, sizeof(*s->weight_lut)); if (!s->weight_lut) return AVERROR(ENOMEM); - for (i = 0; i < s->max_meaningful_diff; i++) + for (int i = 0; i < s->max_meaningful_diff; i++) s->weight_lut[i] = exp(-i * s->pdiff_scale); CHECK_ODD_FIELD(research_size, "Luma research window");