SCI: Merge and cleanup LZW decompressors#6550
Conversation
| // SCI0: LSB-first. | ||
| // SCI01/1: MSB-first, code size is increased one code earlier than necessary. | ||
| // This is known as an "early change" bug in LZW implementations. |
There was a problem hiding this comment.
I'm a bit confused here. The "early change" bug was introduced in early implementations of the LZW algorithm, but here it's introduced in newer SCI versions. Was this introduced by accident, perhaps?
There was a problem hiding this comment.
Yes, it's very confusing that their second LZW implementation introduced this bug! I don't have any insight beyond that; it's a common mistake to make in LZW but it doesn't really matter as long as both the encoder and decoder behave the same.
My guess is that Sierra didn't know they introduced this bug in their second implementation. They already swapped the bit order, so it's not like any of the old stuff and new stuff would have been compatible. But it is funny that if it weren't for this, the only difference would be "flip the bits".
There was a problem hiding this comment.
Odd indeed. Thanks for the explanation :)
|
Excellent work! Much cleaner and readable implementation I've briefly tested this out, and it works great. Thanks for your work! |
Oh my wow 😹 |
This PR ports the LZW decompressor from my SCI tools to ScummVM. This replaces two FreeSCI-era decompressors with one small documented one.
That's right, we're compressing the decompressors.
SCI has two LZW compression formats. They only have two minor differences. The first is the bit order, the second is an off-by-one bug. The bug is so common in LZW implementations that it has a name and made the LZW wiki page: "early change".
I don't think it's known to the SCI community that the formats only differ by these two things. I learned it the hard way when developing my decompressors. I think what usually happens is that the FreeSCI code for the second algorithm just gets ported around. It works, but it's based on disassembly and not very comprehensible. (As the FreeSCI comments acknowledged.)
This decompressor helps generate my sci-scripts repository, where it gets run on every script in almost every game/version, so it's well used. I've also ran it against every LZW-compressed resource in my corpus.
This affects all SCI0-SCI1 games, but it shouldn't change any behavior unless I've messed something up =)