From patchwork Fri Oct 29 15:18: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: 31256 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:a610:0:0:0:0:0 with SMTP id q16csp1803643ioi; Fri, 29 Oct 2021 08:19:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypWuOKGMu6NfbBQLpMtnHVMRzISswpTZEeMv+sRFYbEut8fVbWjgHzr9pehRjyMt2Qm1P8 X-Received: by 2002:a17:907:961d:: with SMTP id gb29mr15212116ejc.457.1635520752814; Fri, 29 Oct 2021 08:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635520752; cv=none; d=google.com; s=arc-20160816; b=XEMMeryjXUmAEF6ZiQrlTpl2FSjTBEoLYYJpstk3vx1Ob4aNG/I1vvnAfjJkiD/BTa vaWFTYnjPmTuUoAdGO8l1Sqm3aOrkfp8s3QmucrZoLKy/FZ380794tjcfj5sW9LOHaqn w6ed+sQTEww8pSqN5S3T0Nli739IcdKzKlIgosb2FOfiE1EOCAQdvujWhDno8ptPflQh 8q6ou/B2E6dwRimYFiDiKF1hLfc37HyQ2SqtNLJ7a+3qp0OZYzzeGG+tzuvVPRWiRZ39 LOCxorrakbX3D4RNrq4EmBLg1BV7uGNweyRe0Ozhog9WgRrpeeY4ly94DRsvZqIsFuNy To2A== 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=SaB/QynQV2V9S26QFjm8jlEBnLaIO3fTUb6wnAIMDuobMVyo+FnU1yK5Hrd1kqsneT 0QqhlyQk7JlFoV3HUbEZP11Z6M6NxhugQoXUGQcLj6L9hG5SJEEiMp42zcZ3qixD7YOT nDm42xNi+q0nPHrWLtvc5CAM9hXhz0PHJzeBHlb9RQd5CqtDeITTMrn9pxVtikhEpeCo gqyMwcaQ4jMjJ41gXciyyDojndno70gQdFDy+xFXHcvH1wWDH8LPfIgntOEaFXLj1LPi hHKAduT678bJJ8PJD3YiQgqrLURwx7My5ttEvXbmd29PZHP279MrJFbzjiu+EpGQw4ES QqEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=T9HznKXE; 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 g19si8362926ejz.358.2021.10.29.08.19.11; Fri, 29 Oct 2021 08:19:12 -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=T9HznKXE; 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 2A85B68A82F; Fri, 29 Oct 2021 18:19:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 38DDD68981E for ; Fri, 29 Oct 2021 18:19:01 +0300 (EEST) Received: by mail-ed1-f46.google.com with SMTP id r4so39202705edi.5 for ; Fri, 29 Oct 2021 08:19:01 -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=T9HznKXEo5JlnjxkqB5bYlrQp+w+Hjrxe2Q9S//bp5IxioYkApkyd+J/nfq+fJWifs Va3M94U6VJAKgvZKFa4DvFB8L2Y6TXaO6xt9sjhCsc6ysaEM+nTCY6uNUz+C1PPeSQ6m 44XdEhBIitqnnfBkIZ54T/bbrabbSwhTn7DCJ9fExs/i9MSOcsjfBeFzERQ6yt4rAAa2 Fmusu+4e5ap8VePbalN8YSVFw4wXSHPQwpx++P+zdhu6PQDxrdrZ0thO6zeieYB7y1+v e9CFcVozNv69t4kx6YCGA56hSmglAfjP0G3KJVgDztB6JddnjrNS2x/KFv/ToXiVfLdV JHGw== 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=AFAXR8mUK8l1LrFqe/0XHnHHNCc1OUgbToVy6/6DHO7GppuM62pY/LB5etlx+o2Rln pkRcaHgBLnEYBi6C3t1VckuaHXp5g/6GgmxYo0NNm0AjxRIgPHLpmNW3lX+NopKk1U1Y TbARgrzLzdpzOoVseXDlN4KM5GKfmXfX6Y9VHeqoZMOHKEVy+V1O8HryqLRLyCKvjpyW LQEzMAUHB2NkZ/PYthvm1lQ7x2kte+t/Yine1AVGFMuYQEkHfdhZVTXb8iPMrCy8EG0N FCZCUYA36ozZih+dm6z9vws1oOQRCew7dKKxdZxyn7lGOtGAsaJMYGoSCFy/fFL3aU+T z3Mw== X-Gm-Message-State: AOAM530Rr3YoQMFCQEq3DCjhmcHYq7RxkoTLbhLtAOJ8OqiFxJWQv3XJ ZY7lvc5yHwYijmuLw2jS4pLDbrlDt04= X-Received: by 2002:a17:907:961d:: with SMTP id gb29mr15210892ejc.457.1635520740683; Fri, 29 Oct 2021 08:19:00 -0700 (PDT) Received: from localhost.localdomain ([212.15.177.28]) by smtp.gmail.com with ESMTPSA id gb3sm3101386ejc.81.2021.10.29.08.18.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Oct 2021 08:19:00 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 Oct 2021 17:18:57 +0200 Message-Id: <20211029151903.1078367-1-onemda@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/7] 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: mB1+GfoNInKU 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");