| 1 | /* compress.c -- compress a memory buffer |
|---|
| 2 | * Copyright (C) 1995-1998 Jean-loup Gailly. |
|---|
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
|---|
| 4 | */ |
|---|
| 5 | |
|---|
| 6 | /* @(#) $Id: //suprahd/releases/suprahd_163/suprahd_ztvapp640_163/drivers/graphics/ZLIB/compress.c#1 $ |
|---|
| 7 | * $Revision: #1 $ |
|---|
| 8 | * $DateTime: 2006/02/24 17:51:46 $ |
|---|
| 9 | * $Change: 42566 $ |
|---|
| 10 | * $Author: pryush.sharma $ |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "zlib.h" |
|---|
| 15 | |
|---|
| 16 | /* =========================================================================== |
|---|
| 17 | Compresses the source buffer into the destination buffer. The level |
|---|
| 18 | parameter has the same meaning as in deflateInit. sourceLen is the byte |
|---|
| 19 | length of the source buffer. Upon entry, destLen is the total size of the |
|---|
| 20 | destination buffer, which must be at least 0.1% larger than sourceLen plus |
|---|
| 21 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. |
|---|
| 22 | |
|---|
| 23 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough |
|---|
| 24 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, |
|---|
| 25 | Z_STREAM_ERROR if the level parameter is invalid. |
|---|
| 26 | */ |
|---|
| 27 | int ZEXPORT compress2 ( |
|---|
| 28 | Bytef *dest, |
|---|
| 29 | uLongf *destLen, |
|---|
| 30 | const Bytef *source, |
|---|
| 31 | uLong sourceLen, |
|---|
| 32 | int level) |
|---|
| 33 | { |
|---|
| 34 | z_stream stream; |
|---|
| 35 | int err; |
|---|
| 36 | |
|---|
| 37 | stream.next_in = (Bytef*)source; |
|---|
| 38 | stream.avail_in = (uInt)sourceLen; |
|---|
| 39 | #ifdef MAXSEG_64K |
|---|
| 40 | /* Check for source > 64K on 16-bit machine: */ |
|---|
| 41 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; |
|---|
| 42 | #endif |
|---|
| 43 | stream.next_out = dest; |
|---|
| 44 | stream.avail_out = (uInt)*destLen; |
|---|
| 45 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; |
|---|
| 46 | |
|---|
| 47 | stream.zalloc = (alloc_func)0; |
|---|
| 48 | stream.zfree = (free_func)0; |
|---|
| 49 | stream.opaque = (voidpf)0; |
|---|
| 50 | |
|---|
| 51 | err = deflateInit(&stream, level); |
|---|
| 52 | if (err != Z_OK) return err; |
|---|
| 53 | |
|---|
| 54 | err = deflate(&stream, Z_FINISH); |
|---|
| 55 | if (err != Z_STREAM_END) { |
|---|
| 56 | deflateEnd(&stream); |
|---|
| 57 | return err == Z_OK ? Z_BUF_ERROR : err; |
|---|
| 58 | } |
|---|
| 59 | *destLen = stream.total_out; |
|---|
| 60 | |
|---|
| 61 | err = deflateEnd(&stream); |
|---|
| 62 | return err; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | /* =========================================================================== |
|---|
| 66 | */ |
|---|
| 67 | int ZEXPORT compress ( |
|---|
| 68 | Bytef *dest, |
|---|
| 69 | uLongf *destLen, |
|---|
| 70 | const Bytef *source, |
|---|
| 71 | uLong sourceLen) |
|---|
| 72 | { |
|---|
| 73 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); |
|---|
| 74 | } |
|---|