How can I do LZW decoding in Java?

佐手、 提交于 2019-12-29 06:59:19

问题


I have a database which contains picture data stored as a binary blob. The documentation says the data is encoded using LZW. I thought that I could decode it using the Zip or GZip input streams found in the Java library, but it didn't work - I got an exception that said the format of the data is not correct.

From what I've read, the library uses DEFLATE, which is not LZW. Also, I've read about some licensing problems for using the LZW algorithm.

What can I use to decode the data? Is there a library? Do I have to implement it myself? What about the licensing problems?


回答1:


Here are a couple of links:

  • http://www.cs.sfu.ca/CC/365/li/squeeze/LZW.html

  • http://u.cs.biu.ac.il/~freskom1/AlgProg1/Progs/LZW.java

  • http://www.codeproject.com/KB/java/lzw.aspx

And there are others.

Indeed if the images are LZW compressed TIFF files, The Java Advanced Imaging API apparently supports decoding directly (though not encoding it seems).




回答2:


I know the question is old, but I just wanted to add a great resource about LZW:

http://www.matthewflickinger.com/lab/whatsinagif/lzw_image_data.asp

It's more specifically about the use of LZW in GIF images, but it explains the compression and decompression algorithms pretty well.




回答3:


You can also try with 7-Zip JBinding which uses the 7zip library internally. It's quite easy to use.




回答4:


I went through a surprising amount of LZW implementations before finding one that worked for my case.

UncompressedInputStream from the BioJava project worked for me, when I needed to unpack a .pax file.



来源:https://stackoverflow.com/questions/2424998/how-can-i-do-lzw-decoding-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!