xref: /openbmc/u-boot/include/jffs2/mini_inflate.h (revision e8f80a5a)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*-------------------------------------------------------------------------
3  * Filename:      mini_inflate.h
4  * Version:       $Id: mini_inflate.h,v 1.2 2002/01/17 00:53:20 nyet Exp $
5  * Copyright:     Copyright (C) 2001, Russ Dill
6  * Author:        Russ Dill <Russ.Dill@asu.edu>
7  * Description:   Mini deflate implementation
8  *-----------------------------------------------------------------------*/
9 
10 typedef __SIZE_TYPE__ size;
11 
12 #define NO_ERROR 0
13 #define COMP_UNKNOWN 1	 /* The specififed bytype is invalid */
14 #define CODE_NOT_FOUND 2 /* a huffman code in the stream could not be decoded */
15 #define TOO_MANY_BITS 3	 /* pull_bits was passed an argument that is too
16 			  * large */
17 
18 /* This struct represents an entire huffman code set. It has various lookup
19  * tables to speed decoding */
20 struct huffman_set {
21 	int bits;	 /* maximum bit length */
22 	int num_symbols; /* Number of symbols this code can represent */
23 	int *lengths;	 /* The bit length of symbols */
24 	int *symbols;	 /* All of the symbols, sorted by the huffman code */
25 	int *count;	 /* the number of codes of this bit length */
26 	int *first;	 /* the first code of this bit length */
27 	int *pos;	 /* the symbol that first represents (in the symbols
28 			  * array) */
29 };
30 
31 struct bitstream {
32 	unsigned char *data; /* increments as we move from byte to byte */
33 	unsigned char bit;   /* 0 to 7 */
34 	void *(*memcpy)(void *, const void *, size);
35 	unsigned long decoded; /* The number of bytes decoded */
36 	int error;
37 
38 	int  distance_count[16];
39 	int  distance_first[16];
40 	int  distance_pos[16];
41 	int  distance_lengths[32];
42 	int  distance_symbols[32];
43 
44 	int  code_count[8];
45 	int  code_first[8];
46 	int  code_pos[8];
47 	int  code_lengths[19];
48 	int  code_symbols[19];
49 
50 	int  length_count[16];
51 	int  length_first[16];
52 	int  length_pos[16];
53 	int  length_lengths[288];
54 	int  length_symbols[288];
55 
56 	struct huffman_set codes;
57 	struct huffman_set lengths;
58 	struct huffman_set distance;
59 };
60 
61 #define NO_COMP 0
62 #define FIXED_COMP 1
63 #define DYNAMIC_COMP 2
64 
65 long decompress_block(unsigned char *dest, unsigned char *source,
66 		      void *(*inflate_memcpy)(void *dest, const void *src, size n));
67