lzham_lzbase.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // File: lzham_lzbase.h
  2. // See Copyright Notice and license at the end of include/lzham.h
  3. #pragma once
  4. #include "lzham_lzdecompbase.h"
  5. //#define LZHAM_LZVERIFY
  6. //#define LZHAM_DISABLE_RAW_BLOCKS
  7. namespace lzham
  8. {
  9. struct CLZBase : CLZDecompBase
  10. {
  11. static uint8 m_slot_tab0[4096];
  12. static uint8 m_slot_tab1[512];
  13. static uint8 m_slot_tab2[256];
  14. void init_slot_tabs();
  15. inline void compute_lzx_position_slot(uint dist, uint& slot, uint& ofs)
  16. {
  17. uint s;
  18. if (dist < 0x1000)
  19. s = m_slot_tab0[dist];
  20. else if (dist < 0x100000)
  21. s = m_slot_tab1[dist >> 11];
  22. else if (dist < 0x1000000)
  23. s = m_slot_tab2[dist >> 16];
  24. else if (dist < 0x2000000)
  25. s = 48 + ((dist - 0x1000000) >> 23);
  26. else if (dist < 0x4000000)
  27. s = 50 + ((dist - 0x2000000) >> 24);
  28. else
  29. s = 52 + ((dist - 0x4000000) >> 25);
  30. ofs = (dist - m_lzx_position_base[s]) & m_lzx_position_extra_mask[s];
  31. slot = s;
  32. LZHAM_ASSERT(s < m_num_lzx_slots);
  33. LZHAM_ASSERT((m_lzx_position_base[slot] + ofs) == dist);
  34. LZHAM_ASSERT(ofs < (1U << m_lzx_position_extra_bits[slot]));
  35. }
  36. };
  37. } // namespace lzham