File Compression

Started by
15 comments, last by GameDev.net 17 years, 6 months ago
Hey everyone. I'm working on a 2D game that is about 10MB in size so far. About 8MB of that is hundreds of 3KB GIF graphics for the animations. When I tried to compress the 10MB using winzip, I only got it down to about 8MB. I'm hoping to get it much smaller than that. I did some searching online and found out that PNG is a better choice than GIF (particularly since I'm not using animated GIF's). But I don't think that alone will get my file size any smaller. Is there a better way to losslessly compress my files? Thanks.
Advertisement
Have you looked at the individual compression ratios? Have you considered joining the individual gif files into a single atlas? That would compress better.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
The problem here is that your image formats are already compressed.

It is rather difficult to compress what has already been compressed.
Quote:Original post by Ximmer
The problem here is that your image formats are already compressed.

It is rather difficult to compress what has already been compressed.


Quite true, as a book I have just read put it
Quote:"Why is it that an already compressed file cannot be compressed further?" The answer, of course, is that such a file has little to no redundancy, so there is nothing to remove. ....Another answer is that if it were possible to compress an already compressed file, then successive compressions would reduce the size of the file until it becomes a single byte, or even a single bit, This, of course, is rediculous since a single byte cannot contain the information present in an arbitrarily large file.


This quote is reffering to lossless compression,such as zip.
Quote:Original post by Fruny
Have you looked at the individual compression ratios? Have you considered joining the individual gif files into a single atlas? That would compress better.


I do believe PNG is superior in general, but I'd like to point out that this advice also holds for PNGs - it can make a *big* difference if your files are all that small.

Also consider variants on zip. A standard zip archive is very wasteful if you have lots of tiny files, even if they aren't pre-compressed files. If making an 'atlas' isn't feasible, consider for example tarring the files first and running gzip on the tar (the .tar.gz combination that is infamous in the Linux world). gzip is perhaps not as sophisticated and it can only archive a single file (hence the *need* to use tar first), but operating on a single file can make a big difference (because files with similar content can be grouped together, more redundancy can be found; zip effectively "restarts" for each file AFAICT). As well, .tar is probably more sparing with metadata than .zip (which IMX adds about 100 bytes plus twice the filename length for each file - and that's if you don't have any folders).

An atlas really is nicer though. Note that you can often reduce the executable size this way too, by removing logic that determines filenames and opens multiple files, replacing it with a little math to find coordinates for each "image". Often this calculation folds into an existing one and costs nothing or almost nothing.
RAR compression also offers a mode where all files are effectively concatenated before being compressed.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Quote:Original post by Wutalife37
Is there a better way to losslessly compress my files?

I feel I should point out that GIF encoding is not lossless, in general. Unless the source image is limited to 256 (potentially including the basic 16 colour palette) a new palette will be created (using an optimised median cut) and the image may be dithered.

Original post by Anonymous Poster
Quite true, as a book I have just read put it
Quote:"Why is it that an already compressed file cannot be compressed further?" The answer, of course, is that such a file has little to no redundancy, so there is nothing to remove. ....Another answer is that if it were possible to compress an already compressed file, then successive compressions would reduce the size of the file until it becomes a single byte, or even a single bit, This, of course, is rediculous since a single byte cannot contain the information present in an arbitrarily large file.
As good as that explanation is, I'm disapointed to read that a published book would propagate such a horrible misspelling of 'ridiculous'. Sorry, I'm a pedant [rolleyes].

Regards
Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Quote:Original post by TheAdmiral
I feel I should point out that GIF encoding is not lossless..........


Not entirely correct: True-Color GIF Example. I was suprised to find this out a few weeks ago.
Here's a few tips in making a PNG that contains plenty of animation frames in one: Lay out the animation frames horizontally into the image. Use pngcrush to compress PNG files into smaller, it's a free tool. You could also Google for "gif optimizer" and try out a few of those tools and see if they make a difference for your GIFs.
Quote:Original post by pkelly83
Quote:Original post by TheAdmiral
I feel I should point out that GIF encoding is not lossless..........


Not entirely correct: True-Color GIF Example. I was suprised to find this out a few weeks ago.
ItsAGIF has been around for years.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement