int
Targa_Write (char *name, int width, int height, int bpp, Uint8 *buf)
{
static Uint8 header[18] = “\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00”;
FILE *f;
header[12] = width & 255;
header[13] = (width >> 8);
header[14] = height & 255;
header[15] = (height >> 8);
header[16] = bpp << 3;
f = fopen (name, "wb");
if (!f)
{
System_Printf ("Targa_Write: failed on %s\n", name);
return 0;
}
System_Printf ("Targa_Write: Saving %s\n", name);
fwrite (header, 1, 18, f);
fwrite (buf, 1, width * height * bpp, f);
fclose (f);
return (1);
}
Two caveats:
- The header thing being a static array? Ugly. Change that. =p
- Passing everything in like this is kinda annoying. The buffer is
assumed to be in the correct format (GL_BGR/GL_BGRA, depending) and
expects the output of glReadPixels - so the buffer is also upside-down.
Fast, cheap, and generally not very useful to end-users IMO. But it’s
better than nothing and users can convert to jpeg just as well as you can
in your code - and easier in fact.
This code is from Project Twilight more or less. I didn’t write it, but
I can say with certainty that you’re free to use it in any program without
worry because nobody is going to mind for a function this simple. =)On Sat, Apr 13, 2002 at 02:34:18AM -0700, Kisai wrote:
I was debugging an SDL app today and I decided to just dump the surfaces
to see what’s wrong. Problem is, that everything uses alpha, so savebmp
is useless to check if the alpha channel is full of garbage.
Would someone happen to know of a lightweight TGA or SGI RGBA file
writing library that I can just pass a block of RGBA pixels (from SDL)
and the dimensions to? I don’t care about compression.
Failing that I’ll have to write something on my own (got half way there
then realized that SGI RGBA format wasn’t packed pixel, each channel is
stored one after the other. TGA on the other hand would need to swap R
and B channels.)
–
Joseph Carter The guy with a rocket launcher
hmm, lunch does sound like a good idea
would taste like a good idea too
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020413/ec39eb37/attachment.pgp