istereo

annotate libs/zlib/compress.c @ 26:862a3329a8f0

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