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