[FFmpeg-devel] [PATCH 14/15] avfilter/palettegen: rename longest to split_axis

Clément Bœsch u at pkh.me
Sat Nov 5 17:26:16 EET 2022


The split heuristic is not based on the length property of the axis
anymore.
---
 libavfilter/vf_palettegen.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c
index 2976012512..9d537f8f37 100644
--- a/libavfilter/vf_palettegen.c
+++ b/libavfilter/vf_palettegen.c
@@ -360,7 +360,7 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx)
     s->nb_boxes = 1;
 
     while (box && box->len > 1) {
-        int i, longest;
+        int i, split_axis;
         double Lv, av, bv;
         uint64_t median, box_weight = 0;
 
@@ -375,20 +375,20 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx)
         Lv = box->axis_variance[0];
         av = box->axis_variance[1];
         bv = box->axis_variance[2];
-        longest = 0;
-        if (bv >= Lv && bv >= av) longest = 2;
-        if (av >= Lv && av >= bv) longest = 1;
-        if (Lv >= av && Lv >= bv) longest = 0;
+        split_axis = 0;
+        if (bv >= Lv && bv >= av) split_axis = 2;
+        if (av >= Lv && av >= bv) split_axis = 1;
+        if (Lv >= av && Lv >= bv) split_axis = 0;
 
         ff_dlog(ctx, "box #%02X [%6d..%-6d] (%6d) w:%-6"PRIu64" var:[%.3f %.3f %.3f] sort by %c (already sorted:%c) ",
                 box_id, box->start, box->start + box->len - 1, box->len, box_weight,
-                Lv, av, bv, "Lab"[longest], box->sorted_by == longest ? 'y':'n');
+                Lv, av, bv, "Lab"[split_axis], box->sorted_by == split_axis ? 'y':'n');
 
-        /* sort the range by its longest axis if it's not already sorted */
-        if (box->sorted_by != longest) {
-            cmp_func cmpf = cmp_funcs[longest];
+        /* sort the range by its split axis if it's not already sorted */
+        if (box->sorted_by != split_axis) {
+            cmp_func cmpf = cmp_funcs[split_axis];
             AV_QSORT(&s->refs[box->start], box->len, const struct color_ref *, cmpf);
-            box->sorted_by = longest;
+            box->sorted_by = split_axis;
         }
 
         /* locate the median where to split */
-- 
2.38.1



More information about the ffmpeg-devel mailing list