istereo2

annotate libs/zlib/compress.c @ 2:81d35769f546

added the tunnel effect source
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 19 Sep 2015 05:51:51 +0300
parents
children
rev   line source
nuclear@2 1 /* compress.c -- compress a memory buffer
nuclear@2 2 * Copyright (C) 1995-2003 Jean-loup Gailly.
nuclear@2 3 * For conditions of distribution and use, see copyright notice in zlib.h
nuclear@2 4 */
nuclear@2 5
nuclear@2 6 /* @(#) $Id$ */
nuclear@2 7
nuclear@2 8 #define ZLIB_INTERNAL
nuclear@2 9 #include "zlib.h"
nuclear@2 10
nuclear@2 11 /* ===========================================================================
nuclear@2 12 Compresses the source buffer into the destination buffer. The level
nuclear@2 13 parameter has the same meaning as in deflateInit. sourceLen is the byte
nuclear@2 14 length of the source buffer. Upon entry, destLen is the total size of the
nuclear@2 15 destination buffer, which must be at least 0.1% larger than sourceLen plus
nuclear@2 16 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
nuclear@2 17
nuclear@2 18 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
nuclear@2 19 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
nuclear@2 20 Z_STREAM_ERROR if the level parameter is invalid.
nuclear@2 21 */
nuclear@2 22 int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
nuclear@2 23 Bytef *dest;
nuclear@2 24 uLongf *destLen;
nuclear@2 25 const Bytef *source;
nuclear@2 26 uLong sourceLen;
nuclear@2 27 int level;
nuclear@2 28 {
nuclear@2 29 z_stream stream;
nuclear@2 30 int err;
nuclear@2 31
nuclear@2 32 stream.next_in = (Bytef*)source;
nuclear@2 33 stream.avail_in = (uInt)sourceLen;
nuclear@2 34 #ifdef MAXSEG_64K
nuclear@2 35 /* Check for source > 64K on 16-bit machine: */
nuclear@2 36 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
nuclear@2 37 #endif
nuclear@2 38 stream.next_out = dest;
nuclear@2 39 stream.avail_out = (uInt)*destLen;
nuclear@2 40 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
nuclear@2 41
nuclear@2 42 stream.zalloc = (alloc_func)0;
nuclear@2 43 stream.zfree = (free_func)0;
nuclear@2 44 stream.opaque = (voidpf)0;
nuclear@2 45
nuclear@2 46 err = deflateInit(&stream, level);
nuclear@2 47 if (err != Z_OK) return err;
nuclear@2 48
nuclear@2 49 err = deflate(&stream, Z_FINISH);
nuclear@2 50 if (err != Z_STREAM_END) {
nuclear@2 51 deflateEnd(&stream);
nuclear@2 52 return err == Z_OK ? Z_BUF_ERROR : err;
nuclear@2 53 }
nuclear@2 54 *destLen = stream.total_out;
nuclear@2 55
nuclear@2 56 err = deflateEnd(&stream);
nuclear@2 57 return err;
nuclear@2 58 }
nuclear@2 59
nuclear@2 60 /* ===========================================================================
nuclear@2 61 */
nuclear@2 62 int ZEXPORT compress (dest, destLen, source, sourceLen)
nuclear@2 63 Bytef *dest;
nuclear@2 64 uLongf *destLen;
nuclear@2 65 const Bytef *source;
nuclear@2 66 uLong sourceLen;
nuclear@2 67 {
nuclear@2 68 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
nuclear@2 69 }
nuclear@2 70
nuclear@2 71 /* ===========================================================================
nuclear@2 72 If the default memLevel or windowBits for deflateInit() is changed, then
nuclear@2 73 this function needs to be updated.
nuclear@2 74 */
nuclear@2 75 uLong ZEXPORT compressBound (sourceLen)
nuclear@2 76 uLong sourceLen;
nuclear@2 77 {
nuclear@2 78 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
nuclear@2 79 }