Compression.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // FILE: Compression.h ///////////////////////////////////////////////////////
  19. // Author: Matthew D. Campbell
  20. //////////////////////////////////////////////////////////////////////////////
  21. #pragma once
  22. #ifndef __COMPRESSION_H__
  23. #define __COMPRESSION_H__
  24. #include "Lib/BaseType.h"
  25. enum CompressionType
  26. {
  27. COMPRESSION_MIN = 0,
  28. COMPRESSION_NONE = COMPRESSION_MIN,
  29. COMPRESSION_REFPACK,
  30. COMPRESSION_MAX = COMPRESSION_REFPACK,
  31. COMPRESSION_NOXLZH,
  32. COMPRESSION_ZLIB1,
  33. COMPRESSION_ZLIB2,
  34. COMPRESSION_ZLIB3,
  35. COMPRESSION_ZLIB4,
  36. COMPRESSION_ZLIB5,
  37. COMPRESSION_ZLIB6,
  38. COMPRESSION_ZLIB7,
  39. COMPRESSION_ZLIB8,
  40. COMPRESSION_ZLIB9,
  41. COMPRESSION_BTREE,
  42. COMPRESSION_HUFF,
  43. };
  44. class CompressionManager
  45. {
  46. public:
  47. static Bool isDataCompressed( const void *mem, Int len );
  48. static CompressionType getCompressionType( const void *mem, Int len );
  49. static Int getMaxCompressedSize( Int uncompressedLen, CompressionType compType );
  50. static Int getUncompressedSize( const void *mem, Int len );
  51. static Int compressData( CompressionType compType, void *src, Int srcLen, void *dest, Int destLen ); // 0 on error
  52. static Int decompressData( void *src, Int srcLen, void *dest, Int destLen ); // 0 on error
  53. static const char *getCompressionNameByType( CompressionType compType );
  54. // For perf timers, so we can have separate ones for compression/decompression
  55. static const char *getDecompressionNameByType( CompressionType compType );
  56. static CompressionType getPreferredCompression( void );
  57. };
  58. #endif // __COMPRESSION_H__