Mercurial > repos > blastem
comparison render_sdl.c @ 1532:b505083dcd87
Added png screenshot support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 24 Mar 2018 19:40:51 -0700 |
parents | 8a3d3bb2cd08 |
children | c59adc305e46 |
comparison
equal
deleted
inserted
replaced
1531:092675db4f37 | 1532:b505083dcd87 |
---|---|
11 #include "blastem.h" | 11 #include "blastem.h" |
12 #include "genesis.h" | 12 #include "genesis.h" |
13 #include "io.h" | 13 #include "io.h" |
14 #include "util.h" | 14 #include "util.h" |
15 #include "ppm.h" | 15 #include "ppm.h" |
16 #include "png.h" | |
16 | 17 |
17 #ifndef DISABLE_OPENGL | 18 #ifndef DISABLE_OPENGL |
18 #include <GL/glew.h> | 19 #include <GL/glew.h> |
19 #endif | 20 #endif |
20 | 21 |
595 uint32_t height = which <= FRAMEBUFFER_EVEN | 596 uint32_t height = which <= FRAMEBUFFER_EVEN |
596 ? (video_standard == VID_NTSC ? 243 : 294) - (overscan_top[video_standard] + overscan_bot[video_standard]) | 597 ? (video_standard == VID_NTSC ? 243 : 294) - (overscan_top[video_standard] + overscan_bot[video_standard]) |
597 : 240; | 598 : 240; |
598 FILE *screenshot_file = NULL; | 599 FILE *screenshot_file = NULL; |
599 uint32_t shot_height, shot_width; | 600 uint32_t shot_height, shot_width; |
601 char *ext; | |
600 if (screenshot_path && which == FRAMEBUFFER_ODD) { | 602 if (screenshot_path && which == FRAMEBUFFER_ODD) { |
601 screenshot_file = fopen(screenshot_path, "wb"); | 603 screenshot_file = fopen(screenshot_path, "wb"); |
602 if (screenshot_file) { | 604 if (screenshot_file) { |
605 #ifndef DISABLE_ZLIB | |
606 ext = path_extension(screenshot_path); | |
607 #endif | |
603 info_message("Saving screenshot to %s\n", screenshot_path); | 608 info_message("Saving screenshot to %s\n", screenshot_path); |
604 } else { | 609 } else { |
605 warning("Failed to open screenshot file %s for writing\n", screenshot_path); | 610 warning("Failed to open screenshot file %s for writing\n", screenshot_path); |
606 } | 611 } |
607 free(screenshot_path); | 612 free(screenshot_path); |
641 | 646 |
642 SDL_GL_SwapWindow(main_window); | 647 SDL_GL_SwapWindow(main_window); |
643 | 648 |
644 if (screenshot_file) { | 649 if (screenshot_file) { |
645 //properly supporting interlaced modes here is non-trivial, so only save the odd field for now | 650 //properly supporting interlaced modes here is non-trivial, so only save the odd field for now |
646 save_ppm(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); | 651 #ifndef DISABLE_ZLIB |
652 if (!strcasecmp(ext, "png")) { | |
653 free(ext); | |
654 save_png(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); | |
655 } else { | |
656 free(ext); | |
657 #endif | |
658 save_ppm(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); | |
659 #ifndef DISABLE_ZLIB | |
660 } | |
661 #endif | |
647 } | 662 } |
648 } else { | 663 } else { |
649 #endif | 664 #endif |
650 if (which <= FRAMEBUFFER_EVEN && last != which) { | 665 if (which <= FRAMEBUFFER_EVEN && last != which) { |
651 uint8_t *cur_dst = (uint8_t *)locked_pixels; | 666 uint8_t *cur_dst = (uint8_t *)locked_pixels; |
668 if (which == FRAMEBUFFER_EVEN) { | 683 if (which == FRAMEBUFFER_EVEN) { |
669 shot_height *= 2; | 684 shot_height *= 2; |
670 } else { | 685 } else { |
671 shot_pitch *= 2; | 686 shot_pitch *= 2; |
672 } | 687 } |
673 save_ppm(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); | 688 #ifndef DISABLE_ZLIB |
689 if (!strcasecmp(ext, "png")) { | |
690 free(ext); | |
691 save_png(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); | |
692 } else { | |
693 free(ext); | |
694 #endif | |
695 save_ppm(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); | |
696 #ifndef DISABLE_ZLIB | |
697 } | |
698 #endif | |
674 } | 699 } |
675 SDL_UnlockTexture(sdl_textures[which]); | 700 SDL_UnlockTexture(sdl_textures[which]); |
676 SDL_Rect src_clip = { | 701 SDL_Rect src_clip = { |
677 .x = overscan_left[video_standard], | 702 .x = overscan_left[video_standard], |
678 .y = overscan_top[video_standard], | 703 .y = overscan_top[video_standard], |