Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
compress.cc
Go to the documentation of this file.
1/* compress.c -- compress a memory buffer
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id: compress.cc,v 1.1 2005-05-12 21:04:53 duns Exp $ */
7
8#define ZLIB_INTERNAL
9#include "zlib.h"
10
11/* ===========================================================================
12 Compresses the source buffer into the destination buffer. The level
13 parameter has the same meaning as in deflateInit. sourceLen is the byte
14 length of the source buffer. Upon entry, destLen is the total size of the
15 destination buffer, which must be at least 0.1% larger than sourceLen plus
16 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
17
18 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
19 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
20 Z_STREAM_ERROR if the level parameter is invalid.
21*/
22int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
23{
24 z_stream stream;
25 int err;
26
27 stream.next_in = (Bytef*)source;
28 stream.avail_in = (uInt)sourceLen;
29#ifdef MAXSEG_64K
30 /* Check for source > 64K on 16-bit machine: */
31 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
32#endif
33 stream.next_out = dest;
34 stream.avail_out = (uInt)*destLen;
35 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
36
37 stream.zalloc = (alloc_func)0;
38 stream.zfree = (free_func)0;
39 stream.opaque = (voidpf)0;
40
41 err = deflateInit(&stream, level);
42 if (err != Z_OK) return err;
43
44 err = deflate(&stream, Z_FINISH);
45 if (err != Z_STREAM_END) {
46 deflateEnd(&stream);
47 return err == Z_OK ? Z_BUF_ERROR : err;
48 }
49 *destLen = stream.total_out;
50
51 err = deflateEnd(&stream);
52 return err;
53}
54
55/* ===========================================================================
56 */
57int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
58{
59 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
60}
61
62/* ===========================================================================
63 If the default memLevel or windowBits for deflateInit() is changed, then
64 this function needs to be updated.
65 */
67{
68 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
69}
uLong ZEXPORT compressBound(uLong sourceLen)
Definition: compress.cc:66
int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen, int level)
Definition: compress.cc:22
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.cc:57
int ZEXPORT deflateEnd(z_streamp strm)
Definition: deflate.cc:670
int ZEXPORT deflate(z_streamp strm, int flush)
Definition: deflate.cc:496
uInt avail_in
Definition: zlib.h:84
Bytef * next_in
Definition: zlib.h:83
alloc_func zalloc
Definition: zlib.h:94
uInt avail_out
Definition: zlib.h:88
free_func zfree
Definition: zlib.h:95
voidpf opaque
Definition: zlib.h:96
uLong total_out
Definition: zlib.h:89
Bytef * next_out
Definition: zlib.h:87
uLong FAR uLongf
Definition: zconf.h:269
Byte FAR * voidpf
Definition: zconf.h:277
#define ZEXPORT
Definition: zconf.h:244
unsigned int uInt
Definition: zconf.h:257
unsigned long uLong
Definition: zconf.h:258
Byte FAR Bytef
Definition: zconf.h:264
#define Z_BUF_ERROR
Definition: zlib.h:154
#define Z_STREAM_END
Definition: zlib.h:148
#define Z_FINISH
Definition: zlib.h:143
#define Z_OK
Definition: zlib.h:147
#define deflateInit(strm, level)
Definition: zlib.h:1174
#define Z_DEFAULT_COMPRESSION
Definition: zlib.h:163