quantization functions
authorhgn <hgodden00@gmail.com>
Tue, 3 Oct 2023 18:17:28 +0000 (19:17 +0100)
committerhgn <hgodden00@gmail.com>
Tue, 3 Oct 2023 18:17:28 +0000 (19:17 +0100)
vg_m.h

diff --git a/vg_m.h b/vg_m.h
index c753be797bc9e1da62b96c29ead2e8e800f7f0b9..4fe4590f944cae4d614e8577ea532998d49e82fa 100644 (file)
--- a/vg_m.h
+++ b/vg_m.h
@@ -32,6 +32,7 @@
 
 #define VG_PIf  3.14159265358979323846264338327950288f
 #define VG_TAUf 6.28318530717958647692528676655900576f
+
 /*
  * -----------------------------------------------------------------------------
  * Section 0.                    Misc Operations
@@ -106,6 +107,22 @@ static inline f32 vg_rad( f32 deg )
    return deg * VG_PIf / 180.0f;
 }
 
+/*
+ * quantize float to bit count
+ */
+static u32 vg_quantf( f32 a, u32 bits, f32 min, f32 max ){
+   u32 mask = (0x1 << bits) - 1;
+   return vg_clampf((a - min) * ((f32)mask/(max-min)), 0.0f, mask );
+}
+
+/*
+ * un-quantize discreet to float
+ */
+static f32 vg_dequantf( u32 q, u32 bits, f32 min, f32 max ){
+   u32 mask = (0x1 << bits) - 1;
+   return min + (f32)q * ((max-min) / (f32)mask);
+}
+
 /*
  * -----------------------------------------------------------------------------
  * Section 2.a                   2D Vectors