]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vf_paletteuse.c
Merge commit '5f5b78aca35d07c771f5c4c73a984be9fe04a0b8'
[ffmpeg] / libavfilter / vf_paletteuse.c
index 977d63a09167a69e9466d8b835e65485c1341aae..8835d8b21cffef1eb26ea667b328e2ee506a5930 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "libavutil/bprint.h"
 #include "libavutil/opt.h"
+#include "libavutil/qsort.h"
 #include "dualinput.h"
 #include "avfilter.h"
 
@@ -315,11 +316,11 @@ end:
  * Note: r, g, and b are the component of c but are passed as well to avoid
  * recomputing them (they are generally computed by the caller for other uses).
  */
-static av_always_inline uint8_t color_get(struct cache_node *cache, uint32_t color,
-                                          uint8_t r, uint8_t g, uint8_t b,
-                                          const struct color_node *map,
-                                          const uint32_t *palette,
-                                          const enum color_search_method search_method)
+static av_always_inline int color_get(struct cache_node *cache, uint32_t color,
+                                      uint8_t r, uint8_t g, uint8_t b,
+                                      const struct color_node *map,
+                                      const uint32_t *palette,
+                                      const enum color_search_method search_method)
 {
     int i;
     const uint8_t rgb[] = {r, g, b};
@@ -345,16 +346,16 @@ static av_always_inline uint8_t color_get(struct cache_node *cache, uint32_t col
     return e->pal_entry;
 }
 
-static av_always_inline uint8_t get_dst_color_err(struct cache_node *cache,
-                                                  uint32_t c, const struct color_node *map,
-                                                  const uint32_t *palette,
-                                                  int *er, int *eg, int *eb,
-                                                  const enum color_search_method search_method)
+static av_always_inline int get_dst_color_err(struct cache_node *cache,
+                                              uint32_t c, const struct color_node *map,
+                                              const uint32_t *palette,
+                                              int *er, int *eg, int *eb,
+                                              const enum color_search_method search_method)
 {
     const uint8_t r = c >> 16 & 0xff;
     const uint8_t g = c >>  8 & 0xff;
     const uint8_t b = c       & 0xff;
-    const uint8_t dstx = color_get(cache, c, r, g, b, map, palette, search_method);
+    const int dstx = color_get(cache, c, r, g, b, map, palette, search_method);
     const uint32_t dstc = palette[dstx];
     *er = r - (dstc >> 16 & 0xff);
     *eg = g - (dstc >>  8 & 0xff);
@@ -592,6 +593,7 @@ static int get_next_color(const uint8_t *color_used, const uint32_t *palette,
     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;
@@ -631,10 +633,11 @@ static int get_next_color(const uint8_t *color_used, const uint32_t *palette,
     if (wr >= wg && wr >= wb) longest = 0;
     if (wg >= wr && wg >= wb) longest = 1;
     if (wb >= wr && wb >= wg) longest = 2;
+    cmpf = cmp_funcs[longest];
     *component = longest;
 
     /* sort along this axis to get median */
-    qsort(tmp_pal, nb_color, sizeof(*tmp_pal), cmp_funcs[longest]);
+    AV_QSORT(tmp_pal, nb_color, struct color, cmpf);
 
     return tmp_pal[nb_color >> 1].pal_id;
 }