Skip to main content
gamedev.net
🔒 Locked

Image compression

Started by Karax Dec 31, 2003 at 4:41 PM 7 replies 600+ views
Original Post
Karax
Karax
Ok this is quite simple (i hope..) i need a way to compress all those bmps i use in the small game i use, mostly to learn how to do it for when i work on bigger projects where compressing the images will save decent space. I looked around for an easy way and the only thing i could find was TAR and GZIP... now i found a way to code compress/uncompress of a file, but i still don''t know how i''ll be able to use the TAR file, open it, and pass the images (in their respective folder if possible) to directX. A little hint would be appreciated ^^;; i looked over the GNU TAR site but didn''t find much help there aside from command line arguments in the huge documentation. Any other way then TAR/GZIP is welcome, i know just about every company out there ues their own way to store their images in a compressed file(s). Considering i don''t plan to make any money from it, the gnu licence doesn''t pose a problem. I''m looking for any information or wrapper that i could learn from on how to perform this. Thank you
invective
invective
What platform are you using? Direct X can load just about anything including S3TC compressed textures. Otherwise, i suggest png, since its pretty flexible and has decent compression.

http://www.libpng.org/
Karax
Karax
hmm true, though the idea was more to get them all into 1 compressed file, i''ll be sure to check that png format out when i have time tomorrow, thank you ^^
risingdragon3
risingdragon3
You should use winzip format and the free gzip library along with unzip and zip files which come in a contrib directory on the main gzip download. I think. Oh wait! not gzip....zlib. Yes.... that''s right the website is: www.gzip.org/zlib. And when you download the main zip file there should be a contrib dir where it should have a winzip format contrib functions. Yep.

Also if you are using direct3d to do a 2d type game you might want to shove all your textures onto one big one to limit the settexture().

-----------------------------
Gamedev for learning.
libGDN for putting it all together.
invective
invective
You can save all your images as png and then just mash them into one file. You will have to write a utility that takes a list of files and gets the size of each file. You then write the filenames and offsets into the header of your archive file, and dump each png into the archive afterwards. To retrieve the texture you want, you open the archive, read the header, find the offset of the file you want, and read the data into a buffer in memory. Pass the buffer to libpng or libjpg to decode.
Deebo
Deebo
I used zip files with jpeg images. when an image is loaded i extract and uncompress in memory and use it with an image class.
When it is no longer being used I save it as a temp file for easy access. When the program quits, temp folder is deleted.
I used the zlib library and programmed automatic zip file searches and extraction into my file manager BTW.
brassfish89
brassfish89
I''d reccomend creating a zip/tarball with all the images and stuff, then use zlib in your game to uncompress it. On a side note, jpegs use lossy compression. Which is fine for photo-like images, but if you use jpegs for computer art (generally pixel art looks the worst when using lossy compression) it will look horrible.

--------
"Hey, what about those baggy pants you kids are wearin'' these days? Aren''t they hip and cool and poppin'' fresh?"-Peter Griffin
"Everytime I see an M followed by a dollar sign I just say "oh god" and go to the next post."-Neurokaotix
the D programming language|google|msdn|XLib reference manual
Deebo
Deebo
Not if you use uncompressed jpegs.
tebriel
tebriel
This all depends to some degree on what you''re using it for, but if you want maximum image compression you have to use an algorithm written *specifically* for that (i.e. jpeg, etc.) and not something general purpose like zip. The specialized compression algorithm will always *destroy* the compression stats of a generalized compression algorithm. If you want lossless compression, an image compression format should still be better, although it''d be less obvious. But don''t use a "general" compression format to compress images, that''s why there''s special algorithms for sound/movies/pictures.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.