From 724f52b906a8d375de8a9b80b8a2b353e2a092d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Tue, 27 Dec 2022 15:05:01 +0100 Subject: [PATCH] avfilter/palettegen: switch to signed arithmetic This prevents mixed sign arithmetic (typically because we have signed color channel differences), which has nasty side effects in C. --- libavfilter/vf_palettegen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c index b8db234fef..99e4512e52 100644 --- a/libavfilter/vf_palettegen.c +++ b/libavfilter/vf_palettegen.c @@ -34,14 +34,14 @@ /* Reference a color and how much it's used */ struct color_ref { uint32_t color; - uint64_t count; + int64_t count; }; /* Store a range of colors */ struct range_box { uint32_t color; // average color int major_axis; // best axis candidate for cutting the box - uint64_t weight; // sum of all the weights of the colors + int64_t weight; // sum of all the weights of the colors int64_t cut_score; // how likely the box is to be cut down (higher implying more likely) int start; // index in PaletteGenContext->refs int len; // number of referenced colors @@ -141,7 +141,7 @@ static void compute_box_stats(PaletteGenContext *s, struct range_box *box) int64_t er2[3] = {0}; /* Compute average color */ - uint64_t sr = 0, sg = 0, sb = 0; + int64_t sr = 0, sg = 0, sb = 0; box->weight = 0; for (int i = box->start; i < box->start + box->len; i++) { const struct color_ref *ref = s->refs[i]; @@ -314,7 +314,7 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx) while (box && box->len > 1) { int i; - uint64_t median, weight; + int64_t median, weight; ff_dlog(ctx, "box #%02X [%6d..%-6d] (%6d) w:%-6"PRIu64" sort by %c (already sorted:%c) ", box_id, box->start, box->start + box->len - 1, box->len, box->weight,