From bbdd7a3f8319ae48a253e764736e524af8c6a5dd Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 19 Dec 2007 20:09:27 +0000 Subject: [PATCH] Now screen shots are generated directly in PNG format. --- ChangeLog | 5 ++++ src/commands/cmd_screen_shot.c | 48 +++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index acbd445e1..a516c22c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-12-16 David A. Capello + + * src/commands/cmd_screen_shot.c (cmd_screen_shot_execute): Now + saves screen shots in PNG format. + 2007-12-13 David A. Capello * src/dialogs/scrsaver.c: Removed. diff --git a/src/commands/cmd_screen_shot.c b/src/commands/cmd_screen_shot.c index f2a6ad878..3446c5c61 100644 --- a/src/commands/cmd_screen_shot.c +++ b/src/commands/cmd_screen_shot.c @@ -26,6 +26,9 @@ #include "commands/commands.h" #include "core/core.h" +#include "file/file.h" +#include "raster/raster.h" +#include "util/misc.h" #endif @@ -35,7 +38,6 @@ static void cmd_screen_shot_execute(const char *argument) char buf[512]; PALETTE pal; BITMAP *bmp; - int c; /* save the active flag which indicate if the mouse is freeze or not */ old_flag = freeze_mouse_flag; @@ -48,7 +50,7 @@ static void cmd_screen_shot_execute(const char *argument) /* get a file name for the capture */ for (c=0; c<10000; c++) { - usprintf(buf, "shot%04d.%s", c, "pcx"); + usprintf(buf, "shot%04d.%s", c, "png"); if (!exists(buf)) break; } @@ -58,7 +60,47 @@ static void cmd_screen_shot_execute(const char *argument) /* save in a bitmap the visible screen portion */ bmp = create_sub_bitmap(ji_screen, 0, 0, JI_SCREEN_W, JI_SCREEN_H); - save_bitmap(buf, bmp, pal); + + /* creates a sprite with one layer, one image to save the bitmap as a PNG */ + { + int imgtype = bitmap_color_depth(bmp) == 8 ? IMAGE_INDEXED: IMAGE_RGB; + Sprite *sprite = sprite_new_with_layer(imgtype, bmp->w, bmp->h); + Image *image = GetImage2(sprite, NULL, NULL, NULL); + int x, y, r, g, b; + + memcpy(sprite_get_palette(sprite, 0), pal, sizeof(PALETTE)); + + /* convert Allegro "BITMAP" to ASE "Image" */ + if (imgtype == IMAGE_RGB) { + ase_uint32 *address = (ase_uint32 *)image->dat; + for (y=0; yh; ++y) { + for (x=0; xw; ++x) { + c = getpixel(bmp, x, y); + r = getr(c); + g = getg(c); + b = getb(c); + *(address++) = _rgba(r, g, b, 255); + } + } + } + else if (imgtype == IMAGE_INDEXED) { + ase_uint8 *address = (ase_uint8 *)image->dat; + for (y=0; yh; ++y) { + for (x=0; xw; ++x) { + *(address++) = getpixel(bmp, x, y); + } + } + } + + /* save the sprite */ + sprite_set_filename(sprite, buf); + sprite_save(sprite); + + /* destroy the sprite */ + sprite_free(sprite); + } + + /* destroy the bitmap */ destroy_bitmap(bmp); /* restore the freeze flag by the previous value */