History

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.

Clément Bœsch committed 3 years ago

Commit 724f52b1 parent 67ce6ad1 file · +4 −4Browse files

Unified · Split

libavfilter/vf_palettegen.c+4−4
@@ -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 */
35struct color_ref {35struct 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 */
41struct range_box {41struct range_box {
42 uint32_t color; // average color42 uint32_t color; // average color
43 int major_axis; // best axis candidate for cutting the box43 int major_axis; // best axis candidate for cutting the box
44 uint64_t weight; // sum of all the weights of the colors44 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->refs46 int start; // index in PaletteGenContext->refs
47 int len; // number of referenced colors47 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,

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