emmanuel-marty / lzsa

Byte-aligned, efficient lossless packer that is optimized for fast decompression on 8-bit micros
Other
236 stars 30 forks source link

13-bit match offset description error #46

Closed jin-x closed 4 years ago

jin-x commented 4 years ago

There's an error in description of 13-bit match in BlockFormat_LZSA2.md You write:

10Z 13-bit offset: read a nibble for offset bits 9-12 and use the inverted bit Z for bit 8 of the offset, then read a byte for offset bits 0-7. set bits 13-15 of the offset to 1.

But you don't mention subtracting 512 from resulting value.

When creating my own unpacking code, I couldn't understand the reason of error. And found this value of 512 only in your sources.


And one more note about stream format (StreamFormat.md)

You write:

0    1                2
0x7b 0x9e             7 6 5 4 3 2 1
                      V V V Z Z Z Z
<--- signature --->   <- traits ->

Trait bits:

  • V: 3 bit code that indicates which block data encoding is used. 0 is LZSA1 and 2 is LZSA2.
  • Z: these bits in the traits are set to 0 for LZSA1 and LZSA2.

Where is zero bit ? Your packer writes 20h into traits byte for LZSA2 and 0 for LZSA1. So it's must be four V bits (if V = 2 means LZSA2). Or five Z bits (but V = 1 means LZSA2 in that case, not V = 2).

emmanuel-marty commented 4 years ago

Good catch, thank you!

I think I added the 512 offset as I was finalizing the format (it is nearly free even on 8 bit CPUs since it's a substraction of 2 from the high byte, and allows for a greater coding range since smaller offsets use different and shorter encodings). I never updated the spec.

Good remark on the version identifier as well, I also corrected it.

Thanks again!

jin-x commented 4 years ago

Good for 512 👍 But there's no bit 0 in Header format description. I see only "7 6 5 4 3 2 1", without "0".