Computing.Net > Forums > Programming > algorithm to compress file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

algorithm to compress file

Reply to Message Icon

Name: alex g.
Date: November 8, 2002 at 08:45:47 Pacific
OS: Win 2000 Pro
CPU/Ram: 132
Comment:

Hello everybody,
does anybody know an algorithm to compress/uncompress a file? Say, i want to compress (shrink) a bitmap file from 100% to 20%. Is there some simple algorithm or code on the net i can use as an example?
Thanks much for all advices,
Alex G.




Sponsored Link
Ads by Google

Response Number 1
Name: AndreasF
Date: November 8, 2002 at 08:57:20 Pacific
Reply:

There's one really simple called Huffman code. Take a look at the web somewhere, I dunno where to go but I can assure you that it is out there.

Woops... found it!
http://www.compressconsult.com/huffman/


0

Response Number 2
Name: AndreasF
Date: November 8, 2002 at 08:58:50 Pacific
Reply:

This one might be easier:

http://www.cs.chalmers.se/Cs/Grundutb/Kurser/sysc/lab1_huffman.html


0

Response Number 3
Name: Jeff J
Date: November 8, 2002 at 15:48:01 Pacific
Reply:

Just one thing about compression ratios: regardless of algorithm, some files compress better than others. Even as compressible as bitmaps often are, complex ones (lots of colors and unique pixels) may only compress to 99%. Conversely, a large one with a single color might go below 1%. For photographic images, 20% is hard to achieve.


0

Response Number 4
Name: Jim
Date: November 8, 2002 at 16:00:11 Pacific
Reply:

Actually, your compression rate is going to depend a lot on what your bitmap file looks like. If it's a color photo, you're going to run into problems. If it's a black and white document, you should be able to get to 20% easily.

Huffman coding isn't all that simple. I recommend you look into run length encoding first. It's a lot simpler than huffman coding, and for some applications is a lot better. Look Here for one source. Here is another.

Lempel-Zev compression is pretty simple, and compresses better than run length encoding. But good luck finding something on the net that doesn't include the Welch extension, which makes it compress better, but complicates it a lot. If you're interested, post here and I'll write up a quick description.


0

Response Number 5
Name: borelli33
Date: November 8, 2002 at 22:13:45 Pacific
Reply:

Actually, I wouldn't use RLE (Run Length Encoding) because it has a much less predictable compression ratio. Huffman isn't exactly easy but compared to Limple-Zev-Welch (LZH) it is simpiler and more consistent. The best advice anyone can give you really is to first gather about 20 or more example files of what you wish to compress. Then run a test using applications that already use these technologies and find out which ones provide the best compression overall and the most consistent or predictable compression (you may also wish to come up with a way to accurately time the process for each file as well) then make your decision based on that researched data. You might even go so far as to come up with an evaluation/performance ratio/index in order to measure your results. Once you have done this you can more efficiently decide which to use based on your research and the complexity of either algorithm. But that's just what I would do; it may be more than you wish to get into.

borelli33


0

Related Posts

See More



Response Number 6
Name: alex g.
Date: November 12, 2002 at 15:37:45 Pacific
Reply:

Thanks for all your replies. Here is the thing though. I can't find code on the net. Do you guys know where i can get free c++ source code that ompresses/decompresses a bitmap file to/from .jpeg file. I don't need a fancy one, just would like to shrink a .bmp file to say 10%-20%. Run Length Encoding code would work fine for me. Spent many hours searching, the only thing i could find was reference to independent JPEG group library, but i am just looking for two simple functions(compressBmp, decompressBmp). Thanks again,
regards Alex G.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Help With C about Crystal Reporting



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: algorithm to compress file

Microsoft Diamond Compression (MDC) www.computing.net/answers/programming/microsoft-diamond-compression-mdc/1779.html

Batch to compare files' size www.computing.net/answers/programming/batch-to-compare-files-size/17428.html

Dos Bat. to edit file (hosts) www.computing.net/answers/programming/dos-bat-to-edit-file-hosts/14581.html