/****************************************************************** * * * Nest version 2 - 3D Wasp Nest Simulator * * Copyright (C) 1997 Sylvain GUERIN * * LIASC, ENST Bretagne & Santa Fe Institute * * * ****************************************************************** E-mail: Sylvain.Guerin@enst-bretagne.fr or: Sylvain Guerin 13 rue des Monts Lorgeaux, 51460 L'EPINE, FRANCE ****************************************************************** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ****************************************************************** Name : compress.h Component : compressing algorithm Fonctionality : contains specifications refering to file compressing (extracted from lzhuf.c written by Haruyasu Yoshizaki 20/11/88) ******************************************************************/ #ifndef __compress_H #define __compress_H #include #include #include #include "config.h" /********** LZSS compression **********/ #define N 4096 /* buffer size */ #define F 60 /* lookahead buffer size */ #define THRESHOLD 2 #define NIL N /* leaf of tree */ /*********** Huffman coding ***********/ #define N_CHAR (256 - THRESHOLD + F) /* kinds of characters (character code = 0..N_CHAR-1) */ #define T (N_CHAR * 2 - 1) /* size of table */ #define R (T - 1) /* position of root */ #define MAX_FREQ 0x8000 /* updates tree when the */ typedef unsigned char uchar; /**************************************/ class CompressAlgorithm { public: CompressAlgorithm (); ~CompressAlgorithm (); /* note pour le pauvre gars qui pourrait venir mettre son nez dans ce code de m.... : les trucs de pierre sur la compression, ca marche pas tout le temps, donc provisoirement, on va faire des system "gzip.... etc...." qu'il sache aussi que je m'associe a son desespoir.... .... sincerement... */ int compress (char* inputPath, char* inputFile); /* cette methode prend le fichier, l'encode, et le sauve avec le suffixe .zhuf en effacant le fichier original */ /* retourne 0 si OK, -1 sinon */ int decompress (char* inputPath, char* inputFile); /* cette methode prend le fichier .zhuf, le decode, et le sauve sans le suffixe .zhuf en effacant le fichier original */ /* retourne 0 si OK, -1 sinon */ int compress (char* inputPath, char* inputFile, char* outputFile); int decompress (char* inputPath, char* inputFile, char* outputFile); /* meme chose, mais n'efface pas les fichiers originaux */ int compress2 (char* inputPath, char* inputFile); int decompress2 (char* inputPath, char* inputFile); int compress2 (char* inputPath, char* inputFile, char* outputFile); int decompress2 (char* inputPath, char* inputFile, char* outputFile); void Encode(void); /* compression */ void Decode(void); /* recover */ int openFiles (char* inFile, char* outFile); void closeFiles (); protected: FILE *infile, *outfile; unsigned long int textsize, codesize, printcount; char wterr[256]; unsigned char text_buf[N + F - 1]; int match_position, match_length, lson[N + 1], rson[N + 257], dad[N + 1]; uchar* p_len; uchar* p_code; uchar* d_code; uchar* d_len; unsigned freq[T + 1]; /* frequency table */ int prnt[T + N_CHAR]; /* pointers to parent nodes, except for the */ /* elements [T..T + N_CHAR - 1] which are used to get */ /* the positions of leaves corresponding to the codes. */ int son[T]; /* pointers to child nodes (son[], son[] + 1) */ unsigned getbuf; uchar getlen; unsigned putbuf; uchar putlen; unsigned code, len; void Error(char *message); void InitTree(void); /* initialize trees */ void InsertNode(int r); /* insert to tree */ void DeleteNode(int p); /* remove from tree */ int GetBit(void); /* get one bit */ int GetByte(void); /* get one byte */ void Putcode(int l, unsigned c); /* output c bits of code */ void StartHuff(void); void reconst(void); void update(int c); void EncodeChar(unsigned c); void EncodePosition(unsigned c); void EncodeEnd(void); int DecodeChar(void); int DecodePosition(void); }; #endif