Page 1 of 1
How Would You Put All Media In One File?
Posted: Fri Dec 25, 2009 8:11 pm
by davidthefat
Like putting all images in Images.dat or something. I have no idea how I would do this since I dont exactly know how an OS would handle that stuff... Or am I trying to complicate an easy thing? In other words, how would I encode the data? I can just use a fancy equation and use fstream right? I dont need additional libs?
Re: How Would You Put All Media In One File?
Posted: Fri Dec 25, 2009 9:04 pm
by dandymcgee
davidthefat wrote:Like putting all images in Images.dat or something. I have no idea how I would do this since I dont exactly know how an OS would handle that stuff... Or am I trying to complicate an easy thing? In other words, how would I encode the data? I can just use a fancy equation and use fstream right? I dont need additional libs?
If you can read the image file by itself without a library, then you can put multiple ones in the same file and it will work (pending some sort of separation that lets you know where each image begins and ends). As far as the OS handling it, you wouldn't be able to view in any standard image editing software since it's your own personal proprietary format, but you could create tools to read/write/view your new format if you really wanted.
Re: How Would You Put All Media In One File?
Posted: Fri Dec 25, 2009 9:08 pm
by MarauderIIC
An OS usually allocates your hard drive space into "blocks" and keeps track of what file starts at what block and how long the file is. Blocks are allowed to only be partially filled (in which case the rest of the block is wasted space, another file does not start there). This has obvious parallels to "all images in one file" sort of thing, and I'm answering what I thought you were trying to ask instead of what you actually did ask =)
As for your specific question, if all your images have the same allotted number of bytes, you could just read x bytes and disregard any padding. For instance, if you allot 512 bytes to each image in your engine and an image is only 256 bytes you would read 512 and the last 256 bytes would be, say, all zeroes, and you would throw those away. Or, if you used a standard image format, you could just read the header info which usually says how large your image is or the file itself has a terminal marker, in which case you could do away with padding.
So your image.dat might have a header itself that says which image starts at what offset in the file (this would allow you to read image on-demand). If it doesn't (ie, you want to load all the images at the start, or don't mind a loading time), you would need to read the file sequentially, counting the terminal markers for each image until you found the image you were looking for.
You, yourself, would just append the info for each image to the end of your image.dat file (and pad it if necessary).
Re: How Would You Put All Media In One File?
Posted: Fri Dec 25, 2009 9:28 pm
by andrew
davidthefat wrote:Like putting all images in Images.dat or something. I have no idea how I would do this since I dont exactly know how an OS would handle that stuff... Or am I trying to complicate an easy thing? In other words, how would I encode the data? I can just use a fancy equation and use fstream right? I dont need additional libs?
Here's some stuff I have bookmarked:
Creating a PAK File Format
Virtual File System
Programming a Virtual File System
It might be a bit more than you wanted.
Re: How Would You Put All Media In One File?
Posted: Fri Dec 25, 2009 10:01 pm
by davidthefat
Thanks all of you
Re: How Would You Put All Media In One File?
Posted: Sat Dec 26, 2009 5:35 am
by short
Perhaps interesting reads, but its in-depth explanation of the mpq file format blizzard entertainment uses in their games. While it is certainly over-the-top for anything personal, the reading to the links I posted below are a wonderful eye opener on how this is done. I REALLY suggest you read the first link if your at all interested, its very informational / interesting if your sort of into it.
Cheers, and Merry Christmas!
http://shadowflare.samods.org/inside_mopaq/
http://wiki.devklog.net/index.php?title ... ive_Format