Save TGA/SGI 32bpp images in SDL?

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.)_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

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.)

If you have gimp (other good gfx packages should also do) you can simply
write the gfx as raw data. Then simply loading it as raw data gimp will
ask you the format of the data.

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:

  1. The header thing being a static array? Ugly. Change that. =p
  2. 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

Check out DevIL, the “developer’s image library”:

http://openil.sourceforge.net/

It supports reading and writing about a dozen image file formats and also
provides lot’s of nice operations that you can perform on them. It used to
be called OpenIL, but the OpenGL people made them change the name.

I’m using it in place of the SDL image reading routines.

-Blake> ----- Original Message -----

From: kisai_z@yahoo.com (Kisai)
To:
Sent: Saturday, April 13, 2002 2:34 AM
Subject: [SDL] Save TGA/SGI 32bpp images in SDL?

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.)


Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl