PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

TGAs

Hello,
a friend of mine would like to know how to use (decompress or whatever) TGAs in his game, as he now uses bitmaps which make the game pretty large and slow. Any suggestions? Fredrik? Carpe? I know you're using TGAs in Argentum...
Thanks,
Shape
Shape,

Check out my tutorials at http://pizza.hvu.nl/~kouwenhs . One of them contains a simple tga loader. TGA's are very simple, as long as you don't save them as compressed tga's. Basically they consist of a 18 byte header (or so) plus the raw image data. I love them for their simplicity. :)

- Jacco.
Thanks a lot, Jacco!
Uhm, what about compressed ones?
Um... if he has a problem with size how is an uncompressed TGA going to help him any?

Why doesn't he store them in a compressed format like jpeg, png, or gif and use the image loading library (imgdecmp.dll)?  Here's an article that describes how to use it.
He's the author of "Dove Hunt" and gifs/jpegs/pngs would look shitty. Maybe, MAYBE pngs, but I dunno...
He should choose whatever image format is most condicive to his existing code, and use gzip to compress them.

Dan East
Ehm yes. Didn't notice that he wanted small files. And yes, zlib is ideal for this. It saves you the hassle of working with a gif compressor, an audio compressor and so on and does all of that on the data type that you like. I even got zlib to load mod files. Or rather, MikMod can load a mod file using zlib. :) Very nifty.
Frank W. Zammetti · 02 Aug 2001, 00:50 UTC
Two questions:

(1) Whar is zlib (I can guess, but I'd still like to be told!) and where can I get it?

(2) Does it work with data stored in memory?  I prefer to develop all my software as stand-alone EXE's butI haven't been able to figure out how to store compressed binary data (read: GIFs or JPGs) and decompress them (short of writing my own algorithms which I'm sure I could manage, but ICK!)

Thanks guys!
Thanks a bunch!!!
-Shape
zlib (gZip) is a non-patented, open source, extremely high performance compression algorithm. It is the primary algorithm used by zip. You can get the source at http://www.gzip.org. zlib is designed to be used similarly to the ANSI-C file functions (fopen, fread, fwrite, etc). It could be adapted to work with memory buffers instead, but it would probably take a pretty good amount of work.
Do you mean that you embed all data directly into your EXE so you won't have to load it? File I/O is really very easy. I'll show you how to decompress a .gz gzipped file into a buffer right now:
[fixed]
#include "zlib.h"

gzFile pgzin=gzopen( "MyGzippedFile.gz", "rb" );
if ( !pgzin )
 return 0;        //failed to open

char buf[100000]; //This buf needs to be large enough
                  //to hold the uncompressed data.
int bytesread=gzread(pgzin, buf, sizeof(buf));
gzclose(pgzin);
[/fixed]

Dan East


Depending on the type of images, TGA may be an easy route.  The compressed TGA's use a simple run-length scheme which can be coded in about 20 lines of C code.

I don't like to depend on unsupported libraries from Microsoft - especially slow and cumbersome ones.

L.B.
Frank W. Zammetti · 07 Aug 2001, 12:26 UTC
I'll have to go play with that a bit.  Yes Dan, I prefer to embed everything into one monolithic EXE, but only because I think that's cleaner in terms of installation and removal.  Wouldn't be much of a hassle to write my own poor-performing compression algo using standard file I/O, but I'd rather have it all in one place.

I certainly know about flexibility, and that approach ain't it, but in my mind (a scary place indeed!) I'd rather sacrifice that flexibility than having to worry about multiple files, possibly in multiple locations.  I've dealt with DLL Hell, like everyone else, far more than I'd ever like, and even though that's not really what we're talking about, anything even remotely like it I disdain.  

However, I may have to re-think that stance seeing as the apparent simplicity and performance of zlib probably makes it a moot point.  Thanks for the insight, I appreciate it!