This prevents mixed sign arithmetic (typically because we have signed color channel differences), which has nasty side effects in C.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -34,14 +34,14 @@ · 33 unmodified lines | |||
| 34 | /* Reference a color and how much it's used */ | 34 | /* Reference a color and how much it's used */ |
| 35 | struct color_ref { | 35 | struct color_ref { |
| 36 | uint32_t color; | 36 | uint32_t color; |
| 37 | uint64_t count; | 37 | int64_t count; |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | /* Store a range of colors */ | 40 | /* Store a range of colors */ |
| 41 | struct range_box { | 41 | struct range_box { |
| 42 | uint32_t color; // average color | 42 | uint32_t color; // average color |
| 43 | int major_axis; // best axis candidate for cutting the box | 43 | int major_axis; // best axis candidate for cutting the box |
| 44 | uint64_t weight; // sum of all the weights of the colors | 44 | int64_t weight; // sum of all the weights of the colors |
| 45 | int64_t cut_score; // how likely the box is to be cut down (higher implying more likely) | 45 | int64_t cut_score; // how likely the box is to be cut down (higher implying more likely) |
| 46 | int start; // index in PaletteGenContext->refs | 46 | int start; // index in PaletteGenContext->refs |
| 47 | int len; // number of referenced colors | 47 | int len; // number of referenced colors |
| @@ -141,7 +141,7 @@ static void compute_box_stats(PaletteGenContext *s, struct range_box *box) · 93 unmodified lines | |||
| 141 | int64_t er2[3] = {0}; | 141 | int64_t er2[3] = {0}; |
| 142 | 142 | ||
| 143 | /* Compute average color */ | 143 | /* Compute average color */ |
| 144 | uint64_t sr = 0, sg = 0, sb = 0; | 144 | int64_t sr = 0, sg = 0, sb = 0; |
| 145 | box->weight = 0; | 145 | box->weight = 0; |
| 146 | for (int i = box->start; i < box->start + box->len; i++) { | 146 | for (int i = box->start; i < box->start + box->len; i++) { |
| 147 | const struct color_ref *ref = s->refs[i]; | 147 | const struct color_ref *ref = s->refs[i]; |
| @@ -314,7 +314,7 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx) · 166 unmodified lines | |||
| 314 | 314 | ||
| 315 | while (box && box->len > 1) { | 315 | while (box && box->len > 1) { |
| 316 | int i; | 316 | int i; |
| 317 | uint64_t median, weight; | 317 | int64_t median, weight; |
| 318 | 318 | ||
| 319 | ff_dlog(ctx, "box #%02X [%6d..%-6d] (%6d) w:%-6"PRIu64" sort by %c (already sorted:%c) ", | 319 | ff_dlog(ctx, "box #%02X [%6d..%-6d] (%6d) w:%-6"PRIu64" sort by %c (already sorted:%c) ", |
| 320 | box_id, box->start, box->start + box->len - 1, box->len, box->weight, | 320 | box_id, box->start, box->start + box->len - 1, box->len, box->weight, |