OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [compress/] [zlib/] [current/] [src/] [compress.c] - Blame information for rev 856

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.