xref: /openbmc/u-boot/include/jffs2/mini_inflate.h (revision ea0364f1)
1 /*-------------------------------------------------------------------------
2  * Filename:      mini_inflate.h
3  * Version:       $Id: mini_inflate.h,v 1.2 2002/01/17 00:53:20 nyet Exp $
4  * Copyright:     Copyright (C) 2001, Russ Dill
5  * Author:        Russ Dill <Russ.Dill@asu.edu>
6  * Description:   Mini deflate implementation
7  *-----------------------------------------------------------------------*/
8 /*
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  *
24  */
25 
26 typedef __SIZE_TYPE__ size;
27 
28 #define NO_ERROR 0
29 #define COMP_UNKNOWN 1	 /* The specififed bytype is invalid */
30 #define CODE_NOT_FOUND 2 /* a huffman code in the stream could not be decoded */
31 #define TOO_MANY_BITS 3	 /* pull_bits was passed an argument that is too
32 			  * large */
33 
34 /* This struct represents an entire huffman code set. It has various lookup
35  * tables to speed decoding */
36 struct huffman_set {
37 	int bits;	 /* maximum bit length */
38 	int num_symbols; /* Number of symbols this code can represent */
39 	int *lengths;	 /* The bit length of symbols */
40 	int *symbols;	 /* All of the symbols, sorted by the huffman code */
41 	int *count;	 /* the number of codes of this bit length */
42 	int *first;	 /* the first code of this bit length */
43 	int *pos;	 /* the symbol that first represents (in the symbols
44 			  * array) */
45 };
46 
47 struct bitstream {
48 	unsigned char *data; /* increments as we move from byte to byte */
49 	unsigned char bit;   /* 0 to 7 */
50 	void *(*memcpy)(void *, const void *, size);
51 	unsigned long decoded; /* The number of bytes decoded */
52 	int error;
53 
54 	int  distance_count[16];
55 	int  distance_first[16];
56 	int  distance_pos[16];
57 	int  distance_lengths[32];
58 	int  distance_symbols[32];
59 
60 	int  code_count[8];
61 	int  code_first[8];
62 	int  code_pos[8];
63 	int  code_lengths[19];
64 	int  code_symbols[19];
65 
66 	int  length_count[16];
67 	int  length_first[16];
68 	int  length_pos[16];
69 	int  length_lengths[288];
70 	int  length_symbols[288];
71 
72 	struct huffman_set codes;
73 	struct huffman_set lengths;
74 	struct huffman_set distance;
75 };
76 
77 #define NO_COMP 0
78 #define FIXED_COMP 1
79 #define DYNAMIC_COMP 2
80 
81 long decompress_block(unsigned char *dest, unsigned char *source,
82 		      void *(*inflate_memcpy)(void *dest, const void *src, size n));
83