LZW.H (3799B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: /CounterStrike/LZW.H 1 3/03/97 10:25a Joe_bostic $ */ 17 /*********************************************************************************************** 18 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : LZW.H * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : 08/28/96 * 28 * * 29 * Last Update : August 28, 1996 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 34 35 #ifndef _LZW_H 36 #define _LZW_H 37 38 #include "buff.h" 39 40 class LZWEngine 41 { 42 public: 43 LZWEngine(void); 44 45 int Compress(Buffer const & input, Buffer const & output); 46 int Uncompress(Buffer const & input, Buffer const & output); 47 48 void Reset(void); 49 50 private: 51 typedef short CodeType; 52 struct CodeClass { 53 CodeType CodeValue; 54 CodeType ParentCode; 55 char CharValue; 56 57 CodeClass(void) {} 58 CodeClass(CodeType code, CodeType parent, char c) : CodeValue(code), ParentCode(parent), CharValue(c) {} 59 60 enum {UNUSED=-1}; 61 void Make_Unused(void) {CodeValue = UNUSED;} 62 bool Is_Unused(void) const {return(CodeValue == UNUSED);} 63 bool Is_Matching(CodeType code, char c) const {return(ParentCode == code && CharValue == c);} 64 }; 65 66 enum { 67 BITS=12, 68 MAX_CODE=((1 << BITS ) - 1), 69 FIRST_CODE=257, 70 END_OF_STREAM=256, 71 TABLE_SIZE=5021 72 }; 73 CodeClass dict[TABLE_SIZE]; 74 75 char decode_stack[TABLE_SIZE]; 76 77 int Find_Child_Node(CodeType parent_code, char child_character); 78 int Decode_String(char * ptr, CodeType code); 79 static int Make_LZW_Hash(CodeType code, char character); 80 }; 81 82 83 int LZW_Compress(Buffer const & inbuff, Buffer const & outbuff); 84 int LZW_Uncompress(Buffer const & inbuff, Buffer const & outbuff); 85 86 #endif