History

avfilter/palette{gen,use}: misc for-loop cosmetics

Clément Bœsch committed 3 years ago

Commit 11926c41 parent 1340fe72 files · +18 −23Browse files

Unified · Split

2 files
  1. libavfilter/vf_palettegen.c +9 −10
  2. libavfilter/vf_paletteuse.c +9 −13
libavfilter/vf_palettegen.c+9−10
@@ -209,13 +209,13 @@ static void compute_box_stats(PaletteGenContext *s, struct range_box *box) · 208 unmodified lines
209209 */
210210 static int get_next_box_id_to_split(PaletteGenContext *s)
211211 {
212− int box_id, best_box_id = -1;
212+ int best_box_id = -1;
213213 int64_t max_score = -1;
214214
215215 if (s->nb_boxes == s->max_colors - s->reserve_transparent)
216216 return -1;
217217
218− for (box_id = 0; box_id < s->nb_boxes; box_id++) {
218+ for (int box_id = 0; box_id < s->nb_boxes; box_id++) {
219219 const struct range_box *box = &s->boxes[box_id];
220220 if (s->boxes[box_id].len >= 2 && box->cut_score > max_score) {
221221 best_box_id = box_id;
@@ -250,13 +250,13 @@ static void split_box(PaletteGenContext *s, struct range_box *box, int n) · 28 unmodified lines
250250 static void write_palette(AVFilterContext *ctx, AVFrame *out)
251251 {
252252 const PaletteGenContext *s = ctx->priv;
253− int x, y, box_id = 0;
253+ int box_id = 0;
254254 uint32_t *pal = (uint32_t *)out->data[0];
255255 const int pal_linesize = out->linesize[0] >> 2;
256256 uint32_t last_color = 0;
257257
258− for (y = 0; y < out->height; y++) {
259− for (x = 0; x < out->width; x++) {
258+ for (int y = 0; y < out->height; y++) {
259+ for (int x = 0; x < out->width; x++) {
260260 if (box_id < s->nb_boxes) {
261261 pal[x] = s->boxes[box_id++].color;
262262 if ((x || y) && pal[x] == last_color)
@@ -282,16 +282,16 @@ static void write_palette(AVFilterContext *ctx, AVFrame *out) · 19 unmodified lines
282282 */
283283 static struct color_ref **load_color_refs(const struct hist_node *hist, int nb_refs)
284284 {
285− int i, j, k = 0;
285+ int k = 0;
286286 struct color_ref **refs = av_malloc_array(nb_refs, sizeof(*refs));
287287
288288 if (!refs)
289289 return NULL;
290290
291− for (j = 0; j < HIST_SIZE; j++) {
291+ for (int j = 0; j < HIST_SIZE; j++) {
292292 const struct hist_node *node = &hist[j];
293293
294− for (i = 0; i < node->nb_entries; i++)
294+ for (int i = 0; i < node->nb_entries; i++)
295295 refs[k++] = &node->entries[i];
296296 }
297297
@@ -391,12 +391,11 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx) · 93 unmodified lines
391391 */
392392 static int color_inc(struct hist_node *hist, uint32_t color)
393393 {
394− int i;
395394 const uint32_t hash = ff_lowbias32(color) & (HIST_SIZE - 1);
396395 struct hist_node *node = &hist[hash];
397396 struct color_ref *e;
398397
399− for (i = 0; i < node->nb_entries; i++) {
398+ for (int i = 0; i < node->nb_entries; i++) {
400399 e = &node->entries[i];
401400 if (e->color == color) {
402401 e->count++;
libavfilter/vf_paletteuse.c+9−13
@@ -231,7 +231,6 @@ struct stack_node { · 230 unmodified lines
231231 */
232232 static av_always_inline int color_get(PaletteUseContext *s, uint32_t color)
233233 {
234− int i;
235234 struct color_info clrinfo;
236235 const uint32_t hash = ff_lowbias32(color) & (CACHE_SIZE - 1);
237236 struct cache_node *node = &s->cache[hash];
@@ -242,7 +241,7 @@ static av_always_inline int color_get(PaletteUseContext *s, uint32_t color) · 4 unmodified lines
242241 return s->transparency_index;
243242 }
244243
245− for (i = 0; i < node->nb_entries; i++) {
244+ for (int i = 0; i < node->nb_entries; i++) {
246245 e = &node->entries[i];
247246 if (e->color == color)
248247 return e->pal_entry;
@@ -284,7 +283,6 @@ static av_always_inline int set_frame(PaletteUseContext *s, AVFrame *out, AVFram · 35 unmodified lines
284283 int x_start, int y_start, int w, int h,
285284 enum dithering_mode dither)
286285 {
287− int x, y;
288286 const int src_linesize = in ->linesize[0] >> 2;
289287 const int dst_linesize = out->linesize[0];
290288 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 · 2 unmodified lines
293291 w += x_start;
294292 h += y_start;
295293
296− for (y = y_start; y < h; y++) {
297− for (x = x_start; x < w; x++) {
294+ for (int y = y_start; y < h; y++) {
295+ for (int x = x_start; x < w; x++) {
298296 int er, eg, eb;
299297
300298 if (dither == DITHERING_BAYER) {
@@ -467,7 +465,7 @@ static int get_next_color(const uint8_t *color_used, const uint32_t *palette, · 166 unmodified lines
467465 int *component, const struct color_rect *box)
468466 {
469467 int wL, wa, wb;
470− int i, longest = 0;
468+ int longest = 0;
471469 unsigned nb_color = 0;
472470 struct color_rect ranges;
473471 struct color tmp_pal[256];
@@ -476,7 +474,7 @@ static int get_next_color(const uint8_t *color_used, const uint32_t *palette, · 2 unmodified lines
476474 ranges.min[0] = ranges.min[1] = ranges.min[2] = 0xffff;
477475 ranges.max[0] = ranges.max[1] = ranges.max[2] = -0xffff;
478476
479− for (i = 0; i < AVPALETTE_COUNT; i++) {
477+ for (int i = 0; i < AVPALETTE_COUNT; i++) {
480478 const uint32_t c = palette[i];
481479 const uint8_t a = c >> 24;
482480 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) · 88 unmodified lines
571569
572570 static void load_colormap(PaletteUseContext *s)
573571 {
574− int i, nb_used = 0;
572+ int nb_used = 0;
575573 uint8_t color_used[AVPALETTE_COUNT] = {0};
576574 uint32_t last_color = 0;
577575 struct color_rect box;
@@ -583,7 +581,7 @@ static void load_colormap(PaletteUseContext *s) · 5 unmodified lines
583581 /* disable transparent colors and dups */
584582 qsort(s->palette, AVPALETTE_COUNT-(s->transparency_index >= 0), sizeof(*s->palette), cmp_pal_entry);
585583
586− for (i = 0; i < AVPALETTE_COUNT; i++) {
584+ for (int i = 0; i < AVPALETTE_COUNT; i++) {
587585 const uint32_t c = s->palette[i];
588586 if (i != 0 && c == last_color) {
589587 color_used[i] = 1;
@@ -874,10 +872,9 @@ static av_cold int init(AVFilterContext *ctx) · 284 unmodified lines
874872 s->set_frame = set_frame_lut[s->dither];
875873
876874 if (s->dither == DITHERING_BAYER) {
877− int i;
878875 const int delta = 1 << (5 - s->bayer_scale); // to avoid too much luma
879876
880− for (i = 0; i < FF_ARRAY_ELEMS(s->ordered_dither); i++)
877+ for (int i = 0; i < FF_ARRAY_ELEMS(s->ordered_dither); i++)
881878 s->ordered_dither[i] = (dither_value(i) >> s->bayer_scale) - delta;
882879 }
883880
@@ -892,11 +889,10 @@ static int activate(AVFilterContext *ctx) · 8 unmodified lines
892889
893890 static av_cold void uninit(AVFilterContext *ctx)
894891 {
895− int i;
896892 PaletteUseContext *s = ctx->priv;
897893
898894 ff_framesync_uninit(&s->fs);
899− for (i = 0; i < CACHE_SIZE; i++)
895+ for (int i = 0; i < CACHE_SIZE; i++)
900896 av_freep(&s->cache[i].entries);
901897 av_frame_free(&s->last_in);
902898 av_frame_free(&s->last_out);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t