Best library to use for saving screenshots of SDL programs

I’m looking for a library that will allow me to save an SDL surface as a
snapshot. Formats would include PNG, GIF, and PCX.

Right now I’m using Imlib and its not totally appropriate. Specifically,
it requires that you pass it an XWindow, which is only defined if SDL is
run under X11.

I’d like some library (or function) that, when given an SDL_Surface,
filename and picture type, will save that picture. It cannot depend on
X, since the program must work on platforms that run SDL but not
necessarily X.

Thanks for any info,
Steve

I’m looking for a library that will allow me to save an SDL surface as a
snapshot. Formats would include PNG, GIF, and PCX.

Right now I’m using Imlib and its not totally appropriate. Specifically,
it requires that you pass it an XWindow, which is only defined if SDL is
run under X11.

I’d like some library (or function) that, when given an SDL_Surface,
filename and picture type, will save that picture. It cannot depend on
X, since the program must work on platforms that run SDL but not
necessarily X.

How about SDL_image? You should be able to directly save the screen
surface to a file in the format of your choice, and that on any platform
SDL runs on.

Alex.–
http://www.gnurou.org

I looked at the description on the SDL page for this, and it seems that
its concerned with loading images from files to a surface, not the other
way around.

I will check out the API further to see if this is possible.

Thanks,
SteveOn February 3, 2002 06:56 am, you wrote:

I’m looking for a library that will allow me to save an SDL surface
as a snapshot. Formats would include PNG, GIF, and PCX.

Right now I’m using Imlib and its not totally appropriate.
Specifically, it requires that you pass it an XWindow, which is only
defined if SDL is run under X11.

I’d like some library (or function) that, when given an SDL_Surface,
filename and picture type, will save that picture. It cannot depend
on X, since the program must work on platforms that run SDL but not
necessarily X.

How about SDL_image? You should be able to directly save the screen
surface to a file in the format of your choice, and that on any
platform SDL runs on.

Alex.

SDL can save images in BMP format. A TGA saver can be found at
ftp://ptah.lnf.kth.se/pub/misc/savetga.c

Since conversion programs are common enough, it’s rarely useful to
spend effort on more than one format for screenshots

Thanks for the info. Unfortunately, the program has a specification that
it must save images in png format. I can drop support for everything
else, but it must at least save in png.

I guess I will do what you have done, and write a saver for png myself.

Thanks,
SteveOn February 3, 2002 11:02 am, you wrote:

SDL can save images in BMP format. A TGA saver can be found at
ftp://ptah.lnf.kth.se/pub/misc/savetga.c

Since conversion programs are common enough, it’s rarely useful to
spend effort on more than one format for screenshots

SAVE_PNG : my function

int Img_Save_Png( char name, unsigned char buffer,
int tx, int ty, int type_img,
int nb_col, RGB *palette )
{
FILE *file=fopen(name,“wb”);
png_structp write_png;
png_infop info_ptr;
unsigned char **row_pointers=NULL; // a modifier pour etre en
// conformite avec libpng
int i=0;

if (!file)
return 0;

write_png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);

info_ptr = png_create_info_struct(write_png);

png_init_io(write_png, file);

info_ptr->width=tx;
info_ptr->height=ty;
info_ptr->rowbytes=tx;
info_ptr->bit_depth=8;
info_ptr->interlace_type=0;

info_ptr->num_palette=0;
info_ptr->palette=NULL;
info_ptr->valid=0;

switch( type_img )
{
 case i_RGB:
  info_ptr->rowbytes *= 3;
  info_ptr->sig_bit.red=8;
  info_ptr->sig_bit.green=8;
  info_ptr->sig_bit.blue=8;
  info_ptr->color_type=PNG_COLOR_TYPE_RGB;
  break;
 case i_GRAY:

info_ptr->sig_bit.gray=8;
info_ptr->color_type=PNG_COLOR_TYPE_GRAY;
break;
case i_PALETTE:
info_ptr->valid=PNG_INFO_PLTE;
info_ptr->num_palette=nb_col;
info_ptr->color_type=PNG_COLOR_TYPE_PALETTE;
info_ptr->palette=(png_color*) malloc(nb_col*sizeof(png_color));
for(i=0; i<nb_col; i++ )
{
info_ptr->palette[i].red=palette[i].r;
info_ptr->palette[i].green=palette[i].v;
info_ptr->palette[i].blue=palette[i].b;
}
break;
}

png_write_info(write_png, info_ptr);

/*
calcul de row_pointers
/
row_pointers=(unsigned char
*) malloc( info_ptr->heightsizeof(unsigned
char
) );
row_pointers[0]=buffer;

for(i=1; i<info_ptr->height; i++ )
{
// this line must be changed to use SDL_Surface
row_pointers[i] = row_pointers[i-1] + info_ptr->rowbytes;
}
png_write_image(write_png, row_pointers);

png_write_end(write_png, info_ptr);

if ( info_ptr ) free( info_ptr->palette );
free( row_pointers );
png_destroy_write_struct(&write_png, &info_ptr);

return 1;

}----------------
Gloire ? mon saigneur Arioch
Murlock (http://www.murlock.org)

----- Original Message -----
From: stephena@roadrunner.nf.net (Stephen Anthony)
To:
Sent: Sunday, February 03, 2002 3:42 PM
Subject: Re: [SDL] Best library to use for saving screenshots of SDL
programs…

On February 3, 2002 11:02 am, you wrote:

SDL can save images in BMP format. A TGA saver can be found at
ftp://ptah.lnf.kth.se/pub/misc/savetga.c

Since conversion programs are common enough, it’s rarely useful to
spend effort on more than one format for screenshots

Thanks for the info. Unfortunately, the program has a specification that
it must save images in png format. I can drop support for everything
else, but it must at least save in png.

I guess I will do what you have done, and write a saver for png myself.

Thanks,
Steve


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

SAVE_PNG : my function

And what good is that without the definition of png_structp, png_infop,
png_create_write_struct, png_create_info_struct, png_init_io, etc?–
Kylotan

SAVE_PNG : my function

And what good is that without the definition of png_structp, png_infop,
png_create_write_struct, png_create_info_struct, png_init_io, etc?

I think those are form libpng, required by SDL_imageOn Sun, 3 Feb 2002 15:43:08 -0000 “Kylotan” wrote:


Sebastian Garcia <@Seba>
Usuario Linux registrado #225450
Debian GNU/Linux ‘Sid’ kernel 2.4.17 sobre AMD K6 II

I think those are form libpng, required by SDL_image

yes

----- Original Message -----
From: s_garcia@speedy.com.ar (Seba)
On Sun, 3 Feb 2002 15:43:08 -0000 “Kylotan” wrote:

Kylotan wrote:

SAVE_PNG : my function

And what good is that without the definition of png_structp, png_infop,
png_create_write_struct, png_create_info_struct, png_init_io, etc?


Kylotan

uh, #include <png.h> helps…–
-==-
Jon Atkins
http://jcatki.2y.net/

programs…

Kylotan wrote:

SAVE_PNG : my function

And what good is that without the definition of png_structp,
png_infop,

png_create_write_struct, png_create_info_struct, png_init_io, etc?


Kylotan

uh, #include <png.h> helps…

So does pointing out which library you’re using when the question was
asking for a library. <png.h> is not a standard header.From: jcatki@jcatki.2y.net (Jonathan Atkins)
To:
Sent: Sunday, February 03, 2002 4:57 PM
Subject: Re: [SDL] Best library to use for saving screenshots of SDL


Kylotan

That’s true, except for a single consideration - gamers prefer the game to
save screenshots in jpg format so they don’t have to convert anything.
It’s certainly convenient to do so, of course. OTOH, many developers will
ask for non-lossy screenshots when it comes to bugs and the like. Targa
is the obvious choice for OpenGL, and BMP is pretty obvious in win32, but
PNG is generally compressed much better than both, pretty much supported
everywhere nowadays, and helping it become more standard is a worthwhile
cause anyway. =) So that’s two formats. I will agree that it’s not
worth supporting every format you can load though.On Sun, Feb 03, 2002 at 03:32:48PM +0100, Mattias Engdegard wrote:

SDL can save images in BMP format. A TGA saver can be found at
ftp://ptah.lnf.kth.se/pub/misc/savetga.c

Since conversion programs are common enough, it’s rarely useful to
spend effort on more than one format for screenshots


Joseph Carter Have chainsaw will travel

“Hey, I’m from this project called Debian… have you heard of it?
Your name seems to be on a bunch of our stuff.”

-------------- 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/20020203/a8fff661/attachment.pgp

“Murlock” wrote:

SAVE_PNG : my function

this won’t work without some pixel format fixup. look at my tga saver for
how this can be done

“Murlock” wrote:

SAVE_PNG : my function

this won’t work without some pixel format fixup. look at my tga saver for
how this can be done

Ok, I’ll fix my ‘old’ function to work with SDL today or tomorrow

MurlockFrom: f91-men@nada.kth.se (Mattias Engdegard)


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

Stephen Anthony writes:

I’m looking for a library that will allow me to save an SDL surface as a
snapshot. Formats would include PNG, GIF, and PCX.

I just noticed that the “mrtg” manual section makes reference to
generating PNG images using the GD library by Thomas Boutell. Maybe
that’ll help you.

Derrell

Thanks for all the help. I think I will go with the option of writing
the necessary code myself.

I can’t remember the names, but one person pointed out some code to me
that saves an SDL surface to a TGA file, and another person posted some
code that writes PNG’s. Now all I have to do is combine them :slight_smile:

I think it will be better that way, since there will be no external
libraries required then.

Thanks,
Steve

Please post any results! :slight_smile: I’d be interested in testing and using it.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Monday 04 February 2002 15:53, Stephen Anthony wrote:

Thanks for all the help. I think I will go with the option of writing
the necessary code myself.

I can’t remember the names, but one person pointed out some code to me
that saves an SDL surface to a TGA file, and another person posted some
code that writes PNG’s. Now all I have to do is combine them :slight_smile:

I think it will be better that way, since there will be no external
libraries required then.