diff mbox series

[FFmpeg-devel,08/15] avfilter/paletteuse: switch to a perceptual model

Message ID 20221105152617.1809282-9-u@pkh.me
State New
Headers show
Series [FFmpeg-devel,01/15] Revert "avfilter/vf_palette(gen|use): support palettes with alpha" | 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 Nov. 5, 2022, 3:26 p.m. UTC
Now the selection of the color is based on a distance built around human
perception of color instead of the unreliable sRGB triplet one.
---
 libavfilter/Makefile                        |   2 +-
 libavfilter/vf_paletteuse.c                 | 196 ++++++++++----------
 tests/ref/fate/filter-paletteuse-bayer      | 142 +++++++-------
 tests/ref/fate/filter-paletteuse-bayer0     | 142 +++++++-------
 tests/ref/fate/filter-paletteuse-nodither   | 142 +++++++-------
 tests/ref/fate/filter-paletteuse-sierra2_4a | 142 +++++++-------
 6 files changed, 387 insertions(+), 379 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index ace0e60ba1..e6b6d59d2d 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -402,7 +402,7 @@  OBJS-$(CONFIG_OWDENOISE_FILTER)              += vf_owdenoise.o
 OBJS-$(CONFIG_PAD_FILTER)                    += vf_pad.o
 OBJS-$(CONFIG_PAD_OPENCL_FILTER)             += vf_pad_opencl.o opencl.o opencl/pad.o
 OBJS-$(CONFIG_PALETTEGEN_FILTER)             += vf_palettegen.o
-OBJS-$(CONFIG_PALETTEUSE_FILTER)             += vf_paletteuse.o framesync.o
+OBJS-$(CONFIG_PALETTEUSE_FILTER)             += vf_paletteuse.o framesync.o palette.o
 OBJS-$(CONFIG_PERMS_FILTER)                  += f_perms.o
 OBJS-$(CONFIG_PERSPECTIVE_FILTER)            += vf_perspective.o
 OBJS-$(CONFIG_PHASE_FILTER)                  += vf_phase.o
diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c
index 0861a70a0b..7c64a63722 100644
--- a/libavfilter/vf_paletteuse.c
+++ b/libavfilter/vf_paletteuse.c
@@ -23,6 +23,8 @@ 
  * Use a palette to downsample an input video stream.
  */
 
+#include <float.h>
+
 #include "libavutil/bprint.h"
 #include "libavutil/file_open.h"
 #include "libavutil/internal.h"
@@ -32,6 +34,7 @@ 
 #include "filters.h"
 #include "framesync.h"
 #include "internal.h"
+#include "palette.h"
 
 enum dithering_mode {
     DITHERING_NONE,
@@ -56,8 +59,13 @@  enum diff_mode {
     NB_DIFF_MODE
 };
 
+struct color_info {
+    uint32_t srgb;
+    float lab[3];
+};
+
 struct color_node {
-    uint32_t val;
+    struct color_info c;
     uint8_t palette_id;
     int split;
     int left_id, right_id;
@@ -103,7 +111,7 @@  typedef struct PaletteUseContext {
     char *dot_filename;
     int color_search_method;
     int calc_mean_err;
-    uint64_t total_mean_err;
+    double total_mean_err;
     int debug_accuracy;
 } PaletteUseContext;
 
@@ -162,33 +170,41 @@  static av_always_inline uint32_t dither_color(uint32_t px, int er, int eg,
          | av_clip_uint8((px       & 0xff) + ((eb * scale) / (1<<shift)));
 }
 
-static av_always_inline int diff(const uint32_t a, const uint32_t b, const int trans_thresh)
+static av_always_inline float diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
 {
-    // XXX: try L*a*b with CIE76 (dL*dL + da*da + db*db)
-    const uint8_t c1[] = {a >> 24, a >> 16 & 0xff, a >> 8 & 0xff, a & 0xff};
-    const uint8_t c2[] = {b >> 24, b >> 16 & 0xff, b >> 8 & 0xff, b & 0xff};
-    const int dr = c1[1] - c2[1];
-    const int dg = c1[2] - c2[2];
-    const int db = c1[3] - c2[3];
-
-    if (c1[0] < trans_thresh && c2[0] < trans_thresh) {
+    const uint8_t alpha_a = a->srgb >> 24;
+    const uint8_t alpha_b = b->srgb >> 24;
+
+    if (alpha_a < trans_thresh && alpha_b < trans_thresh) {
         return 0;
-    } else if (c1[0] >= trans_thresh && c2[0] >= trans_thresh) {
-        return dr*dr + dg*dg + db*db;
+    } else if (alpha_a >= trans_thresh && alpha_b >= trans_thresh) {
+        const float dL = a->lab[0] - b->lab[0];
+        const float da = a->lab[1] - b->lab[1];
+        const float db = a->lab[2] - b->lab[2];
+        return dL*dL + da*da + db*db;
     } else {
-        return 255*255 + 255*255 + 255*255;
+        return 2.f; /* above the oklab max diff */
     }
 }
 
-static av_always_inline uint8_t colormap_nearest_bruteforce(const uint32_t *palette, const uint32_t target, const int trans_thresh)
+static struct color_info get_color_from_srgb(uint32_t srgb)
+{
+    const struct Lab lab = ff_srgb_u8_to_oklab(srgb);
+    struct color_info ret = {.srgb=srgb, .lab={lab.L, lab.a, lab.b}};
+    return ret;
+}
+
+static av_always_inline uint8_t colormap_nearest_bruteforce(const uint32_t *palette, const struct color_info *target, const int trans_thresh)
 {
-    int i, pal_id = -1, min_dist = INT_MAX;
+    int i, pal_id = -1;
+    float min_dist = FLT_MAX;
 
     for (i = 0; i < AVPALETTE_COUNT; i++) {
         const uint32_t c = palette[i];
 
         if (c >> 24 >= trans_thresh) { // ignore transparent entry
-            const int d = diff(palette[i], target, trans_thresh);
+            const struct color_info pal_color = get_color_from_srgb(palette[i]);
+            const float d = diff(&pal_color, target, trans_thresh);
             if (d < min_dist) {
                 pal_id = i;
                 min_dist = d;
@@ -206,14 +222,13 @@  struct nearest_color {
 
 static void colormap_nearest_node(const struct color_node *map,
                                   const int node_pos,
-                                  const uint32_t target,
+                                  const struct color_info *target,
                                   const int trans_thresh,
                                   struct nearest_color *nearest)
 {
     const struct color_node *kd = map + node_pos;
-    const int shift = (2 - kd->split) * 8;
-    int dx, nearer_kd_id, further_kd_id;
-    const uint32_t current = kd->val;
+    int nearer_kd_id, further_kd_id;
+    const struct color_info *current = &kd->c;
     const int current_to_target = diff(target, current, trans_thresh);
 
     if (current_to_target < nearest->dist_sqd) {
@@ -222,7 +237,7 @@  static void colormap_nearest_node(const struct color_node *map,
     }
 
     if (kd->left_id != -1 || kd->right_id != -1) {
-        dx = (int)(target>>shift & 0xff) - (int)(current>>shift & 0xff);
+        const float dx = target->lab[kd->split] - current->lab[kd->split];
 
         if (dx <= 0) nearer_kd_id = kd->left_id,  further_kd_id = kd->right_id;
         else         nearer_kd_id = kd->right_id, further_kd_id = kd->left_id;
@@ -235,7 +250,7 @@  static void colormap_nearest_node(const struct color_node *map,
     }
 }
 
-static av_always_inline uint8_t colormap_nearest_recursive(const struct color_node *node, const uint8_t target, const int trans_thresh)
+static av_always_inline uint8_t colormap_nearest_recursive(const struct color_node *node, const struct color_info *target, const int trans_thresh)
 {
     struct nearest_color res = {.dist_sqd = INT_MAX, .node_pos = -1};
     colormap_nearest_node(node, 0, target, trans_thresh, &res);
@@ -247,17 +262,18 @@  struct stack_node {
     int dx2;
 };
 
-static av_always_inline uint8_t colormap_nearest_iterative(const struct color_node *root, const uint32_t target, const int trans_thresh)
+static av_always_inline uint8_t colormap_nearest_iterative(const struct color_node *root, const struct color_info *target, const int trans_thresh)
 {
-    int pos = 0, best_node_id = -1, best_dist = INT_MAX, cur_color_id = 0;
+    int pos = 0, best_node_id = -1, cur_color_id = 0;
+    float best_dist = FLT_MAX;
     struct stack_node nodes[16];
     struct stack_node *node = &nodes[0];
 
     for (;;) {
 
         const struct color_node *kd = &root[cur_color_id];
-        const uint32_t current = kd->val;
-        const int current_to_target = diff(target, current, trans_thresh);
+        const struct color_info *current = &kd->c;
+        const float current_to_target = diff(target, current, trans_thresh);
 
         /* Compare current color node to the target and update our best node if
          * it's actually better. */
@@ -270,8 +286,7 @@  static av_always_inline uint8_t colormap_nearest_iterative(const struct color_no
 
         /* Check if it's not a leaf */
         if (kd->left_id != -1 || kd->right_id != -1) {
-            const int shift = (2 - kd->split) * 8;
-            const int dx = (target>>shift & 0xff) - (current>>shift & 0xff);
+            const float dx = target->lab[kd->split] - current->lab[kd->split];
             int nearer_kd_id, further_kd_id;
 
             /* Define which side is the most interesting. */
@@ -332,6 +347,7 @@  static av_always_inline int color_get(PaletteUseContext *s, uint32_t color,
                                       const enum color_search_method search_method)
 {
     int i;
+    struct color_info clrinfo;
     const uint8_t rhash = (color>>16) & ((1<<NBITS)-1);
     const uint8_t ghash = (color>> 8) & ((1<<NBITS)-1);
     const uint8_t bhash =  color      & ((1<<NBITS)-1);
@@ -355,7 +371,8 @@  static av_always_inline int color_get(PaletteUseContext *s, uint32_t color,
     if (!e)
         return AVERROR(ENOMEM);
     e->color = color;
-    e->pal_entry = COLORMAP_NEAREST(search_method, s->palette, s->map, color, s->trans_thresh);
+    clrinfo = get_color_from_srgb(color);
+    e->pal_entry = COLORMAP_NEAREST(search_method, s->palette, s->map, &clrinfo, s->trans_thresh);
 
     return e->pal_entry;
 }
@@ -494,20 +511,18 @@  static void disp_node(AVBPrint *buf,
                       int depth)
 {
     const struct color_node *node = &map[node_id];
-    const uint32_t fontcolor = (node->val>>16 & 0xff) > 0x50 &&
-                               (node->val>> 8 & 0xff) > 0x50 &&
-                               (node->val     & 0xff) > 0x50 ? 0 : 0xffffff;
-    const int rgb_comp = node->split;
+    const uint32_t fontcolor = node->c.lab[0] > 0.5 ? 0 : 0xffffff;
+    const int lab_comp = node->split;
     av_bprintf(buf, "%*cnode%d ["
-               "label=\"%c%02X%c%02X%c%02X%c\" "
+               "label=\"%c%.3f%c%.3f%c%.3f%c\" "
                "fillcolor=\"#%06"PRIX32"\" "
                "fontcolor=\"#%06"PRIX32"\"]\n",
                depth*INDENT, ' ', node->palette_id,
-               "[  "[rgb_comp], node->val>>16 & 0xff,
-               "][ "[rgb_comp], node->val>> 8 & 0xff,
-               " ]["[rgb_comp], node->val     & 0xff,
-               "  ]"[rgb_comp],
-               node->val & 0xffffff,
+               "[  "[lab_comp], node->c.lab[0],
+               "][ "[lab_comp], node->c.lab[1],
+               " ]["[lab_comp], node->c.lab[2],
+               "  ]"[lab_comp],
+               node->c.srgb & 0xffffff,
                fontcolor);
     if (parent_id != -1)
         av_bprintf(buf, "%*cnode%d -> node%d\n", depth*INDENT, ' ',
@@ -550,18 +565,18 @@  static int debug_accuracy(const struct color_node *node, const uint32_t *palette
     for (r = 0; r < 256; r++) {
         for (g = 0; g < 256; g++) {
             for (b = 0; b < 256; b++) {
-                const uint32_t argb = 0xff000000 | r<<16 | g<<8 | b;
-                const int r1 = COLORMAP_NEAREST(search_method, palette, node, argb, trans_thresh);
-                const int r2 = colormap_nearest_bruteforce(palette, argb, trans_thresh);
+                const struct color_info target = get_color_from_srgb(0xff000000 | r<<16 | g<<8 | b);
+                const int r1 = COLORMAP_NEAREST(search_method, palette, node, &target, trans_thresh);
+                const int r2 = colormap_nearest_bruteforce(palette, &target, trans_thresh);
                 if (r1 != r2) {
-                    const uint32_t c1 = palette[r1];
-                    const uint32_t c2 = palette[r2];
-                    const int d1 = diff(0xff000000 | c1, argb, trans_thresh);
-                    const int d2 = diff(0xff000000 | c2, argb, trans_thresh);
-                    if (d1 != d2) {
+                    const struct color_info pal_c1 = get_color_from_srgb(0xff000000 | palette[r1]);
+                    const struct color_info pal_c2 = get_color_from_srgb(0xff000000 | palette[r2]);
+                    const float d1 = diff(&pal_c1, &target, trans_thresh);
+                    const float d2 = diff(&pal_c2, &target, trans_thresh);
+                    if (fabsf(d1 - d2) > 0.0001) {
                         av_log(NULL, AV_LOG_ERROR,
-                               "/!\\ %02X%02X%02X: %d ! %d (%06"PRIX32" ! %06"PRIX32") / dist: %d ! %d\n",
-                               r, g, b, r1, r2, c1 & 0xffffff, c2 & 0xffffff, d1, d2);
+                               "/!\\ %02X%02X%02X: %d ! %d (%06"PRIX32" ! %06"PRIX32") / dist: %g ! %g\n",
+                               r, g, b, r1, r2, pal_c1.srgb & 0xffffff, pal_c2.srgb & 0xffffff, d1, d2);
                         ret = 1;
                     }
                 }
@@ -572,66 +587,63 @@  static int debug_accuracy(const struct color_node *node, const uint32_t *palette
 }
 
 struct color {
-    uint32_t value;
+    struct Lab value;
     uint8_t pal_id;
 };
 
 struct color_rect {
-    uint8_t min[3];
-    uint8_t max[3];
+    float min[3];
+    float max[3];
 };
 
 typedef int (*cmp_func)(const void *, const void *);
 
-#define DECLARE_CMP_FUNC(name, pos)                     \
+#define DECLARE_CMP_FUNC(name)                          \
 static int cmp_##name(const void *pa, const void *pb)   \
 {                                                       \
     const struct color *a = pa;                         \
     const struct color *b = pb;                         \
-    return   (int)(a->value >> (8 * (2 - (pos))) & 0xff)     \
-           - (int)(b->value >> (8 * (2 - (pos))) & 0xff);    \
+    return FFDIFFSIGN(a->value.name, b->value.name);    \
 }
 
-DECLARE_CMP_FUNC(r, 0)
-DECLARE_CMP_FUNC(g, 1)
-DECLARE_CMP_FUNC(b, 2)
+DECLARE_CMP_FUNC(L)
+DECLARE_CMP_FUNC(a)
+DECLARE_CMP_FUNC(b)
 
-static const cmp_func cmp_funcs[] = {cmp_r, cmp_g, cmp_b};
+static const cmp_func cmp_funcs[] = {cmp_L, cmp_a, cmp_b};
 
 static int get_next_color(const uint8_t *color_used, const uint32_t *palette,
                           int *component, const struct color_rect *box)
 {
-    int wr, wg, wb;
+    float wL, wa, wb;
     int i, longest = 0;
     unsigned nb_color = 0;
     struct color_rect ranges;
     struct color tmp_pal[256];
     cmp_func cmpf;
 
-    ranges.min[0] = ranges.min[1] = ranges.min[2] = 0xff;
-    ranges.max[0] = ranges.max[1] = ranges.max[2] = 0x00;
+    ranges.min[0] = ranges.min[1] = ranges.min[2] = FLT_MAX;
+    ranges.max[0] = ranges.max[1] = ranges.max[2] = -FLT_MAX;
 
     for (i = 0; i < AVPALETTE_COUNT; i++) {
         const uint32_t c = palette[i];
         const uint8_t a = c >> 24;
-        const uint8_t r = c >> 16 & 0xff;
-        const uint8_t g = c >>  8 & 0xff;
-        const uint8_t b = c       & 0xff;
+        const struct Lab lab = ff_srgb_u8_to_oklab(c);
 
         if (color_used[i] || (a != 0xff) ||
-            r < box->min[0] || g < box->min[1] || b < box->min[2] ||
-            r > box->max[0] || g > box->max[1] || b > box->max[2])
+            lab.L < box->min[0] || lab.a < box->min[1] || lab.b < box->min[2] ||
+            lab.L > box->max[0] || lab.a > box->max[1] || lab.b > box->max[2])
             continue;
 
-        if (r < ranges.min[0]) ranges.min[0] = r;
-        if (g < ranges.min[1]) ranges.min[1] = g;
-        if (b < ranges.min[2]) ranges.min[2] = b;
+        if (lab.L < ranges.min[0]) ranges.min[0] = lab.L;
+        if (lab.a < ranges.min[1]) ranges.min[1] = lab.a;
+        if (lab.b < ranges.min[2]) ranges.min[2] = lab.b;
 
-        if (r > ranges.max[0]) ranges.max[0] = r;
-        if (g > ranges.max[1]) ranges.max[1] = g;
-        if (b > ranges.max[2]) ranges.max[2] = b;
+        if (lab.L > ranges.max[0]) ranges.max[0] = lab.L;
+        if (lab.a > ranges.max[1]) ranges.max[1] = lab.a;
+        if (lab.b > ranges.max[2]) ranges.max[2] = lab.b;
 
-        tmp_pal[nb_color].value  = c;
+        tmp_pal[nb_color].value  = lab;
         tmp_pal[nb_color].pal_id = i;
 
         nb_color++;
@@ -641,12 +653,12 @@  static int get_next_color(const uint8_t *color_used, const uint32_t *palette,
         return -1;
 
     /* define longest axis that will be the split component */
-    wr = ranges.max[0] - ranges.min[0];
-    wg = ranges.max[1] - ranges.min[1];
+    wL = ranges.max[0] - ranges.min[0];
+    wa = ranges.max[1] - ranges.min[1];
     wb = ranges.max[2] - ranges.min[2];
-    if (wr >= wg && wr >= wb) longest = 0;
-    if (wg >= wr && wg >= wb) longest = 1;
-    if (wb >= wr && wb >= wg) longest = 2;
+    if (wb >= wL && wb >= wa) longest = 2;
+    if (wa >= wL && wa >= wb) longest = 1;
+    if (wL >= wa && wL >= wb) longest = 0;
     cmpf = cmp_funcs[longest];
     *component = longest;
 
@@ -663,9 +675,8 @@  static int colormap_insert(struct color_node *map,
                            const int trans_thresh,
                            const struct color_rect *box)
 {
-    uint32_t c;
     int component, cur_id;
-    uint8_t comp_value;
+    float comp_value;
     int node_left_id = -1, node_right_id = -1;
     struct color_node *node;
     struct color_rect box1, box2;
@@ -676,19 +687,18 @@  static int colormap_insert(struct color_node *map,
 
     /* create new node with that color */
     cur_id = (*nb_used)++;
-    c = palette[pal_id];
     node = &map[cur_id];
     node->split = component;
     node->palette_id = pal_id;
-    node->val = c;
+    node->c = get_color_from_srgb(palette[pal_id]);
 
     color_used[pal_id] = 1;
 
     /* get the two boxes this node creates */
     box1 = box2 = *box;
-    comp_value = node->val >> ((2 - component) * 8) & 0xff;
+    comp_value = node->c.lab[component];
     box1.max[component] = comp_value;
-    box2.min[component] = FFMIN(comp_value + 1, 255);
+    box2.min[component] = comp_value + FLT_EPSILON;
 
     node_left_id = colormap_insert(map, color_used, nb_used, palette, trans_thresh, &box1);
 
@@ -735,8 +745,8 @@  static void load_colormap(PaletteUseContext *s)
         }
     }
 
-    box.min[0] = box.min[1] = box.min[2] = 0x00;
-    box.max[0] = box.max[1] = box.max[2] = 0xff;
+    box.min[0] = box.min[1] = box.min[2] = -FLT_MAX;
+    box.max[0] = box.max[1] = box.max[2] = FLT_MAX;
 
     colormap_insert(s->map, color_used, &nb_used, s->palette, s->trans_thresh, &box);
 
@@ -759,15 +769,13 @@  static void debug_mean_error(PaletteUseContext *s, const AVFrame *in1,
     const int src1_linesize = in1->linesize[0] >> 2;
     const int src2_linesize = in2->linesize[0];
     const float div = in1->width * in1->height * 3;
-    unsigned mean_err = 0;
+    float mean_err = 0.f;
 
     for (y = 0; y < in1->height; y++) {
         for (x = 0; x < in1->width; x++) {
-            const uint32_t c1 = src1[x];
-            const uint32_t c2 = palette[src2[x]];
-            const uint32_t argb1 = 0xff000000 | c1;
-            const uint32_t argb2 = 0xff000000 | c2;
-            mean_err += diff(argb1, argb2, s->trans_thresh);
+            const struct color_info c1 = get_color_from_srgb(0xff000000 | src1[x]);
+            const struct color_info c2 = get_color_from_srgb(0xff000000 | palette[src2[x]]);
+            mean_err += diff(&c1, &c2, s->trans_thresh);
         }
         src1 += src1_linesize;
         src2 += src2_linesize;
diff --git a/tests/ref/fate/filter-paletteuse-bayer b/tests/ref/fate/filter-paletteuse-bayer
index 5ca0115053..00c3a07229 100644
--- a/tests/ref/fate/filter-paletteuse-bayer
+++ b/tests/ref/fate/filter-paletteuse-bayer
@@ -3,74 +3,74 @@ 
 #codec_id 0: rawvideo
 #dimensions 0: 320x180
 #sar 0: 1/1
-0,          0,          0,        1,   230400, 0x7b259d08
-0,          1,          1,        1,   230400, 0xf04095e0
-0,          2,          2,        1,   230400, 0x84d49cd5
-0,          3,          3,        1,   230400, 0xd7a29aaf
-0,          4,          4,        1,   230400, 0x9047947c
-0,          5,          5,        1,   230400, 0xfeb990e7
-0,          6,          6,        1,   230400, 0x51ee9295
-0,          7,          7,        1,   230400, 0x66fd4833
-0,          8,          8,        1,   230400, 0x4c0948f0
-0,          9,          9,        1,   230400, 0x632b4776
-0,         10,         10,        1,   230400, 0x7a3c87e2
-0,         11,         11,        1,   230400, 0x4a9286ba
-0,         12,         12,        1,   230400, 0x54dc8649
-0,         13,         13,        1,   230400, 0x92628944
-0,         14,         14,        1,   230400, 0x80f9899f
-0,         15,         15,        1,   230400, 0x5cd78bd8
-0,         16,         16,        1,   230400, 0x4b4ca390
-0,         17,         17,        1,   230400, 0x82cca153
-0,         18,         18,        1,   230400, 0x65f1a2d0
-0,         19,         19,        1,   230400, 0x7df6ae4c
-0,         20,         20,        1,   230400, 0x909baccc
-0,         21,         21,        1,   230400, 0x1892ac65
-0,         22,         22,        1,   230400, 0x3247bb32
-0,         23,         23,        1,   230400, 0x592fbbe5
-0,         24,         24,        1,   230400, 0x189db9d5
-0,         25,         25,        1,   230400, 0x1a38b8da
-0,         26,         26,        1,   230400, 0xccd6bd07
-0,         27,         27,        1,   230400, 0xd4a2bc53
-0,         28,         28,        1,   230400, 0x9ce3bb4e
-0,         29,         29,        1,   230400, 0x5ffdc4db
-0,         30,         30,        1,   230400, 0xc885c7c9
-0,         31,         31,        1,   230400, 0xe27b9d33
-0,         32,         32,        1,   230400, 0xac03a256
-0,         33,         33,        1,   230400, 0xa2c73929
-0,         34,         34,        1,   230400, 0x33793b73
-0,         35,         35,        1,   230400, 0x1e400add
-0,         36,         36,        1,   230400, 0x98e50c6e
-0,         37,         37,        1,   230400, 0x68ed226d
-0,         38,         38,        1,   230400, 0x569e23cb
-0,         39,         39,        1,   230400, 0x82bf3fc0
-0,         40,         40,        1,   230400, 0x2b202e86
-0,         41,         41,        1,   230400, 0x7acd2dee
-0,         42,         42,        1,   230400, 0xfe872e42
-0,         43,         43,        1,   230400, 0x026c12e5
-0,         44,         44,        1,   230400, 0x81561399
-0,         45,         45,        1,   230400, 0xa08c13b6
-0,         46,         46,        1,   230400, 0x89e712f5
-0,         47,         47,        1,   230400, 0x569011ac
-0,         48,         48,        1,   230400, 0xd4691112
-0,         49,         49,        1,   230400, 0x2e50165a
-0,         50,         50,        1,   230400, 0x0a1215b6
-0,         51,         51,        1,   230400, 0x3c5316e3
-0,         52,         52,        1,   230400, 0x079c1393
-0,         53,         53,        1,   230400, 0x39ca1c48
-0,         54,         54,        1,   230400, 0xe27f199c
-0,         55,         55,        1,   230400, 0x10ab1bab
-0,         56,         56,        1,   230400, 0xeab017c3
-0,         57,         57,        1,   230400, 0x5f701f77
-0,         58,         58,        1,   230400, 0x01371d7d
-0,         59,         59,        1,   230400, 0x22751e99
-0,         60,         60,        1,   230400, 0xaee91a97
-0,         61,         61,        1,   230400, 0x27b41f32
-0,         62,         62,        1,   230400, 0x4ff32bb1
-0,         63,         63,        1,   230400, 0x86e02864
-0,         64,         64,        1,   230400, 0x5eb52b3e
-0,         65,         65,        1,   230400, 0xd9252ba8
-0,         66,         66,        1,   230400, 0x72232d9b
-0,         67,         67,        1,   230400, 0x599a206f
-0,         68,         68,        1,   230400, 0x4d2c1ca5
-0,         69,         69,        1,   230400, 0x9166293b
-0,         70,         70,        1,   230400, 0x00992453
+0,          0,          0,        1,   230400, 0xb10296af
+0,          1,          1,        1,   230400, 0x46299027
+0,          2,          2,        1,   230400, 0xe0209504
+0,          3,          3,        1,   230400, 0xfe8e93a0
+0,          4,          4,        1,   230400, 0x3ec88da3
+0,          5,          5,        1,   230400, 0x06918aaa
+0,          6,          6,        1,   230400, 0x215a8ba4
+0,          7,          7,        1,   230400, 0x74614048
+0,          8,          8,        1,   230400, 0xe46a409e
+0,          9,          9,        1,   230400, 0x20834060
+0,         10,         10,        1,   230400, 0x29258036
+0,         11,         11,        1,   230400, 0x16207f8b
+0,         12,         12,        1,   230400, 0x90dc7e61
+0,         13,         13,        1,   230400, 0x59937f90
+0,         14,         14,        1,   230400, 0x6a487fe8
+0,         15,         15,        1,   230400, 0x73e98214
+0,         16,         16,        1,   230400, 0x48119a78
+0,         17,         17,        1,   230400, 0x999899df
+0,         18,         18,        1,   230400, 0x0d7f9b24
+0,         19,         19,        1,   230400, 0xc581a5b7
+0,         20,         20,        1,   230400, 0xaf1ea56f
+0,         21,         21,        1,   230400, 0xe010a52c
+0,         22,         22,        1,   230400, 0x8eacb3ab
+0,         23,         23,        1,   230400, 0x9e60b383
+0,         24,         24,        1,   230400, 0x69aeb25b
+0,         25,         25,        1,   230400, 0x1febb1e1
+0,         26,         26,        1,   230400, 0x5d65b4e0
+0,         27,         27,        1,   230400, 0x79ecb43f
+0,         28,         28,        1,   230400, 0x3c3eb35a
+0,         29,         29,        1,   230400, 0xb96cc086
+0,         30,         30,        1,   230400, 0x07b0c1ba
+0,         31,         31,        1,   230400, 0xe3c798ae
+0,         32,         32,        1,   230400, 0xf7389e03
+0,         33,         33,        1,   230400, 0x63222e23
+0,         34,         34,        1,   230400, 0xbe063030
+0,         35,         35,        1,   230400, 0x2819fdf3
+0,         36,         36,        1,   230400, 0x7e0bfef1
+0,         37,         37,        1,   230400, 0xee321a8b
+0,         38,         38,        1,   230400, 0x5fce1a96
+0,         39,         39,        1,   230400, 0x530a35a4
+0,         40,         40,        1,   230400, 0xa5ce2647
+0,         41,         41,        1,   230400, 0x969a25d4
+0,         42,         42,        1,   230400, 0x4f012620
+0,         43,         43,        1,   230400, 0x50bc0870
+0,         44,         44,        1,   230400, 0xc6de08a6
+0,         45,         45,        1,   230400, 0xe08b092e
+0,         46,         46,        1,   230400, 0x9a6a08d7
+0,         47,         47,        1,   230400, 0x788d074c
+0,         48,         48,        1,   230400, 0x08124376
+0,         49,         49,        1,   230400, 0xcb3748ed
+0,         50,         50,        1,   230400, 0x33e747f1
+0,         51,         51,        1,   230400, 0x9a2f4994
+0,         52,         52,        1,   230400, 0x501246e6
+0,         53,         53,        1,   230400, 0x11644de9
+0,         54,         54,        1,   230400, 0xef294aca
+0,         55,         55,        1,   230400, 0x3ade4cb3
+0,         56,         56,        1,   230400, 0x56954a34
+0,         57,         57,        1,   230400, 0x513e4feb
+0,         58,         58,        1,   230400, 0x828f4ea6
+0,         59,         59,        1,   230400, 0x76b04fc7
+0,         60,         60,        1,   230400, 0x67434c78
+0,         61,         61,        1,   230400, 0xf05250fd
+0,         62,         62,        1,   230400, 0xf4cd5ac5
+0,         63,         63,        1,   230400, 0x4e4056d9
+0,         64,         64,        1,   230400, 0x6af258fa
+0,         65,         65,        1,   230400, 0xa4525a55
+0,         66,         66,        1,   230400, 0xf3c15c01
+0,         67,         67,        1,   230400, 0x407553ae
+0,         68,         68,        1,   230400, 0x913e5009
+0,         69,         69,        1,   230400, 0x7fe95b6b
+0,         70,         70,        1,   230400, 0x24cb57fe
diff --git a/tests/ref/fate/filter-paletteuse-bayer0 b/tests/ref/fate/filter-paletteuse-bayer0
index 85b3832f19..b7b80257d6 100644
--- a/tests/ref/fate/filter-paletteuse-bayer0
+++ b/tests/ref/fate/filter-paletteuse-bayer0
@@ -3,74 +3,74 @@ 
 #codec_id 0: rawvideo
 #dimensions 0: 320x180
 #sar 0: 1/1
-0,          0,          0,        1,   230400, 0xfb6042d2
-0,          1,          1,        1,   230400, 0x1c193c09
-0,          2,          2,        1,   230400, 0x183442f8
-0,          3,          3,        1,   230400, 0xa9634084
-0,          4,          4,        1,   230400, 0x90df3d2f
-0,          5,          5,        1,   230400, 0x59d7389f
-0,          6,          6,        1,   230400, 0xb9bd3a30
-0,          7,          7,        1,   230400, 0x9874ee38
-0,          8,          8,        1,   230400, 0xf661f01f
-0,          9,          9,        1,   230400, 0xacbcedbd
-0,         10,         10,        1,   230400, 0x05f02d59
-0,         11,         11,        1,   230400, 0xc54c2cc8
-0,         12,         12,        1,   230400, 0x19c92d61
-0,         13,         13,        1,   230400, 0x14902fb2
-0,         14,         14,        1,   230400, 0x99b62fb6
-0,         15,         15,        1,   230400, 0x3fc63293
-0,         16,         16,        1,   230400, 0x1eed4b38
-0,         17,         17,        1,   230400, 0xe9d747e0
-0,         18,         18,        1,   230400, 0x9825496f
-0,         19,         19,        1,   230400, 0x94625411
-0,         20,         20,        1,   230400, 0xed7052a3
-0,         21,         21,        1,   230400, 0x80d552dc
-0,         22,         22,        1,   230400, 0x89b360bb
-0,         23,         23,        1,   230400, 0xee9a616a
-0,         24,         24,        1,   230400, 0x30bb5f86
-0,         25,         25,        1,   230400, 0x5ec15eae
-0,         26,         26,        1,   230400, 0x0956633e
-0,         27,         27,        1,   230400, 0x72df62fa
-0,         28,         28,        1,   230400, 0xbafd61d0
-0,         29,         29,        1,   230400, 0x393f81f3
-0,         30,         30,        1,   230400, 0xba6a848c
-0,         31,         31,        1,   230400, 0x502ba0d9
-0,         32,         32,        1,   230400, 0xc81ba71d
-0,         33,         33,        1,   230400, 0x54cdf270
-0,         34,         34,        1,   230400, 0xe951f3e2
-0,         35,         35,        1,   230400, 0xbf15baa1
-0,         36,         36,        1,   230400, 0xbf96bb12
-0,         37,         37,        1,   230400, 0xcdd5cafe
-0,         38,         38,        1,   230400, 0x97b1cbb4
-0,         39,         39,        1,   230400, 0x955ae28f
-0,         40,         40,        1,   230400, 0x6a8dd28f
-0,         41,         41,        1,   230400, 0x8f02d268
-0,         42,         42,        1,   230400, 0x3075d269
-0,         43,         43,        1,   230400, 0x29e8b910
-0,         44,         44,        1,   230400, 0xb35ab888
-0,         45,         45,        1,   230400, 0xc3afb942
-0,         46,         46,        1,   230400, 0xeba8b860
-0,         47,         47,        1,   230400, 0x5de8b7ab
-0,         48,         48,        1,   230400, 0x90233679
-0,         49,         49,        1,   230400, 0x5fbc3abb
-0,         50,         50,        1,   230400, 0xeaa73b87
-0,         51,         51,        1,   230400, 0xbd0a3c4b
-0,         52,         52,        1,   230400, 0xeddb39ba
-0,         53,         53,        1,   230400, 0x269d4131
-0,         54,         54,        1,   230400, 0xae3e3e8c
-0,         55,         55,        1,   230400, 0x65f54056
-0,         56,         56,        1,   230400, 0xf2173c5b
-0,         57,         57,        1,   230400, 0xbd714477
-0,         58,         58,        1,   230400, 0xb60c42ed
-0,         59,         59,        1,   230400, 0x8def43a5
-0,         60,         60,        1,   230400, 0xe6a73f05
-0,         61,         61,        1,   230400, 0xedfe4430
-0,         62,         62,        1,   230400, 0x76c5505a
-0,         63,         63,        1,   230400, 0xf48d4d04
-0,         64,         64,        1,   230400, 0xa49950b5
-0,         65,         65,        1,   230400, 0xc64d51d8
-0,         66,         66,        1,   230400, 0xa08253ec
-0,         67,         67,        1,   230400, 0xd6ef4609
-0,         68,         68,        1,   230400, 0x27a241e7
-0,         69,         69,        1,   230400, 0xe5f74b4a
-0,         70,         70,        1,   230400, 0xb0194751
+0,          0,          0,        1,   230400, 0x01fe2d8a
+0,          1,          1,        1,   230400, 0x6f4627f6
+0,          2,          2,        1,   230400, 0xce492cae
+0,          3,          3,        1,   230400, 0x95bf2b0e
+0,          4,          4,        1,   230400, 0x4d212758
+0,          5,          5,        1,   230400, 0xfddd244c
+0,          6,          6,        1,   230400, 0x2bdc258d
+0,          7,          7,        1,   230400, 0x98bedba9
+0,          8,          8,        1,   230400, 0x1708dd0a
+0,          9,          9,        1,   230400, 0xff3ddc41
+0,         10,         10,        1,   230400, 0xed4318e1
+0,         11,         11,        1,   230400, 0xb38718ac
+0,         12,         12,        1,   230400, 0x0789190e
+0,         13,         13,        1,   230400, 0x5f271ae5
+0,         14,         14,        1,   230400, 0x76651b29
+0,         15,         15,        1,   230400, 0x6c301d7c
+0,         16,         16,        1,   230400, 0xb62d3725
+0,         17,         17,        1,   230400, 0x54dc33c3
+0,         18,         18,        1,   230400, 0xa9ee3569
+0,         19,         19,        1,   230400, 0xf6d23cec
+0,         20,         20,        1,   230400, 0xdcad3c8a
+0,         21,         21,        1,   230400, 0x00363bf2
+0,         22,         22,        1,   230400, 0xd12d4957
+0,         23,         23,        1,   230400, 0xab8c49a6
+0,         24,         24,        1,   230400, 0x1ad84813
+0,         25,         25,        1,   230400, 0xabd9478b
+0,         26,         26,        1,   230400, 0x12e14baf
+0,         27,         27,        1,   230400, 0x9ee14ae0
+0,         28,         28,        1,   230400, 0xd12449c8
+0,         29,         29,        1,   230400, 0x0e2a6b56
+0,         30,         30,        1,   230400, 0xe8576d6f
+0,         31,         31,        1,   230400, 0x37d98437
+0,         32,         32,        1,   230400, 0xb289885b
+0,         33,         33,        1,   230400, 0x0089d63d
+0,         34,         34,        1,   230400, 0x0014d741
+0,         35,         35,        1,   230400, 0x5a7fa00f
+0,         36,         36,        1,   230400, 0x7b6fa0fe
+0,         37,         37,        1,   230400, 0xf282b3cf
+0,         38,         38,        1,   230400, 0xc677b478
+0,         39,         39,        1,   230400, 0x8baec95a
+0,         40,         40,        1,   230400, 0x6983b858
+0,         41,         41,        1,   230400, 0x465eb79e
+0,         42,         42,        1,   230400, 0x5e30b848
+0,         43,         43,        1,   230400, 0x910e9ed3
+0,         44,         44,        1,   230400, 0x5f3e9f2d
+0,         45,         45,        1,   230400, 0xccf39fbf
+0,         46,         46,        1,   230400, 0x781a9f7d
+0,         47,         47,        1,   230400, 0x59e49e00
+0,         48,         48,        1,   230400, 0xe7c97e5b
+0,         49,         49,        1,   230400, 0xda7e838b
+0,         50,         50,        1,   230400, 0x34088343
+0,         51,         51,        1,   230400, 0x731b844c
+0,         52,         52,        1,   230400, 0x8e1581fc
+0,         53,         53,        1,   230400, 0x51d888c0
+0,         54,         54,        1,   230400, 0x461185dd
+0,         55,         55,        1,   230400, 0xc933880d
+0,         56,         56,        1,   230400, 0xb9c28413
+0,         57,         57,        1,   230400, 0x33f08cbc
+0,         58,         58,        1,   230400, 0x02688a80
+0,         59,         59,        1,   230400, 0x424c8b6a
+0,         60,         60,        1,   230400, 0xf1288742
+0,         61,         61,        1,   230400, 0x4780898b
+0,         62,         62,        1,   230400, 0xfbd59439
+0,         63,         63,        1,   230400, 0x770d9032
+0,         64,         64,        1,   230400, 0x53b99251
+0,         65,         65,        1,   230400, 0x8de79376
+0,         66,         66,        1,   230400, 0x292a95c3
+0,         67,         67,        1,   230400, 0x60dc8b46
+0,         68,         68,        1,   230400, 0xeb4288ca
+0,         69,         69,        1,   230400, 0xb9da9475
+0,         70,         70,        1,   230400, 0xc524912c
diff --git a/tests/ref/fate/filter-paletteuse-nodither b/tests/ref/fate/filter-paletteuse-nodither
index a2e61c3690..2e49c90642 100644
--- a/tests/ref/fate/filter-paletteuse-nodither
+++ b/tests/ref/fate/filter-paletteuse-nodither
@@ -3,74 +3,74 @@ 
 #codec_id 0: rawvideo
 #dimensions 0: 320x180
 #sar 0: 1/1
-0,          0,          0,        1,   230400, 0x690560cb
-0,          1,          1,        1,   230400, 0x197a5a54
-0,          2,          2,        1,   230400, 0x665961db
-0,          3,          3,        1,   230400, 0xce0b5fa8
-0,          4,          4,        1,   230400, 0xa40e5cb0
-0,          5,          5,        1,   230400, 0xa5aa58da
-0,          6,          6,        1,   230400, 0x8e0259bb
-0,          7,          7,        1,   230400, 0x476d0dba
-0,          8,          8,        1,   230400, 0xfb1b0e8c
-0,          9,          9,        1,   230400, 0x50f60d3b
-0,         10,         10,        1,   230400, 0x12cd4bab
-0,         11,         11,        1,   230400, 0x4c274b13
-0,         12,         12,        1,   230400, 0xea494b0a
-0,         13,         13,        1,   230400, 0x118c4cc1
-0,         14,         14,        1,   230400, 0xd4224db7
-0,         15,         15,        1,   230400, 0xc3014f88
-0,         16,         16,        1,   230400, 0xe07a6838
-0,         17,         17,        1,   230400, 0x1b97659a
-0,         18,         18,        1,   230400, 0xf104670c
-0,         19,         19,        1,   230400, 0x7b63733d
-0,         20,         20,        1,   230400, 0x2c237200
-0,         21,         21,        1,   230400, 0x775d7248
-0,         22,         22,        1,   230400, 0xcaee7f9e
-0,         23,         23,        1,   230400, 0x4e4680a1
-0,         24,         24,        1,   230400, 0x21fb7e53
-0,         25,         25,        1,   230400, 0xf0297db6
-0,         26,         26,        1,   230400, 0x79a9829d
-0,         27,         27,        1,   230400, 0x8ccb80f7
-0,         28,         28,        1,   230400, 0xf4dd807f
-0,         29,         29,        1,   230400, 0xb6cc8696
-0,         30,         30,        1,   230400, 0x6c8a8917
-0,         31,         31,        1,   230400, 0x9e08615a
-0,         32,         32,        1,   230400, 0xc098685b
-0,         33,         33,        1,   230400, 0x5c09e710
-0,         34,         34,        1,   230400, 0xe4c4e9be
-0,         35,         35,        1,   230400, 0xac59c150
-0,         36,         36,        1,   230400, 0x6045c272
-0,         37,         37,        1,   230400, 0xf71ee6dc
-0,         38,         38,        1,   230400, 0xc82ce6f6
-0,         39,         39,        1,   230400, 0xb7ed039a
-0,         40,         40,        1,   230400, 0xda93f241
-0,         41,         41,        1,   230400, 0x194bf23b
-0,         42,         42,        1,   230400, 0xe7e6f2e2
-0,         43,         43,        1,   230400, 0xe479d834
-0,         44,         44,        1,   230400, 0xefdfd87e
-0,         45,         45,        1,   230400, 0xec66d8c0
-0,         46,         46,        1,   230400, 0x3a6bd81b
-0,         47,         47,        1,   230400, 0xb5d1d700
-0,         48,         48,        1,   230400, 0x3bc69e8b
-0,         49,         49,        1,   230400, 0x723fa455
-0,         50,         50,        1,   230400, 0x7c49a392
-0,         51,         51,        1,   230400, 0x272ea4b7
-0,         52,         52,        1,   230400, 0xebdda081
-0,         53,         53,        1,   230400, 0xfd26ab99
-0,         54,         54,        1,   230400, 0xfa02a891
-0,         55,         55,        1,   230400, 0xda2caa7f
-0,         56,         56,        1,   230400, 0x2360a611
-0,         57,         57,        1,   230400, 0xaa3baefd
-0,         58,         58,        1,   230400, 0x0961ad5c
-0,         59,         59,        1,   230400, 0x48d2ae47
-0,         60,         60,        1,   230400, 0x20eda81b
-0,         61,         61,        1,   230400, 0x8821adbb
-0,         62,         62,        1,   230400, 0x1150b810
-0,         63,         63,        1,   230400, 0x08dab596
-0,         64,         64,        1,   230400, 0x4731b7a5
-0,         65,         65,        1,   230400, 0xf382b87e
-0,         66,         66,        1,   230400, 0xdba7bac2
-0,         67,         67,        1,   230400, 0xf569acf9
-0,         68,         68,        1,   230400, 0x22d8a95d
-0,         69,         69,        1,   230400, 0xed0bb4fb
-0,         70,         70,        1,   230400, 0x2dccb218
+0,          0,          0,        1,   230400, 0xda3668c3
+0,          1,          1,        1,   230400, 0xe38c63c9
+0,          2,          2,        1,   230400, 0xc3e56916
+0,          3,          3,        1,   230400, 0x8ce566f1
+0,          4,          4,        1,   230400, 0x99b2640a
+0,          5,          5,        1,   230400, 0xa5066135
+0,          6,          6,        1,   230400, 0x35616241
+0,          7,          7,        1,   230400, 0x745a16de
+0,          8,          8,        1,   230400, 0x53af17d6
+0,          9,          9,        1,   230400, 0x566416cb
+0,         10,         10,        1,   230400, 0x8244546a
+0,         11,         11,        1,   230400, 0x214353d6
+0,         12,         12,        1,   230400, 0xdf925444
+0,         13,         13,        1,   230400, 0xc248565a
+0,         14,         14,        1,   230400, 0x2fa85718
+0,         15,         15,        1,   230400, 0x520b5943
+0,         16,         16,        1,   230400, 0xc4cf70cb
+0,         17,         17,        1,   230400, 0x3a6270db
+0,         18,         18,        1,   230400, 0xf7bd71e3
+0,         19,         19,        1,   230400, 0x12807d95
+0,         20,         20,        1,   230400, 0x332f7c3f
+0,         21,         21,        1,   230400, 0xcf4c7c0f
+0,         22,         22,        1,   230400, 0x911f8a0e
+0,         23,         23,        1,   230400, 0x3e228a70
+0,         24,         24,        1,   230400, 0x61c988ac
+0,         25,         25,        1,   230400, 0xb0858866
+0,         26,         26,        1,   230400, 0x57de8c17
+0,         27,         27,        1,   230400, 0x4bfc8ac8
+0,         28,         28,        1,   230400, 0x74a489e5
+0,         29,         29,        1,   230400, 0xdb5490df
+0,         30,         30,        1,   230400, 0x776292cf
+0,         31,         31,        1,   230400, 0xae486ba1
+0,         32,         32,        1,   230400, 0x6e3f707d
+0,         33,         33,        1,   230400, 0x263bfbca
+0,         34,         34,        1,   230400, 0xe1d7fdc4
+0,         35,         35,        1,   230400, 0xdc58c970
+0,         36,         36,        1,   230400, 0x74d4cb3c
+0,         37,         37,        1,   230400, 0x18d9ec35
+0,         38,         38,        1,   230400, 0x3760ec21
+0,         39,         39,        1,   230400, 0xc4fe0800
+0,         40,         40,        1,   230400, 0xa455f91a
+0,         41,         41,        1,   230400, 0xce4bf7e4
+0,         42,         42,        1,   230400, 0xeafef8f9
+0,         43,         43,        1,   230400, 0x4ab1df5d
+0,         44,         44,        1,   230400, 0x97d6df79
+0,         45,         45,        1,   230400, 0x1b64e00c
+0,         46,         46,        1,   230400, 0x5f33df02
+0,         47,         47,        1,   230400, 0x1badde2f
+0,         48,         48,        1,   230400, 0xac7fba78
+0,         49,         49,        1,   230400, 0xe945bf9c
+0,         50,         50,        1,   230400, 0x8ce6bed7
+0,         51,         51,        1,   230400, 0x209abff6
+0,         52,         52,        1,   230400, 0x229dbcb3
+0,         53,         53,        1,   230400, 0xb3ccc5f7
+0,         54,         54,        1,   230400, 0x9d9dc246
+0,         55,         55,        1,   230400, 0x8bbec364
+0,         56,         56,        1,   230400, 0x3699c05f
+0,         57,         57,        1,   230400, 0x37b7c94b
+0,         58,         58,        1,   230400, 0x7c91c7e8
+0,         59,         59,        1,   230400, 0xc7dfc81c
+0,         60,         60,        1,   230400, 0x3d6dc2b3
+0,         61,         61,        1,   230400, 0x1a80c7d8
+0,         62,         62,        1,   230400, 0xabced0e4
+0,         63,         63,        1,   230400, 0x922fcdfd
+0,         64,         64,        1,   230400, 0x251ad0b1
+0,         65,         65,        1,   230400, 0xde2cd0df
+0,         66,         66,        1,   230400, 0x74d2d3f4
+0,         67,         67,        1,   230400, 0x0bb5c9c1
+0,         68,         68,        1,   230400, 0x312dc634
+0,         69,         69,        1,   230400, 0x499bd13c
+0,         70,         70,        1,   230400, 0x8ec5cf57
diff --git a/tests/ref/fate/filter-paletteuse-sierra2_4a b/tests/ref/fate/filter-paletteuse-sierra2_4a
index d257820a32..e654a5c8f3 100644
--- a/tests/ref/fate/filter-paletteuse-sierra2_4a
+++ b/tests/ref/fate/filter-paletteuse-sierra2_4a
@@ -3,74 +3,74 @@ 
 #codec_id 0: rawvideo
 #dimensions 0: 320x180
 #sar 0: 1/1
-0,          0,          0,        1,   230400, 0xa4f85758
-0,          1,          1,        1,   230400, 0xbe83505c
-0,          2,          2,        1,   230400, 0x0a09584e
-0,          3,          3,        1,   230400, 0xd2065629
-0,          4,          4,        1,   230400, 0x11eb5319
-0,          5,          5,        1,   230400, 0x61024f4c
-0,          6,          6,        1,   230400, 0xd5384faa
-0,          7,          7,        1,   230400, 0xdeae0343
-0,          8,          8,        1,   230400, 0xcb640541
-0,          9,          9,        1,   230400, 0xea2602c3
-0,         10,         10,        1,   230400, 0xa7974293
-0,         11,         11,        1,   230400, 0x67cd4287
-0,         12,         12,        1,   230400, 0x83fa437a
-0,         13,         13,        1,   230400, 0x852b42bf
-0,         14,         14,        1,   230400, 0x6d2d434c
-0,         15,         15,        1,   230400, 0x20c44629
-0,         16,         16,        1,   230400, 0xf2a35f57
-0,         17,         17,        1,   230400, 0x232959ec
-0,         18,         18,        1,   230400, 0x1f8e5c48
-0,         19,         19,        1,   230400, 0x88dc69bd
-0,         20,         20,        1,   230400, 0x4b6866f3
-0,         21,         21,        1,   230400, 0xe8f966dc
-0,         22,         22,        1,   230400, 0xe0877466
-0,         23,         23,        1,   230400, 0x8799748c
-0,         24,         24,        1,   230400, 0xcab871bc
-0,         25,         25,        1,   230400, 0x2e0372b4
-0,         26,         26,        1,   230400, 0x15fb77d5
-0,         27,         27,        1,   230400, 0xbadf75fc
-0,         28,         28,        1,   230400, 0xa4977626
-0,         29,         29,        1,   230400, 0x5b987943
-0,         30,         30,        1,   230400, 0x9ed57c09
-0,         31,         31,        1,   230400, 0x565d5105
-0,         32,         32,        1,   230400, 0x901b5a07
-0,         33,         33,        1,   230400, 0x8dc4e9a8
-0,         34,         34,        1,   230400, 0x0b9cee1c
-0,         35,         35,        1,   230400, 0x2bcdbe37
-0,         36,         36,        1,   230400, 0xf3e2bf71
-0,         37,         37,        1,   230400, 0xb718da67
-0,         38,         38,        1,   230400, 0x8f59da64
-0,         39,         39,        1,   230400, 0x8812f9aa
-0,         40,         40,        1,   230400, 0xe0dae6a3
-0,         41,         41,        1,   230400, 0xd2c7e5b7
-0,         42,         42,        1,   230400, 0xea2ae5d2
-0,         43,         43,        1,   230400, 0x2d66ca25
-0,         44,         44,        1,   230400, 0xf0d3cac6
-0,         45,         45,        1,   230400, 0xb9acccac
-0,         46,         46,        1,   230400, 0x8523ca4a
-0,         47,         47,        1,   230400, 0x92b9c9ef
-0,         48,         48,        1,   230400, 0x0a88946e
-0,         49,         49,        1,   230400, 0xe33699b8
-0,         50,         50,        1,   230400, 0x5e7b9917
-0,         51,         51,        1,   230400, 0xdac99998
-0,         52,         52,        1,   230400, 0xb5c995fc
-0,         53,         53,        1,   230400, 0x908b9f50
-0,         54,         54,        1,   230400, 0x60d59ced
-0,         55,         55,        1,   230400, 0x212e9f55
-0,         56,         56,        1,   230400, 0x95e69b2a
-0,         57,         57,        1,   230400, 0x6c38a34a
-0,         58,         58,        1,   230400, 0xeb32a103
-0,         59,         59,        1,   230400, 0x0131a1b7
-0,         60,         60,        1,   230400, 0xd59b9c4e
-0,         61,         61,        1,   230400, 0x2fc0a13f
-0,         62,         62,        1,   230400, 0x7a40adf9
-0,         63,         63,        1,   230400, 0x5cdbab2f
-0,         64,         64,        1,   230400, 0xcdc0ada8
-0,         65,         65,        1,   230400, 0x2f5faf32
-0,         66,         66,        1,   230400, 0xd463b224
-0,         67,         67,        1,   230400, 0xe337a2d5
-0,         68,         68,        1,   230400, 0xe775a0c1
-0,         69,         69,        1,   230400, 0x726aab49
-0,         70,         70,        1,   230400, 0x74dda81e
+0,          0,          0,        1,   230400, 0x020e46e2
+0,          1,          1,        1,   230400, 0x2e5b3ece
+0,          2,          2,        1,   230400, 0xc2a8456d
+0,          3,          3,        1,   230400, 0xd91341d5
+0,          4,          4,        1,   230400, 0xf46a3f61
+0,          5,          5,        1,   230400, 0x9ef53c6e
+0,          6,          6,        1,   230400, 0xe5803ec3
+0,          7,          7,        1,   230400, 0xb6f6f233
+0,          8,          8,        1,   230400, 0x2f84f2af
+0,          9,          9,        1,   230400, 0x690bf214
+0,         10,         10,        1,   230400, 0x358531c8
+0,         11,         11,        1,   230400, 0x5f8a3093
+0,         12,         12,        1,   230400, 0x1a17321d
+0,         13,         13,        1,   230400, 0xf088328d
+0,         14,         14,        1,   230400, 0x5e2731fe
+0,         15,         15,        1,   230400, 0x17e03504
+0,         16,         16,        1,   230400, 0x2fad4ec8
+0,         17,         17,        1,   230400, 0x6a514ce8
+0,         18,         18,        1,   230400, 0x213c4e3e
+0,         19,         19,        1,   230400, 0x520c59b2
+0,         20,         20,        1,   230400, 0x853a583a
+0,         21,         21,        1,   230400, 0xdb1456a9
+0,         22,         22,        1,   230400, 0xfe0863eb
+0,         23,         23,        1,   230400, 0x57906589
+0,         24,         24,        1,   230400, 0xeb5063f3
+0,         25,         25,        1,   230400, 0x4a1f6338
+0,         26,         26,        1,   230400, 0x46ff6867
+0,         27,         27,        1,   230400, 0x59e2666e
+0,         28,         28,        1,   230400, 0x8f22656f
+0,         29,         29,        1,   230400, 0x1079673d
+0,         30,         30,        1,   230400, 0xbe566ad0
+0,         31,         31,        1,   230400, 0xb5454233
+0,         32,         32,        1,   230400, 0x241a48c2
+0,         33,         33,        1,   230400, 0x16dddaf2
+0,         34,         34,        1,   230400, 0xb2addfae
+0,         35,         35,        1,   230400, 0x78ccaeda
+0,         36,         36,        1,   230400, 0x3e27ad31
+0,         37,         37,        1,   230400, 0x7384c6b3
+0,         38,         38,        1,   230400, 0xea3ac6a5
+0,         39,         39,        1,   230400, 0x651be84a
+0,         40,         40,        1,   230400, 0x46a6d505
+0,         41,         41,        1,   230400, 0xbe48d2fb
+0,         42,         42,        1,   230400, 0x6addd4c8
+0,         43,         43,        1,   230400, 0xc6a6b808
+0,         44,         44,        1,   230400, 0xb909b874
+0,         45,         45,        1,   230400, 0xf915b8e8
+0,         46,         46,        1,   230400, 0x467fb903
+0,         47,         47,        1,   230400, 0x7865b875
+0,         48,         48,        1,   230400, 0x1125af18
+0,         49,         49,        1,   230400, 0xf390b5ef
+0,         50,         50,        1,   230400, 0xbc76b349
+0,         51,         51,        1,   230400, 0x8426b721
+0,         52,         52,        1,   230400, 0x5b67b444
+0,         53,         53,        1,   230400, 0x4388bb8b
+0,         54,         54,        1,   230400, 0xdb06b95d
+0,         55,         55,        1,   230400, 0xc192bc26
+0,         56,         56,        1,   230400, 0x2b62b745
+0,         57,         57,        1,   230400, 0x7e3ec04f
+0,         58,         58,        1,   230400, 0x4954bdec
+0,         59,         59,        1,   230400, 0x988bbe84
+0,         60,         60,        1,   230400, 0xeb6bba83
+0,         61,         61,        1,   230400, 0x5610c02c
+0,         62,         62,        1,   230400, 0x7d76cac6
+0,         63,         63,        1,   230400, 0xcfa4c72d
+0,         64,         64,        1,   230400, 0x9c7cc904
+0,         65,         65,        1,   230400, 0xdda0c95a
+0,         66,         66,        1,   230400, 0xe9c0cc0f
+0,         67,         67,        1,   230400, 0x45abbf0d
+0,         68,         68,        1,   230400, 0x4a6eb99f
+0,         69,         69,        1,   230400, 0x7337c806
+0,         70,         70,        1,   230400, 0xf143c589