[xiph-cvs] cvs commit: w3d wavelet_coeff.c

Holger Waechtler holger at xiph.org
Tue Nov 20 08:22:04 PST 2001



holger      01/11/20 08:22:04

  Modified:    .        wavelet_coeff.c
  Log:
  implemented gray code encoding instead of coefficient significance mask encoding
  switch this feature on/off by #define GRAY_CODES in wavelet_coeff.c
  
  This may lead to longer runlengths and overestimation of coefficients.
  
  Thanks to Adam J. Richter <adam at yggdrasil.com> for the idea!

Revision  Changes    Path
1.8       +23 -1     w3d/wavelet_coeff.c

Index: wavelet_coeff.c
===================================================================
RCS file: /usr/local/cvsroot/w3d/wavelet_coeff.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- wavelet_coeff.c	2001/11/20 13:06:37	1.7
+++ wavelet_coeff.c	2001/11/20 16:22:04	1.8
@@ -3,15 +3,30 @@
 #include "rle.h"
 
 
+#define GRAY_CODES 1
 
+#if defined(GRAY_CODES)
 static inline
+uint16_t binary_to_gray (uint16_t x) { return  x ^ (x >> 1); }
+
+static inline
+uint16_t gray_to_binary (uint16_t x)
+{ int i; for (i=1; i<16; i+=i) x ^= x >> i; return x; }
+#endif
+
+
+static inline
 void encode_coeff (ENTROPY_CODER significand_bitstream [],
                    ENTROPY_CODER insignificand_bitstream [],
                    TYPE coeff)
 {
-   static TYPE mask [2] = { 0, ~0 };
    int sign = (coeff >> (8*sizeof(TYPE)-1)) & 1;
+#if defined(GRAY_CODES)
+   TYPE significance = binary_to_gray(coeff);
+#else
+   static TYPE mask [2] = { 0, ~0 };
    TYPE significance = coeff ^ mask[sign];
+#endif
    int i = TYPE_BITS;
 
    do {
@@ -31,7 +46,9 @@
 TYPE decode_coeff (ENTROPY_CODER significand_bitstream [],
                    ENTROPY_CODER insignificand_bitstream [])
 {
+#if !defined(GRAY_CODES)
    static TYPE mask [2] = { 0, ~0 };
+#endif
    TYPE significance = 0;
    int sign;
    int i = TYPE_BITS;
@@ -50,7 +67,12 @@
    while (--i >= 0)
       significance |= INPUT_BIT(&insignificand_bitstream[i]) << i;
 
+#if defined(GRAY_CODES)
+   significance |= sign << (8*sizeof(TYPE)-1);
+   return gray_to_binary(significance);
+#else
    return (significance ^ mask[sign]);
+#endif
 }
 
 

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list