LZW.H 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/LZW.H 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** 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 ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : LZW.H *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 08/28/96 *
  26. * *
  27. * Last Update : August 28, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  32. #ifndef _LZW_H
  33. #define _LZW_H
  34. #include "buff.h"
  35. class LZWEngine
  36. {
  37. public:
  38. LZWEngine(void);
  39. int Compress(Buffer const & input, Buffer const & output);
  40. int Uncompress(Buffer const & input, Buffer const & output);
  41. void Reset(void);
  42. private:
  43. typedef short CodeType;
  44. struct CodeClass {
  45. CodeType CodeValue;
  46. CodeType ParentCode;
  47. char CharValue;
  48. CodeClass(void) {}
  49. CodeClass(CodeType code, CodeType parent, char c) : CodeValue(code), ParentCode(parent), CharValue(c) {}
  50. enum {UNUSED=-1};
  51. void Make_Unused(void) {CodeValue = UNUSED;}
  52. bool Is_Unused(void) const {return(CodeValue == UNUSED);}
  53. bool Is_Matching(CodeType code, char c) const {return(ParentCode == code && CharValue == c);}
  54. };
  55. enum {
  56. BITS=12,
  57. MAX_CODE=((1 << BITS ) - 1),
  58. FIRST_CODE=257,
  59. END_OF_STREAM=256,
  60. TABLE_SIZE=5021
  61. };
  62. CodeClass dict[TABLE_SIZE];
  63. char decode_stack[TABLE_SIZE];
  64. int Find_Child_Node(CodeType parent_code, char child_character);
  65. int Decode_String(char * ptr, CodeType code);
  66. static int Make_LZW_Hash(CodeType code, char character);
  67. };
  68. int LZW_Compress(Buffer const & inbuff, Buffer const & outbuff);
  69. int LZW_Uncompress(Buffer const & inbuff, Buffer const & outbuff);
  70. #endif