1 //Copyright Paul Reiche, Fred Ford. 1992-2002 2 3 /* 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 19 #ifndef LIBS_DECOMP_LZH_H_ 20 #define LIBS_DECOMP_LZH_H_ 21 22 #include "libs/declib.h" 23 #include "libs/memlib.h" 24 25 /* LZSS Parameters */ 26 27 #define N 4096 /* Size of string buffer */ 28 #define F 16 /* Size of look-ahead buffer */ 29 //#define F 60 /* Size of look-ahead buffer */ 30 #define THRESHOLD 2 31 #define NIL N /* End of tree's node */ 32 33 /* Huffman coding parameters */ 34 35 #define N_CHAR (256 - THRESHOLD + F) 36 /* character code (= 0..N_CHAR-1) */ 37 #define T (N_CHAR * 2 - 1) /* Size of table */ 38 #define R (T - 1) /* root position */ 39 #define MAX_FREQ 0x8000 40 /* update when cumulative frequency */ 41 42 struct _LZHCODE_DESC 43 { 44 COUNT buf_index, restart_index, bytes_left; 45 BYTE text_buf[N + F - 1]; 46 /* reconstruct freq tree */ 47 COUNT freq[T + 1]; /* cumulative freq table */ 48 /* 49 * pointing parent nodes. 50 * area [T..(T + N_CHAR - 1)] are pointers for leaves 51 */ 52 COUNT prnt[T + N_CHAR]; 53 /* pointing children nodes (son[], son[] + 1)*/ 54 COUNT son[T]; 55 UWORD workbuf; 56 BYTE workbuflen; 57 58 STREAM_TYPE StreamType; 59 60 void *Stream; 61 DWORD StreamIndex, StreamLength; 62 63 STREAM_MODE StreamMode; 64 PVOIDFUNC CleanupFunc; 65 }; 66 67 typedef struct _LZHCODE_DESC LZHCODE_DESC; 68 typedef LZHCODE_DESC *PLZHCODE_DESC; 69 70 #define InChar() (_StreamType == FILE_STREAM ? \ 71 GetResFileChar ((uio_Stream *)_Stream) : \ 72 (int)*_Stream++) 73 #define OutChar(c) (_StreamType == FILE_STREAM ? \ 74 PutResFileChar ((c), (uio_Stream *)_Stream) : \ 75 (*_Stream++ = (BYTE)(c))) 76 77 78 #define AllocCodeDesc() HCalloc (sizeof (LZHCODE_DESC)) 79 #define FreeCodeDesc HFree 80 81 extern void _update (COUNT c); 82 extern void StartHuff (void); 83 84 extern PLZHCODE_DESC _lpCurCodeDesc; 85 extern STREAM_TYPE _StreamType; 86 extern BYTE* _Stream; 87 extern UWORD _workbuf; 88 extern BYTE _workbuflen; 89 90 #endif /* LIBS_DECOMP_LZH_H_ */ 91 92