• Advertisement

Archived

This topic is now archived and is closed to further replies.

Saving (and loading) several images into one file?

This topic is 5028 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! This is my first post and I've just registered, but I've been searching and reading this forums a *lot* for the past 2/3 weeks and I figured this was the best place for me to ask my question(s). There is a post similar to mine but the answers weren't what I wanted. How can I save several images (probably bitmaps) to one file and load them afterwards? I'm using devcpp with sdl to make a game. I've just begun but I don't want people to be able to mess around with the game's images when I put it up on my site for download.. So, I was wondering if there's a way of saving all images into one large file and load them from within the game. I've seen it done on a game called Uplink (http://www.introversion.co.uk/uplink , I think) and I think it was some kind of compression system or something.. If that's is not possible then is there a way of joining them with the final exe? (Tough I don't like the idea, it would make the executable *really* big. Thank's in advance for any answer. Asclepius [edited by - Asclepius on April 14, 2004 4:54:19 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
If I recall correctly, Uplink just took all the game data, zipped them, renamed the zip files and XORed every bit in all the files by some number. The game then read in the data, XORed it again and performed the unzip funtion. You could write somthing similar. Or you could write a program that takes a filename, gets the binary size of the file and writes in as a package. Somthing like this:
File 1 = bitmap 10000 bytes
File 2 = text file 500 bytes
File 3 = text file 550 bytes
The game data file would be 11050 bytes long, plus a header which would include offsets for the locations in the file where the other 3 files are, and their sizes. The game would load all this in and seperate it into resource structures or class or whatever.

Share this post


Link to post
Share on other sites
I''ve done something very simular to that, where it creates a file of any filetype and combines them into one. In addition I use encryption to keep the files from being directly opened. I created another program to load it. The only problem that I encountered, was trying to load the image in DirectX. Instead for now, I have it just output the file to the origional files so that they can be loaded that way for now. I would like to know how to directly load the bitmaps from the file though. If you want the source code, email me:
guyaton@hotmail.com




~Guyaton

Share this post


Link to post
Share on other sites
There are lots of ways you can do it. If you want to keep it simple, you can just create your own file format. Maybe something like this:

Header
- int: size of header in bytes
- int: number of images in file:
- int array: number of bytes for each image block

Each image block:
- int: image width
- int: image height
- int: image color depth
- int: image size in bytes
- byte array: image data

Thus, your file would be a header plus the appropriate number of image blocks, which would be each to jump around and load whichever image you needed.

Share this post


Link to post
Share on other sites
once you do that, how do you load the bitmap into memory so that you can load it as a texture? That''s the part i''m having problems with.



~Guyaton

Share this post


Link to post
Share on other sites
DirectX has functions that take a memory address. I don''t recall there names, but they exactly like the file based load routines, only they load from memory. Like LoadSurfaceFromMemory or something like that.

Share this post


Link to post
Share on other sites
You could zip and then use the zlib library to read the zip file at runtime.

-----------------------------------------------------
Writer, Programer, Cook, I''m a Jack of all Trades
Current Design project: Ambitions Slave

Share this post


Link to post
Share on other sites
Or use my PAK file archive I wrote for this purpose... You can find information on what it is, and how it works in general on this page:
http://toolmaker.homeip.net/index.php?page=5

Since I still haven''t fixed my download script(Will start doing that today), I placed it in my upload folder. You can download the archive DLL, C++ headers required to use the interface(And a small wrapper for it) and documentation at http://toolmaker.homeip.net/upload/ToolPAKv110.zip

It''s simple to use, and the DLL is pretty small. It probably saves you the hassle of writing your own or use zlib. It doesn''t have compression, but does use encryption and CRC32 checks to ensure data integrity. It also supports multiple archives(You just have multiple archive objects or reuse one).

If you are going to use it, lemme know if you got any ideas suggestions for it.

Toolmaker



My site
/* -Earth is 98% full. Please delete anybody you can.*/

Share this post


Link to post
Share on other sites
quote:
Original post by OOCCO
Creating a PAK file format


What''s the point in that? Writing your own custom library, is kinda pointless when there are so many other utilities around, such as zlib, my pak archiver, etc.?

Toolmaker



My site
/* -Earth is 98% full. Please delete anybody you can.*/

Share this post


Link to post
Share on other sites
Thank''s for the replies. I''ll save the page for the other ideas but I think there are two things I might do:

1) I''ll encrypt the file and put a function in the game do decrypt it (I''m working on a encryption algorithm with a friend so I''ll probably use it), then, from the game, save the images back to bmp and load them (I''m using the SDL_LoadBMP function) and finally delete them again. Maybe I won''t need to write them to the disk, there''s probably a way of loading directly to SDL_Surface pointers but I''m sure I''ll figure it out.

2)Use the Toolmaker Pak Archiver, it would be extremely simple and I believe it would work right. Maybe, to make it even more harder to crack, encrypt the file with my own algorithm.

I''ll talk to my friend who''s making the game with me (not programming, he doesn''t know how - he designs the tiles and such and gives ideas) and then decide what is the best solution.

Probably I''ll choose the second one, for it would be a lot easier.

I believe this topic was answered completely, I don''t know if it has to be closed or something by me or by the sysadmins..

If anyone whishes to say something (more), I''ll be coming here regularly so don''t be afraid I don''t get to see your answer / idea / sugestion!

THANK YOU ALL again, it''s so good to know a place where your questions are answered well and quick!

If you find any error or something like that forgive me but english is not my main-language, I''m Portuguese.

Share this post


Link to post
Share on other sites
quote:
What's the point in that? Writing your own custom library, is kinda pointless when there are so many other utilities around, such as zlib, my pak archiver, etc.?
It's a good learning experience - why exactly did you write a PAK system if there are "so many other utilities around"? It's one adequate solution to his problem so I thought I'd mention it. Not everyone may want to use your utility or any other that is around.

[edited by - OOCCO on April 15, 2004 10:28:18 AM]

Share this post


Link to post
Share on other sites
Guyaton, couldn't a smart game player then Alt+Tab the game, copy the bitmap and save it elsewhere?

EDIT: I just noticed that the PAK file format article above mentioned use of the D3DXCreateTextureFromFileInMemory() function, so all you'd need to do is decrypt it in memory and load it. Wow, DX makes it so easy. Oh yeah, and that's assuming you're using DirectX...

Stay Clausal,

Red Sodium

[edited by - red_sodium on April 15, 2004 10:29:43 AM]

Share this post


Link to post
Share on other sites
Quote from red_sodium:

"Guyaton, couldn't a smart game player then Alt+Tab the game, copy the bitmap and save it elsewhere?"

There are ways of disallowing the alt+tab and windows key (and such) which might give the player that chance.

However, the purpose here is not letting the player replace the graphics: he can do whatever he wants with them, I don't care as long as the game isn't altered.

Also, if none of the keys worked, a smart game player could do a printscreen, so there are always ways of "stealing" graphics.

I've been trying out the pak archiver from Toolmaker but I didn't got on well with it; I believe it used some win32 functions and I want to make a portable (as much as I can, anyway) game. I guess I'll stick to the first option..

[ correction to the 1 option ]
(1) I'll encrypt the file (my own format, as BriTeg sugested, containing all the images) and put a function in the game do decrypt it (I'm working on a encryption algorithm with a friend so I'll probably use it), then, from the game, save the images back to bmp and load them (I'm using the SDL_LoadBMP function) and finally delete them again. Maybe I won't need to write them to the disk, there's probably a way of loading directly to SDL_Surfaces / sprites but I'm sure I'll figure it out.



[edited by - Asclepius on April 15, 2004 6:13:00 PM]

Share this post


Link to post
Share on other sites
You can.. Should be pretty easy, actually, you just have to implement your own SDL_RWops to read from the pak-file and off you go. The LoadBMP is, as far as I know, just a macro that creates a standard RWop for reading from a file and passes that to the actual LoadBMP-function.

EDIT: Oh, and even if you don't, don't even start to think about disabling alt-tab.. You really annoy your users with that.


[edited by - Wuntvor on April 15, 2004 6:13:11 PM]

Share this post


Link to post
Share on other sites
I''m going to recommend zlib, because I''m pretty sure it can read a file out of a zip without having to save the file again first.

Although encryption is another problem. There are a couple file encryption algorithms out there that you could use to encrypt the entire archive, XOR being the easiest.

Share this post


Link to post
Share on other sites
quote:
Original post by Asclepius

I''ve been trying out the pak archiver from Toolmaker but I didn''t got on well with it; I believe it used some win32 functions and I want to make a portable (as much as I can, anyway) game. I guess I''ll stick to the first option..



I am glad that you at least tried it . But yeah, it uses Win32 functions and I don''t plan on changing that. I hate Linux, and thus I refuse to convert this into a crossplatfrom DLL/Shared Object. But thanks for trying.

Toolmaker





My site
/* -Earth is 98% full. Please delete anybody you can.*/

Share this post


Link to post
Share on other sites
Toolmaker, no problem, if it was a win32-only game I would certainly use it.

BTW, why do you *hate* linux? I mean, I use both and don''t dislike none of them.. What do you find so bad about linux? I just started using it a couple weeks ago and I haven''t encountered problems so far.. Have you found lots? A bit off-subject but I was curious as I just started using it and I wanted to hear opinions on it.

Thank''s for your link anyway, I''ll use it if i do an app for windows! I think it''s really useful

Asclepius

Share this post


Link to post
Share on other sites

  • Advertisement