DEADSOFTWARE

new code for blood particles (other particles are turned off temporarily): almost...
[d2df-sdl.git] / src / lib / vampimg / ZLib / iminftrees.pas
1 Unit iminftrees;
3 { inftrees.h -- header to use inftrees.c
4 inftrees.c -- generate Huffman trees for efficient decoding
5 Copyright (C) 1995-1998 Mark Adler
7 WARNING: this file should *not* be used by applications. It is
8 part of the implementation of the compression library and is
9 subject to change.
11 Pascal tranlastion
12 Copyright (C) 1998 by Jacques Nomssi Nzali
13 For conditions of distribution and use, see copyright notice in readme.txt
14 }
16 Interface
18 {$I imzconf.inc}
20 uses
21 imzutil, impaszlib;
24 { Maximum size of dynamic tree. The maximum found in a long but non-
25 exhaustive search was 1004 huft structures (850 for length/literals
26 and 154 for distances, the latter actually the result of an
27 exhaustive search). The actual maximum is not known, but the
28 value below is more than safe. }
29 const
30 MANY = 1440;
33 {$ifdef DEBUG}
34 var
35 inflate_hufts : uInt;
36 {$endif}
38 function inflate_trees_bits(
39 var c : array of uIntf; { 19 code lengths }
40 var bb : uIntf; { bits tree desired/actual depth }
41 var tb : pinflate_huft; { bits tree result }
42 var hp : array of Inflate_huft; { space for trees }
43 var z : z_stream { for messages }
44 ) : int;
46 function inflate_trees_dynamic(
47 nl : uInt; { number of literal/length codes }
48 nd : uInt; { number of distance codes }
49 var c : Array of uIntf; { that many (total) code lengths }
50 var bl : uIntf; { literal desired/actual bit depth }
51 var bd : uIntf; { distance desired/actual bit depth }
52 var tl : pInflate_huft; { literal/length tree result }
53 var td : pInflate_huft; { distance tree result }
54 var hp : array of Inflate_huft; { space for trees }
55 var z : z_stream { for messages }
56 ) : int;
58 function inflate_trees_fixed (
59 var bl : uInt; { literal desired/actual bit depth }
60 var bd : uInt; { distance desired/actual bit depth }
61 var tl : pInflate_huft; { literal/length tree result }
62 var td : pInflate_huft; { distance tree result }
63 var z : z_stream { for memory allocation }
64 ) : int;
67 implementation
69 const
70 inflate_copyright = 'inflate 1.1.2 Copyright 1995-1998 Mark Adler';
72 {
73 If you use the zlib library in a product, an acknowledgment is welcome
74 in the documentation of your product. If for some reason you cannot
75 include such an acknowledgment, I would appreciate that you keep this
76 copyright string in the executable of your product.
77 }
80 const
81 { Tables for deflate from PKZIP's appnote.txt. }
82 cplens : Array [0..30] Of uInt { Copy lengths for literal codes 257..285 }
83 = (3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
84 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0);
85 { actually lengths - 2; also see note #13 above about 258 }
87 invalid_code = 112;
89 cplext : Array [0..30] Of uInt { Extra bits for literal codes 257..285 }
90 = (0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
91 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, invalid_code, invalid_code);
93 cpdist : Array [0..29] Of uInt { Copy offsets for distance codes 0..29 }
94 = (1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
95 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
96 8193, 12289, 16385, 24577);
98 cpdext : Array [0..29] Of uInt { Extra bits for distance codes }
99 = (0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
100 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
101 12, 12, 13, 13);
103 { Huffman code decoding is performed using a multi-level table lookup.
104 The fastest way to decode is to simply build a lookup table whose
105 size is determined by the longest code. However, the time it takes
106 to build this table can also be a factor if the data being decoded
107 is not very long. The most common codes are necessarily the
108 shortest codes, so those codes dominate the decoding time, and hence
109 the speed. The idea is you can have a shorter table that decodes the
110 shorter, more probable codes, and then point to subsidiary tables for
111 the longer codes. The time it costs to decode the longer codes is
112 then traded against the time it takes to make longer tables.
114 This results of this trade are in the variables lbits and dbits
115 below. lbits is the number of bits the first level table for literal/
116 length codes can decode in one step, and dbits is the same thing for
117 the distance codes. Subsequent tables are also less than or equal to
118 those sizes. These values may be adjusted either when all of the
119 codes are shorter than that, in which case the longest code length in
120 bits is used, or when the shortest code is *longer* than the requested
121 table size, in which case the length of the shortest code in bits is
122 used.
124 There are two different values for the two tables, since they code a
125 different number of possibilities each. The literal/length table
126 codes 286 possible values, or in a flat code, a little over eight
127 bits. The distance table codes 30 possible values, or a little less
128 than five bits, flat. The optimum values for speed end up being
129 about one bit more than those, so lbits is 8+1 and dbits is 5+1.
130 The optimum values may differ though from machine to machine, and
131 possibly even between compilers. Your mileage may vary. }
134 { If BMAX needs to be larger than 16, then h and x[] should be uLong. }
135 const
136 BMAX = 15; { maximum bit length of any code }
138 {$DEFINE USE_PTR}
140 function huft_build(
141 var b : array of uIntf; { code lengths in bits (all assumed <= BMAX) }
142 n : uInt; { number of codes (assumed <= N_MAX) }
143 s : uInt; { number of simple-valued codes (0..s-1) }
144 const d : array of uIntf; { list of base values for non-simple codes }
145 { array of word }
146 const e : array of uIntf; { list of extra bits for non-simple codes }
147 { array of byte }
148 t : ppInflate_huft; { result: starting table }
149 var m : uIntf; { maximum lookup bits, returns actual }
150 var hp : array of inflate_huft; { space for trees }
151 var hn : uInt; { hufts used in space }
152 var v : array of uIntf { working area: values in order of bit length }
153 ) : int;
154 { Given a list of code lengths and a maximum table size, make a set of
155 tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
156 if the given code set is incomplete (the tables are still built in this
157 case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
158 lengths), or Z_MEM_ERROR if not enough memory. }
159 Var
160 a : uInt; { counter for codes of length k }
161 c : Array [0..BMAX] Of uInt; { bit length count table }
162 f : uInt; { i repeats in table every f entries }
163 g : int; { maximum code length }
164 h : int; { table level }
165 i : uInt; {register} { counter, current code }
166 j : uInt; {register} { counter }
167 k : Int; {register} { number of bits in current code }
168 l : int; { bits per table (returned in m) }
169 mask : uInt; { (1 shl w) - 1, to avoid cc -O bug on HP }
170 p : ^uIntf; {register} { pointer into c[], b[], or v[] }
171 q : pInflate_huft; { points to current table }
172 r : inflate_huft; { table entry for structure assignment }
173 u : Array [0..BMAX-1] Of pInflate_huft; { table stack }
174 w : int; {register} { bits before this table = (l*h) }
175 x : Array [0..BMAX] Of uInt; { bit offsets, then code stack }
176 {$IFDEF USE_PTR}
177 xp : puIntf; { pointer into x }
178 {$ELSE}
179 xp : uInt;
180 {$ENDIF}
181 y : int; { number of dummy codes added }
182 z : uInt; { number of entries in current table }
183 Begin
184 { Generate counts for each bit length }
185 FillChar(c,SizeOf(c),0) ; { clear c[] }
187 for i := 0 to n-1 do
188 Inc (c[b[i]]); { assume all entries <= BMAX }
190 If (c[0] = n) Then { null input--all zero length codes }
191 Begin
192 t^ := pInflate_huft(NIL);
193 m := 0 ;
194 huft_build := Z_OK ;
195 Exit;
196 End ;
198 { Find minimum and maximum length, bound [m] by those }
199 l := m;
200 for j:=1 To BMAX do
201 if (c[j] <> 0) then
202 break;
203 k := j ; { minimum code length }
204 if (uInt(l) < j) then
205 l := j;
206 for i := BMAX downto 1 do
207 if (c[i] <> 0) then
208 break ;
209 g := i ; { maximum code length }
210 if (uInt(l) > i) then
211 l := i;
212 m := l;
214 { Adjust last length count to fill out codes, if needed }
215 y := 1 shl j ;
216 while (j < i) do
217 begin
218 Dec(y, c[j]) ;
219 if (y < 0) then
220 begin
221 huft_build := Z_DATA_ERROR; { bad input: more codes than bits }
222 exit;
223 end ;
224 Inc(j) ;
225 y := y shl 1
226 end;
227 Dec (y, c[i]) ;
228 if (y < 0) then
229 begin
230 huft_build := Z_DATA_ERROR; { bad input: more codes than bits }
231 exit;
232 end;
233 Inc(c[i], y);
235 { Generate starting offsets into the value table FOR each length }
236 {$IFDEF USE_PTR}
237 x[1] := 0;
238 j := 0;
240 p := @c[1];
241 xp := @x[2];
243 dec(i); { note that i = g from above }
244 WHILE (i > 0) DO
245 BEGIN
246 inc(j, p^);
247 xp^ := j;
248 inc(p);
249 inc(xp);
250 dec(i);
251 END;
252 {$ELSE}
253 x[1] := 0;
254 j := 0 ;
255 for i := 1 to g do
256 begin
257 x[i] := j;
258 Inc(j, c[i]);
259 end;
260 {$ENDIF}
262 { Make a table of values in order of bit lengths }
263 for i := 0 to n-1 do
264 begin
265 j := b[i];
266 if (j <> 0) then
267 begin
268 v[ x[j] ] := i;
269 Inc(x[j]);
270 end;
271 end;
272 n := x[g]; { set n to length of v }
274 { Generate the Huffman codes and for each, make the table entries }
275 i := 0 ;
276 x[0] := 0 ; { first Huffman code is zero }
277 p := Addr(v) ; { grab values in bit order }
278 h := -1 ; { no tables yet--level -1 }
279 w := -l ; { bits decoded = (l*h) }
281 u[0] := pInflate_huft(NIL); { just to keep compilers happy }
282 q := pInflate_huft(NIL); { ditto }
283 z := 0 ; { ditto }
285 { go through the bit lengths (k already is bits in shortest code) }
286 while (k <= g) Do
287 begin
288 a := c[k] ;
289 while (a<>0) Do
290 begin
291 Dec (a) ;
292 { here i is the Huffman code of length k bits for value p^ }
293 { make tables up to required level }
294 while (k > w + l) do
295 begin
297 Inc (h) ;
298 Inc (w, l); { add bits already decoded }
299 { previous table always l bits }
300 { compute minimum size table less than or equal to l bits }
302 { table size upper limit }
303 z := g - w;
304 If (z > uInt(l)) Then
305 z := l;
307 { try a k-w bit table }
308 j := k - w;
309 f := 1 shl j;
310 if (f > a+1) Then { too few codes for k-w bit table }
311 begin
312 Dec(f, a+1); { deduct codes from patterns left }
313 {$IFDEF USE_PTR}
314 xp := Addr(c[k]);
316 if (j < z) then
317 begin
318 Inc(j);
319 while (j < z) do
320 begin { try smaller tables up to z bits }
321 f := f shl 1;
322 Inc (xp) ;
323 If (f <= xp^) Then
324 break; { enough codes to use up j bits }
325 Dec(f, xp^); { else deduct codes from patterns }
326 Inc(j);
327 end;
328 end;
329 {$ELSE}
330 xp := k;
332 if (j < z) then
333 begin
334 Inc (j) ;
335 While (j < z) Do
336 begin { try smaller tables up to z bits }
337 f := f * 2;
338 Inc (xp) ;
339 if (f <= c[xp]) then
340 Break ; { enough codes to use up j bits }
341 Dec (f, c[xp]) ; { else deduct codes from patterns }
342 Inc (j);
343 end;
344 end;
345 {$ENDIF}
346 end;
348 z := 1 shl j; { table entries for j-bit table }
350 { allocate new table }
351 if (hn + z > MANY) then { (note: doesn't matter for fixed) }
352 begin
353 huft_build := Z_MEM_ERROR; { not enough memory }
354 exit;
355 end;
357 q := @hp[hn];
358 u[h] := q;
359 Inc(hn, z);
361 { connect to last table, if there is one }
362 if (h <> 0) then
363 begin
364 x[h] := i; { save pattern for backing up }
365 r.bits := Byte(l); { bits to dump before this table }
366 r.exop := Byte(j); { bits in this table }
367 j := i shr (w - l);
368 {r.base := uInt( q - u[h-1] -j);} { offset to this table }
369 r.base := (ptr2int(q) - ptr2int(u[h-1]) ) div sizeof(q^) - j;
370 huft_Ptr(u[h-1])^[j] := r; { connect to last table }
371 end
372 else
373 t^ := q; { first table is returned result }
374 end;
376 { set up table entry in r }
377 r.bits := Byte(k - w);
379 { C-code: if (p >= v + n) - see ZUTIL.PAS for comments }
381 if ptr2int(p)>=ptr2int(@(v[n])) then { also works under DPMI ?? }
382 r.exop := 128 + 64 { out of values--invalid code }
383 else
384 if (p^ < s) then
385 begin
386 if (p^ < 256) then { 256 is end-of-block code }
387 r.exop := 0
388 Else
389 r.exop := 32 + 64; { EOB_code; }
390 r.base := p^; { simple code is just the value }
391 Inc(p);
392 end
393 Else
394 begin
395 r.exop := Byte(e[p^-s] + 16 + 64); { non-simple--look up in lists }
396 r.base := d[p^-s];
397 Inc (p);
398 end ;
400 { fill code-like entries with r }
401 f := 1 shl (k - w);
402 j := i shr w;
403 while (j < z) do
404 begin
405 huft_Ptr(q)^[j] := r;
406 Inc(j, f);
407 end;
409 { backwards increment the k-bit code i }
410 j := 1 shl (k-1) ;
411 while (i and j) <> 0 do
412 begin
413 i := i xor j; { bitwise exclusive or }
414 j := j shr 1
415 end ;
416 i := i xor j;
418 { backup over finished tables }
419 mask := (1 shl w) - 1; { needed on HP, cc -O bug }
420 while ((i and mask) <> x[h]) do
421 begin
422 Dec(h); { don't need to update q }
423 Dec(w, l);
424 mask := (1 shl w) - 1;
425 end;
427 end;
429 Inc(k);
430 end;
432 { Return Z_BUF_ERROR if we were given an incomplete table }
433 if (y <> 0) And (g <> 1) then
434 huft_build := Z_BUF_ERROR
435 else
436 huft_build := Z_OK;
437 end; { huft_build}
440 function inflate_trees_bits(
441 var c : array of uIntf; { 19 code lengths }
442 var bb : uIntf; { bits tree desired/actual depth }
443 var tb : pinflate_huft; { bits tree result }
444 var hp : array of Inflate_huft; { space for trees }
445 var z : z_stream { for messages }
446 ) : int;
447 var
448 r : int;
449 hn : uInt; { hufts used in space }
450 v : PuIntArray; { work area for huft_build }
451 begin
452 hn := 0;
453 v := PuIntArray( ZALLOC(z, 19, sizeof(uInt)) );
454 if (v = Z_NULL) then
455 begin
456 inflate_trees_bits := Z_MEM_ERROR;
457 exit;
458 end;
460 r := huft_build(c, 19, 19, cplens, cplext,
461 {puIntf(Z_NULL), puIntf(Z_NULL),}
462 @tb, bb, hp, hn, v^);
463 if (r = Z_DATA_ERROR) then
464 z.msg := 'oversubscribed dynamic bit lengths tree'
465 else
466 if (r = Z_BUF_ERROR) or (bb = 0) then
467 begin
468 z.msg := 'incomplete dynamic bit lengths tree';
469 r := Z_DATA_ERROR;
470 end;
471 ZFREE(z, v);
472 inflate_trees_bits := r;
473 end;
476 function inflate_trees_dynamic(
477 nl : uInt; { number of literal/length codes }
478 nd : uInt; { number of distance codes }
479 var c : Array of uIntf; { that many (total) code lengths }
480 var bl : uIntf; { literal desired/actual bit depth }
481 var bd : uIntf; { distance desired/actual bit depth }
482 var tl : pInflate_huft; { literal/length tree result }
483 var td : pInflate_huft; { distance tree result }
484 var hp : array of Inflate_huft; { space for trees }
485 var z : z_stream { for messages }
486 ) : int;
487 var
488 r : int;
489 hn : uInt; { hufts used in space }
490 v : PuIntArray; { work area for huft_build }
491 begin
492 hn := 0;
493 { allocate work area }
494 v := PuIntArray( ZALLOC(z, 288, sizeof(uInt)) );
495 if (v = Z_NULL) then
496 begin
497 inflate_trees_dynamic := Z_MEM_ERROR;
498 exit;
499 end;
501 { build literal/length tree }
502 r := huft_build(c, nl, 257, cplens, cplext, @tl, bl, hp, hn, v^);
503 if (r <> Z_OK) or (bl = 0) then
504 begin
505 if (r = Z_DATA_ERROR) then
506 z.msg := 'oversubscribed literal/length tree'
507 else
508 if (r <> Z_MEM_ERROR) then
509 begin
510 z.msg := 'incomplete literal/length tree';
511 r := Z_DATA_ERROR;
512 end;
514 ZFREE(z, v);
515 inflate_trees_dynamic := r;
516 exit;
517 end;
519 { build distance tree }
520 r := huft_build(puIntArray(@c[nl])^, nd, 0,
521 cpdist, cpdext, @td, bd, hp, hn, v^);
522 if (r <> Z_OK) or ((bd = 0) and (nl > 257)) then
523 begin
524 if (r = Z_DATA_ERROR) then
525 z.msg := 'oversubscribed literal/length tree'
526 else
527 if (r = Z_BUF_ERROR) then
528 begin
529 {$ifdef PKZIP_BUG_WORKAROUND}
530 r := Z_OK;
531 end;
532 {$else}
533 z.msg := 'incomplete literal/length tree';
534 r := Z_DATA_ERROR;
535 end
536 else
537 if (r <> Z_MEM_ERROR) then
538 begin
539 z.msg := 'empty distance tree with lengths';
540 r := Z_DATA_ERROR;
541 end;
542 ZFREE(z, v);
543 inflate_trees_dynamic := r;
544 exit;
545 {$endif}
546 end;
548 { done }
549 ZFREE(z, v);
550 inflate_trees_dynamic := Z_OK;
551 end;
553 {$UNDEF BUILDFIXED}
555 { build fixed tables only once--keep them here }
556 {$IFNDEF BUILDFIXED}
557 { locals }
558 var
559 fixed_built : Boolean = false;
560 const
561 FIXEDH = 544; { number of hufts used by fixed tables }
562 var
563 fixed_mem : array[0..FIXEDH-1] of inflate_huft;
564 fixed_bl : uInt;
565 fixed_bd : uInt;
566 fixed_tl : pInflate_huft;
567 fixed_td : pInflate_huft;
569 {$ELSE}
571 { inffixed.h -- table for decoding fixed codes }
573 {local}
574 const
575 fixed_bl = uInt(9);
576 {local}
577 const
578 fixed_bd = uInt(5);
579 {local}
580 const
581 fixed_tl : array [0..288-1] of inflate_huft = (
582 Exop, { number of extra bits or operation }
583 bits : Byte; { number of bits in this code or subcode }
584 {pad : uInt;} { pad structure to a power of 2 (4 bytes for }
585 { 16-bit, 8 bytes for 32-bit int's) }
586 base : uInt; { literal, length base, or distance base }
587 { or table offset }
589 ((96,7),256), ((0,8),80), ((0,8),16), ((84,8),115), ((82,7),31),
590 ((0,8),112), ((0,8),48), ((0,9),192), ((80,7),10), ((0,8),96),
591 ((0,8),32), ((0,9),160), ((0,8),0), ((0,8),128), ((0,8),64),
592 ((0,9),224), ((80,7),6), ((0,8),88), ((0,8),24), ((0,9),144),
593 ((83,7),59), ((0,8),120), ((0,8),56), ((0,9),208), ((81,7),17),
594 ((0,8),104), ((0,8),40), ((0,9),176), ((0,8),8), ((0,8),136),
595 ((0,8),72), ((0,9),240), ((80,7),4), ((0,8),84), ((0,8),20),
596 ((85,8),227), ((83,7),43), ((0,8),116), ((0,8),52), ((0,9),200),
597 ((81,7),13), ((0,8),100), ((0,8),36), ((0,9),168), ((0,8),4),
598 ((0,8),132), ((0,8),68), ((0,9),232), ((80,7),8), ((0,8),92),
599 ((0,8),28), ((0,9),152), ((84,7),83), ((0,8),124), ((0,8),60),
600 ((0,9),216), ((82,7),23), ((0,8),108), ((0,8),44), ((0,9),184),
601 ((0,8),12), ((0,8),140), ((0,8),76), ((0,9),248), ((80,7),3),
602 ((0,8),82), ((0,8),18), ((85,8),163), ((83,7),35), ((0,8),114),
603 ((0,8),50), ((0,9),196), ((81,7),11), ((0,8),98), ((0,8),34),
604 ((0,9),164), ((0,8),2), ((0,8),130), ((0,8),66), ((0,9),228),
605 ((80,7),7), ((0,8),90), ((0,8),26), ((0,9),148), ((84,7),67),
606 ((0,8),122), ((0,8),58), ((0,9),212), ((82,7),19), ((0,8),106),
607 ((0,8),42), ((0,9),180), ((0,8),10), ((0,8),138), ((0,8),74),
608 ((0,9),244), ((80,7),5), ((0,8),86), ((0,8),22), ((192,8),0),
609 ((83,7),51), ((0,8),118), ((0,8),54), ((0,9),204), ((81,7),15),
610 ((0,8),102), ((0,8),38), ((0,9),172), ((0,8),6), ((0,8),134),
611 ((0,8),70), ((0,9),236), ((80,7),9), ((0,8),94), ((0,8),30),
612 ((0,9),156), ((84,7),99), ((0,8),126), ((0,8),62), ((0,9),220),
613 ((82,7),27), ((0,8),110), ((0,8),46), ((0,9),188), ((0,8),14),
614 ((0,8),142), ((0,8),78), ((0,9),252), ((96,7),256), ((0,8),81),
615 ((0,8),17), ((85,8),131), ((82,7),31), ((0,8),113), ((0,8),49),
616 ((0,9),194), ((80,7),10), ((0,8),97), ((0,8),33), ((0,9),162),
617 ((0,8),1), ((0,8),129), ((0,8),65), ((0,9),226), ((80,7),6),
618 ((0,8),89), ((0,8),25), ((0,9),146), ((83,7),59), ((0,8),121),
619 ((0,8),57), ((0,9),210), ((81,7),17), ((0,8),105), ((0,8),41),
620 ((0,9),178), ((0,8),9), ((0,8),137), ((0,8),73), ((0,9),242),
621 ((80,7),4), ((0,8),85), ((0,8),21), ((80,8),258), ((83,7),43),
622 ((0,8),117), ((0,8),53), ((0,9),202), ((81,7),13), ((0,8),101),
623 ((0,8),37), ((0,9),170), ((0,8),5), ((0,8),133), ((0,8),69),
624 ((0,9),234), ((80,7),8), ((0,8),93), ((0,8),29), ((0,9),154),
625 ((84,7),83), ((0,8),125), ((0,8),61), ((0,9),218), ((82,7),23),
626 ((0,8),109), ((0,8),45), ((0,9),186), ((0,8),13), ((0,8),141),
627 ((0,8),77), ((0,9),250), ((80,7),3), ((0,8),83), ((0,8),19),
628 ((85,8),195), ((83,7),35), ((0,8),115), ((0,8),51), ((0,9),198),
629 ((81,7),11), ((0,8),99), ((0,8),35), ((0,9),166), ((0,8),3),
630 ((0,8),131), ((0,8),67), ((0,9),230), ((80,7),7), ((0,8),91),
631 ((0,8),27), ((0,9),150), ((84,7),67), ((0,8),123), ((0,8),59),
632 ((0,9),214), ((82,7),19), ((0,8),107), ((0,8),43), ((0,9),182),
633 ((0,8),11), ((0,8),139), ((0,8),75), ((0,9),246), ((80,7),5),
634 ((0,8),87), ((0,8),23), ((192,8),0), ((83,7),51), ((0,8),119),
635 ((0,8),55), ((0,9),206), ((81,7),15), ((0,8),103), ((0,8),39),
636 ((0,9),174), ((0,8),7), ((0,8),135), ((0,8),71), ((0,9),238),
637 ((80,7),9), ((0,8),95), ((0,8),31), ((0,9),158), ((84,7),99),
638 ((0,8),127), ((0,8),63), ((0,9),222), ((82,7),27), ((0,8),111),
639 ((0,8),47), ((0,9),190), ((0,8),15), ((0,8),143), ((0,8),79),
640 ((0,9),254), ((96,7),256), ((0,8),80), ((0,8),16), ((84,8),115),
641 ((82,7),31), ((0,8),112), ((0,8),48), ((0,9),193), ((80,7),10),
642 ((0,8),96), ((0,8),32), ((0,9),161), ((0,8),0), ((0,8),128),
643 ((0,8),64), ((0,9),225), ((80,7),6), ((0,8),88), ((0,8),24),
644 ((0,9),145), ((83,7),59), ((0,8),120), ((0,8),56), ((0,9),209),
645 ((81,7),17), ((0,8),104), ((0,8),40), ((0,9),177), ((0,8),8),
646 ((0,8),136), ((0,8),72), ((0,9),241), ((80,7),4), ((0,8),84),
647 ((0,8),20), ((85,8),227), ((83,7),43), ((0,8),116), ((0,8),52),
648 ((0,9),201), ((81,7),13), ((0,8),100), ((0,8),36), ((0,9),169),
649 ((0,8),4), ((0,8),132), ((0,8),68), ((0,9),233), ((80,7),8),
650 ((0,8),92), ((0,8),28), ((0,9),153), ((84,7),83), ((0,8),124),
651 ((0,8),60), ((0,9),217), ((82,7),23), ((0,8),108), ((0,8),44),
652 ((0,9),185), ((0,8),12), ((0,8),140), ((0,8),76), ((0,9),249),
653 ((80,7),3), ((0,8),82), ((0,8),18), ((85,8),163), ((83,7),35),
654 ((0,8),114), ((0,8),50), ((0,9),197), ((81,7),11), ((0,8),98),
655 ((0,8),34), ((0,9),165), ((0,8),2), ((0,8),130), ((0,8),66),
656 ((0,9),229), ((80,7),7), ((0,8),90), ((0,8),26), ((0,9),149),
657 ((84,7),67), ((0,8),122), ((0,8),58), ((0,9),213), ((82,7),19),
658 ((0,8),106), ((0,8),42), ((0,9),181), ((0,8),10), ((0,8),138),
659 ((0,8),74), ((0,9),245), ((80,7),5), ((0,8),86), ((0,8),22),
660 ((192,8),0), ((83,7),51), ((0,8),118), ((0,8),54), ((0,9),205),
661 ((81,7),15), ((0,8),102), ((0,8),38), ((0,9),173), ((0,8),6),
662 ((0,8),134), ((0,8),70), ((0,9),237), ((80,7),9), ((0,8),94),
663 ((0,8),30), ((0,9),157), ((84,7),99), ((0,8),126), ((0,8),62),
664 ((0,9),221), ((82,7),27), ((0,8),110), ((0,8),46), ((0,9),189),
665 ((0,8),14), ((0,8),142), ((0,8),78), ((0,9),253), ((96,7),256),
666 ((0,8),81), ((0,8),17), ((85,8),131), ((82,7),31), ((0,8),113),
667 ((0,8),49), ((0,9),195), ((80,7),10), ((0,8),97), ((0,8),33),
668 ((0,9),163), ((0,8),1), ((0,8),129), ((0,8),65), ((0,9),227),
669 ((80,7),6), ((0,8),89), ((0,8),25), ((0,9),147), ((83,7),59),
670 ((0,8),121), ((0,8),57), ((0,9),211), ((81,7),17), ((0,8),105),
671 ((0,8),41), ((0,9),179), ((0,8),9), ((0,8),137), ((0,8),73),
672 ((0,9),243), ((80,7),4), ((0,8),85), ((0,8),21), ((80,8),258),
673 ((83,7),43), ((0,8),117), ((0,8),53), ((0,9),203), ((81,7),13),
674 ((0,8),101), ((0,8),37), ((0,9),171), ((0,8),5), ((0,8),133),
675 ((0,8),69), ((0,9),235), ((80,7),8), ((0,8),93), ((0,8),29),
676 ((0,9),155), ((84,7),83), ((0,8),125), ((0,8),61), ((0,9),219),
677 ((82,7),23), ((0,8),109), ((0,8),45), ((0,9),187), ((0,8),13),
678 ((0,8),141), ((0,8),77), ((0,9),251), ((80,7),3), ((0,8),83),
679 ((0,8),19), ((85,8),195), ((83,7),35), ((0,8),115), ((0,8),51),
680 ((0,9),199), ((81,7),11), ((0,8),99), ((0,8),35), ((0,9),167),
681 ((0,8),3), ((0,8),131), ((0,8),67), ((0,9),231), ((80,7),7),
682 ((0,8),91), ((0,8),27), ((0,9),151), ((84,7),67), ((0,8),123),
683 ((0,8),59), ((0,9),215), ((82,7),19), ((0,8),107), ((0,8),43),
684 ((0,9),183), ((0,8),11), ((0,8),139), ((0,8),75), ((0,9),247),
685 ((80,7),5), ((0,8),87), ((0,8),23), ((192,8),0), ((83,7),51),
686 ((0,8),119), ((0,8),55), ((0,9),207), ((81,7),15), ((0,8),103),
687 ((0,8),39), ((0,9),175), ((0,8),7), ((0,8),135), ((0,8),71),
688 ((0,9),239), ((80,7),9), ((0,8),95), ((0,8),31), ((0,9),159),
689 ((84,7),99), ((0,8),127), ((0,8),63), ((0,9),223), ((82,7),27),
690 ((0,8),111), ((0,8),47), ((0,9),191), ((0,8),15), ((0,8),143),
691 ((0,8),79), ((0,9),255)
692 );
694 {local}
695 const
696 fixed_td : array[0..32-1] of inflate_huft = (
697 (Exop:80;bits:5;base:1), (Exop:87;bits:5;base:257), (Exop:83;bits:5;base:17),
698 (Exop:91;bits:5;base:4097), (Exop:81;bits:5;base), (Exop:89;bits:5;base:1025),
699 (Exop:85;bits:5;base:65), (Exop:93;bits:5;base:16385), (Exop:80;bits:5;base:3),
700 (Exop:88;bits:5;base:513), (Exop:84;bits:5;base:33), (Exop:92;bits:5;base:8193),
701 (Exop:82;bits:5;base:9), (Exop:90;bits:5;base:2049), (Exop:86;bits:5;base:129),
702 (Exop:192;bits:5;base:24577), (Exop:80;bits:5;base:2), (Exop:87;bits:5;base:385),
703 (Exop:83;bits:5;base:25), (Exop:91;bits:5;base:6145), (Exop:81;bits:5;base:7),
704 (Exop:89;bits:5;base:1537), (Exop:85;bits:5;base:97), (Exop:93;bits:5;base:24577),
705 (Exop:80;bits:5;base:4), (Exop:88;bits:5;base:769), (Exop:84;bits:5;base:49),
706 (Exop:92;bits:5;base:12289), (Exop:82;bits:5;base:13), (Exop:90;bits:5;base:3073),
707 (Exop:86;bits:5;base:193), (Exop:192;bits:5;base:24577)
708 );
709 {$ENDIF}
711 function inflate_trees_fixed(
712 var bl : uInt; { literal desired/actual bit depth }
713 var bd : uInt; { distance desired/actual bit depth }
714 var tl : pInflate_huft; { literal/length tree result }
715 var td : pInflate_huft; { distance tree result }
716 var z : z_stream { for memory allocation }
717 ) : int;
718 type
719 pFixed_table = ^fixed_table;
720 fixed_table = array[0..288-1] of uIntf;
721 var
722 k : int; { temporary variable }
723 c : pFixed_table; { length list for huft_build }
724 v : PuIntArray; { work area for huft_build }
725 var
726 f : uInt; { number of hufts used in fixed_mem }
727 begin
728 { build fixed tables if not already (multiple overlapped executions ok) }
729 if not fixed_built then
730 begin
731 f := 0;
733 { allocate memory }
734 c := pFixed_table( ZALLOC(z, 288, sizeof(uInt)) );
735 if (c = Z_NULL) then
736 begin
737 inflate_trees_fixed := Z_MEM_ERROR;
738 exit;
739 end;
740 v := PuIntArray( ZALLOC(z, 288, sizeof(uInt)) );
741 if (v = Z_NULL) then
742 begin
743 ZFREE(z, c);
744 inflate_trees_fixed := Z_MEM_ERROR;
745 exit;
746 end;
748 { literal table }
749 for k := 0 to Pred(144) do
750 c^[k] := 8;
751 for k := 144 to Pred(256) do
752 c^[k] := 9;
753 for k := 256 to Pred(280) do
754 c^[k] := 7;
755 for k := 280 to Pred(288) do
756 c^[k] := 8;
757 fixed_bl := 9;
758 huft_build(c^, 288, 257, cplens, cplext, @fixed_tl, fixed_bl,
759 fixed_mem, f, v^);
761 { distance table }
762 for k := 0 to Pred(30) do
763 c^[k] := 5;
764 fixed_bd := 5;
765 huft_build(c^, 30, 0, cpdist, cpdext, @fixed_td, fixed_bd,
766 fixed_mem, f, v^);
768 { done }
769 ZFREE(z, v);
770 ZFREE(z, c);
771 fixed_built := True;
772 end;
773 bl := fixed_bl;
774 bd := fixed_bd;
775 tl := fixed_tl;
776 td := fixed_td;
777 inflate_trees_fixed := Z_OK;
778 end; { inflate_trees_fixed }
781 end.