diff mbox series

[FFmpeg-devel,v2,25/32] avfilter/palette: add lowbias32 hashing

Message ID 20221227231814.2520181-26-u@pkh.me
State Accepted
Commit 3cafbdc083914d3a921fb241625ca8b6ccae1297
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
---
 libavfilter/palette.c | 10 ++++++++++
 libavfilter/palette.h |  5 +++++
 2 files changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/libavfilter/palette.c b/libavfilter/palette.c
index 03e48fc71e..e21ab6ff4d 100644
--- a/libavfilter/palette.c
+++ b/libavfilter/palette.c
@@ -208,3 +208,13 @@  uint32_t ff_oklab_int_to_srgb_u8(struct Lab c)
 
     return r<<16 | g<<8 | b;
 }
+
+uint32_t ff_lowbias32(uint32_t x)
+{
+    x ^= x >> 16;
+    x *= 0x7feb352d;
+    x ^= x >> 15;
+    x *= 0x846ca68b;
+    x ^= x >> 16;
+    return x;
+}
diff --git a/libavfilter/palette.h b/libavfilter/palette.h
index 6839bf6fc6..d3acc854ba 100644
--- a/libavfilter/palette.h
+++ b/libavfilter/palette.h
@@ -55,4 +55,9 @@  struct Lab ff_srgb_u8_to_oklab_int(uint32_t srgb);
  */
 uint32_t ff_oklab_int_to_srgb_u8(struct Lab c);
 
+/*
+ * lowbias32 hashing from https://nullprogram.com/blog/2018/07/31/
+ */
+uint32_t ff_lowbias32(uint32_t x);
+
 #endif /* AVFILTER_PALETTE_H */