diff mbox series

[FFmpeg-devel,v2,14/32] avfilter/palettegen: rename variance to cut_score

Message ID 20221227231814.2520181-15-u@pkh.me
State Accepted
Commit 187f5e7f908efee4bb8d4743d910cf6ea4e2ee0f
Headers show
Series [FFmpeg-devel,v2,01/32] avfilter/palettegen: allow a minimum of 2 colors | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Clément Bœsch Dec. 27, 2022, 11:17 p.m. UTC
"Variance" wasn't exactly the correct word; "cut score" is more
agnostic, which will be useful when changing the algorithm in the next
commit.
---
 libavfilter/vf_palettegen.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c
index ca1e02444c..7ecb1211ba 100644
--- a/libavfilter/vf_palettegen.c
+++ b/libavfilter/vf_palettegen.c
@@ -42,7 +42,7 @@  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 variance;   // overall variance of the box (how much the colors are spread)
+    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
     int sorted_by;      // whether range of colors is sorted by red (0), green (1) or blue (2)
@@ -171,25 +171,25 @@  static void compute_box_stats(PaletteGenContext *s, struct range_box *box)
     if (er2[0] >= er2[1] && er2[0] >= er2[2]) box->major_axis = 0;
     if (er2[1] >= er2[0] && er2[1] >= er2[2]) box->major_axis = 1; // prefer green again
 
-    box->variance = er2[0] + er2[1] + er2[2];
+    box->cut_score = er2[0] + er2[1] + er2[2];
 }
 
 /**
- * Find the next box to split: pick the one with the highest variance
+ * Find the next box to split: pick the one with the highest cut score
  */
 static int get_next_box_id_to_split(PaletteGenContext *s)
 {
     int box_id, best_box_id = -1;
-    int64_t max_variance = -1;
+    int64_t max_score = -1;
 
     if (s->nb_boxes == s->max_colors - s->reserve_transparent)
         return -1;
 
     for (box_id = 0; box_id < s->nb_boxes; box_id++) {
         struct range_box *box = &s->boxes[box_id];
-        if (s->boxes[box_id].len >= 2 && box->variance > max_variance) {
+        if (s->boxes[box_id].len >= 2 && box->cut_score > max_score) {
             best_box_id = box_id;
-            max_variance = box->variance;
+            max_score = box->cut_score;
         }
     }
     return best_box_id;