2 * Copyright (c) 1985, 1986 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
6 * James A. Woods, derived from original work by Spencer Thomas
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #ifndef __cmcompress__h_
39 #define __cmcompress__h_
49 * Set USERMEM to the maximum amount of physical user memory available
50 * in bytes. USERMEM is used to determine the maximum BITS that can be used
53 * SACREDMEM is the amount of physical memory saved for others; compress
61 # define USERMEM 450000 /* default user memory */
65 # define BITS 12 /* max bits/code for 16-bit machine */
66 # define NO_UCHAR /* also if "unsigned char" functions as signed char */
68 #endif /* pdp11 */ /* don't forget to compile with -i */
71 # if USERMEM >= (433484+SACREDMEM)
74 # if USERMEM >= (229600+SACREDMEM)
77 # if USERMEM >= (127536+SACREDMEM)
80 # if USERMEM >= (73464+SACREDMEM)
91 #ifdef PBITS /* Preferred BITS for this memory size */
98 # define HSIZE 69001 /* 95% occupancy */
101 # define HSIZE 35023 /* 94% occupancy */
104 # define HSIZE 18013 /* 91% occupancy */
107 # define HSIZE 9001 /* 91% occupancy */
110 # define HSIZE 5003 /* 80% occupancy */
114 * a code_int must be able to hold 2**BITS values of type int, and also -1
117 typedef long int code_int
;
119 typedef int code_int
;
122 #ifdef SIGNED_COMPARE_SLOW
123 typedef unsigned long int count_int
;
124 typedef unsigned short int count_short
;
126 typedef long int count_int
;
130 typedef char char_type
;
132 typedef unsigned char char_type
;
137 struct cmcompress_stream
139 int n_bits
; /* number of bits/code */
140 int maxbits
; /* user settable max # bits/code */
141 code_int maxcode
; /* maximum code, given n_bits */
142 code_int maxmaxcode
; /* should NEVER generate this code */
144 count_int htab
[HSIZE
];
145 unsigned short codetab
[HSIZE
];
147 code_int hsize
; /* for dynamic table sizing */
148 code_int free_ent
; /* first unused entry */
149 int nomagic
; /* Use a 3-byte magic number header, unless old file */
152 * block compression parameters -- after all codes are used up,
153 * and compression rate changes, start over.
158 count_int checkpoint
;
165 /* compress internals */
167 long int in_count
; /* length of input */
168 long int bytes_out
; /* length of compressed output */
169 long int out_count
; /* # of codes output (for debugging) */
179 /* For input and output */
180 int (*input_stream
)(void*);
181 int (*output_stream
)(void*, const char*,int);
185 int cmcompress_compress_initialize(struct cmcompress_stream
* cdata
);
186 int cmcompress_compress_start(struct cmcompress_stream
* cdata
);
187 int cmcompress_compress(struct cmcompress_stream
* cdata
, void* buff
, size_t n
);
188 int cmcompress_compress_finalize(struct cmcompress_stream
* cdata
);
195 #endif /* __cmcompress__h_ */