flamewing / mdcomp

Assorted compression formats for the Sega Mega Drive
Other
44 stars 4 forks source link

Moduled Kosinski+ pads incorrectly #3

Closed Clownacy closed 6 years ago

Clownacy commented 6 years ago

If you compress and decompress a file (in my case ARZ's level art), the decompressed file won't match the original. I found two ways to fix this, but I'm unfamiliar with Moduled formats, so I'm not sure which is best:

kosplus.cc mentions that Kosinski+ doesn't need padding, so the first option is probably nonsense that just removes a feature. However, I'm not sure why the compressed file needs padding to an even byte, so I can't say for sure that the second option is best either.

If the single-byte padding is absolutely necessary, I guess moduled_kosplus can just be set to 2u instead.

flamewing commented 6 years ago

Looking over, it is a general big in the implementation: BasicDecoder::encode should be the one padding the final file size to even size, not the individual encoders. The encoder::encode method should also probably be private and the BasicDecoder class be made a friend also. And a few minor improvements.

Will look more closely tonight.

flamewing commented 6 years ago

I think this should fix, but I won't be able to test until tomorrow night. Will leave it open until it is properly tested.

flamewing commented 6 years ago

After a few false starts because Gnome Builder decided I wanted things installed to ~/.cache/gnome-builder/install instead of in /usr/local, I finally managed to confirm that it is fixed.

Need also to add some size checks to all these cases; moduled formats only work if the uncompressed file is strictly less than 64kB in size because there are only 2 bytes for size.