diff options
Diffstat (limited to 'src/v_video.c')
-rw-r--r-- | src/v_video.c | 112 |
1 files changed, 111 insertions, 1 deletions
diff --git a/src/v_video.c b/src/v_video.c index 0cf64926..330e0d51 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -44,6 +44,11 @@ #include "w_wad.h" #include "z_zone.h" +#include "config.h" +#ifdef HAVE_LIBPNG +#include <png.h> +#endif + // TODO: There are separate RANGECHECK defines for different games, but this // is common code. Fix this. #define RANGECHECK @@ -706,6 +711,87 @@ void WritePCXfile(char *filename, byte *data, Z_Free (pcx); } +#ifdef HAVE_LIBPNG +// +// WritePNGfile +// + +static void error_fn(png_structp p, png_const_charp s) +{ + printf("libpng error: %s\n", s); +} + +static void warning_fn(png_structp p, png_const_charp s) +{ + printf("libpng warning: %s\n", s); +} + +void WritePNGfile(char *filename, byte *data, + int width, int height, + byte *palette) +{ + png_structp ppng; + png_infop pinfo; + png_colorp pcolor; + FILE *handle; + int i; + + handle = fopen(filename, "wb"); + if (!handle) + { + return; + } + + ppng = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, + error_fn, warning_fn); + if (!ppng) + { + return; + } + + pinfo = png_create_info_struct(ppng); + if (!pinfo) + { + png_destroy_write_struct(&ppng, NULL); + return; + } + + png_init_io(ppng, handle); + + png_set_IHDR(ppng, pinfo, width, height, + 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + pcolor = malloc(sizeof(*pcolor) * 256); + if (!pcolor) + { + png_destroy_write_struct(&ppng, &pinfo); + return; + } + + for (i = 0; i < 256; i++) + { + pcolor[i].red = *(palette + 3 * i); + pcolor[i].green = *(palette + 3 * i + 1); + pcolor[i].blue = *(palette + 3 * i + 2); + } + + png_set_PLTE(ppng, pinfo, pcolor, 256); + free(pcolor); + + png_write_info(ppng, pinfo); + + for (i = 0; i < SCREENHEIGHT; i++) + { + png_write_row(ppng, data + i*SCREENWIDTH); + } + + png_write_end(ppng, pinfo); + png_destroy_write_struct(&ppng, &pinfo); + fclose(handle); +} +#endif + // // V_ScreenShot // @@ -714,12 +800,25 @@ void V_ScreenShot(char *format) { int i; char lbmname[16]; // haleyjd 20110213: BUG FIX - 12 is too small! + char *ext; + extern int png_screenshots; // find a file name to save it to +#ifdef HAVE_LIBPNG + if (png_screenshots) + { + ext = "png"; + } + else +#endif + { + ext = "pcx"; + } + for (i=0; i<=99; i++) { - sprintf(lbmname, format, i); + sprintf(lbmname, format, i, ext); if (!M_FileExists(lbmname)) { @@ -732,10 +831,21 @@ void V_ScreenShot(char *format) I_Error ("V_ScreenShot: Couldn't create a PCX"); } +#ifdef HAVE_LIBPNG + if (png_screenshots) + { + WritePNGfile(lbmname, I_VideoBuffer, + SCREENWIDTH, SCREENHEIGHT, + W_CacheLumpName (DEH_String("PLAYPAL"), PU_CACHE)); + } + else +#endif + { // save the pcx file WritePCXfile(lbmname, I_VideoBuffer, SCREENWIDTH, SCREENHEIGHT, W_CacheLumpName (DEH_String("PLAYPAL"), PU_CACHE)); + } } #define MOUSE_SPEED_BOX_WIDTH 120 |