From patchwork Tue Dec 27 23:18:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 39796 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp3762933pzb; Tue, 27 Dec 2022 15:22:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXvQqOz5LurAHqypi1kSUnCW4CORXraAbp+OCtQ6qeIBymfmpta08rrnD0sJtm46TEExmziA X-Received: by 2002:a17:906:3095:b0:809:c1f4:ea09 with SMTP id 21-20020a170906309500b00809c1f4ea09mr18170370ejv.69.1672183377437; Tue, 27 Dec 2022 15:22:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672183377; cv=none; d=google.com; s=arc-20160816; b=QIALeRBWcWJZoa2VWY7WVEU/nDjXtMEEOrpbcuNeVnIRHYqK9tugk7U5Ka5XZj1L0Y AOd+iQYCKnFA+N7B1IgymoaFOYCBAVqBLXlDimeKA2QhJpcr8jmGqvZH2hPJIemJX+fr N/WebVH/PA2VDmJGCy98KsftAApG0LAyInpV2HaSqcFCs1TjvrZwhhfOCyk5zAr0jxk1 gM/uXeTez7SUWJ69kLiEXCJcV3+seoKLNICP36YnmFUAVRsxs+cJ9XqaArrGtz36T6+N YFYWNd5GKl1fdGBdghS/T69X66F+unESCyF9+2AxuaMSW+4hoZ2bZ3fVg1dS8YbdytL5 wQqg== 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:dkim-signature:delivered-to; bh=bEM/JstIKpxmq+1PAjjlDWtTuo4Pl3s5BhGjjlR3L4Q=; b=GeU+4Kiqs4K6ULSBmEKJKjgD9EcYpP0Z21GxgzUnw982qP8FMn7oTi7r8EjsnMtIqU LceXthc7QnKdFDrF8y/H6HNuV0s/naHbY/yXbXTrEaN8/QreXXT/qJFAm8vSmPjo9841 7lc3QWYZKu0bDmWjqaCeFvFAakhCd0JHIG1TpjSdIvBF3Xv7wE9++rbi3BTJ5/4XQkMy iNBRA5ggA51w6anHaeIS9bCAfonPEA0ZQ1Z66Vw0wZPaFND5rx5yvmyBGO+7Z0lxU3+0 Zp8L5zcbOUa6c4mM1kcQ9mnjobzNUkWlw2b5KgLZqaeO0D6DnThu8JyfdFjTTcqAMECa xtdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=BWM2BQ3+; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hb8-20020a170907160800b007c1727f7c57si13021903ejc.243.2022.12.27.15.22.57; Tue, 27 Dec 2022 15:22:57 -0800 (PST) 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=BWM2BQ3+; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EE62368BA11; Wed, 28 Dec 2022 01:18:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D914D68BCF1 for ; Wed, 28 Dec 2022 01:18:36 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1672183100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9RzDh/0Y74liWzPxY2YrTZMoNOPKNh4vBarV2+2E5Z8=; b=BWM2BQ3+5+o1CROs9+kETFz0vDj1kGIJLcU3VhgeloS7WsFC9dUjxdyEf3qeAaqivNvF8z mGlCA44rbn3Wg2HzMyxxN4NlpoaU5qt3TsmuSrYHAy/82fjJwaVRdTxPwwNLfgCuNos6XV Jcoy1d1jcCWi/qOHP1bjnsKmoEgCu4M= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 94b2c0f3; Tue, 27 Dec 2022 23:18:20 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Dec 2022 00:18:14 +0100 Message-Id: <20221227231814.2520181-33-u@pkh.me> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221227231814.2520181-1-u@pkh.me> References: <20221105152617.1809282-1-u@pkh.me> <20221227231814.2520181-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 32/32] avfilter/palette{gen, use}: misc for-loop cosmetics 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 Cc: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: hqyhbVp9/kGI --- libavfilter/vf_palettegen.c | 19 +++++++++---------- libavfilter/vf_paletteuse.c | 22 +++++++++------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c index 97e12f7274..4b69d3c63b 100644 --- a/libavfilter/vf_palettegen.c +++ b/libavfilter/vf_palettegen.c @@ -209,13 +209,13 @@ static void compute_box_stats(PaletteGenContext *s, struct range_box *box) */ static int get_next_box_id_to_split(PaletteGenContext *s) { - int box_id, best_box_id = -1; + int best_box_id = -1; int64_t max_score = -1; if (s->nb_boxes == s->max_colors - s->reserve_transparent) return -1; - for (box_id = 0; box_id < s->nb_boxes; box_id++) { + for (int box_id = 0; box_id < s->nb_boxes; box_id++) { const struct range_box *box = &s->boxes[box_id]; if (s->boxes[box_id].len >= 2 && box->cut_score > max_score) { best_box_id = box_id; @@ -250,13 +250,13 @@ static void split_box(PaletteGenContext *s, struct range_box *box, int n) static void write_palette(AVFilterContext *ctx, AVFrame *out) { const PaletteGenContext *s = ctx->priv; - int x, y, box_id = 0; + int box_id = 0; uint32_t *pal = (uint32_t *)out->data[0]; const int pal_linesize = out->linesize[0] >> 2; uint32_t last_color = 0; - for (y = 0; y < out->height; y++) { - for (x = 0; x < out->width; x++) { + for (int y = 0; y < out->height; y++) { + for (int x = 0; x < out->width; x++) { if (box_id < s->nb_boxes) { pal[x] = s->boxes[box_id++].color; if ((x || y) && pal[x] == last_color) @@ -282,16 +282,16 @@ static void write_palette(AVFilterContext *ctx, AVFrame *out) */ static struct color_ref **load_color_refs(const struct hist_node *hist, int nb_refs) { - int i, j, k = 0; + int k = 0; struct color_ref **refs = av_malloc_array(nb_refs, sizeof(*refs)); if (!refs) return NULL; - for (j = 0; j < HIST_SIZE; j++) { + for (int j = 0; j < HIST_SIZE; j++) { const struct hist_node *node = &hist[j]; - for (i = 0; i < node->nb_entries; i++) + for (int i = 0; i < node->nb_entries; i++) refs[k++] = &node->entries[i]; } @@ -391,12 +391,11 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx) */ static int color_inc(struct hist_node *hist, uint32_t color) { - int i; const uint32_t hash = ff_lowbias32(color) & (HIST_SIZE - 1); struct hist_node *node = &hist[hash]; struct color_ref *e; - for (i = 0; i < node->nb_entries; i++) { + for (int i = 0; i < node->nb_entries; i++) { e = &node->entries[i]; if (e->color == color) { e->count++; diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c index e3462b4abb..33d0b0e722 100644 --- a/libavfilter/vf_paletteuse.c +++ b/libavfilter/vf_paletteuse.c @@ -231,7 +231,6 @@ struct stack_node { */ static av_always_inline int color_get(PaletteUseContext *s, uint32_t color) { - int i; struct color_info clrinfo; const uint32_t hash = ff_lowbias32(color) & (CACHE_SIZE - 1); struct cache_node *node = &s->cache[hash]; @@ -242,7 +241,7 @@ static av_always_inline int color_get(PaletteUseContext *s, uint32_t color) return s->transparency_index; } - for (i = 0; i < node->nb_entries; i++) { + for (int i = 0; i < node->nb_entries; i++) { e = &node->entries[i]; if (e->color == color) return e->pal_entry; @@ -284,7 +283,6 @@ static av_always_inline int set_frame(PaletteUseContext *s, AVFrame *out, AVFram int x_start, int y_start, int w, int h, enum dithering_mode dither) { - int x, y; const int src_linesize = in ->linesize[0] >> 2; const int dst_linesize = out->linesize[0]; uint32_t *src = ((uint32_t *)in ->data[0]) + y_start*src_linesize; @@ -293,8 +291,8 @@ static av_always_inline int set_frame(PaletteUseContext *s, AVFrame *out, AVFram w += x_start; h += y_start; - for (y = y_start; y < h; y++) { - for (x = x_start; x < w; x++) { + for (int y = y_start; y < h; y++) { + for (int x = x_start; x < w; x++) { int er, eg, eb; if (dither == DITHERING_BAYER) { @@ -467,7 +465,7 @@ static int get_next_color(const uint8_t *color_used, const uint32_t *palette, int *component, const struct color_rect *box) { int wL, wa, wb; - int i, longest = 0; + int longest = 0; unsigned nb_color = 0; struct color_rect ranges; struct color tmp_pal[256]; @@ -476,7 +474,7 @@ static int get_next_color(const uint8_t *color_used, const uint32_t *palette, ranges.min[0] = ranges.min[1] = ranges.min[2] = 0xffff; ranges.max[0] = ranges.max[1] = ranges.max[2] = -0xffff; - for (i = 0; i < AVPALETTE_COUNT; i++) { + for (int i = 0; i < AVPALETTE_COUNT; i++) { const uint32_t c = palette[i]; const uint8_t a = c >> 24; const struct Lab lab = ff_srgb_u8_to_oklab_int(c); @@ -571,7 +569,7 @@ static int cmp_pal_entry(const void *a, const void *b) static void load_colormap(PaletteUseContext *s) { - int i, nb_used = 0; + int nb_used = 0; uint8_t color_used[AVPALETTE_COUNT] = {0}; uint32_t last_color = 0; struct color_rect box; @@ -583,7 +581,7 @@ static void load_colormap(PaletteUseContext *s) /* disable transparent colors and dups */ qsort(s->palette, AVPALETTE_COUNT-(s->transparency_index >= 0), sizeof(*s->palette), cmp_pal_entry); - for (i = 0; i < AVPALETTE_COUNT; i++) { + for (int i = 0; i < AVPALETTE_COUNT; i++) { const uint32_t c = s->palette[i]; if (i != 0 && c == last_color) { color_used[i] = 1; @@ -874,10 +872,9 @@ static av_cold int init(AVFilterContext *ctx) s->set_frame = set_frame_lut[s->dither]; if (s->dither == DITHERING_BAYER) { - int i; const int delta = 1 << (5 - s->bayer_scale); // to avoid too much luma - for (i = 0; i < FF_ARRAY_ELEMS(s->ordered_dither); i++) + for (int i = 0; i < FF_ARRAY_ELEMS(s->ordered_dither); i++) s->ordered_dither[i] = (dither_value(i) >> s->bayer_scale) - delta; } @@ -892,11 +889,10 @@ static int activate(AVFilterContext *ctx) static av_cold void uninit(AVFilterContext *ctx) { - int i; PaletteUseContext *s = ctx->priv; ff_framesync_uninit(&s->fs); - for (i = 0; i < CACHE_SIZE; i++) + for (int i = 0; i < CACHE_SIZE; i++) av_freep(&s->cache[i].entries); av_frame_free(&s->last_in); av_frame_free(&s->last_out);