23 #include "../ogg/ogg.h"
25 #define BUFFER_INCREMENT 256
27 static unsigned long mask[]=
28 {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
29 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
30 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
31 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
32 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
33 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
34 0x3fffffff,0x7fffffff,0xffffffff };
36 static unsigned int mask8B[]=
37 {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
40 memset(b,0,
sizeof(*b));
110 value=(value&
mask[
bits])<<(32-bits);
155 unsigned char *ptr=(
unsigned char *)source;
164 w(b,(
unsigned long)(ptr[
i]),8);
173 memmove(b->
ptr,source,bytes);
181 w(b,(
unsigned long)(ptr[bytes]>>(8-bits)),bits);
183 w(b,(
unsigned long)(ptr[bytes]),bits);
207 memset(b,0,
sizeof(*b));
215 memset(b,0,
sizeof(*b));
275 return (ret>>(m>>1))>>((m+1)>>1);
372 ret=(ret>>(m>>1))>>((m+1)>>1);
456 static int ilog(
unsigned int v){
468 void report(
char *
in){
469 fprintf(stderr,
"%s",in);
473 void cliptest(
unsigned long *b,
int vals,
int bits,
int *comp,
int compsize){
482 if(bytes!=compsize)report(
"wrong number of bytes!\n");
483 for(i=0;i<bytes;i++)
if(buffer[i]!=comp[i]){
484 for(i=0;i<bytes;i++)fprintf(stderr,
"%x %x\n",(
int)buffer[i],(
int)comp[i]);
485 report(
"wrote incorrect value!\n");
489 int tbit=bits?bits:ilog(b[i]);
491 report(
"out of data!\n");
493 report(
"looked at incorrect value!\n");
496 report(
"looked at single bit incorrect value!\n");
499 report(
"read incorrect single bit value!\n");
502 report(
"read incorrect value!\n");
505 if(
oggpack_bytes(&r)!=bytes)report(
"leftover bytes after read!\n");
508 void cliptestB(
unsigned long *b,
int vals,
int bits,
int *comp,
int compsize){
517 if(bytes!=compsize)report(
"wrong number of bytes!\n");
518 for(i=0;i<bytes;i++)
if(buffer[i]!=comp[i]){
519 for(i=0;i<bytes;i++)fprintf(stderr,
"%x %x\n",(
int)buffer[i],(
int)comp[i]);
520 report(
"wrote incorrect value!\n");
524 int tbit=bits?bits:ilog(b[i]);
526 report(
"out of data!\n");
528 report(
"looked at incorrect value!\n");
531 report(
"looked at single bit incorrect value!\n");
534 report(
"read incorrect single bit value!\n");
537 report(
"read incorrect value!\n");
540 if(
oggpackB_bytes(&r)!=bytes)report(
"leftover bytes after read!\n");
546 static unsigned long testbuffer1[]=
547 {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
548 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
551 static unsigned long testbuffer2[]=
552 {216531625
L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
553 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
554 85525151,0,12321,1,349528352};
557 static unsigned long testbuffer3[]=
558 {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,
559 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
562 static unsigned long large[]=
563 {2136531625
L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
564 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
565 85525151,0,12321,1,2146528352};
568 static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
569 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
571 static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
572 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
576 static int two[6]={61,255,255,251,231,29};
577 static int twoB[6]={247,63,255,253,249,120};
580 static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
581 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
582 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
583 100,52,4,14,18,86,77,1};
584 static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
585 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
586 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
587 200,20,254,4,58,106,176,144,0};
590 static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
591 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
593 static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
594 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
598 static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
599 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
600 84,75,159,2,1,0,132,192,8,0,0,18,22};
601 static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
602 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
603 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
606 static int six[7]={17,177,170,242,169,19,148};
607 static int sixB[7]={136,141,85,79,149,200,41};
613 fprintf(stderr,
"\nSmall preclipped packing (LSb): ");
614 cliptest(testbuffer1,test1size,0,one,onesize);
615 fprintf(stderr,
"ok.");
617 fprintf(stderr,
"\nNull bit call (LSb): ");
618 cliptest(testbuffer3,test3size,0,two,twosize);
619 fprintf(stderr,
"ok.");
621 fprintf(stderr,
"\nLarge preclipped packing (LSb): ");
622 cliptest(testbuffer2,test2size,0,three,threesize);
623 fprintf(stderr,
"ok.");
625 fprintf(stderr,
"\n32 bit preclipped packing (LSb): ");
627 for(i=0;i<test2size;i++)
632 for(i=0;i<test2size;i++){
633 if(
oggpack_look(&r,32)==-1)report(
"out of data. failed!");
635 fprintf(stderr,
"%ld != %ld (%lx!=%lx):",
oggpack_look(&r,32),large[i],
637 report(
"read incorrect value!\n");
641 if(
oggpack_bytes(&r)!=bytes)report(
"leftover bytes after read!\n");
642 fprintf(stderr,
"ok.");
644 fprintf(stderr,
"\nSmall unclipped packing (LSb): ");
645 cliptest(testbuffer1,test1size,7,four,foursize);
646 fprintf(stderr,
"ok.");
648 fprintf(stderr,
"\nLarge unclipped packing (LSb): ");
649 cliptest(testbuffer2,test2size,17,five,fivesize);
650 fprintf(stderr,
"ok.");
652 fprintf(stderr,
"\nSingle bit unclipped packing (LSb): ");
653 cliptest(testbuffer3,test3size,1,six,sixsize);
654 fprintf(stderr,
"ok.");
656 fprintf(stderr,
"\nTesting read past end (LSb): ");
660 fprintf(stderr,
"failed; got -1 prematurely.\n");
666 fprintf(stderr,
"failed; read past end without -1.\n");
671 fprintf(stderr,
"failed 2; got -1 prematurely.\n");
677 fprintf(stderr,
"failed 3; got -1 prematurely.\n");
682 fprintf(stderr,
"failed; read past end without -1.\n");
687 fprintf(stderr,
"failed; read past end without -1.\n");
690 fprintf(stderr,
"ok.\n");
698 fprintf(stderr,
"\nSmall preclipped packing (MSb): ");
699 cliptestB(testbuffer1,test1size,0,oneB,onesize);
700 fprintf(stderr,
"ok.");
702 fprintf(stderr,
"\nNull bit call (MSb): ");
703 cliptestB(testbuffer3,test3size,0,twoB,twosize);
704 fprintf(stderr,
"ok.");
706 fprintf(stderr,
"\nLarge preclipped packing (MSb): ");
707 cliptestB(testbuffer2,test2size,0,threeB,threesize);
708 fprintf(stderr,
"ok.");
710 fprintf(stderr,
"\n32 bit preclipped packing (MSb): ");
712 for(i=0;i<test2size;i++)
717 for(i=0;i<test2size;i++){
720 fprintf(stderr,
"%ld != %ld (%lx!=%lx):",
oggpackB_look(&r,32),large[i],
722 report(
"read incorrect value!\n");
726 if(
oggpackB_bytes(&r)!=bytes)report(
"leftover bytes after read!\n");
727 fprintf(stderr,
"ok.");
729 fprintf(stderr,
"\nSmall unclipped packing (MSb): ");
730 cliptestB(testbuffer1,test1size,7,fourB,foursize);
731 fprintf(stderr,
"ok.");
733 fprintf(stderr,
"\nLarge unclipped packing (MSb): ");
734 cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
735 fprintf(stderr,
"ok.");
737 fprintf(stderr,
"\nSingle bit unclipped packing (MSb): ");
738 cliptestB(testbuffer3,test3size,1,sixB,sixsize);
739 fprintf(stderr,
"ok.");
741 fprintf(stderr,
"\nTesting read past end (MSb): ");
745 fprintf(stderr,
"failed; got -1 prematurely.\n");
751 fprintf(stderr,
"failed; read past end without -1.\n");
756 fprintf(stderr,
"failed 2; got -1 prematurely.\n");
762 fprintf(stderr,
"failed 3; got -1 prematurely.\n");
767 fprintf(stderr,
"failed; read past end without -1.\n");
772 fprintf(stderr,
"failed; read past end without -1.\n");
775 fprintf(stderr,
"ok.\n\n");
782 #undef BUFFER_INCREMENT
long oggpackB_look(oggpack_buffer *b, int bits)
long oggpackB_look1(oggpack_buffer *b)
unsigned char * oggpackB_get_buffer(oggpack_buffer *b)
GLsizei const GLfloat * value
void oggpackB_write(oggpack_buffer *b, unsigned long value, int bits)
void oggpackB_writeinit(oggpack_buffer *b)
long oggpack_read(oggpack_buffer *b, int bits)
void oggpack_reset(oggpack_buffer *b)
void oggpack_writecopy(oggpack_buffer *b, void *source, long bits)
void oggpackB_adv1(oggpack_buffer *b)
long oggpack_look1(oggpack_buffer *b)
void oggpackB_writecopy(oggpack_buffer *b, void *source, long bits)
unsigned char * oggpack_get_buffer(oggpack_buffer *b)
void oggpackB_readinit(oggpack_buffer *b, unsigned char *buf, int bytes)
void oggpackB_reset(oggpack_buffer *b)
GLsizei GLsizei GLcharARB * source
GLubyte GLubyte GLubyte GLubyte w
long oggpack_read1(oggpack_buffer *b)
void oggpackB_adv(oggpack_buffer *b, int bits)
long oggpackB_read1(oggpack_buffer *b)
void oggpack_writetrunc(oggpack_buffer *b, long bits)
long oggpackB_bytes(oggpack_buffer *b)
long oggpackB_bits(oggpack_buffer *b)
long oggpack_bytes(oggpack_buffer *b)
long oggpack_bits(oggpack_buffer *b)
long oggpackB_read(oggpack_buffer *b, int bits)
void oggpack_adv1(oggpack_buffer *b)
void oggpack_writeinit(oggpack_buffer *b)
void oggpackB_writealign(oggpack_buffer *b)
GLdouble GLdouble GLdouble r
void oggpack_write(oggpack_buffer *b, unsigned long value, int bits)
void oggpack_writeclear(oggpack_buffer *b)
void oggpackB_writetrunc(oggpack_buffer *b, long bits)
void oggpack_adv(oggpack_buffer *b, int bits)
void oggpack_writealign(oggpack_buffer *b)
void oggpackB_writeclear(oggpack_buffer *b)
void oggpack_readinit(oggpack_buffer *b, unsigned char *buf, int bytes)
long oggpack_look(oggpack_buffer *b, int bits)