| 1 | /* |
|---|
| 2 | * $Id: //suprahd/releases/suprahd_163/suprahd_ztvapp640_163/drivers/graphics/PNG/lpng102/zlib.h#1 $ |
|---|
| 3 | * $Revision: #1 $ |
|---|
| 4 | * $DateTime: 2006/02/24 17:51:46 $ |
|---|
| 5 | * $Change: 42566 $ |
|---|
| 6 | * $Author: pryush.sharma $ |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | /* zlib.h -- interface of the 'zlib' general purpose compression library |
|---|
| 10 | version 1.1.3, July 9th, 1998 |
|---|
| 11 | |
|---|
| 12 | Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler |
|---|
| 13 | |
|---|
| 14 | This software is provided 'as-is', without any express or implied |
|---|
| 15 | warranty. In no event will the authors be held liable for any damages |
|---|
| 16 | arising from the use of this software. |
|---|
| 17 | |
|---|
| 18 | Permission is granted to anyone to use this software for any purpose, |
|---|
| 19 | including commercial applications, and to alter it and redistribute it |
|---|
| 20 | freely, subject to the following restrictions: |
|---|
| 21 | |
|---|
| 22 | 1. The origin of this software must not be misrepresented; you must not |
|---|
| 23 | claim that you wrote the original software. If you use this software |
|---|
| 24 | in a product, an acknowledgment in the product documentation would be |
|---|
| 25 | appreciated but is not required. |
|---|
| 26 | 2. Altered source versions must be plainly marked as such, and must not be |
|---|
| 27 | misrepresented as being the original software. |
|---|
| 28 | 3. This notice may not be removed or altered from any source distribution. |
|---|
| 29 | |
|---|
| 30 | Jean-loup Gailly Mark Adler |
|---|
| 31 | jloup@gzip.org madler@alumni.caltech.edu |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | The data format used by the zlib library is described by RFCs (Request for |
|---|
| 35 | Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt |
|---|
| 36 | (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). |
|---|
| 37 | */ |
|---|
| 38 | |
|---|
| 39 | #ifndef _ZLIB_H |
|---|
| 40 | #define _ZLIB_H |
|---|
| 41 | |
|---|
| 42 | #include "zconf.h" |
|---|
| 43 | |
|---|
| 44 | #ifdef __cplusplus |
|---|
| 45 | extern "C" { |
|---|
| 46 | #endif |
|---|
| 47 | |
|---|
| 48 | #define ZLIB_VERSION "1.1.3" |
|---|
| 49 | |
|---|
| 50 | /* |
|---|
| 51 | The 'zlib' compression library provides in-memory compression and |
|---|
| 52 | decompression functions, including integrity checks of the uncompressed |
|---|
| 53 | data. This version of the library supports only one compression method |
|---|
| 54 | (deflation) but other algorithms will be added later and will have the same |
|---|
| 55 | stream interface. |
|---|
| 56 | |
|---|
| 57 | Compression can be done in a single step if the buffers are large |
|---|
| 58 | enough (for example if an input file is mmap'ed), or can be done by |
|---|
| 59 | repeated calls of the compression function. In the latter case, the |
|---|
| 60 | application must provide more input and/or consume the output |
|---|
| 61 | (providing more output space) before each call. |
|---|
| 62 | |
|---|
| 63 | The library also supports reading and writing files in gzip (.gz) format |
|---|
| 64 | with an interface similar to that of stdio. |
|---|
| 65 | |
|---|
| 66 | The library does not install any signal handler. The decoder checks |
|---|
| 67 | the consistency of the compressed data, so the library should never |
|---|
| 68 | crash even in case of corrupted input. |
|---|
| 69 | */ |
|---|
| 70 | |
|---|
| 71 | typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); |
|---|
| 72 | typedef void (*free_func) OF((voidpf opaque, voidpf address)); |
|---|
| 73 | |
|---|
| 74 | struct internal_state; |
|---|
| 75 | |
|---|
| 76 | typedef struct z_stream_s { |
|---|
| 77 | Bytef *next_in; /* next input byte */ |
|---|
| 78 | uInt avail_in; /* number of bytes available at next_in */ |
|---|
| 79 | uLong total_in; /* total nb of input bytes read so far */ |
|---|
| 80 | |
|---|
| 81 | Bytef *next_out; /* next output byte should be put there */ |
|---|
| 82 | uInt avail_out; /* remaining free space at next_out */ |
|---|
| 83 | uLong total_out; /* total nb of bytes output so far */ |
|---|
| 84 | |
|---|
| 85 | char *msg; /* last error message, NULL if no error */ |
|---|
| 86 | struct internal_state FAR *state; /* not visible by applications */ |
|---|
| 87 | |
|---|
| 88 | alloc_func zalloc; /* used to allocate the internal state */ |
|---|
| 89 | free_func zfree; /* used to free the internal state */ |
|---|
| 90 | voidpf opaque; /* private data object passed to zalloc and zfree */ |
|---|
| 91 | |
|---|
| 92 | int data_type; /* best guess about the data type: ascii or binary */ |
|---|
| 93 | uLong adler; /* adler32 value of the uncompressed data */ |
|---|
| 94 | uLong reserved; /* reserved for future use */ |
|---|
| 95 | } z_stream; |
|---|
| 96 | |
|---|
| 97 | typedef z_stream FAR *z_streamp; |
|---|
| 98 | |
|---|
| 99 | /* |
|---|
| 100 | The application must update next_in and avail_in when avail_in has |
|---|
| 101 | dropped to zero. It must update next_out and avail_out when avail_out |
|---|
| 102 | has dropped to zero. The application must initialize zalloc, zfree and |
|---|
| 103 | opaque before calling the init function. All other fields are set by the |
|---|
| 104 | compression library and must not be updated by the application. |
|---|
| 105 | |
|---|
| 106 | The opaque value provided by the application will be passed as the first |
|---|
| 107 | parameter for calls of zalloc and zfree. This can be useful for custom |
|---|
| 108 | memory management. The compression library attaches no meaning to the |
|---|
| 109 | opaque value. |
|---|
| 110 | |
|---|
| 111 | zalloc must return Z_NULL if there is not enough memory for the object. |
|---|
| 112 | If zlib is used in a multi-threaded application, zalloc and zfree must be |
|---|
| 113 | thread safe. |
|---|
| 114 | |
|---|
| 115 | On 16-bit systems, the functions zalloc and zfree must be able to allocate |
|---|
| 116 | exactly 65536 bytes, but will not be required to allocate more than this |
|---|
| 117 | if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, |
|---|
| 118 | pointers returned by zalloc for objects of exactly 65536 bytes *must* |
|---|
| 119 | have their offset normalized to zero. The default allocation function |
|---|
| 120 | provided by this library ensures this (see zutil.c). To reduce memory |
|---|
| 121 | requirements and avoid any allocation of 64K objects, at the expense of |
|---|
| 122 | compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). |
|---|
| 123 | |
|---|
| 124 | The fields total_in and total_out can be used for statistics or |
|---|
| 125 | progress reports. After compression, total_in holds the total size of |
|---|
| 126 | the uncompressed data and may be saved for use in the decompressor |
|---|
| 127 | (particularly if the decompressor wants to decompress everything in |
|---|
| 128 | a single step). |
|---|
| 129 | */ |
|---|
| 130 | |
|---|
| 131 | /* constants */ |
|---|
| 132 | |
|---|
| 133 | #define Z_NO_FLUSH 0 |
|---|
| 134 | #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ |
|---|
| 135 | #define Z_SYNC_FLUSH 2 |
|---|
| 136 | #define Z_FULL_FLUSH 3 |
|---|
| 137 | #define Z_FINISH 4 |
|---|
| 138 | /* Allowed flush values; see deflate() below for details */ |
|---|
| 139 | |
|---|
| 140 | #define Z_OK 0 |
|---|
| 141 | #define Z_STREAM_END 1 |
|---|
| 142 | #define Z_NEED_DICT 2 |
|---|
| 143 | #define Z_ERRNO (-1) |
|---|
| 144 | #define Z_STREAM_ERROR (-2) |
|---|
| 145 | #define Z_DATA_ERROR (-3) |
|---|
| 146 | #define Z_MEM_ERROR (-4) |
|---|
| 147 | #define Z_BUF_ERROR (-5) |
|---|
| 148 | #define Z_VERSION_ERROR (-6) |
|---|
| 149 | /* Return codes for the compression/decompression functions. Negative |
|---|
| 150 | * values are errors, positive values are used for special but normal events. |
|---|
| 151 | */ |
|---|
| 152 | |
|---|
| 153 | #define Z_NO_COMPRESSION 0 |
|---|
| 154 | #define Z_BEST_SPEED 1 |
|---|
| 155 | #define Z_BEST_COMPRESSION 9 |
|---|
| 156 | #define Z_DEFAULT_COMPRESSION (-1) |
|---|
| 157 | /* compression levels */ |
|---|
| 158 | |
|---|
| 159 | #define Z_FILTERED 1 |
|---|
| 160 | #define Z_HUFFMAN_ONLY 2 |
|---|
| 161 | #define Z_DEFAULT_STRATEGY 0 |
|---|
| 162 | /* compression strategy; see deflateInit2() below for details */ |
|---|
| 163 | |
|---|
| 164 | #define Z_BINARY 0 |
|---|
| 165 | #define Z_ASCII 1 |
|---|
| 166 | #define Z_UNKNOWN 2 |
|---|
| 167 | /* Possible values of the data_type field */ |
|---|
| 168 | |
|---|
| 169 | #define Z_DEFLATED 8 |
|---|
| 170 | /* The deflate compression method (the only one supported in this version) */ |
|---|
| 171 | |
|---|
| 172 | #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ |
|---|
| 173 | |
|---|
| 174 | #define zlib_version zlibVersion() |
|---|
| 175 | /* for compatibility with versions < 1.0.2 */ |
|---|
| 176 | |
|---|
| 177 | /* basic functions */ |
|---|
| 178 | |
|---|
| 179 | ZEXTERN const char * ZEXPORT zlibVersion OF((void)); |
|---|
| 180 | /* The application can compare zlibVersion and ZLIB_VERSION for consistency. |
|---|
| 181 | If the first character differs, the library code actually used is |
|---|
| 182 | not compatible with the zlib.h header file used by the application. |
|---|
| 183 | This check is automatically made by deflateInit and png_inflateInit. |
|---|
| 184 | */ |
|---|
| 185 | |
|---|
| 186 | /* |
|---|
| 187 | ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); |
|---|
| 188 | |
|---|
| 189 | Initializes the internal stream state for compression. The fields |
|---|
| 190 | zalloc, zfree and opaque must be initialized before by the caller. |
|---|
| 191 | If zalloc and zfree are set to Z_NULL, deflateInit updates them to |
|---|
| 192 | use default allocation functions. |
|---|
| 193 | |
|---|
| 194 | The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: |
|---|
| 195 | 1 gives best speed, 9 gives best compression, 0 gives no compression at |
|---|
| 196 | all (the input data is simply copied a block at a time). |
|---|
| 197 | Z_DEFAULT_COMPRESSION requests a default compromise between speed and |
|---|
| 198 | compression (currently equivalent to level 6). |
|---|
| 199 | |
|---|
| 200 | deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not |
|---|
| 201 | enough memory, Z_STREAM_ERROR if level is not a valid compression level, |
|---|
| 202 | Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible |
|---|
| 203 | with the version assumed by the caller (ZLIB_VERSION). |
|---|
| 204 | msg is set to null if there is no error message. deflateInit does not |
|---|
| 205 | perform any compression: this will be done by deflate(). |
|---|
| 206 | */ |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); |
|---|
| 210 | /* |
|---|
| 211 | deflate compresses as much data as possible, and stops when the input |
|---|
| 212 | buffer becomes empty or the output buffer becomes full. It may introduce some |
|---|
| 213 | output latency (reading input without producing any output) except when |
|---|
| 214 | forced to flush. |
|---|
| 215 | |
|---|
| 216 | The detailed semantics are as follows. deflate performs one or both of the |
|---|
| 217 | following actions: |
|---|
| 218 | |
|---|
| 219 | - Compress more input starting at next_in and update next_in and avail_in |
|---|
| 220 | accordingly. If not all input can be processed (because there is not |
|---|
| 221 | enough room in the output buffer), next_in and avail_in are updated and |
|---|
| 222 | processing will resume at this point for the next call of deflate(). |
|---|
| 223 | |
|---|
| 224 | - Provide more output starting at next_out and update next_out and avail_out |
|---|
| 225 | accordingly. This action is forced if the parameter flush is non zero. |
|---|
| 226 | Forcing flush frequently degrades the compression ratio, so this parameter |
|---|
| 227 | should be set only when necessary (in interactive applications). |
|---|
| 228 | Some output may be provided even if flush is not set. |
|---|
| 229 | |
|---|
| 230 | Before the call of deflate(), the application should ensure that at least |
|---|
| 231 | one of the actions is possible, by providing more input and/or consuming |
|---|
| 232 | more output, and updating avail_in or avail_out accordingly; avail_out |
|---|
| 233 | should never be zero before the call. The application can consume the |
|---|
| 234 | compressed output when it wants, for example when the output buffer is full |
|---|
| 235 | (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK |
|---|
| 236 | and with zero avail_out, it must be called again after making room in the |
|---|
| 237 | output buffer because there might be more output pending. |
|---|
| 238 | |
|---|
| 239 | If the parameter flush is set to Z_SYNC_FLUSH, all pending output is |
|---|
| 240 | flushed to the output buffer and the output is aligned on a byte boundary, so |
|---|
| 241 | that the decompressor can get all input data available so far. (In particular |
|---|
| 242 | avail_in is zero after the call if enough output space has been provided |
|---|
| 243 | before the call.) Flushing may degrade compression for some compression |
|---|
| 244 | algorithms and so it should be used only when necessary. |
|---|
| 245 | |
|---|
| 246 | If flush is set to Z_FULL_FLUSH, all output is flushed as with |
|---|
| 247 | Z_SYNC_FLUSH, and the compression state is reset so that decompression can |
|---|
| 248 | restart from this point if previous compressed data has been damaged or if |
|---|
| 249 | random access is desired. Using Z_FULL_FLUSH too often can seriously degrade |
|---|
| 250 | the compression. |
|---|
| 251 | |
|---|
| 252 | If deflate returns with avail_out == 0, this function must be called again |
|---|
| 253 | with the same value of the flush parameter and more output space (updated |
|---|
| 254 | avail_out), until the flush is complete (deflate returns with non-zero |
|---|
| 255 | avail_out). |
|---|
| 256 | |
|---|
| 257 | If the parameter flush is set to Z_FINISH, pending input is processed, |
|---|
| 258 | pending output is flushed and deflate returns with Z_STREAM_END if there |
|---|
| 259 | was enough output space; if deflate returns with Z_OK, this function must be |
|---|
| 260 | called again with Z_FINISH and more output space (updated avail_out) but no |
|---|
| 261 | more input data, until it returns with Z_STREAM_END or an error. After |
|---|
| 262 | deflate has returned Z_STREAM_END, the only possible operations on the |
|---|
| 263 | stream are deflateReset or deflateEnd. |
|---|
| 264 | |
|---|
| 265 | Z_FINISH can be used immediately after deflateInit if all the compression |
|---|
| 266 | is to be done in a single step. In this case, avail_out must be at least |
|---|
| 267 | 0.1% larger than avail_in plus 12 bytes. If deflate does not return |
|---|
| 268 | Z_STREAM_END, then it must be called again as described above. |
|---|
| 269 | |
|---|
| 270 | deflate() sets strm->adler to the adler32 checksum of all input read |
|---|
| 271 | so far (that is, total_in bytes). |
|---|
| 272 | |
|---|
| 273 | deflate() may update data_type if it can make a good guess about |
|---|
| 274 | the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered |
|---|
| 275 | binary. This field is only for information purposes and does not affect |
|---|
| 276 | the compression algorithm in any manner. |
|---|
| 277 | |
|---|
| 278 | deflate() returns Z_OK if some progress has been made (more input |
|---|
| 279 | processed or more output produced), Z_STREAM_END if all input has been |
|---|
| 280 | consumed and all output has been produced (only when flush is set to |
|---|
| 281 | Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example |
|---|
| 282 | if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible |
|---|
| 283 | (for example avail_in or avail_out was zero). |
|---|
| 284 | */ |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); |
|---|
| 288 | /* |
|---|
| 289 | All dynamically allocated data structures for this stream are freed. |
|---|
| 290 | This function discards any unprocessed input and does not flush any |
|---|
| 291 | pending output. |
|---|
| 292 | |
|---|
| 293 | deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the |
|---|
| 294 | stream state was inconsistent, Z_DATA_ERROR if the stream was freed |
|---|
| 295 | prematurely (some input or output was discarded). In the error case, |
|---|
| 296 | msg may be set but then points to a static string (which must not be |
|---|
| 297 | deallocated). |
|---|
| 298 | */ |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | /* |
|---|
| 302 | ZEXTERN int ZEXPORT png_inflateInit OF((z_streamp strm)); |
|---|
| 303 | |
|---|
| 304 | Initializes the internal stream state for decompression. The fields |
|---|
| 305 | next_in, avail_in, zalloc, zfree and opaque must be initialized before by |
|---|
| 306 | the caller. If next_in is not Z_NULL and avail_in is large enough (the exact |
|---|
| 307 | value depends on the compression method), png_inflateInit determines the |
|---|
| 308 | compression method from the zlib header and allocates all data structures |
|---|
| 309 | accordingly; otherwise the allocation will be deferred to the first call of |
|---|
| 310 | png_inflate. If zalloc and zfree are set to Z_NULL, png_inflateInit updates them to |
|---|
| 311 | use default allocation functions. |
|---|
| 312 | |
|---|
| 313 | png_inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough |
|---|
| 314 | memory, Z_VERSION_ERROR if the zlib library version is incompatible with the |
|---|
| 315 | version assumed by the caller. msg is set to null if there is no error |
|---|
| 316 | message. png_inflateInit does not perform any decompression apart from reading |
|---|
| 317 | the zlib header if present: this will be done by png_inflate(). (So next_in and |
|---|
| 318 | avail_in may be modified, but next_out and avail_out are unchanged.) |
|---|
| 319 | */ |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | ZEXTERN int ZEXPORT png_inflate OF((z_streamp strm, int flush)); |
|---|
| 323 | /* |
|---|
| 324 | png_inflate decompresses as much data as possible, and stops when the input |
|---|
| 325 | buffer becomes empty or the output buffer becomes full. It may some |
|---|
| 326 | introduce some output latency (reading input without producing any output) |
|---|
| 327 | except when forced to flush. |
|---|
| 328 | |
|---|
| 329 | The detailed semantics are as follows. png_inflate performs one or both of the |
|---|
| 330 | following actions: |
|---|
| 331 | |
|---|
| 332 | - Decompress more input starting at next_in and update next_in and avail_in |
|---|
| 333 | accordingly. If not all input can be processed (because there is not |
|---|
| 334 | enough room in the output buffer), next_in is updated and processing |
|---|
| 335 | will resume at this point for the next call of png_inflate(). |
|---|
| 336 | |
|---|
| 337 | - Provide more output starting at next_out and update next_out and avail_out |
|---|
| 338 | accordingly. png_inflate() provides as much output as possible, until there |
|---|
| 339 | is no more input data or no more space in the output buffer (see below |
|---|
| 340 | about the flush parameter). |
|---|
| 341 | |
|---|
| 342 | Before the call of png_inflate(), the application should ensure that at least |
|---|
| 343 | one of the actions is possible, by providing more input and/or consuming |
|---|
| 344 | more output, and updating the next_* and avail_* values accordingly. |
|---|
| 345 | The application can consume the uncompressed output when it wants, for |
|---|
| 346 | example when the output buffer is full (avail_out == 0), or after each |
|---|
| 347 | call of png_inflate(). If png_inflate returns Z_OK and with zero avail_out, it |
|---|
| 348 | must be called again after making room in the output buffer because there |
|---|
| 349 | might be more output pending. |
|---|
| 350 | |
|---|
| 351 | If the parameter flush is set to Z_SYNC_FLUSH, png_inflate flushes as much |
|---|
| 352 | output as possible to the output buffer. The flushing behavior of png_inflate is |
|---|
| 353 | not specified for values of the flush parameter other than Z_SYNC_FLUSH |
|---|
| 354 | and Z_FINISH, but the current implementation actually flushes as much output |
|---|
| 355 | as possible anyway. |
|---|
| 356 | |
|---|
| 357 | png_inflate() should normally be called until it returns Z_STREAM_END or an |
|---|
| 358 | error. However if all decompression is to be performed in a single step |
|---|
| 359 | (a single call of png_inflate), the parameter flush should be set to |
|---|
| 360 | Z_FINISH. In this case all pending input is processed and all pending |
|---|
| 361 | output is flushed; avail_out must be large enough to hold all the |
|---|
| 362 | uncompressed data. (The size of the uncompressed data may have been saved |
|---|
| 363 | by the compressor for this purpose.) The next operation on this stream must |
|---|
| 364 | be png_inflateEnd to deallocate the decompression state. The use of Z_FINISH |
|---|
| 365 | is never required, but can be used to inform png_inflate that a faster routine |
|---|
| 366 | may be used for the single png_inflate() call. |
|---|
| 367 | |
|---|
| 368 | If a preset dictionary is needed at this point (see png_inflateSetDictionary |
|---|
| 369 | below), png_inflate sets strm-adler to the adler32 checksum of the |
|---|
| 370 | dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise |
|---|
| 371 | it sets strm->adler to the adler32 checksum of all output produced |
|---|
| 372 | so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or |
|---|
| 373 | an error code as described below. At the end of the stream, png_inflate() |
|---|
| 374 | checks that its computed adler32 checksum is equal to that saved by the |
|---|
| 375 | compressor and returns Z_STREAM_END only if the checksum is correct. |
|---|
| 376 | |
|---|
| 377 | png_inflate() returns Z_OK if some progress has been made (more input processed |
|---|
| 378 | or more output produced), Z_STREAM_END if the end of the compressed data has |
|---|
| 379 | been reached and all uncompressed output has been produced, Z_NEED_DICT if a |
|---|
| 380 | preset dictionary is needed at this point, Z_DATA_ERROR if the input data was |
|---|
| 381 | corrupted (input stream not conforming to the zlib format or incorrect |
|---|
| 382 | adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent |
|---|
| 383 | (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not |
|---|
| 384 | enough memory, Z_BUF_ERROR if no progress is possible or if there was not |
|---|
| 385 | enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR |
|---|
| 386 | case, the application may then call png_inflateSync to look for a good |
|---|
| 387 | compression block. |
|---|
| 388 | */ |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | ZEXTERN int ZEXPORT png_inflateEnd OF((z_streamp strm)); |
|---|
| 392 | /* |
|---|
| 393 | All dynamically allocated data structures for this stream are freed. |
|---|
| 394 | This function discards any unprocessed input and does not flush any |
|---|
| 395 | pending output. |
|---|
| 396 | |
|---|
| 397 | png_inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state |
|---|
| 398 | was inconsistent. In the error case, msg may be set but then points to a |
|---|
| 399 | static string (which must not be deallocated). |
|---|
| 400 | */ |
|---|
| 401 | |
|---|
| 402 | /* Advanced functions */ |
|---|
| 403 | |
|---|
| 404 | /* |
|---|
| 405 | The following functions are needed only in some special applications. |
|---|
| 406 | */ |
|---|
| 407 | |
|---|
| 408 | /* |
|---|
| 409 | ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, |
|---|
| 410 | int level, |
|---|
| 411 | int method, |
|---|
| 412 | int windowBits, |
|---|
| 413 | int memLevel, |
|---|
| 414 | int strategy)); |
|---|
| 415 | |
|---|
| 416 | This is another version of deflateInit with more compression options. The |
|---|
| 417 | fields next_in, zalloc, zfree and opaque must be initialized before by |
|---|
| 418 | the caller. |
|---|
| 419 | |
|---|
| 420 | The method parameter is the compression method. It must be Z_DEFLATED in |
|---|
| 421 | this version of the library. |
|---|
| 422 | |
|---|
| 423 | The windowBits parameter is the base two logarithm of the window size |
|---|
| 424 | (the size of the history buffer). It should be in the range 8..15 for this |
|---|
| 425 | version of the library. Larger values of this parameter result in better |
|---|
| 426 | compression at the expense of memory usage. The default value is 15 if |
|---|
| 427 | deflateInit is used instead. |
|---|
| 428 | |
|---|
| 429 | The memLevel parameter specifies how much memory should be allocated |
|---|
| 430 | for the internal compression state. memLevel=1 uses minimum memory but |
|---|
| 431 | is slow and reduces compression ratio; memLevel=9 uses maximum memory |
|---|
| 432 | for optimal speed. The default value is 8. See zconf.h for total memory |
|---|
| 433 | usage as a function of windowBits and memLevel. |
|---|
| 434 | |
|---|
| 435 | The strategy parameter is used to tune the compression algorithm. Use the |
|---|
| 436 | value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a |
|---|
| 437 | filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no |
|---|
| 438 | string match). Filtered data consists mostly of small values with a |
|---|
| 439 | somewhat random distribution. In this case, the compression algorithm is |
|---|
| 440 | tuned to compress them better. The effect of Z_FILTERED is to force more |
|---|
| 441 | Huffman coding and less string matching; it is somewhat intermediate |
|---|
| 442 | between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects |
|---|
| 443 | the compression ratio but not the correctness of the compressed output even |
|---|
| 444 | if it is not set appropriately. |
|---|
| 445 | |
|---|
| 446 | deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
|---|
| 447 | memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid |
|---|
| 448 | method). msg is set to null if there is no error message. deflateInit2 does |
|---|
| 449 | not perform any compression: this will be done by deflate(). |
|---|
| 450 | */ |
|---|
| 451 | |
|---|
| 452 | ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, |
|---|
| 453 | const Bytef *dictionary, |
|---|
| 454 | uInt dictLength)); |
|---|
| 455 | /* |
|---|
| 456 | Initializes the compression dictionary from the given byte sequence |
|---|
| 457 | without producing any compressed output. This function must be called |
|---|
| 458 | immediately after deflateInit, deflateInit2 or deflateReset, before any |
|---|
| 459 | call of deflate. The compressor and decompressor must use exactly the same |
|---|
| 460 | dictionary (see png_inflateSetDictionary). |
|---|
| 461 | |
|---|
| 462 | The dictionary should consist of strings (byte sequences) that are likely |
|---|
| 463 | to be encountered later in the data to be compressed, with the most commonly |
|---|
| 464 | used strings preferably put towards the end of the dictionary. Using a |
|---|
| 465 | dictionary is most useful when the data to be compressed is short and can be |
|---|
| 466 | predicted with good accuracy; the data can then be compressed better than |
|---|
| 467 | with the default empty dictionary. |
|---|
| 468 | |
|---|
| 469 | Depending on the size of the compression data structures selected by |
|---|
| 470 | deflateInit or deflateInit2, a part of the dictionary may in effect be |
|---|
| 471 | discarded, for example if the dictionary is larger than the window size in |
|---|
| 472 | deflate or deflate2. Thus the strings most likely to be useful should be |
|---|
| 473 | put at the end of the dictionary, not at the front. |
|---|
| 474 | |
|---|
| 475 | Upon return of this function, strm->adler is set to the Adler32 value |
|---|
| 476 | of the dictionary; the decompressor may later use this value to determine |
|---|
| 477 | which dictionary has been used by the compressor. (The Adler32 value |
|---|
| 478 | applies to the whole dictionary even if only a subset of the dictionary is |
|---|
| 479 | actually used by the compressor.) |
|---|
| 480 | |
|---|
| 481 | deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a |
|---|
| 482 | parameter is invalid (such as NULL dictionary) or the stream state is |
|---|
| 483 | inconsistent (for example if deflate has already been called for this stream |
|---|
| 484 | or if the compression method is bsort). deflateSetDictionary does not |
|---|
| 485 | perform any compression: this will be done by deflate(). |
|---|
| 486 | */ |
|---|
| 487 | |
|---|
| 488 | ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, |
|---|
| 489 | z_streamp source)); |
|---|
| 490 | /* |
|---|
| 491 | Sets the destination stream as a complete copy of the source stream. |
|---|
| 492 | |
|---|
| 493 | This function can be useful when several compression strategies will be |
|---|
| 494 | tried, for example when there are several ways of pre-processing the input |
|---|
| 495 | data with a filter. The streams that will be discarded should then be freed |
|---|
| 496 | by calling deflateEnd. Note that deflateCopy duplicates the internal |
|---|
| 497 | compression state which can be quite large, so this strategy is slow and |
|---|
| 498 | can consume lots of memory. |
|---|
| 499 | |
|---|
| 500 | deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not |
|---|
| 501 | enough memory, Z_STREAM_ERROR if the source stream state was inconsistent |
|---|
| 502 | (such as zalloc being NULL). msg is left unchanged in both source and |
|---|
| 503 | destination. |
|---|
| 504 | */ |
|---|
| 505 | |
|---|
| 506 | ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); |
|---|
| 507 | /* |
|---|
| 508 | This function is equivalent to deflateEnd followed by deflateInit, |
|---|
| 509 | but does not free and reallocate all the internal compression state. |
|---|
| 510 | The stream will keep the same compression level and any other attributes |
|---|
| 511 | that may have been set by deflateInit2. |
|---|
| 512 | |
|---|
| 513 | deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source |
|---|
| 514 | stream state was inconsistent (such as zalloc or state being NULL). |
|---|
| 515 | */ |
|---|
| 516 | |
|---|
| 517 | ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, |
|---|
| 518 | int level, |
|---|
| 519 | int strategy)); |
|---|
| 520 | /* |
|---|
| 521 | Dynamically update the compression level and compression strategy. The |
|---|
| 522 | interpretation of level and strategy is as in deflateInit2. This can be |
|---|
| 523 | used to switch between compression and straight copy of the input data, or |
|---|
| 524 | to switch to a different kind of input data requiring a different |
|---|
| 525 | strategy. If the compression level is changed, the input available so far |
|---|
| 526 | is compressed with the old level (and may be flushed); the new level will |
|---|
| 527 | take effect only at the next call of deflate(). |
|---|
| 528 | |
|---|
| 529 | Before the call of deflateParams, the stream state must be set as for |
|---|
| 530 | a call of deflate(), since the currently available input may have to |
|---|
| 531 | be compressed and flushed. In particular, strm->avail_out must be non-zero. |
|---|
| 532 | |
|---|
| 533 | deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source |
|---|
| 534 | stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR |
|---|
| 535 | if strm->avail_out was zero. |
|---|
| 536 | */ |
|---|
| 537 | |
|---|
| 538 | /* |
|---|
| 539 | ZEXTERN int ZEXPORT png_inflateInit2 OF((z_streamp strm, |
|---|
| 540 | int windowBits)); |
|---|
| 541 | |
|---|
| 542 | This is another version of png_inflateInit with an extra parameter. The |
|---|
| 543 | fields next_in, avail_in, zalloc, zfree and opaque must be initialized |
|---|
| 544 | before by the caller. |
|---|
| 545 | |
|---|
| 546 | The windowBits parameter is the base two logarithm of the maximum window |
|---|
| 547 | size (the size of the history buffer). It should be in the range 8..15 for |
|---|
| 548 | this version of the library. The default value is 15 if png_inflateInit is used |
|---|
| 549 | instead. If a compressed stream with a larger window size is given as |
|---|
| 550 | input, png_inflate() will return with the error code Z_DATA_ERROR instead of |
|---|
| 551 | trying to allocate a larger window. |
|---|
| 552 | |
|---|
| 553 | png_inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
|---|
| 554 | memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative |
|---|
| 555 | memLevel). msg is set to null if there is no error message. png_inflateInit2 |
|---|
| 556 | does not perform any decompression apart from reading the zlib header if |
|---|
| 557 | present: this will be done by png_inflate(). (So next_in and avail_in may be |
|---|
| 558 | modified, but next_out and avail_out are unchanged.) |
|---|
| 559 | */ |
|---|
| 560 | |
|---|
| 561 | ZEXTERN int ZEXPORT png_inflateSetDictionary OF((z_streamp strm, |
|---|
| 562 | const Bytef *dictionary, |
|---|
| 563 | uInt dictLength)); |
|---|
| 564 | /* |
|---|
| 565 | Initializes the decompression dictionary from the given uncompressed byte |
|---|
| 566 | sequence. This function must be called immediately after a call of png_inflate |
|---|
| 567 | if this call returned Z_NEED_DICT. The dictionary chosen by the compressor |
|---|
| 568 | can be determined from the Adler32 value returned by this call of |
|---|
| 569 | png_inflate. The compressor and decompressor must use exactly the same |
|---|
| 570 | dictionary (see deflateSetDictionary). |
|---|
| 571 | |
|---|
| 572 | png_inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a |
|---|
| 573 | parameter is invalid (such as NULL dictionary) or the stream state is |
|---|
| 574 | inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the |
|---|
| 575 | expected one (incorrect Adler32 value). png_inflateSetDictionary does not |
|---|
| 576 | perform any decompression: this will be done by subsequent calls of |
|---|
| 577 | png_inflate(). |
|---|
| 578 | */ |
|---|
| 579 | |
|---|
| 580 | ZEXTERN int ZEXPORT png_inflateSync OF((z_streamp strm)); |
|---|
| 581 | /* |
|---|
| 582 | Skips invalid compressed data until a full flush point (see above the |
|---|
| 583 | description of deflate with Z_FULL_FLUSH) can be found, or until all |
|---|
| 584 | available input is skipped. No output is provided. |
|---|
| 585 | |
|---|
| 586 | png_inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR |
|---|
| 587 | if no more input was provided, Z_DATA_ERROR if no flush point has been found, |
|---|
| 588 | or Z_STREAM_ERROR if the stream structure was inconsistent. In the success |
|---|
| 589 | case, the application may save the current current value of total_in which |
|---|
| 590 | indicates where valid compressed data was found. In the error case, the |
|---|
| 591 | application may repeatedly call png_inflateSync, providing more input each time, |
|---|
| 592 | until success or end of the input data. |
|---|
| 593 | */ |
|---|
| 594 | |
|---|
| 595 | ZEXTERN int ZEXPORT png_inflateReset OF((z_streamp strm)); |
|---|
| 596 | /* |
|---|
| 597 | This function is equivalent to png_inflateEnd followed by png_inflateInit, |
|---|
| 598 | but does not free and reallocate all the internal decompression state. |
|---|
| 599 | The stream will keep attributes that may have been set by png_inflateInit2. |
|---|
| 600 | |
|---|
| 601 | png_inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source |
|---|
| 602 | stream state was inconsistent (such as zalloc or state being NULL). |
|---|
| 603 | */ |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | /* utility functions */ |
|---|
| 607 | |
|---|
| 608 | /* |
|---|
| 609 | The following utility functions are implemented on top of the |
|---|
| 610 | basic stream-oriented functions. To simplify the interface, some |
|---|
| 611 | default options are assumed (compression level and memory usage, |
|---|
| 612 | standard memory allocation functions). The source code of these |
|---|
| 613 | utility functions can easily be modified if you need special options. |
|---|
| 614 | */ |
|---|
| 615 | |
|---|
| 616 | ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, |
|---|
| 617 | const Bytef *source, uLong sourceLen)); |
|---|
| 618 | /* |
|---|
| 619 | Compresses the source buffer into the destination buffer. sourceLen is |
|---|
| 620 | the byte length of the source buffer. Upon entry, destLen is the total |
|---|
| 621 | size of the destination buffer, which must be at least 0.1% larger than |
|---|
| 622 | sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the |
|---|
| 623 | compressed buffer. |
|---|
| 624 | This function can be used to compress a whole file at once if the |
|---|
| 625 | input file is mmap'ed. |
|---|
| 626 | compress returns Z_OK if success, Z_MEM_ERROR if there was not |
|---|
| 627 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
|---|
| 628 | buffer. |
|---|
| 629 | */ |
|---|
| 630 | |
|---|
| 631 | ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, |
|---|
| 632 | const Bytef *source, uLong sourceLen, |
|---|
| 633 | int level)); |
|---|
| 634 | /* |
|---|
| 635 | Compresses the source buffer into the destination buffer. The level |
|---|
| 636 | parameter has the same meaning as in deflateInit. sourceLen is the byte |
|---|
| 637 | length of the source buffer. Upon entry, destLen is the total size of the |
|---|
| 638 | destination buffer, which must be at least 0.1% larger than sourceLen plus |
|---|
| 639 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. |
|---|
| 640 | |
|---|
| 641 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
|---|
| 642 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, |
|---|
| 643 | Z_STREAM_ERROR if the level parameter is invalid. |
|---|
| 644 | */ |
|---|
| 645 | |
|---|
| 646 | ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, |
|---|
| 647 | const Bytef *source, uLong sourceLen)); |
|---|
| 648 | /* |
|---|
| 649 | Decompresses the source buffer into the destination buffer. sourceLen is |
|---|
| 650 | the byte length of the source buffer. Upon entry, destLen is the total |
|---|
| 651 | size of the destination buffer, which must be large enough to hold the |
|---|
| 652 | entire uncompressed data. (The size of the uncompressed data must have |
|---|
| 653 | been saved previously by the compressor and transmitted to the decompressor |
|---|
| 654 | by some mechanism outside the scope of this compression library.) |
|---|
| 655 | Upon exit, destLen is the actual size of the compressed buffer. |
|---|
| 656 | This function can be used to decompress a whole file at once if the |
|---|
| 657 | input file is mmap'ed. |
|---|
| 658 | |
|---|
| 659 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not |
|---|
| 660 | enough memory, Z_BUF_ERROR if there was not enough room in the output |
|---|
| 661 | buffer, or Z_DATA_ERROR if the input data was corrupted. |
|---|
| 662 | */ |
|---|
| 663 | |
|---|
| 664 | |
|---|
| 665 | typedef voidp gzFile; |
|---|
| 666 | |
|---|
| 667 | ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); |
|---|
| 668 | /* |
|---|
| 669 | Opens a gzip (.gz) file for reading or writing. The mode parameter |
|---|
| 670 | is as in fopen ("rb" or "wb") but can also include a compression level |
|---|
| 671 | ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for |
|---|
| 672 | Huffman only compression as in "wb1h". (See the description |
|---|
| 673 | of deflateInit2 for more information about the strategy parameter.) |
|---|
| 674 | |
|---|
| 675 | gzopen can be used to read a file which is not in gzip format; in this |
|---|
| 676 | case gzread will directly read from the file without decompression. |
|---|
| 677 | |
|---|
| 678 | gzopen returns NULL if the file could not be opened or if there was |
|---|
| 679 | insufficient memory to allocate the (de)compression state; errno |
|---|
| 680 | can be checked to distinguish the two cases (if errno is zero, the |
|---|
| 681 | zlib error is Z_MEM_ERROR). */ |
|---|
| 682 | |
|---|
| 683 | ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); |
|---|
| 684 | /* |
|---|
| 685 | gzdopen() associates a gzFile with the file descriptor fd. File |
|---|
| 686 | descriptors are obtained from calls like open, dup, creat, pipe or |
|---|
| 687 | fileno (in the file has been previously opened with fopen). |
|---|
| 688 | The mode parameter is as in gzopen. |
|---|
| 689 | The next call of gzclose on the returned gzFile will also close the |
|---|
| 690 | file descriptor fd, just like fclose(fdopen(fd), mode) closes the file |
|---|
| 691 | descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). |
|---|
| 692 | gzdopen returns NULL if there was insufficient memory to allocate |
|---|
| 693 | the (de)compression state. |
|---|
| 694 | */ |
|---|
| 695 | |
|---|
| 696 | ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); |
|---|
| 697 | /* |
|---|
| 698 | Dynamically update the compression level or strategy. See the description |
|---|
| 699 | of deflateInit2 for the meaning of these parameters. |
|---|
| 700 | gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not |
|---|
| 701 | opened for writing. |
|---|
| 702 | */ |
|---|
| 703 | |
|---|
| 704 | ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); |
|---|
| 705 | /* |
|---|
| 706 | Reads the given number of uncompressed bytes from the compressed file. |
|---|
| 707 | If the input file was not in gzip format, gzread copies the given number |
|---|
| 708 | of bytes into the buffer. |
|---|
| 709 | gzread returns the number of uncompressed bytes actually read (0 for |
|---|
| 710 | end of file, -1 for error). */ |
|---|
| 711 | |
|---|
| 712 | ZEXTERN int ZEXPORT gzwrite OF((gzFile file, |
|---|
| 713 | const voidp buf, unsigned len)); |
|---|
| 714 | /* |
|---|
| 715 | Writes the given number of uncompressed bytes into the compressed file. |
|---|
| 716 | gzwrite returns the number of uncompressed bytes actually written |
|---|
| 717 | (0 in case of error). |
|---|
| 718 | */ |
|---|
| 719 | |
|---|
| 720 | ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); |
|---|
| 721 | /* |
|---|
| 722 | Converts, formats, and writes the args to the compressed file under |
|---|
| 723 | control of the format string, as in fprintf. gzprintf returns the number of |
|---|
| 724 | uncompressed bytes actually written (0 in case of error). |
|---|
| 725 | */ |
|---|
| 726 | |
|---|
| 727 | ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); |
|---|
| 728 | /* |
|---|
| 729 | Writes the given null-terminated string to the compressed file, excluding |
|---|
| 730 | the terminating null character. |
|---|
| 731 | gzputs returns the number of characters written, or -1 in case of error. |
|---|
| 732 | */ |
|---|
| 733 | |
|---|
| 734 | ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); |
|---|
| 735 | /* |
|---|
| 736 | Reads bytes from the compressed file until len-1 characters are read, or |
|---|
| 737 | a newline character is read and transferred to buf, or an end-of-file |
|---|
| 738 | condition is encountered. The string is then terminated with a null |
|---|
| 739 | character. |
|---|
| 740 | gzgets returns buf, or Z_NULL in case of error. |
|---|
| 741 | */ |
|---|
| 742 | |
|---|
| 743 | ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); |
|---|
| 744 | /* |
|---|
| 745 | Writes c, converted to an unsigned char, into the compressed file. |
|---|
| 746 | gzputc returns the value that was written, or -1 in case of error. |
|---|
| 747 | */ |
|---|
| 748 | |
|---|
| 749 | ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); |
|---|
| 750 | /* |
|---|
| 751 | Reads one byte from the compressed file. gzgetc returns this byte |
|---|
| 752 | or -1 in case of end of file or error. |
|---|
| 753 | */ |
|---|
| 754 | |
|---|
| 755 | ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); |
|---|
| 756 | /* |
|---|
| 757 | Flushes all pending output into the compressed file. The parameter |
|---|
| 758 | flush is as in the deflate() function. The return value is the zlib |
|---|
| 759 | error number (see function gzerror below). gzflush returns Z_OK if |
|---|
| 760 | the flush parameter is Z_FINISH and all output could be flushed. |
|---|
| 761 | gzflush should be called only when strictly necessary because it can |
|---|
| 762 | degrade compression. |
|---|
| 763 | */ |
|---|
| 764 | |
|---|
| 765 | ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, |
|---|
| 766 | z_off_t offset, int whence)); |
|---|
| 767 | /* |
|---|
| 768 | Sets the starting position for the next gzread or gzwrite on the |
|---|
| 769 | given compressed file. The offset represents a number of bytes in the |
|---|
| 770 | uncompressed data stream. The whence parameter is defined as in lseek(2); |
|---|
| 771 | the value SEEK_END is not supported. |
|---|
| 772 | If the file is opened for reading, this function is emulated but can be |
|---|
| 773 | extremely slow. If the file is opened for writing, only forward seeks are |
|---|
| 774 | supported; gzseek then compresses a sequence of zeroes up to the new |
|---|
| 775 | starting position. |
|---|
| 776 | |
|---|
| 777 | gzseek returns the resulting offset location as measured in bytes from |
|---|
| 778 | the beginning of the uncompressed stream, or -1 in case of error, in |
|---|
| 779 | particular if the file is opened for writing and the new starting position |
|---|
| 780 | would be before the current position. |
|---|
| 781 | */ |
|---|
| 782 | |
|---|
| 783 | ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); |
|---|
| 784 | /* |
|---|
| 785 | Rewinds the given file. This function is supported only for reading. |
|---|
| 786 | |
|---|
| 787 | gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) |
|---|
| 788 | */ |
|---|
| 789 | |
|---|
| 790 | ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); |
|---|
| 791 | /* |
|---|
| 792 | Returns the starting position for the next gzread or gzwrite on the |
|---|
| 793 | given compressed file. This position represents a number of bytes in the |
|---|
| 794 | uncompressed data stream. |
|---|
| 795 | |
|---|
| 796 | gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) |
|---|
| 797 | */ |
|---|
| 798 | |
|---|
| 799 | ZEXTERN int ZEXPORT gzeof OF((gzFile file)); |
|---|
| 800 | /* |
|---|
| 801 | Returns 1 when EOF has previously been detected reading the given |
|---|
| 802 | input stream, otherwise zero. |
|---|
| 803 | */ |
|---|
| 804 | |
|---|
| 805 | ZEXTERN int ZEXPORT gzclose OF((gzFile file)); |
|---|
| 806 | /* |
|---|
| 807 | Flushes all pending output if necessary, closes the compressed file |
|---|
| 808 | and deallocates all the (de)compression state. The return value is the zlib |
|---|
| 809 | error number (see function gzerror below). |
|---|
| 810 | */ |
|---|
| 811 | |
|---|
| 812 | ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); |
|---|
| 813 | /* |
|---|
| 814 | Returns the error message for the last error which occurred on the |
|---|
| 815 | given compressed file. errnum is set to zlib error number. If an |
|---|
| 816 | error occurred in the file system and not in the compression library, |
|---|
| 817 | errnum is set to Z_ERRNO and the application may consult errno |
|---|
| 818 | to get the exact error code. |
|---|
| 819 | */ |
|---|
| 820 | |
|---|
| 821 | /* checksum functions */ |
|---|
| 822 | |
|---|
| 823 | /* |
|---|
| 824 | These functions are not related to compression but are exported |
|---|
| 825 | anyway because they might be useful in applications using the |
|---|
| 826 | compression library. |
|---|
| 827 | */ |
|---|
| 828 | |
|---|
| 829 | ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); |
|---|
| 830 | |
|---|
| 831 | /* |
|---|
| 832 | Update a running Adler-32 checksum with the bytes buf[0..len-1] and |
|---|
| 833 | return the updated checksum. If buf is NULL, this function returns |
|---|
| 834 | the required initial value for the checksum. |
|---|
| 835 | An Adler-32 checksum is almost as reliable as a CRC32 but can be computed |
|---|
| 836 | much faster. Usage example: |
|---|
| 837 | |
|---|
| 838 | uLong adler = adler32(0L, Z_NULL, 0); |
|---|
| 839 | |
|---|
| 840 | while (read_buffer(buffer, length) != EOF) { |
|---|
| 841 | adler = adler32(adler, buffer, length); |
|---|
| 842 | } |
|---|
| 843 | if (adler != original_adler) error(); |
|---|
| 844 | */ |
|---|
| 845 | |
|---|
| 846 | ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); |
|---|
| 847 | /* |
|---|
| 848 | Update a running crc with the bytes buf[0..len-1] and return the updated |
|---|
| 849 | crc. If buf is NULL, this function returns the required initial value |
|---|
| 850 | for the crc. Pre- and post-conditioning (one's complement) is performed |
|---|
| 851 | within this function so it shouldn't be done by the application. |
|---|
| 852 | Usage example: |
|---|
| 853 | |
|---|
| 854 | uLong crc = crc32(0L, Z_NULL, 0); |
|---|
| 855 | |
|---|
| 856 | while (read_buffer(buffer, length) != EOF) { |
|---|
| 857 | crc = crc32(crc, buffer, length); |
|---|
| 858 | } |
|---|
| 859 | if (crc != original_crc) error(); |
|---|
| 860 | */ |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | /* various hacks, don't look :) */ |
|---|
| 864 | |
|---|
| 865 | /* deflateInit and png_inflateInit are macros to allow checking the zlib version |
|---|
| 866 | * and the compiler's view of z_stream: |
|---|
| 867 | */ |
|---|
| 868 | ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, |
|---|
| 869 | const char *version, int stream_size)); |
|---|
| 870 | ZEXTERN int ZEXPORT png_inflateInit_ OF((z_streamp strm, |
|---|
| 871 | const char *version, int stream_size)); |
|---|
| 872 | ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, |
|---|
| 873 | int windowBits, int memLevel, |
|---|
| 874 | int strategy, const char *version, |
|---|
| 875 | int stream_size)); |
|---|
| 876 | ZEXTERN int ZEXPORT png_inflateInit2_ OF((z_streamp strm, int windowBits, |
|---|
| 877 | const char *version, int stream_size)); |
|---|
| 878 | #define deflateInit(strm, level) \ |
|---|
| 879 | deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) |
|---|
| 880 | #define png_inflateInit(strm) \ |
|---|
| 881 | png_inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) |
|---|
| 882 | #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ |
|---|
| 883 | deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ |
|---|
| 884 | (strategy), ZLIB_VERSION, sizeof(z_stream)) |
|---|
| 885 | #define png_inflateInit2(strm, windowBits) \ |
|---|
| 886 | png_inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) |
|---|
| 887 | |
|---|
| 888 | |
|---|
| 889 | #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) |
|---|
| 890 | struct internal_state {int dummy;}; /* hack for buggy compilers */ |
|---|
| 891 | #endif |
|---|
| 892 | |
|---|
| 893 | ZEXTERN const char * ZEXPORT zError OF((int err)); |
|---|
| 894 | ZEXTERN int ZEXPORT png_inflateSyncPoint OF((z_streamp z)); |
|---|
| 895 | ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); |
|---|
| 896 | |
|---|
| 897 | #ifdef __cplusplus |
|---|
| 898 | } |
|---|
| 899 | #endif |
|---|
| 900 | |
|---|
| 901 | #endif /* _ZLIB_H */ |
|---|