Advertisement
cr88192

BSRLZ0 (Initial)

Apr 2nd, 2021
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. Rice+STF LZ77
  2. * Aim: Rice+STF LZ77 Codec
  3. * Optimize for low-cost implementation.
  4. ** Decoder should be relatively simple with low memory requirements.
  5. * Aim for higher compression (at lower speeds) than LZ4 or RP2.
  6.  
  7.  
  8. === AdRice ===
  9.  
  10. Will use an LSB-first bitstream.
  11.  
  12. Will use a prefix with zero or more zero bits terminated by a 1 bit.
  13.  
  14. The Q prefix will range from 0-7, a prefix with 8 zero bits will encode an escape:
  15. * 8 bits: 0x00
  16. * 8 bits: STF Index
  17.  
  18. In other cases, the Q prefix will be followed by a K bit suffix (P). The value will be decoded as (Q<<K)|P;
  19.  
  20. K will be updated based on Q:
  21. * 0: K-- if K>0
  22. * 1: Leave as-is
  23. * 2..7: K++ (Implicitly clammped to 8).
  24.  
  25. The AdRice contexts will have a starting K of 4.
  26.  
  27.  
  28. === STF ===
  29.  
  30. This will be a positional entropy transform.
  31. It aims to order symbols (roughly) in the order of their priority.
  32.  
  33. The native implementation is a 256 byte array, with an 8-bit position rover.
  34. An index (I) is used to fetch a value from the circular array (mod-256), and then the array is updated based on the index.
  35.  
  36. The initial state for the array will encode values from 00 to FF in order, with an initial rover value of 00.
  37.  
  38.  
  39. Will use slightly different behaviors based on the index (I):
  40. * 0: Do Nothing
  41. * 1..31: Swap symbols at I with I-1
  42. * Else:
  43. ** Swap symbols at I with 255;
  44. ** Rotate window by 1 position (so 255 is now at 0).
  45.  
  46.  
  47. Nominally, STF indices will be encoded using Rice, in a form known as STFRice.
  48. This may be denoted with a context given as an argument, so "STFRice(Lit)" may mean a STF+Rice symbol encoded in the "Literals" context. Each STFRice context will have its own array, rover, and K value.
  49.  
  50.  
  51. === VLN ===
  52.  
  53. VLN Values may also be encoded using AdRice:
  54. * 00..1F: 0.. 31, 0
  55. * 20..2F: 32.. 63, 1
  56. * 30..3F: 64.. 127, 2
  57. * 40..4F: 128.. 255, 3
  58. * 50..5F: 256.. 511, 4
  59. * 60..6F: 512.. 1023, 5
  60. * 70..7F: 1024.. 2047, 6
  61. * 80..8F: 2048.. 4095, 7
  62. * 90..9F: 4096.. 8191, 8
  63. * A0..AF: 8192..16383, 9
  64. * B0..BF: 16384..32767, 10
  65. * C0..CF: 32768..65535, 11
  66.  
  67.  
  68. === LZ Stream ===
  69.  
  70. Will consist of a series of Tag bytes giving a literal byte count and match length.
  71.  
  72. STFRice(Tag):
  73. * High 4 bits: Literal Bytes (0-14)
  74. * Low 4 bits: Match Length (3-17)
  75.  
  76. If there are 15 or more literal bytes, then the tag will encode 15, and will be followed by a VLN encoding the actual length, VLN(Len).
  77.  
  78. A similar encoding will be used for matches longer than 17 bytes, which will also be encoded as VLN(Len). Otherwise, a separate VLN is not used.
  79.  
  80. The match length will be followed by the distance, encoded as VLN(Dist).
  81. After the distance, a series of literal bytes may be encoded as STFRice(Lit).
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement