vrshoot

annotate libs/zlib/compress.c @ 3:c179c72369be

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