26 #define BUFFER_INCREMENT 256
28 static const unsigned long mask[]=
29 {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
30 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
31 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
32 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
33 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
34 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
35 0x3fffffff,0x7fffffff,0xffffffff };
38 {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
102 b->
ptr[1]=(
unsigned char)(value>>(8-b->
endbit));
104 b->
ptr[2]=(
unsigned char)(value>>(16-b->
endbit));
106 b->
ptr[3]=(
unsigned char)(value>>(24-b->
endbit));
109 b->
ptr[4]=(
unsigned char)(value>>(32-b->
endbit));
139 value=(value&
mask[
bits])<<(32-bits);
145 b->
ptr[1]=(
unsigned char)(value>>(16+b->
endbit));
147 b->
ptr[2]=(
unsigned char)(value>>(8+b->
endbit));
149 b->
ptr[3]=(
unsigned char)(value>>(b->
endbit));
152 b->
ptr[4]=(
unsigned char)(value<<(8-b->
endbit));
187 unsigned char *ptr=(
unsigned char *)source;
196 w(b,(
unsigned long)(ptr[
i]),8);
201 if(!b->
ptr)
goto err;
218 w(b,(
unsigned long)(ptr[bytes]>>(8-bits)),bits);
220 w(b,(
unsigned long)(ptr[bytes]),bits);
279 else if(!bits)
return(0L);
310 else if(!bits)
return(0L);
325 return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
384 else if(!bits)
return(0L);
427 else if(!bits)
return(0L);
442 ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
529 static int ilog(
unsigned int v){
541 void report(
char *
in){
542 fprintf(stderr,
"%s",in);
546 void cliptest(
unsigned long *b,
int vals,
int bits,
int *
comp,
int compsize){
555 if(bytes!=compsize)report(
"wrong number of bytes!\n");
556 for(i=0;i<bytes;i++)
if(buffer[i]!=comp[i]){
557 for(i=0;i<bytes;i++)fprintf(stderr,
"%x %x\n",(
int)buffer[i],(
int)comp[i]);
558 report(
"wrote incorrect value!\n");
562 int tbit=bits?bits:
ilog(b[i]);
564 report(
"out of data!\n");
566 report(
"looked at incorrect value!\n");
569 report(
"looked at single bit incorrect value!\n");
572 report(
"read incorrect single bit value!\n");
575 report(
"read incorrect value!\n");
578 if(
oggpack_bytes(&r)!=bytes)report(
"leftover bytes after read!\n");
581 void cliptestB(
unsigned long *b,
int vals,
int bits,
int *comp,
int compsize){
590 if(bytes!=compsize)report(
"wrong number of bytes!\n");
591 for(i=0;i<bytes;i++)
if(buffer[i]!=comp[i]){
592 for(i=0;i<bytes;i++)fprintf(stderr,
"%x %x\n",(
int)buffer[i],(
int)comp[i]);
593 report(
"wrote incorrect value!\n");
597 int tbit=bits?bits:
ilog(b[i]);
599 report(
"out of data!\n");
601 report(
"looked at incorrect value!\n");
604 report(
"looked at single bit incorrect value!\n");
607 report(
"read incorrect single bit value!\n");
610 report(
"read incorrect value!\n");
613 if(
oggpackB_bytes(&r)!=bytes)report(
"leftover bytes after read!\n");
619 static unsigned long testbuffer1[]=
620 {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
621 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
624 static unsigned long testbuffer2[]=
625 {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
626 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
627 85525151,0,12321,1,349528352};
630 static unsigned long testbuffer3[]=
631 {1,0,14,0,1,0,12,0,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,1,1,1,0,0,1,
632 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
635 static unsigned long large[]=
636 {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
637 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
638 85525151,0,12321,1,2146528352};
641 static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
642 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
644 static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
645 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
649 static int two[6]={61,255,255,251,231,29};
650 static int twoB[6]={247,63,255,253,249,120};
653 static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
654 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
655 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
656 100,52,4,14,18,86,77,1};
657 static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
658 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
659 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
660 200,20,254,4,58,106,176,144,0};
663 static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
664 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
666 static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
667 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
671 static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
672 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
673 84,75,159,2,1,0,132,192,8,0,0,18,22};
674 static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
675 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
676 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
679 static int six[7]={17,177,170,242,169,19,148};
680 static int sixB[7]={136,141,85,79,149,200,41};
686 fprintf(stderr,
"\nSmall preclipped packing (LSb): ");
687 cliptest(testbuffer1,test1size,0,one,onesize);
688 fprintf(stderr,
"ok.");
690 fprintf(stderr,
"\nNull bit call (LSb): ");
691 cliptest(testbuffer3,test3size,0,two,twosize);
692 fprintf(stderr,
"ok.");
694 fprintf(stderr,
"\nLarge preclipped packing (LSb): ");
695 cliptest(testbuffer2,test2size,0,three,threesize);
696 fprintf(stderr,
"ok.");
698 fprintf(stderr,
"\n32 bit preclipped packing (LSb): ");
700 for(i=0;i<test2size;i++)
705 for(i=0;i<test2size;i++){
706 if(
oggpack_look(&r,32)==-1)report(
"out of data. failed!");
708 fprintf(stderr,
"%ld != %ld (%lx!=%lx):",
oggpack_look(&r,32),large[i],
710 report(
"read incorrect value!\n");
714 if(
oggpack_bytes(&r)!=bytes)report(
"leftover bytes after read!\n");
715 fprintf(stderr,
"ok.");
717 fprintf(stderr,
"\nSmall unclipped packing (LSb): ");
718 cliptest(testbuffer1,test1size,7,four,foursize);
719 fprintf(stderr,
"ok.");
721 fprintf(stderr,
"\nLarge unclipped packing (LSb): ");
722 cliptest(testbuffer2,test2size,17,five,fivesize);
723 fprintf(stderr,
"ok.");
725 fprintf(stderr,
"\nSingle bit unclipped packing (LSb): ");
726 cliptest(testbuffer3,test3size,1,six,sixsize);
727 fprintf(stderr,
"ok.");
729 fprintf(stderr,
"\nTesting read past end (LSb): ");
733 fprintf(stderr,
"failed; got -1 prematurely.\n");
739 fprintf(stderr,
"failed; read past end without -1.\n");
744 fprintf(stderr,
"failed 2; got -1 prematurely.\n");
750 fprintf(stderr,
"failed 3; got -1 prematurely.\n");
755 fprintf(stderr,
"failed; read past end without -1.\n");
760 fprintf(stderr,
"failed; read past end without -1.\n");
764 fprintf(stderr,
"ok.\n");
772 fprintf(stderr,
"\nSmall preclipped packing (MSb): ");
773 cliptestB(testbuffer1,test1size,0,oneB,onesize);
774 fprintf(stderr,
"ok.");
776 fprintf(stderr,
"\nNull bit call (MSb): ");
777 cliptestB(testbuffer3,test3size,0,twoB,twosize);
778 fprintf(stderr,
"ok.");
780 fprintf(stderr,
"\nLarge preclipped packing (MSb): ");
781 cliptestB(testbuffer2,test2size,0,threeB,threesize);
782 fprintf(stderr,
"ok.");
784 fprintf(stderr,
"\n32 bit preclipped packing (MSb): ");
786 for(i=0;i<test2size;i++)
791 for(i=0;i<test2size;i++){
794 fprintf(stderr,
"%ld != %ld (%lx!=%lx):",
oggpackB_look(&r,32),large[i],
796 report(
"read incorrect value!\n");
800 if(
oggpackB_bytes(&r)!=bytes)report(
"leftover bytes after read!\n");
801 fprintf(stderr,
"ok.");
803 fprintf(stderr,
"\nSmall unclipped packing (MSb): ");
804 cliptestB(testbuffer1,test1size,7,fourB,foursize);
805 fprintf(stderr,
"ok.");
807 fprintf(stderr,
"\nLarge unclipped packing (MSb): ");
808 cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
809 fprintf(stderr,
"ok.");
811 fprintf(stderr,
"\nSingle bit unclipped packing (MSb): ");
812 cliptestB(testbuffer3,test3size,1,sixB,sixsize);
813 fprintf(stderr,
"ok.");
815 fprintf(stderr,
"\nTesting read past end (MSb): ");
819 fprintf(stderr,
"failed; got -1 prematurely.\n");
825 fprintf(stderr,
"failed; read past end without -1.\n");
830 fprintf(stderr,
"failed 2; got -1 prematurely.\n");
836 fprintf(stderr,
"failed 3; got -1 prematurely.\n");
841 fprintf(stderr,
"failed; read past end without -1.\n");
846 fprintf(stderr,
"failed; read past end without -1.\n");
850 fprintf(stderr,
"ok.\n\n");
857 #undef BUFFER_INCREMENT
static void oggpack_writecopy_helper(oggpack_buffer *b, void *source, long bits, void(*w)(oggpack_buffer *, unsigned long, int), int msb)
long oggpackB_bits(oggpack_buffer *b)
int main(int argc, char **argv)
long oggpack_bits(oggpack_buffer *b)
long oggpack_look(oggpack_buffer *b, int bits)
void oggpackB_writeclear(oggpack_buffer *b)
unsigned char * oggpackB_get_buffer(oggpack_buffer *b)
long oggpackB_read(oggpack_buffer *b, int bits)
void oggpackB_writecopy(oggpack_buffer *b, void *source, long bits)
void oggpack_write(oggpack_buffer *b, unsigned long value, int bits)
int oggpackB_writecheck(oggpack_buffer *b)
long oggpackB_bytes(oggpack_buffer *b)
static int comp(const void *a, const void *b)
long oggpack_look1(oggpack_buffer *b)
void oggpackB_adv1(oggpack_buffer *b)
void oggpack_writetrunc(oggpack_buffer *b, long bits)
void oggpack_writecopy(oggpack_buffer *b, void *source, long bits)
void oggpackB_reset(oggpack_buffer *b)
void oggpackB_write(oggpack_buffer *b, unsigned long value, int bits)
void oggpack_adv(oggpack_buffer *b, int bits)
EGLContext EGLenum EGLClientBuffer buffer
void oggpackB_writetrunc(oggpack_buffer *b, long bits)
long oggpackB_look(oggpack_buffer *b, int bits)
void oggpackB_adv(oggpack_buffer *b, int bits)
long oggpackB_look1(oggpack_buffer *b)
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
long oggpackB_read1(oggpack_buffer *b)
void oggpack_adv1(oggpack_buffer *b)
void oggpack_readinit(oggpack_buffer *b, unsigned char *buf, int bytes)
EGLSurface EGLint void ** value
GLenum GLuint GLsizei const GLchar * buf
static int ilog(unsigned int v)
int oggpack_writecheck(oggpack_buffer *b)
void oggpack_writeinit(oggpack_buffer *b)
long oggpack_bytes(oggpack_buffer *b)
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLdouble GLdouble GLdouble r
void oggpack_reset(oggpack_buffer *b)
GLdouble GLdouble GLdouble b
GLint GLint GLint GLint GLint w
unsigned char * oggpack_get_buffer(oggpack_buffer *b)
void oggpackB_writeinit(oggpack_buffer *b)
static const unsigned int mask8B[]
void oggpack_writealign(oggpack_buffer *b)
void oggpack_writeclear(oggpack_buffer *b)
long oggpack_read(oggpack_buffer *b, int bits)
GLsizei GLsizei GLchar * source
long oggpack_read1(oggpack_buffer *b)
void oggpackB_readinit(oggpack_buffer *b, unsigned char *buf, int bytes)
void oggpackB_writealign(oggpack_buffer *b)