低内存条件下的LZW压缩/解压 [英] LZW compression/decompression under low memory conditions

查看:33
本文介绍了低内存条件下的LZW压缩/解压的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以指点我如何在低内存条件下(<2k)实现 lzw 压缩/解压缩.这可能吗?

Can anybody give pointers how I can implement lzw compression/decompression in low memory conditions (< 2k). is that possible?

推荐答案

大家使用的 zlib 库臃肿等问题(嵌入式).我很确定它不适用于您的情况.我有更多的内存,可能是 16K,但无法适应.它分配和归零大块内存并保留内容的副本等.算法也许可以做到,但找到现有代码是一个挑战.

The zlib library that everyone uses is bloated among other problems (for embedded). I am pretty sure it wont work for your case. I had a little more memory maybe 16K and couldnt get it to fit. It allocates and zeros large chunks of memory and keeps copies of stuff, etc. The algorithm can maybe do it but finding existing code is the challenge.

我用 http://lzfx.googlecode.com 解压循环很小,它是较旧的 lz 类型压缩依赖于先前的结果,因此您需要访问未压缩的结果...下一个字节是 0x5,下一个字节是 0x23,接下来的 15 个字节是前 15 200 个字节的副本,接下来的 6 个字节是 127 年前的副本...较新的 lz 算法是基于可变宽度表的,根据实现方式可以变大或增长.

I went with http://lzfx.googlecode.com The decompression loop is tiny, it is the older lz type compression that relies on the prior results so you need to have access to the uncompressed results...The next byte is a 0x5, the next byte is a 0x23, the next 15 bytes are a copy of the 15 200 bytes ago, the next 6 bytes are a copy of 127 ago...the newer lz algorithm is variable width table based that can be big or grow depending on how implemented.

我正在处理重复数据,并试图将几 K 压缩到几百,我认为压缩率约为 50%,虽然不是很好,但完成了工作,解压程序很小.上面的lzfx包很小,不像zlib,像两个main函数里面有代码,而不是几十个文件.您可能会更改缓冲区的深度,如果您愿意,可能会改进压缩算法.我确实必须修改解压缩代码(可能是 20 或 30 行代码),它的指针很重,我将其切换到数组,因为在我的嵌入式环境中指针位于错误的位置.Burns 可能是一个额外的寄存器,取决于你如何实现它和你的编译器.我也这样做了,因此我可以抽象字节的提取和存储,因为我将它们打包到不可字节寻址的内存中.

I was dealing with repetitive data and trying to squeeze a few K down into a few hundred, I think the compression was about 50%, not great but did the job and the decompression routine was tiny. The lzfx package above is small, not like zlib, like two main functions that have the code right there, not dozens of files. You could likely change the depth of the buffer, perhaps improve the compression algorithm if you so desire. I did have to modify the decompression code (like 20 or 30 lines of code perhaps) it was pointer heavy and I switched it to arrays because in my embedded environment the pointers were in the wrong place. Burns maybe an extra register or not depending on how you implement it and your compiler. I also did that so I could abstract the fetches and the stores of the bytes as I had them packed into memory that wasnt byte addressable.

如果您发现更好的东西,请在此处发布或通过 stackoverflow 联系我,我也对其他嵌入式解决方案非常感兴趣.我搜索了很多,上面是我发现的唯一有用的一个,我很幸运,我的数据使用该算法压缩得足够好......暂时.

If you find something better please post it here or ping me through stackoverflow, I am also very interested in other embedded solutions. I searched quite a bit and the above was the only useful one I found and I was lucky that my data was such that it compressed well enough using that algorithm...for now.

这篇关于低内存条件下的LZW压缩/解压的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆