diff --git a/Source/Makefile.am b/Source/Makefile.am index 4f48b0ab..84710d2f 100644 --- a/Source/Makefile.am +++ b/Source/Makefile.am @@ -26,6 +26,7 @@ winmbf_SOURCES = \ hu_stuff.c hu_stuff.h \ i_main.c \ i_net.c i_net.h \ + i_savepng.c i_savepng.h \ i_sound.c i_sound.h \ i_system.c i_system.h \ i_video.c i_video.h \ @@ -80,5 +81,5 @@ winmbf_SOURCES = \ w_wad.c w_wad.h \ wi_stuff.c wi_stuff.h \ z_zone.c z_zone.h -winmbf_CFLAGS = @SDL_CFLAGS@ @SDL_image_CFLAGS@ @SDL_mixer_CFLAGS@ @SDL_net_CFLAGS@ -winmbf_LDADD = @SDL_LIBS@ @SDL_image_LIBS@ @SDL_mixer_LIBS@ @SDL_net_LIBS@ +winmbf_CFLAGS = @SDL_CFLAGS@ @SDL_mixer_CFLAGS@ @SDL_net_CFLAGS@ +winmbf_LDADD = @SDL_LIBS@ @SDL_mixer_LIBS@ @SDL_net_LIBS@ diff --git a/Source/d_main.c b/Source/d_main.c index 334b6d67..ddf79a8f 100644 --- a/Source/d_main.c +++ b/Source/d_main.c @@ -31,13 +31,12 @@ #include "d_io.h" // haleyjd #include "SDL_filesystem.h" // [FG] SDL_GetPrefPath() +#include "SDL_stdinc.h" // [FG] SDL_qsort() #include #include #include -#include "SDL_stdinc.h" // [FG] SDL_qsort() - #include "doomdef.h" #include "doomstat.h" #include "dstrings.h" @@ -52,6 +51,7 @@ #include "m_misc.h" #include "m_misc2.h" // [FG] M_StringDuplicate() #include "m_menu.h" +#include "i_savepng.h" // [FG] SavePNG #include "i_system.h" #include "i_sound.h" #include "i_video.h" @@ -1372,6 +1372,9 @@ void D_DoomMain(void) int p, slot; char file[PATH_MAX+1]; // killough 3/22/98 + // [FG] save screenshots in PNG format + I_InitSavePNG(); + setbuf(stdout,NULL); #if defined(_WIN32) diff --git a/Source/i_savepng.c b/Source/i_savepng.c new file mode 100644 index 00000000..dc112b76 --- /dev/null +++ b/Source/i_savepng.c @@ -0,0 +1,84 @@ +// +// Copyright(C) 2020 Fabian Greffrath +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// DESCRIPTION: +// Dynamically load SDL2_Image for PNG screenshots. +// + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_DLOPEN +#include +#elif _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#endif + +#include "doomtype.h" +#include "i_savepng.h" + +savepng_t SavePNG = NULL; + +static const char *sdl2_image_libs[] = { +#ifdef HAVE_DLOPEN + "libSDL2_image-2.0.so.0", + "libSDL2_image-2.0.so", + "libSDL2_image.so", +#elif _WIN32 + "SDL2_image.dll", +#endif +}; + +void I_InitSavePNG (void) +{ + int i; + +#ifdef HAVE_DLOPEN + void *sdl2_image_lib = NULL; + void *savepng_func = NULL; +#elif _WIN32 + HMODULE sdl2_image_lib = NULL; + FARPROC savepng_func = NULL; +#endif + + for (i = 0; i < arrlen(sdl2_image_libs); i++) + { +#ifdef HAVE_DLOPEN + sdl2_image_lib = dlopen(sdl2_image_libs[i], RTLD_LAZY); +#elif _WIN32 + sdl2_image_lib = LoadLibrary(TEXT(sdl2_image_libs[i])); +#endif + if (sdl2_image_lib != NULL) + { + break; + } + } + + if (sdl2_image_lib != NULL) + { +#ifdef HAVE_DLOPEN + savepng_func = dlsym(sdl2_image_lib, "IMG_SavePNG"); +#elif _WIN32 + savepng_func = GetProcAddress(sdl2_image_lib, "IMG_SavePNG"); +#endif + } + + SavePNG = (savepng_t) savepng_func; +} diff --git a/Source/i_savepng.h b/Source/i_savepng.h new file mode 100644 index 00000000..16bbcda9 --- /dev/null +++ b/Source/i_savepng.h @@ -0,0 +1,32 @@ +// +// Copyright(C) 2020 Fabian Greffrath +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// DESCRIPTION: +// Dynamically load SDL2_Image for PNG screenshots. +// + +#ifndef __I_SAVEPNG__ +#define __I_SAVEPNG__ + +typedef int (*savepng_t)(void *, const char *); + +extern savepng_t SavePNG; + +extern void I_InitSavePNG (void); + +#endif diff --git a/Source/i_video.c b/Source/i_video.c index 84b1bd3a..bff52c44 100644 --- a/Source/i_video.c +++ b/Source/i_video.c @@ -28,11 +28,6 @@ #include "SDL.h" // haleyjd -#include "config.h" -#ifdef HAVE_SDL_IMAGE -#include "SDL_image.h" -#endif - #include "z_zone.h" /* memory allocation wrappers -- killough */ #include "doomstat.h" #include "v_video.h" @@ -46,6 +41,7 @@ #include "m_menu.h" #include "wi_stuff.h" #include "i_video.h" +#include "i_savepng.h" // [FG] SavePNG() SDL_Surface *sdlscreen; @@ -840,13 +836,13 @@ void I_ShutdownGraphics(void) } } +// [FG] save screenshots in PNG format boolean I_WritePNGfile(char *filename) { -#ifdef HAVE_SDL_IMAGE - return IMG_SavePNG(sdlscreen, filename) == 0; -#else - return false; -#endif + if (SavePNG) + return SavePNG(sdlscreen, filename) == 0; + else + return false; } extern boolean setsizeneeded; diff --git a/Source/m_menu.c b/Source/m_menu.c index c0374d2e..119b0697 100644 --- a/Source/m_menu.c +++ b/Source/m_menu.c @@ -49,6 +49,8 @@ #include "m_menu.h" #include "d_deh.h" #include "m_misc.h" +#include "m_misc2.h" // [FG] M_StringDuplicate() +#include "i_savepng.h" // [FG] SavePNG() extern patch_t* hu_font[HU_FONTSIZE]; extern boolean message_dontfuckwithme; @@ -2995,11 +2997,7 @@ setup_menu_t gen_settings1[] = { // General Settings screen1 {"Translucency filter percentage", S_NUM, m_null, G_X, G_Y + general_transpct*8, {"tran_filter_pct"}, 0, 0, M_Trans}, -#ifdef HAVE_SDL_IMAGE - {"PCX instead of PNG for screenshots", S_YESNO, m_null, G_X, -#else {"PCX instead of BMP for screenshots", S_YESNO, m_null, G_X, -#endif G_Y + general_pcx*8, {"screenshot_pcx"}}, {"Flash Icon During Disk IO", S_YESNO, m_null, G_X, @@ -5621,6 +5619,16 @@ void M_Init(void) { strcpy(OptionsMenu[scrnsize].name, "M_DISP"); } + + // [FG] save screenshots in PNG format + if (SavePNG) + { + const char *bmp_text, *png_text; + + bmp_text = gen_settings1[general_pcx+1].m_text; + png_text = M_StringReplace(bmp_text, "BMP", "PNG"); + gen_settings1[general_pcx+1].m_text = png_text; + } } // killough 10/98: allow runtime changing of menu order diff --git a/Source/m_misc.c b/Source/m_misc.c index d26c23dd..cda991c0 100644 --- a/Source/m_misc.c +++ b/Source/m_misc.c @@ -46,6 +46,7 @@ #include "s_sound.h" #include "sounds.h" #include "d_main.h" +#include "i_savepng.h" // [FG] SavePNG() #include "d_io.h" #include @@ -1054,11 +1055,7 @@ default_t defaults[] = { "screenshot_pcx", &screenshot_pcx, NULL, {1}, {0,1}, number, ss_gen, wad_no, -#ifdef HAVE_SDL_IMAGE - "1 to take a screenshot in PCX format, 0 for PNG" -#else - "1 to take a screenshot in PCX format, 0 for BMP" -#endif + "1 to take a screenshot in PCX format, 0 for BMP (or PNG)" }, { @@ -2429,6 +2426,7 @@ boolean WriteBMPfile(char *filename, byte *data, int width, return I_EndRead(), true; // killough 10/98 } +// [FG] save screenshots in PNG format boolean WritePNGfile(char *filename, byte *data, int width, int height, byte *palette) { @@ -2457,11 +2455,7 @@ void M_ScreenShot (void) do sprintf(lbmname, //jff 3/30/98 pcx or bmp? -#ifdef HAVE_SDL_IMAGE - screenshot_pcx ? "doom%02d.pcx" : "doom%02d.png", shot++); -#else - screenshot_pcx ? "doom%02d.pcx" : "doom%02d.bmp", shot++); -#endif + screenshot_pcx ? "doom%02d.pcx" : (SavePNG ? "doom%02d.png" : "doom%02d.bmp"), shot++); while (!access(lbmname,0) && --tries); if (tries) @@ -2479,11 +2473,7 @@ void M_ScreenShot (void) // killough 10/98: detect failure and remove file if error // killough 11/98: add hires support -#ifdef HAVE_SDL_IMAGE - if (!(success = (screenshot_pcx ? WritePCXfile : WritePNGfile) -#else - if (!(success = (screenshot_pcx ? WritePCXfile : WriteBMPfile) -#endif + if (!(success = (screenshot_pcx ? WritePCXfile : (SavePNG ? WritePNGfile : WriteBMPfile)) (lbmname,linear, SCREENWIDTH<