[xiph-commits] r16269 - branches/theora-gumboot/lib/dec

gumboot at svn.xiph.org gumboot at svn.xiph.org
Mon Jul 13 03:28:19 PDT 2009


Author: gumboot
Date: 2009-07-13 03:28:19 -0700 (Mon, 13 Jul 2009)
New Revision: 16269

Modified:
   branches/theora-gumboot/lib/dec/bitpack.c
   branches/theora-gumboot/lib/dec/bitpack.h
   branches/theora-gumboot/lib/dec/decinfo.c
   branches/theora-gumboot/lib/dec/huffdec.c
Log:
Another 5% recovered from bit packing.  Once again, still in dirty-hack form.


Modified: branches/theora-gumboot/lib/dec/bitpack.c
===================================================================
--- branches/theora-gumboot/lib/dec/bitpack.c	2009-07-12 22:05:02 UTC (rev 16268)
+++ branches/theora-gumboot/lib/dec/bitpack.c	2009-07-13 10:28:19 UTC (rev 16269)
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include "bitpack.h"
 
+#if !defined(NEW_BITPACK)
 void theorapackB_readinit(oggpack_buffer *_b,unsigned char *_buf,int _bytes){
   memset(_b,0,sizeof(*_b));
   _b->buffer=_b->ptr=_buf;
@@ -119,3 +120,86 @@
 unsigned char *theorapackB_get_buffer(oggpack_buffer *_b){
   return _b->buffer;
 }
+#endif
+
+
+#define BIT_WINDOW_SIZE 32
+#define BIT_WINDOW_MASK 0xFFFFFFFFUL
+
+void theorapackC_readinit(oggpack_buffer *_b,unsigned char *_buf,int _bytes,int _bits){
+  memset(_b,0,sizeof(*_b));
+  _b->endbit=-_bits;
+  _b->ptr=_buf;
+  _b->buffer=_buf+_bytes;
+}
+
+static unsigned int inline theorapackC_refill(oggpack_buffer *_b,int _bits)
+{
+  int available=_b->endbit;
+  unsigned int window=_b->storage&BIT_WINDOW_MASK;
+  unsigned char const *ptr=_b->ptr;
+  unsigned char const *stop=_b->buffer;
+
+  if (ptr>=stop)
+    available=0x40000000;
+  while(available<=BIT_WINDOW_SIZE-8)
+  {
+    available+=8;
+    window|=*ptr++<<(BIT_WINDOW_SIZE-available);
+    if (ptr>=stop)
+      available=0x40000000;
+  }
+  _b->ptr=(unsigned char *)ptr;
+  if (_bits>available)
+    window|=*ptr>>(available&7);
+
+  _b->endbit=available;
+  return window&BIT_WINDOW_MASK;
+}
+
+int theorapackC_look1(oggpack_buffer *_b){
+  int available=_b->endbit;
+  unsigned int window=_b->storage&BIT_WINDOW_MASK;
+  if (1>available)_b->storage=window=theorapackC_refill(_b,1);
+  return window>>(BIT_WINDOW_SIZE-1);
+}
+
+void theorapackC_adv1(oggpack_buffer *_b){
+  _b->storage<<=1;
+  _b->endbit--;
+}
+
+/*Here we assume that 0<=_bits&&_bits<=32.*/
+long theorapackC_read(oggpack_buffer *_b,int _bits){
+  int available=_b->endbit;
+  unsigned int window=_b->storage&BIT_WINDOW_MASK;
+  long result;
+  if(_bits==0)return 0;
+  if(_bits>available){
+    window=theorapackC_refill(_b,_bits);
+    available=_b->endbit;
+  }
+  result=window>>(BIT_WINDOW_SIZE-_bits);
+  available-=_bits;
+  window<<=1;
+  window<<=_bits-1;
+  _b->endbit=available;
+  _b->storage=window;
+  return result;
+}
+
+int theorapackC_read1(oggpack_buffer *_b){
+  int available=_b->endbit;
+  unsigned int window=_b->storage&BIT_WINDOW_MASK;
+  int result;
+  if (1>available){
+    window=theorapackC_refill(_b,1);
+    available=_b->endbit;
+  }
+  result=window>>(BIT_WINDOW_SIZE-1);
+  available--;
+  window<<=1;
+  _b->endbit=available;
+  _b->storage=window;
+  return result;
+}

Modified: branches/theora-gumboot/lib/dec/bitpack.h
===================================================================
--- branches/theora-gumboot/lib/dec/bitpack.h	2009-07-12 22:05:02 UTC (rev 16268)
+++ branches/theora-gumboot/lib/dec/bitpack.h	2009-07-13 10:28:19 UTC (rev 16269)
@@ -34,5 +34,20 @@
 /*static int theorapackB_look(oggpack_buffer *_b,int _bits,long *_ret);*/
 /*static void theorapackB_adv(oggpack_buffer *_b,int _bits);*/
 
+void theorapackC_readinit(oggpack_buffer *_b,unsigned char *_buf,int _bytes,int _bits);
+int theorapackC_look1(oggpack_buffer *_b);
+void theorapackC_adv1(oggpack_buffer *_b);
+/*Here we assume 0<=_bits&&_bits<=32.*/
+long theorapackC_read(oggpack_buffer *_b,int _bits);
+int theorapackC_read1(oggpack_buffer *_b);
 
+#define NEW_BITPACK
+#if defined(NEW_BITPACK)
+#define theorapackB_readinit(_b,_buf,_bytes) theorapackC_readinit(_b,_buf,_bytes,0)
+#define theorapackB_look1(_b,_ret) (*(_ret)=theorapackC_look1(_b),0)
+#define theorapackB_adv1(_b) theorapackC_adv1(_b)
+#define theorapackB_read(_b,_bits,_ret) (*(_ret)=theorapackC_read(_b,_bits),0)
+#define theorapackB_read1(_b,_ret) (*(_ret)=theorapackC_read1(_b),0)
 #endif
+
+#endif

Modified: branches/theora-gumboot/lib/dec/decinfo.c
===================================================================
--- branches/theora-gumboot/lib/dec/decinfo.c	2009-07-12 22:05:02 UTC (rev 16268)
+++ branches/theora-gumboot/lib/dec/decinfo.c	2009-07-13 10:28:19 UTC (rev 16269)
@@ -111,14 +111,14 @@
   int  i;
   /*Read the vendor string.*/
   len=oc_unpack_length(_opb);
-  if(len<0||len>_opb->storage-theorapackB_bytes(_opb))return TH_EBADHEADER;
+  if(len<0/*||len>_opb->storage-theorapackB_bytes(_opb)*/)return TH_EBADHEADER;
   _tc->vendor=_ogg_malloc((size_t)len+1);
   oc_unpack_octets(_opb,_tc->vendor,len);
   _tc->vendor[len]='\0';
   /*Read the user comments.*/
   _tc->comments=(int)oc_unpack_length(_opb);
   len=_tc->comments;
-  if(len<0||len>(LONG_MAX>>2)||len<<2>_opb->storage-theorapackB_bytes(_opb)){
+  if(len<0||len>(LONG_MAX>>2)/*||len<<2>_opb->storage-theorapackB_bytes(_opb)*/){
     _tc->comments=0;
     return TH_EBADHEADER;
   }
@@ -128,7 +128,7 @@
    _tc->comments*sizeof(_tc->user_comments[0]));
   for(i=0;i<_tc->comments;i++){
     len=oc_unpack_length(_opb);
-    if(len<0||len>_opb->storage-theorapackB_bytes(_opb)){
+    if(len<0/*||len>_opb->storage-theorapackB_bytes(_opb)*/){
       _tc->comments=i;
       return TH_EBADHEADER;
     }

Modified: branches/theora-gumboot/lib/dec/huffdec.c
===================================================================
--- branches/theora-gumboot/lib/dec/huffdec.c	2009-07-12 22:05:02 UTC (rev 16268)
+++ branches/theora-gumboot/lib/dec/huffdec.c	2009-07-13 10:28:19 UTC (rev 16269)
@@ -75,6 +75,7 @@
   they are only used here. Declaring local static versions so they
   can be inlined saves considerable function call overhead.*/
 
+#if !defined(NEW_BITPACK)
 /*Read in bits without advancing the bitptr.
   Here we assume 0<=_bits&&_bits<=32.*/
 static int theorapackB_look(oggpack_buffer *_b,int _bits,long *_ret){
@@ -115,8 +116,64 @@
   _b->endbyte+=_bits>>3;
   _b->endbit=_bits&7;
 }
+#endif
 
+#define BIT_WINDOW_SIZE 32
+#define BIT_WINDOW_MASK 0xFFFFFFFFUL
 
+#define theorapackB_look(_b,_bits,_ret) (*(_ret)=theorapackC_look(_b,_bits),0)
+#define theorapackB_adv(_b,_bits) theorapackC_adv(_b,_bits)
+
+static unsigned int inline theorapackC_refill(oggpack_buffer *_b,int _bits)
+{
+  int available=_b->endbit;
+  unsigned int window=_b->storage&BIT_WINDOW_MASK;
+  unsigned char const *ptr=_b->ptr;
+  unsigned char const *stop=_b->buffer;
+
+  if (ptr>=stop)
+    available=0x40000000;
+  while(available<=BIT_WINDOW_SIZE-8)
+  {
+    available+=8;
+    window|=*ptr++<<BIT_WINDOW_SIZE-available;
+    if (ptr>=stop)
+      available=0x40000000;
+  }
+  _b->ptr=(unsigned char *)ptr;
+  if (_bits>available)
+    window|=*ptr>>(available&7);
+
+  _b->endbit=available;
+  return window&BIT_WINDOW_MASK;
+}
+
+
+/*Read in bits without advancing the bitptr.
+  Here we assume 0<=_bits&&_bits<=32.*/
+static long theorapackC_look(oggpack_buffer *_b,int _bits){
+  int available=_b->endbit;
+  unsigned int window=_b->storage&BIT_WINDOW_MASK;
+  long result;
+  if(_bits==0)return 0;
+  if(_bits>available)_b->storage=window=theorapackC_refill(_b,_bits);
+  result=window>>(BIT_WINDOW_SIZE-_bits);
+  return result;
+}
+
+/*advance the bitptr*/
+static void theorapackC_adv(oggpack_buffer *_b,int _bits){
+  if(_bits)
+  {
+    unsigned int window=_b->storage&BIT_WINDOW_MASK;
+    window<<=1;
+    window<<=_bits-1;
+    _b->storage=window;
+    _b->endbit-=_bits;
+  }
+}
+
+
 /*The log_2 of the size of a lookup table is allowed to grow to relative to
    the number of unique nodes it contains.
   E.g., if OC_HUFF_SLUSH is 2, then at most 75% of the space in the tree is



More information about the commits mailing list