diff golomb.h @ 1306:799839d1e2e1 libavcodec

golomb rice codes use gradients instead of prediction errors as context model store independant quantization tables for each point merge contexts with opposit sign
author michaelni
date Fri, 13 Jun 2003 21:31:28 +0000
parents fa181d095027
children 8479b875a989
line wrap: on
line diff
--- a/golomb.h	Fri Jun 13 09:36:13 2003 +0000
+++ b/golomb.h	Fri Jun 13 21:31:28 2003 +0000
@@ -178,6 +178,37 @@
     }
 }
 
+/**
+ * read unsigned golomb rice code.
+ */
+static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){
+    unsigned int buf;
+    int log;
+    
+    OPEN_READER(re, gb);
+    UPDATE_CACHE(re, gb);
+    buf=GET_CACHE(re, gb);
+
+    log= av_log2(buf);
+//printf("buf:%X log:%d\n", buf, log);
+    if(log > 31-limit){
+        buf >>= log - k;
+        buf += (30-log)<<k;
+        LAST_SKIP_BITS(re, gb, 32 + k - log);
+        CLOSE_READER(re, gb);
+    
+        return buf;
+    }else if(log == 31-limit){
+        buf >>= log - esc_len;
+        buf -= 1<<esc_len;
+        LAST_SKIP_BITS(re, gb, esc_len + limit + 1);
+        CLOSE_READER(re, gb);
+    
+        return buf + 1;
+    }else
+        return -1;
+}
+
 #ifdef TRACE
 
 static inline int get_ue(GetBitContext *s, char *file, char *func, int line){
@@ -279,3 +310,22 @@
 #endif
     set_ue_golomb(pb, i);
 }
+
+/**
+ * write unsigned golomb rice code.
+ */
+static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){
+    int e;
+    
+    assert(i>=0);
+    
+    e= i>>k;
+    if(e<limit){
+        put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1)));
+    }else{
+//    printf("set %08X, %d\n", (1<<esc_len) + i - 1, limit + esc_len + 1); 
+        put_bits(pb, limit + esc_len + 1, (1<<esc_len) + i - 1);
+//        put_bits(pb, 1, limit + 1);
+//        put_bits(pb, i - 1, esc_len);
+    }
+}