-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compressing with small window size #300
Comments
Did this end up working well for you? I have max 64kb of ram to use and currently the tdefl takes about 350kb which I definitely don't have. I am new to compression, what does "window size" mean? |
It's working well with the changes I proposed, but you have to know what you're doing. To know what window size means in respect to gzip, I'm sure chatGPT or google can tell you, as they are far better in explaining than me ;-) |
Oh I see. What it can look at to compress it. I am looking to compress 1400 bytes to about 500 so 4095 would be perfect. I will mess around with it and see if I can figure it out. How much memory did you need for tdefl_compressor in the end? Thanks for the quick answer! |
Managed to get the compressor struct down to only 41kb. Good enough for my micro controller's RAM. Just had to modify the enums. I was able to successfully compress a 1400 byte array to about 500. Not sure what the limit is with this small but still very good compression.
|
For a zlib compressed file that needs to be decompressed by an MCU with very limited memory, I want to use a window size of only 4096. I started by defining
TDEFL_LESS_MEMORY
, and changingTDEFL_LZ_DICT_SIZE
to 4096, which leaded to corrupted zlib files. After some more investigation, it appeared I could lowerTDEFL_LZ_DICT_SIZE
to 16384 and 8192, but anything below would corrupt the output file.Eventually I managed to fix it, because I found some hardcoded values in the source of
tdefl_compress_normal
:8U * 1024U
in https://github.com/richgel999/miniz/blob/master/miniz_tdef.c#L1185and
31 * 1024
in https://github.com/richgel999/miniz/blob/master/miniz_tdef.c#L1234Changing both of the hardcoded values to 4096 solved the problem, and, in combination with the right
TDEFL_LZ_DICT_SIZE
, leaded to valid zlib files with window size 4096.As I'm not exactly know what I'm messing with ;-) , I didn't want to make this in to a PR. Ideally, it probably should use the window_bits parameter in
int mz_inflateInit2(mz_streamp pStream, int window_bits)
(which is restricted to 15 and -15 at the moment, and only used to check if the value is negative or positive).The text was updated successfully, but these errors were encountered: