Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.9 KiB

  1. //========= Copyright � 1996-2007, Valve Corporation, All rights reserved. ============//
  2. //
  3. // LZSS Codec. Designed for fast cheap gametime encoding/decoding. Compression results
  4. // are not aggresive as other alogrithms, but gets 2:1 on most arbitrary uncompressed data.
  5. //
  6. //=====================================================================================//
  7. #ifndef _LZSS_H
  8. #define _LZSS_H
  9. #pragma once
  10. #if defined( PLAT_LITTLE_ENDIAN )
  11. #define LZSS_ID (('S'<<24)|('S'<<16)|('Z'<<8)|('L'))
  12. #else
  13. #define LZSS_ID (('L'<<24)|('Z'<<16)|('S'<<8)|('S'))
  14. #endif
  15. // bind the buffer for correct identification
  16. struct lzss_header_t
  17. {
  18. unsigned int id;
  19. unsigned int actualSize; // always little endian
  20. };
  21. class CUtlBuffer;
  22. #define DEFAULT_LZSS_WINDOW_SIZE 4096
  23. class CLZSS
  24. {
  25. public:
  26. unsigned char* Compress( unsigned char *pInput, int inputlen, unsigned int *pOutputSize );
  27. unsigned char* CompressNoAlloc( unsigned char *pInput, int inputlen, unsigned char *pOutput, unsigned int *pOutputSize );
  28. unsigned int Uncompress( unsigned char *pInput, unsigned char *pOutput );
  29. //unsigned int Uncompress( unsigned char *pInput, CUtlBuffer &buf );
  30. unsigned int SafeUncompress( unsigned char *pInput, unsigned char *pOutput, unsigned int unBufSize );
  31. bool IsCompressed( unsigned char *pInput );
  32. unsigned int GetActualSize( unsigned char *pInput );
  33. // windowsize must be a power of two.
  34. FORCEINLINE CLZSS( int nWindowSize = DEFAULT_LZSS_WINDOW_SIZE );
  35. private:
  36. // expected to be sixteen bytes
  37. struct lzss_node_t
  38. {
  39. unsigned char *pData;
  40. lzss_node_t *pPrev;
  41. lzss_node_t *pNext;
  42. char empty[4];
  43. };
  44. struct lzss_list_t
  45. {
  46. lzss_node_t *pStart;
  47. lzss_node_t *pEnd;
  48. };
  49. void BuildHash( unsigned char *pData );
  50. lzss_list_t *m_pHashTable;
  51. lzss_node_t *m_pHashTarget;
  52. int m_nWindowSize;
  53. };
  54. FORCEINLINE CLZSS::CLZSS( int nWindowSize )
  55. {
  56. m_nWindowSize = nWindowSize;
  57. }
  58. #endif