Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -209,13 +209,13 @@ static void compute_box_stats(PaletteGenContext *s, struct range_box *box) · 208 unmodified lines | |||
| 209 | */ | 209 | */ |
| 210 | static int get_next_box_id_to_split(PaletteGenContext *s) | 210 | static int get_next_box_id_to_split(PaletteGenContext *s) |
| 211 | { | 211 | { |
| 212 | int box_id, best_box_id = -1; | 212 | int best_box_id = -1; |
| 213 | int64_t max_score = -1; | 213 | int64_t max_score = -1; |
| 214 | 214 | ||
| 215 | if (s->nb_boxes == s->max_colors - s->reserve_transparent) | 215 | if (s->nb_boxes == s->max_colors - s->reserve_transparent) |
| 216 | return -1; | 216 | return -1; |
| 217 | 217 | ||
| 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++) { |
| 219 | const struct range_box *box = &s->boxes[box_id]; | 219 | const struct range_box *box = &s->boxes[box_id]; |
| 220 | if (s->boxes[box_id].len >= 2 && box->cut_score > max_score) { | 220 | if (s->boxes[box_id].len >= 2 && box->cut_score > max_score) { |
| 221 | best_box_id = box_id; | 221 | best_box_id = box_id; |
| @@ -250,13 +250,13 @@ static void split_box(PaletteGenContext *s, struct range_box *box, int n) · 28 unmodified lines | |||
| 250 | static void write_palette(AVFilterContext *ctx, AVFrame *out) | 250 | static void write_palette(AVFilterContext *ctx, AVFrame *out) |
| 251 | { | 251 | { |
| 252 | const PaletteGenContext *s = ctx->priv; | 252 | const PaletteGenContext *s = ctx->priv; |
| 253 | int x, y, box_id = 0; | 253 | int box_id = 0; |
| 254 | uint32_t *pal = (uint32_t *)out->data[0]; | 254 | uint32_t *pal = (uint32_t *)out->data[0]; |
| 255 | const int pal_linesize = out->linesize[0] >> 2; | 255 | const int pal_linesize = out->linesize[0] >> 2; |
| 256 | uint32_t last_color = 0; | 256 | uint32_t last_color = 0; |
| 257 | 257 | ||
| 258 | for (y = 0; y < out->height; y++) { | 258 | for (int y = 0; y < out->height; y++) { |
| 259 | for (x = 0; x < out->width; x++) { | 259 | for (int x = 0; x < out->width; x++) { |
| 260 | if (box_id < s->nb_boxes) { | 260 | if (box_id < s->nb_boxes) { |
| 261 | pal[x] = s->boxes[box_id++].color; | 261 | pal[x] = s->boxes[box_id++].color; |
| 262 | if ((x || y) && pal[x] == last_color) | 262 | if ((x || y) && pal[x] == last_color) |
| @@ -282,16 +282,16 @@ static void write_palette(AVFilterContext *ctx, AVFrame *out) · 19 unmodified lines | |||
| 282 | */ | 282 | */ |
| 283 | static struct color_ref **load_color_refs(const struct hist_node *hist, int nb_refs) | 283 | static struct color_ref **load_color_refs(const struct hist_node *hist, int nb_refs) |
| 284 | { | 284 | { |
| 285 | int i, j, k = 0; | 285 | int k = 0; |
| 286 | struct color_ref **refs = av_malloc_array(nb_refs, sizeof(*refs)); | 286 | struct color_ref **refs = av_malloc_array(nb_refs, sizeof(*refs)); |
| 287 | 287 | ||
| 288 | if (!refs) | 288 | if (!refs) |
| 289 | return NULL; | 289 | return NULL; |
| 290 | 290 | ||
| 291 | for (j = 0; j < HIST_SIZE; j++) { | 291 | for (int j = 0; j < HIST_SIZE; j++) { |
| 292 | const struct hist_node *node = &hist[j]; | 292 | const struct hist_node *node = &hist[j]; |
| 293 | 293 | ||
| 294 | for (i = 0; i < node->nb_entries; i++) | 294 | for (int i = 0; i < node->nb_entries; i++) |
| 295 | refs[k++] = &node->entries[i]; | 295 | refs[k++] = &node->entries[i]; |
| 296 | } | 296 | } |
| 297 | 297 | ||
| @@ -391,12 +391,11 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx) · 93 unmodified lines | |||
| 391 | */ | 391 | */ |
| 392 | static int color_inc(struct hist_node *hist, uint32_t color) | 392 | static int color_inc(struct hist_node *hist, uint32_t color) |
| 393 | { | 393 | { |
| 394 | int i; | ||
| 395 | const uint32_t hash = ff_lowbias32(color) & (HIST_SIZE - 1); | 394 | const uint32_t hash = ff_lowbias32(color) & (HIST_SIZE - 1); |
| 396 | struct hist_node *node = &hist[hash]; | 395 | struct hist_node *node = &hist[hash]; |
| 397 | struct color_ref *e; | 396 | struct color_ref *e; |
| 398 | 397 | ||
| 399 | for (i = 0; i < node->nb_entries; i++) { | 398 | for (int i = 0; i < node->nb_entries; i++) { |
| 400 | e = &node->entries[i]; | 399 | e = &node->entries[i]; |
| 401 | if (e->color == color) { | 400 | if (e->color == color) { |
| 402 | e->count++; | 401 | e->count++; |
| @@ -231,7 +231,6 @@ struct stack_node { · 230 unmodified lines | |||
| 231 | */ | 231 | */ |
| 232 | static av_always_inline int color_get(PaletteUseContext *s, uint32_t color) | 232 | static av_always_inline int color_get(PaletteUseContext *s, uint32_t color) |
| 233 | { | 233 | { |
| 234 | int i; | ||
| 235 | struct color_info clrinfo; | 234 | struct color_info clrinfo; |
| 236 | const uint32_t hash = ff_lowbias32(color) & (CACHE_SIZE - 1); | 235 | const uint32_t hash = ff_lowbias32(color) & (CACHE_SIZE - 1); |
| 237 | struct cache_node *node = &s->cache[hash]; | 236 | 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 | |||
| 242 | return s->transparency_index; | 241 | return s->transparency_index; |
| 243 | } | 242 | } |
| 244 | 243 | ||
| 245 | for (i = 0; i < node->nb_entries; i++) { | 244 | for (int i = 0; i < node->nb_entries; i++) { |
| 246 | e = &node->entries[i]; | 245 | e = &node->entries[i]; |
| 247 | if (e->color == color) | 246 | if (e->color == color) |
| 248 | return e->pal_entry; | 247 | return e->pal_entry; |
| @@ -284,7 +283,6 @@ static av_always_inline int set_frame(PaletteUseContext *s, AVFrame *out, AVFram · 35 unmodified lines | |||
| 284 | int x_start, int y_start, int w, int h, | 283 | int x_start, int y_start, int w, int h, |
| 285 | enum dithering_mode dither) | 284 | enum dithering_mode dither) |
| 286 | { | 285 | { |
| 287 | int x, y; | ||
| 288 | const int src_linesize = in ->linesize[0] >> 2; | 286 | const int src_linesize = in ->linesize[0] >> 2; |
| 289 | const int dst_linesize = out->linesize[0]; | 287 | const int dst_linesize = out->linesize[0]; |
| 290 | uint32_t *src = ((uint32_t *)in ->data[0]) + y_start*src_linesize; | 288 | 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 | |||
| 293 | w += x_start; | 291 | w += x_start; |
| 294 | h += y_start; | 292 | h += y_start; |
| 295 | 293 | ||
| 296 | for (y = y_start; y < h; y++) { | 294 | for (int y = y_start; y < h; y++) { |
| 297 | for (x = x_start; x < w; x++) { | 295 | for (int x = x_start; x < w; x++) { |
| 298 | int er, eg, eb; | 296 | int er, eg, eb; |
| 299 | 297 | ||
| 300 | if (dither == DITHERING_BAYER) { | 298 | 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 | |||
| 467 | int *component, const struct color_rect *box) | 465 | int *component, const struct color_rect *box) |
| 468 | { | 466 | { |
| 469 | int wL, wa, wb; | 467 | int wL, wa, wb; |
| 470 | int i, longest = 0; | 468 | int longest = 0; |
| 471 | unsigned nb_color = 0; | 469 | unsigned nb_color = 0; |
| 472 | struct color_rect ranges; | 470 | struct color_rect ranges; |
| 473 | struct color tmp_pal[256]; | 471 | 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 | |||
| 476 | ranges.min[0] = ranges.min[1] = ranges.min[2] = 0xffff; | 474 | ranges.min[0] = ranges.min[1] = ranges.min[2] = 0xffff; |
| 477 | ranges.max[0] = ranges.max[1] = ranges.max[2] = -0xffff; | 475 | ranges.max[0] = ranges.max[1] = ranges.max[2] = -0xffff; |
| 478 | 476 | ||
| 479 | for (i = 0; i < AVPALETTE_COUNT; i++) { | 477 | for (int i = 0; i < AVPALETTE_COUNT; i++) { |
| 480 | const uint32_t c = palette[i]; | 478 | const uint32_t c = palette[i]; |
| 481 | const uint8_t a = c >> 24; | 479 | const uint8_t a = c >> 24; |
| 482 | const struct Lab lab = ff_srgb_u8_to_oklab_int(c); | 480 | 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 | |||
| 571 | 569 | ||
| 572 | static void load_colormap(PaletteUseContext *s) | 570 | static void load_colormap(PaletteUseContext *s) |
| 573 | { | 571 | { |
| 574 | int i, nb_used = 0; | 572 | int nb_used = 0; |
| 575 | uint8_t color_used[AVPALETTE_COUNT] = {0}; | 573 | uint8_t color_used[AVPALETTE_COUNT] = {0}; |
| 576 | uint32_t last_color = 0; | 574 | uint32_t last_color = 0; |
| 577 | struct color_rect box; | 575 | struct color_rect box; |
| @@ -583,7 +581,7 @@ static void load_colormap(PaletteUseContext *s) · 5 unmodified lines | |||
| 583 | /* disable transparent colors and dups */ | 581 | /* disable transparent colors and dups */ |
| 584 | qsort(s->palette, AVPALETTE_COUNT-(s->transparency_index >= 0), sizeof(*s->palette), cmp_pal_entry); | 582 | qsort(s->palette, AVPALETTE_COUNT-(s->transparency_index >= 0), sizeof(*s->palette), cmp_pal_entry); |
| 585 | 583 | ||
| 586 | for (i = 0; i < AVPALETTE_COUNT; i++) { | 584 | for (int i = 0; i < AVPALETTE_COUNT; i++) { |
| 587 | const uint32_t c = s->palette[i]; | 585 | const uint32_t c = s->palette[i]; |
| 588 | if (i != 0 && c == last_color) { | 586 | if (i != 0 && c == last_color) { |
| 589 | color_used[i] = 1; | 587 | color_used[i] = 1; |
| @@ -874,10 +872,9 @@ static av_cold int init(AVFilterContext *ctx) · 284 unmodified lines | |||
| 874 | s->set_frame = set_frame_lut[s->dither]; | 872 | s->set_frame = set_frame_lut[s->dither]; |
| 875 | 873 | ||
| 876 | if (s->dither == DITHERING_BAYER) { | 874 | if (s->dither == DITHERING_BAYER) { |
| 877 | int i; | ||
| 878 | const int delta = 1 << (5 - s->bayer_scale); // to avoid too much luma | 875 | const int delta = 1 << (5 - s->bayer_scale); // to avoid too much luma |
| 879 | 876 | ||
| 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++) |
| 881 | s->ordered_dither[i] = (dither_value(i) >> s->bayer_scale) - delta; | 878 | s->ordered_dither[i] = (dither_value(i) >> s->bayer_scale) - delta; |
| 882 | } | 879 | } |
| 883 | 880 | ||
| @@ -892,11 +889,10 @@ static int activate(AVFilterContext *ctx) · 8 unmodified lines | |||
| 892 | 889 | ||
| 893 | static av_cold void uninit(AVFilterContext *ctx) | 890 | static av_cold void uninit(AVFilterContext *ctx) |
| 894 | { | 891 | { |
| 895 | int i; | ||
| 896 | PaletteUseContext *s = ctx->priv; | 892 | PaletteUseContext *s = ctx->priv; |
| 897 | 893 | ||
| 898 | ff_framesync_uninit(&s->fs); | 894 | ff_framesync_uninit(&s->fs); |
| 899 | for (i = 0; i < CACHE_SIZE; i++) | 895 | for (int i = 0; i < CACHE_SIZE; i++) |
| 900 | av_freep(&s->cache[i].entries); | 896 | av_freep(&s->cache[i].entries); |
| 901 | av_frame_free(&s->last_in); | 897 | av_frame_free(&s->last_in); |
| 902 | av_frame_free(&s->last_out); | 898 | av_frame_free(&s->last_out); |