Team Fortress 2 Source Code as on 22/4/2020
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.

69 lines
1.9 KiB

  1. //========= Copyright 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. #define LZSS_ID uint32( BigLong( ('L'<<24)|('Z'<<16)|('S'<<8)|('S') ) )
  11. #define SNAPPY_ID uint32( BigLong( ('S'<<24)|('N'<<16)|('A'<<8)|('P') ) )
  12. // bind the buffer for correct identification
  13. struct lzss_header_t
  14. {
  15. unsigned int id;
  16. unsigned int actualSize; // always little endian
  17. };
  18. class CUtlBuffer;
  19. #define DEFAULT_LZSS_WINDOW_SIZE 4096
  20. class CLZSS
  21. {
  22. public:
  23. unsigned char* Compress( const unsigned char *pInput, int inputlen, unsigned int *pOutputSize );
  24. unsigned char* CompressNoAlloc( const unsigned char *pInput, int inputlen, unsigned char *pOutput, unsigned int *pOutputSize );
  25. unsigned int Uncompress( const unsigned char *pInput, unsigned char *pOutput );
  26. //unsigned int Uncompress( unsigned char *pInput, CUtlBuffer &buf );
  27. unsigned int SafeUncompress( const unsigned char *pInput, unsigned char *pOutput, unsigned int unBufSize );
  28. static bool IsCompressed( const unsigned char *pInput );
  29. static unsigned int GetActualSize( const unsigned char *pInput );
  30. // windowsize must be a power of two.
  31. FORCEINLINE CLZSS( int nWindowSize = DEFAULT_LZSS_WINDOW_SIZE );
  32. private:
  33. // expected to be sixteen bytes
  34. struct lzss_node_t
  35. {
  36. const unsigned char *pData;
  37. lzss_node_t *pPrev;
  38. lzss_node_t *pNext;
  39. char empty[4];
  40. };
  41. struct lzss_list_t
  42. {
  43. lzss_node_t *pStart;
  44. lzss_node_t *pEnd;
  45. };
  46. void BuildHash( const unsigned char *pData );
  47. lzss_list_t *m_pHashTable;
  48. lzss_node_t *m_pHashTarget;
  49. int m_nWindowSize;
  50. };
  51. FORCEINLINE CLZSS::CLZSS( int nWindowSize )
  52. {
  53. m_nWindowSize = nWindowSize;
  54. }
  55. #endif