94 #define MAXCODES (MAXLCODES+MAXDCODES) 101 unsigned long outlen;
102 unsigned long outcnt;
105 const unsigned char *
in;
132 while (s->bitcnt < need) {
133 if (s->incnt == s->inlen)
135 val |= (
long)(s->in[s->incnt++]) << s->bitcnt;
140 s->bitbuf = (
int)(val >> need);
144 return (
int)(val & ((1L << need) - 1));
173 if (s->incnt + 4 > s->inlen)
175 len = s->in[s->incnt++];
176 len |= s->in[s->incnt++] << 8;
177 if (s->in[s->incnt++] != (~len & 0xff) ||
178 s->in[s->incnt++] != ((~len >> 8) & 0xff))
182 if (s->incnt + len > s->inlen)
185 if (s->outcnt + len > s->outlen)
188 s->out[s->outcnt++] = s->in[s->incnt++];
243 code = first = index = 0;
244 for (len = 1; len <=
MAXBITS; len++) {
246 count = h->count[
len];
247 if (code - count < first)
248 return h->symbol[index + (code -
first)];
276 code = first = index = 0;
284 if (code - count < first) {
286 s->bitcnt = (s->bitcnt -
len) & 7;
287 return h->symbol[index + (code -
first)];
298 if (s->incnt == s->inlen)
300 bitbuf = s->in[s->incnt++];
348 for (len = 0; len <=
MAXBITS; len++)
350 for (symbol = 0; symbol <
n; symbol++)
351 (h->count[length[symbol]])++;
352 if (h->count[0] == n)
357 for (len = 1; len <=
MAXBITS; len++) {
359 left -= h->count[
len];
366 for (len = 1; len <
MAXBITS; len++)
367 offs[len + 1] = offs[len] + h->count[len];
373 for (symbol = 0; symbol <
n; symbol++)
374 if (length[symbol] != 0)
375 h->symbol[offs[length[symbol]]++] = symbol;
437 const struct huffman *lencode,
438 const struct huffman *distcode)
443 static const short lens[29] = {
444 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
445 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
446 static const short lext[29] = {
447 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
448 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
449 static const short dists[30] = {
450 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
451 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
452 8193, 12289, 16385, 24577};
453 static const short dext[30] = {
454 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
455 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
460 symbol =
decode(s, lencode);
466 if (s->outcnt == s->outlen)
468 s->out[s->outcnt] = symbol;
472 else if (symbol > 256) {
477 len = lens[symbol] +
bits(s, lext[symbol]);
480 symbol =
decode(s, distcode);
483 dist = dists[symbol] +
bits(s, dext[symbol]);
484 #ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 485 if (dist > s->outcnt)
491 if (s->outcnt + len > s->outlen)
495 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 499 s->out[s->outcnt - dist];
506 }
while (symbol != 256);
538 static int virgin = 1;
541 static struct huffman lencode, distcode;
549 lencode.count = lencnt;
550 lencode.symbol = lensym;
551 distcode.count = distcnt;
552 distcode.symbol = distsym;
555 for (symbol = 0; symbol < 144; symbol++)
557 for (; symbol < 256; symbol++)
559 for (; symbol < 280; symbol++)
566 for (symbol = 0; symbol <
MAXDCODES; symbol++)
568 construct(&distcode, lengths, MAXDCODES);
575 return codes(s, &lencode, &distcode);
667 int nlen, ndist, ncode;
673 struct huffman lencode, distcode;
674 static const short order[19] =
675 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
678 lencode.count = lencnt;
679 lencode.symbol = lensym;
680 distcode.count = distcnt;
681 distcode.symbol = distsym;
684 nlen =
bits(s, 5) + 257;
685 ndist =
bits(s, 5) + 1;
686 ncode =
bits(s, 4) + 4;
691 for (index = 0; index < ncode; index++)
692 lengths[order[index]] =
bits(s, 3);
693 for (; index < 19; index++)
694 lengths[order[index]] = 0;
703 while (index < nlen + ndist) {
707 symbol =
decode(s, &lencode);
711 lengths[index++] = symbol;
717 len = lengths[index - 1];
718 symbol = 3 +
bits(s, 2);
720 else if (symbol == 17)
721 symbol = 3 +
bits(s, 3);
723 symbol = 11 +
bits(s, 7);
724 if (index + symbol > nlen + ndist)
727 lengths[index++] =
len;
732 if (lengths[256] == 0)
736 err =
construct(&lencode, lengths, nlen);
737 if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
741 err =
construct(&distcode, lengths + nlen, ndist);
742 if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
746 return codes(s, &lencode, &distcode);
794 unsigned long *destlen,
795 const unsigned char *
source,
796 unsigned long *sourcelen)
809 s.inlen = *sourcelen;
815 if (setjmp(s.env) != 0)
837 *sourcelen = s.incnt;
GLenum GLuint GLenum GLsizei length
for(n=1;n< outline->n_points;n++)
local int construct(struct huffman *h, const short *length, int n)
GLfloat GLfloat GLfloat GLfloat h
int puff(unsigned char *dest, unsigned long *destlen, const unsigned char *source, unsigned long *sourcelen)
GLuint GLdouble GLdouble GLint GLint order
GLsizei GLsizei GLchar * source
local int decode(struct state *s, const struct huffman *h)
local int out(void *out_desc, unsigned char *buf, unsigned len)
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
local int dynamic(struct state *s)
GLsizei GLenum GLenum GLuint GLenum GLsizei * lengths
GLuint GLuint GLsizei count
local int bits(struct state *s, int need)
local int stored(struct state *s)
local int codes(struct state *s, const struct huffman *lencode, const struct huffman *distcode)
local int fixed(struct state *s)