Archived

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

BrentBarrett

Compression of large files

Recommended Posts

I''m using DirectX 9/Direct3D to create a 2D game. I''m using a rather large bitmap for the main town. Because I am using bitmaps and a high color depth for alpha channeling, the size of the bitmap file is up around 100 megabytes. If I keep going at it with bitmaps of this size, then my game will go into the gigabytes range. What''s a commonly used and effective way for compressing and uncompressing large bitmaps without loss of any data like the alpha channel. (I hope I worded that right)

Share this post


Link to post
Share on other sites
What is the purpose of this enormous bitmap? Do you really need its dimensions so large? 100 megabytes sounds like a hell of alot. You could try PNG.

Oh, and unhelpful linky.

Share this post


Link to post
Share on other sites
may I recommend breaking the huge bitmap into tiles? lots of smaller files could be dynamically loaded as the user roams.

btw, if you want to code your own loader, check out the PRF format from:

http://www.muppetlabs.com/~breadbox/software/prf.html

lonesock

Piranha are people too.

Share this post


Link to post
Share on other sites
Yeah. It''s likely that you''ll find a lot of repeated uses of tiles, too. So you could just store one set of all the different tiles, and a big array of tile indices. Then use PNG compression on your tile image (and possibly ZIP on the array, which you''ll probably store as a binary file), and you''re all set.

Share this post


Link to post
Share on other sites
For gosh-darn sakes, change your design! Consider tiles, like others have suggested. Suppose some one actually is willing to download a game with such monster file sizes, what kind of machine are they going to require to load and process graphics that large into memory in real-time? Just converting to PNG isn''t going to solve your problem.

Share this post


Link to post
Share on other sites
yes, big bitmap == death. your town will get bigger and bigger and your bitmap will get bigger and bigger. then your app will die because you have exceeded the memory of your machine. use tiles.

and to answer this question:
quote:

What's a commonly used and effective way for compressing and uncompressing large bitmaps without loss of any data like the alpha channel. (I hope I worded that right)



people don't use huge bitmaps. they use tiles.

TILES!

-me

[edited by - Palidine on March 30, 2004 2:14:31 PM]

Share this post


Link to post
Share on other sites
Hey, thanks for the advice, guys; hang with me though I''ve got just a few more questions. Tiling takes care of the in-game memory, but how much can tiling help for actual game size? I mean, if I split a 100 meg bitmap into a hundred smaller 1 meg tiles, that''s still a 100 meg game. If I''m going to be making several villages like this, then that easily makes the game a gigabyte in size. Now, supposing I converted all of the formats to png, and then even zipped it from there, would the compression cause me to lose color quality? And would I unzip those files all at once at compile time, or one-by-one as I need them during run time?

Share this post


Link to post
Share on other sites
Tiling can help for the total game size if some of the tiles are repeated. As the game designer, you need to enforce that if you want to reuse tiles.

There are things you can do to get away from this model: for example, generate the background (like ground textures) proceduraly from some function, then just overlay the buildings (or whatever) on that. PNG supports transparency, so you're already ahead there.

You'll find that when images are compressed in png (or jpg), then zipping the result is a waste of time and processor power. You might not want to leave them as individual files, but just stitch them together yourself with some kind of index, and don't worry about a zip lib.

PNG is lossless, so you will not end up losing color info, but you also won't get exceptional compression ratios either (maybe reduce by half?). If that is an issue you may want to go to jpg (no transparency) and just eat the quality loss.

Also, I think I remember someone making a patched png encoder that allowed lossy encoding, to reduce the size. This wouldn't affect the decoding (think of the lossy part as a pre-processor), so it's no trouble for your png loading lib. You'll have to google it, though.

lonesock

Piranha are people too.

[edited by - lonesock on March 30, 2004 8:07:38 PM]

Share this post


Link to post
Share on other sites
I''m not sure you understand what the guys mean by tiles..... they don''t mean break the bitmap up into 100 or 1000 smaller squares (that would require dynamic loading and scrolling code.....)

Tiles are something like what Mario used on the NES (everyone must remember Mario on the NES).... there were certain textures for walls, pipes and trees and so on... what YOU have to do when using the tiles, is have a sort of script or area in your code that details exactly what tiles get placed and where they are placed.
Also the tiles are normally quite small, so for example a wall tile could be 32x32 pixels, and what you would do is have that tile repeat itself for however much wall you needed.....

Hope this helps........ anyone got any other way to explain tiles ?

Share this post


Link to post
Share on other sites
Most engines develop perhaps 10 kinds of grass tiles, 10 kinds of rock tiles, 10 kinds of path tiles, ... each of which is maybe 64x64 pixels or so. Then, in the editor, you place tiles, and then other objects, to make for the game world.

By re-using tiles, you cut your "100 meg" game down to a "1 meg" game.

If you think that tiling like this will make the world horribly repeatable, then look at Warcraft III: it uses a few tiles, re-used a lot! Actually, looking at the Warcraft III editor is a really good idea for most people making games tools. You could do much worse.

Share this post


Link to post
Share on other sites
Yeah. Give the critical eyeball to Warcraft III, and to Starcraft too. Turn on the tile grid in the editor. Starcraft isn''t isometric; it''s a lot of very small, very cleverly designed square tiles.

Share this post


Link to post
Share on other sites
Just out of curiosity how did Baldur''s Gate I/II and all the games based on that engine handle this. Presumably every area is its own bitmap. Did they just use a huge bitmap broken into 256x256 (or some other power of 2) tiles?

If I where doing a design like this I would break my huge bitmap up into 256x256 chunks and then load them as I go. Presumming that your character does not move terribly quick you could then load the tiles on the fly as your position in the world changes similar to how GTA streams in the world as you go.

Also as a side note I''d recommend looking into texture compression so you maximize the number of tiles you can hold in video memory at one time.

Dan

Share this post


Link to post
Share on other sites
Ha, ya, I undertand tiling. Sorry, I know the details in my head, just not communicating them very well. The village won''t really be "tile-able". Think of a village from Saga Frontier 2. The village we''re making is hand drawn and a little more detailed. It''s the only village in the game, so we feel the extra attention is fine. Going back to the Saga Frontier 2 example, there just isn''t a lot of tiles that could be re-used. Basically, I''m just breaking the village up to reduce the amount that has to be loaded and held in memory. So it''ll pretty much be a 100 unique tiles that make one unique village. Well, from your replies it seems like my files may not end up being as big as I think they will. Thanks again for all of your help.

Share this post


Link to post
Share on other sites
PNG? why does everyone always recommend PNG? use DDS files.
nVidia recommends them over all others, b/c they are compressed directly on the video card. saves a huge amount of bandwidth. you can get a photoshop plugin from the nvidia developer website.

and yeah, definatly break up your map into a tileset.

Share this post


Link to post
Share on other sites
If you use DDS files, isn''t your app limited to only running on machines with recent nVidia video cards and drivers?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can download dds files directly to modern hardware (ati as well), but you have to write a decoder for older hardware (then again, you have to write a png reader anyways if you use png). You can use www.imagelib.org for your dds decoding (but wait until 1.6.7 is out, this WE) as well.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can also use the open source ZLIB (same as .zip compression) package.. which comes with ready-made DLL''s.

Breaking it up into tiles is still a good idea, even if none are repeated. Compression will be better.

Share this post


Link to post
Share on other sites
If you really plan on just displaying every single bit of that town as a unique file, then I don''t know what point there is to using png. Png is good for things like a loaf of bread or a gold coin, something that needs to use a color key. This town obviously won''t so I would suggest jpeg. To do a test I took a 500kb bmp file and exported a 85% compresion jpg and it came out 11kb. Now I realize that comepresion rates vary based on percentages, but if I''m not mistaken this is a much better solution than png. I think just about any picture you have should compress to at least 50% with no noticable quality loss.

Share this post


Link to post
Share on other sites