Sign in to follow this  
39ster

Packing and Unpacking images

Recommended Posts

What would be the best way to store a multiple images in one file? Is there a standard file format or library that most people use? Let's say i want a file named "PlayerSprites.gg" and it packs all the player bitmaps into that one file. I'm using SDL + OpenGL.

Share this post


Link to post
Share on other sites
You can use SDL to extract images from zip files. You can change the extension on the .zip file, and name it something like myImageArchive.idc so to casual people playing your game, it'd look like a unknown file type.

The benefit of this, is that you can easily zip/unzip the images for your game without having to code some separate tool to do this for you. I've never personally done this with SDL, so you'll have to go to that link to find out how.

Share this post


Link to post
Share on other sites
Hmm, looks good but i wonder if there is a way to turn compression off? The images will already be .png files. No point in double compressing them, it will just waste processing time.

EDIT: Actually there does seem to be an option called "Store" which won't do any compressing.

Share this post


Link to post
Share on other sites
Making your own pack file format isn't as hard as one might think. It could simply have the following structure:

[[4 byte item ID] [4 byte item data size] [item data]], [...], [...]

When you open the pack file, just read the ID and size of each item, store its file offset, and when you need access to the actual data you know exactly where in the file it is and how big it is.

If you're feeling adventurous you can refer to each item by name (string) instead.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this