From db2869d7e0ff15a1050c7b8c4b1a8d41b35fd7c8 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 24 Mar 2018 19:40:51 -0700 Subject: Added png screenshot support --- render_sdl.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'render_sdl.c') diff --git a/render_sdl.c b/render_sdl.c index 39ed3e8..c761136 100755 --- a/render_sdl.c +++ b/render_sdl.c @@ -13,6 +13,7 @@ #include "io.h" #include "util.h" #include "ppm.h" +#include "png.h" #ifndef DISABLE_OPENGL #include @@ -597,9 +598,13 @@ void render_framebuffer_updated(uint8_t which, int width) : 240; FILE *screenshot_file = NULL; uint32_t shot_height, shot_width; + char *ext; if (screenshot_path && which == FRAMEBUFFER_ODD) { screenshot_file = fopen(screenshot_path, "wb"); if (screenshot_file) { +#ifndef DISABLE_ZLIB + ext = path_extension(screenshot_path); +#endif info_message("Saving screenshot to %s\n", screenshot_path); } else { warning("Failed to open screenshot file %s for writing\n", screenshot_path); @@ -643,7 +648,17 @@ void render_framebuffer_updated(uint8_t which, int width) if (screenshot_file) { //properly supporting interlaced modes here is non-trivial, so only save the odd field for now - save_ppm(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); +#ifndef DISABLE_ZLIB + if (!strcasecmp(ext, "png")) { + free(ext); + save_png(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); + } else { + free(ext); +#endif + save_ppm(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); +#ifndef DISABLE_ZLIB + } +#endif } } else { #endif @@ -670,7 +685,17 @@ void render_framebuffer_updated(uint8_t which, int width) } else { shot_pitch *= 2; } - save_ppm(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); +#ifndef DISABLE_ZLIB + if (!strcasecmp(ext, "png")) { + free(ext); + save_png(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); + } else { + free(ext); +#endif + save_ppm(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); +#ifndef DISABLE_ZLIB + } +#endif } SDL_UnlockTexture(sdl_textures[which]); SDL_Rect src_clip = { -- cgit v1.2.3