lzmadec.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*++
  2. Copyright (c) Alex Ionescu. All rights reserved.
  3. Module Name:
  4. lzmadec.h
  5. Abstract:
  6. This header file contains C-style definitions, constants, and enumerations
  7. that map back to the LZMA Standard, specifically the probability model that
  8. is used for encoding probabilities.
  9. Author:
  10. Alex Ionescu (@aionescu) 15-Apr-2020 - Initial version
  11. Environment:
  12. Windows & Linux, user mode and kernel mode.
  13. --*/
  14. #pragma once
  15. //
  16. // Literals can be 0-255 and are encoded in 3 different types of slots based on
  17. // the previous literal decoded and the "match byte" used.
  18. //
  19. #define LZMA_LITERALS 256
  20. #define LZMA_LC_TYPES 3
  21. #define LZMA_LC_MODEL_SIZE (LZMA_LC_TYPES * LZMA_LITERALS)
  22. //
  23. // These are the hardcoded LZMA properties we support for position and coders
  24. //
  25. #define LZMA_LC 3
  26. #define LZMA_PB 2
  27. #define LZMA_LP 0
  28. #define LZMA_LITERAL_CODERS (1 << LZMA_LC)
  29. #define LZMA_POSITION_COUNT (1 << LZMA_PB)
  30. //
  31. // Lengths are described in three different ways using "low", "mid", and "high"
  32. // bit trees. The first two trees encode 3 bits, the last encodes 8. We never
  33. // encode a length less than 2 bytes, since that's wasteful.
  34. //
  35. #define LZMA_MAX_LOW_LENGTH (1 << 3)
  36. #define LZMA_MAX_MID_LENGTH (1 << 3)
  37. #define LZMA_MAX_HIGH_LENGTH (1 << 8)
  38. #define LZMA_MIN_LENGTH 2
  39. //
  40. // Distances can be encoded in different ways, based on the distance slot.
  41. // Lengths of 2, 3, 4 bytes are directly encoded with their own slot. Lengths
  42. // over 5 share a slot, which is then further subdivded into 3 different ways
  43. // of encoding them, which are described in the source.
  44. //
  45. #define LZMA_DISTANCE_SLOTS 64
  46. #define LZMA_FIRST_CONTEXT_DISTANCE_SLOT 4
  47. #define LZMA_FIRST_FIXED_DISTANCE_SLOT 14
  48. #define LZMA_DISTANCE_ALIGN_BITS 4
  49. #define LZMA_DISTANCE_ALIGN_SLOTS (1 << LZMA_DISTANCE_ALIGN_BITS)
  50. //
  51. // Total number of probabilities that we need to store
  52. //
  53. #define LZMA_BIT_MODEL_SLOTS (1174 + \
  54. (LZMA_LITERAL_CODERS * \
  55. LZMA_LC_MODEL_SIZE))
  56. //
  57. // The LZMA probability bit model is typically based on the last LZMA sequences
  58. // that were decoded. There are 11 such possibilities that are tracked.
  59. //
  60. typedef enum _LZMA_SEQUENCE_STATE
  61. {
  62. //
  63. // State where we last saw three literals
  64. //
  65. LzmaLitLitLitState,
  66. //
  67. // States where we last saw two literals preceeded by a non-literal
  68. //
  69. LzmaMatchLitLitState,
  70. LzmaRepLitLitState,
  71. LzmaLitShortrepLitLitState,
  72. //
  73. // States where we last saw one literal preceeded by a non-literal
  74. //
  75. LzmaMatchLitState,
  76. LzmaRepLitState,
  77. LzmaLitShortrepLitState,
  78. //
  79. // Separator between states where we last saw at least one literal
  80. //
  81. LzmaMaxLitState,
  82. //
  83. // States where we last saw a non-literal preceeded by a literal
  84. //
  85. LzmaLitMatchState = 7,
  86. LzmaLitRepState,
  87. LzmaLitShortrepState,
  88. //
  89. // States where we last saw two non-literals
  90. //
  91. LzmaNonlitMatchState,
  92. LzmaNonlitRepState,
  93. //
  94. // Separator for number of total states
  95. //
  96. LzmaMaxState
  97. } LZMA_SEQUENCE_STATE, * PLZMA_SEQUENCE_STATE;