annotate src/zlib-1.2.7/compress.c @ 23:619f715526df sv_v2.1

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