diff mbox series

[FFmpeg-devel,v2,27/32] avfilter/paletteuse: use lowbias32 for color hashing

Message ID 20221227231814.2520181-28-u@pkh.me
State Accepted
Commit 6c7b54e9622b304db4230bcd8136c7daf47b6a6a
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:18 p.m. UTC
Impact is more negligible than previous commit but still faster (1.02x).
---
 libavfilter/vf_paletteuse.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c
index c32b73ab9a..c2d6333662 100644
--- a/libavfilter/vf_paletteuse.c
+++ b/libavfilter/vf_paletteuse.c
@@ -70,8 +70,7 @@  struct color_node {
     int left_id, right_id;
 };
 
-#define NBITS 5
-#define CACHE_SIZE (1<<(3*NBITS))
+#define CACHE_SIZE (1<<15)
 
 struct cached_color {
     uint32_t color;
@@ -346,10 +345,7 @@  static av_always_inline int color_get(PaletteUseContext *s, uint32_t color,
 {
     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);
-    const unsigned hash = rhash<<(NBITS*2) | ghash<<NBITS | bhash;
+    const uint32_t hash = ff_lowbias32(color) & (CACHE_SIZE - 1);
     struct cache_node *node = &s->cache[hash];
     struct cached_color *e;