1 | {Portable Network Graphics Delphi ZLIB linking (16 May 2002) }
|
---|
2 |
|
---|
3 | {This unit links ZLIB to pngimage unit in order to implement }
|
---|
4 | {the library. It's now using the new ZLIB version, 1.1.4 }
|
---|
5 | {Note: The .obj files must be located in the subdirectory \obj}
|
---|
6 |
|
---|
7 | unit pngzlib;
|
---|
8 |
|
---|
9 | interface
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | TAlloc = function (AppData: Pointer; Items, Size: Integer): Pointer;
|
---|
14 | TFree = procedure (AppData, Block: Pointer);
|
---|
15 |
|
---|
16 | // Internal structure. Ignore.
|
---|
17 | TZStreamRec = packed record
|
---|
18 | next_in: PChar; // next input byte
|
---|
19 | avail_in: Integer; // number of bytes available at next_in
|
---|
20 | total_in: Integer; // total nb of input bytes read so far
|
---|
21 |
|
---|
22 | next_out: PChar; // next output byte should be put here
|
---|
23 | avail_out: Integer; // remaining free space at next_out
|
---|
24 | total_out: Integer; // total nb of bytes output so far
|
---|
25 |
|
---|
26 | msg: PChar; // last error message, NULL if no error
|
---|
27 | internal: Pointer; // not visible by applications
|
---|
28 |
|
---|
29 | zalloc: TAlloc; // used to allocate the internal state
|
---|
30 | zfree: TFree; // used to free the internal state
|
---|
31 | AppData: Pointer; // private data object passed to zalloc and zfree
|
---|
32 |
|
---|
33 | data_type: Integer; // best guess about the data type: ascii or binary
|
---|
34 | adler: Integer; // adler32 value of the uncompressed data
|
---|
35 | reserved: Integer; // reserved for future use
|
---|
36 | end;
|
---|
37 |
|
---|
38 | function inflateInit_(var strm: TZStreamRec; version: PChar;
|
---|
39 | recsize: Integer): Integer; forward;
|
---|
40 | function inflate(var strm: TZStreamRec; flush: Integer): Integer; forward;
|
---|
41 | function inflateEnd(var strm: TZStreamRec): Integer; forward;
|
---|
42 | function deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar;
|
---|
43 | recsize: Integer): Integer; forward;
|
---|
44 | function deflate(var strm: TZStreamRec; flush: Integer): Integer; forward;
|
---|
45 | function deflateEnd(var strm: TZStreamRec): Integer; forward;
|
---|
46 |
|
---|
47 | const
|
---|
48 | zlib_version = '1.1.4';
|
---|
49 |
|
---|
50 | function adler32(adler: Integer; buf: PChar; len: Integer): Integer;
|
---|
51 |
|
---|
52 |
|
---|
53 | const
|
---|
54 | Z_NO_FLUSH = 0;
|
---|
55 | Z_PARTIAL_FLUSH = 1;
|
---|
56 | Z_SYNC_FLUSH = 2;
|
---|
57 | Z_FULL_FLUSH = 3;
|
---|
58 | Z_FINISH = 4;
|
---|
59 |
|
---|
60 | Z_OK = 0;
|
---|
61 | Z_STREAM_END = 1;
|
---|
62 | Z_NEED_DICT = 2;
|
---|
63 | Z_ERRNO = (-1);
|
---|
64 | Z_STREAM_ERROR = (-2);
|
---|
65 | Z_DATA_ERROR = (-3);
|
---|
66 | Z_MEM_ERROR = (-4);
|
---|
67 | Z_BUF_ERROR = (-5);
|
---|
68 | Z_VERSION_ERROR = (-6);
|
---|
69 |
|
---|
70 | Z_NO_COMPRESSION = 0;
|
---|
71 | Z_BEST_SPEED = 1;
|
---|
72 | Z_BEST_COMPRESSION = 9;
|
---|
73 | Z_DEFAULT_COMPRESSION = (-1);
|
---|
74 |
|
---|
75 | Z_FILTERED = 1;
|
---|
76 | Z_HUFFMAN_ONLY = 2;
|
---|
77 | Z_DEFAULT_STRATEGY = 0;
|
---|
78 |
|
---|
79 | Z_BINARY = 0;
|
---|
80 | Z_ASCII = 1;
|
---|
81 | Z_UNKNOWN = 2;
|
---|
82 |
|
---|
83 | Z_DEFLATED = 8;
|
---|
84 |
|
---|
85 | _z_errmsg: array[0..9] of PChar = (
|
---|
86 | 'need dictionary', // Z_NEED_DICT (2)
|
---|
87 | 'stream end', // Z_STREAM_END (1)
|
---|
88 | '', // Z_OK (0)
|
---|
89 | 'file error', // Z_ERRNO (-1)
|
---|
90 | 'stream error', // Z_STREAM_ERROR (-2)
|
---|
91 | 'data error', // Z_DATA_ERROR (-3)
|
---|
92 | 'insufficient memory', // Z_MEM_ERROR (-4)
|
---|
93 | 'buffer error', // Z_BUF_ERROR (-5)
|
---|
94 | 'incompatible version', // Z_VERSION_ERROR (-6)
|
---|
95 | ''
|
---|
96 | );
|
---|
97 |
|
---|
98 | implementation
|
---|
99 |
|
---|
100 | {$L obj\deflate.obj}
|
---|
101 | {$L obj\trees.obj}
|
---|
102 | {$L obj\inflate.obj}
|
---|
103 | {$L obj\inftrees.obj}
|
---|
104 | {$L obj\adler32.obj}
|
---|
105 | {$L obj\infblock.obj}
|
---|
106 | {$L obj\infcodes.obj}
|
---|
107 | {$L obj\infutil.obj}
|
---|
108 | {$L obj\inffast.obj}
|
---|
109 |
|
---|
110 | procedure _tr_init; external;
|
---|
111 | procedure _tr_tally; external;
|
---|
112 | procedure _tr_flush_block; external;
|
---|
113 | procedure _tr_align; external;
|
---|
114 | procedure _tr_stored_block; external;
|
---|
115 | function adler32; external;
|
---|
116 | procedure inflate_blocks_new; external;
|
---|
117 | procedure inflate_blocks; external;
|
---|
118 | procedure inflate_blocks_reset; external;
|
---|
119 | procedure inflate_blocks_free; external;
|
---|
120 | procedure inflate_set_dictionary; external;
|
---|
121 | procedure inflate_trees_bits; external;
|
---|
122 | procedure inflate_trees_dynamic; external;
|
---|
123 | procedure inflate_trees_fixed; external;
|
---|
124 | procedure inflate_codes_new; external;
|
---|
125 | procedure inflate_codes; external;
|
---|
126 | procedure inflate_codes_free; external;
|
---|
127 | procedure _inflate_mask; external;
|
---|
128 | procedure inflate_flush; external;
|
---|
129 | procedure inflate_fast; external;
|
---|
130 |
|
---|
131 | procedure _memset(P: Pointer; B: Byte; count: Integer);cdecl;
|
---|
132 | begin
|
---|
133 | FillChar(P^, count, B);
|
---|
134 | end;
|
---|
135 |
|
---|
136 | procedure _memcpy(dest, source: Pointer; count: Integer);cdecl;
|
---|
137 | begin
|
---|
138 | Move(source^, dest^, count);
|
---|
139 | end;
|
---|
140 |
|
---|
141 |
|
---|
142 | // deflate compresses data
|
---|
143 | function deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar;
|
---|
144 | recsize: Integer): Integer; external;
|
---|
145 | function deflate(var strm: TZStreamRec; flush: Integer): Integer; external;
|
---|
146 | function deflateEnd(var strm: TZStreamRec): Integer; external;
|
---|
147 |
|
---|
148 | // inflate decompresses data
|
---|
149 | function inflateInit_(var strm: TZStreamRec; version: PChar;
|
---|
150 | recsize: Integer): Integer; external;
|
---|
151 | function inflate(var strm: TZStreamRec; flush: Integer): Integer; external;
|
---|
152 | function inflateEnd(var strm: TZStreamRec): Integer; external;
|
---|
153 | function inflateReset(var strm: TZStreamRec): Integer; external;
|
---|
154 |
|
---|
155 |
|
---|
156 | function zcalloc(AppData: Pointer; Items, Size: Integer): Pointer;
|
---|
157 | begin
|
---|
158 | GetMem(Result, Items*Size);
|
---|
159 | end;
|
---|
160 |
|
---|
161 | procedure zcfree(AppData, Block: Pointer);
|
---|
162 | begin
|
---|
163 | FreeMem(Block);
|
---|
164 | end;
|
---|
165 |
|
---|
166 | end.
|
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|