VIDEO: Produce SCREENSHOT images in PNG format if libpng is available in the host build environment

This commit is contained in:
Mark Pizzolato 2015-09-27 16:14:55 -07:00
parent 0a2eb2997c
commit 4921d92650
6 changed files with 229 additions and 28 deletions

View file

@ -41,8 +41,8 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;VAX_610;USE_SHARED;USE_SIM_VIDEO;HAVE_LIBSDL;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;;&quot;../../windows-build/libpng-1.6.18&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;VAX_610;USE_SHARED;USE_SIM_VIDEO;HAVE_LIBSDL;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC;HAVE_LIBPNG"
KeepComments="false"
MinimalRebuild="true"
BasicRuntimeChecks="0"
@ -65,9 +65,9 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/fixed:no"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-StaticD.lib dxguid.lib Imm32.lib Version.lib pcrestaticd.lib pcreposixstaticd.lib"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-StaticD.lib dxguid.lib Imm32.lib Version.lib pcrestaticd.lib pcreposixstaticd.lib libpng16.lib zlib.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;;&quot;../../windows-build/libpng-1.6.18/projects/vstudio 2008/Debug Library&quot;"
GenerateDebugInformation="true"
SubSystem="1"
StackReserveSize="10485760"
@ -128,8 +128,8 @@
FavorSizeOrSpeed="1"
OmitFramePointers="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;VAX_610;USE_SHARED;USE_SIM_VIDEO;HAVE_LIBSDL;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;;&quot;../../windows-build/libpng-1.6.18&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;VAX_610;USE_SHARED;USE_SIM_VIDEO;HAVE_LIBSDL;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC;HAVE_LIBPNG"
KeepComments="false"
StringPooling="true"
RuntimeLibrary="0"
@ -152,9 +152,9 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/fixed:no"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-Static.lib dxguid.lib Imm32.lib Version.lib pcrestatic.lib pcreposixstatic.lib"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-Static.lib dxguid.lib Imm32.lib Version.lib pcrestatic.lib pcreposixstatic.lib libpng16.lib zlib.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;;&quot;../../windows-build/libpng-1.6.18/projects/vstudio 2008/Release Library&quot;"
GenerateDebugInformation="false"
SubSystem="1"
StackReserveSize="10485760"

View file

@ -41,8 +41,8 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;VAX_630;USE_SHARED;USE_SIM_VIDEO;HAVE_LIBSDL;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;;&quot;../../windows-build/libpng-1.6.18&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;VAX_630;USE_SHARED;USE_SIM_VIDEO;HAVE_LIBSDL;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC;HAVE_LIBPNG"
KeepComments="false"
MinimalRebuild="true"
BasicRuntimeChecks="0"
@ -65,9 +65,9 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/fixed:no"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-StaticD.lib dxguid.lib Imm32.lib Version.lib pcrestaticd.lib pcreposixstaticd.lib"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-StaticD.lib dxguid.lib Imm32.lib Version.lib pcrestaticd.lib pcreposixstaticd.lib libpng16.lib zlib.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;;&quot;../../windows-build/libpng-1.6.18/projects/vstudio 2008/Debug Library&quot;"
GenerateDebugInformation="true"
SubSystem="1"
StackReserveSize="10485760"
@ -128,8 +128,8 @@
FavorSizeOrSpeed="1"
OmitFramePointers="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;VAX_630;USE_SHARED;USE_SIM_VIDEO;HAVE_LIBSDL;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;;&quot;../../windows-build/libpng-1.6.18&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;VAX_630;USE_SHARED;USE_SIM_VIDEO;HAVE_LIBSDL;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC;HAVE_LIBPNG"
KeepComments="false"
StringPooling="true"
RuntimeLibrary="0"
@ -152,9 +152,9 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/fixed:no"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-Static.lib dxguid.lib Imm32.lib Version.lib pcrestatic.lib pcreposixstatic.lib"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-Static.lib dxguid.lib Imm32.lib Version.lib pcrestatic.lib pcreposixstatic.lib libpng16.lib zlib.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;;&quot;../../windows-build/libpng-1.6.18/projects/vstudio 2008/Release Library&quot;"
GenerateDebugInformation="false"
SubSystem="1"
StackReserveSize="10485760"

View file

@ -152,6 +152,7 @@ if not exist ../../windows-build/pthreads/pthread.h goto _notice1
findstr "/c:_MSC_VER >= 1900" ..\..\windows-build\pthreads\pthread.h >NUL
if ERRORLEVEL 1 goto _notice2
if "%_X_LIBSDL%" == "" goto _done_libsdl
if not exist ../../windows-build/libpng* goto _notice2
if not exist ../../windows-build/libSDL/SDL2-2.0.3/include/SDL.h goto _notice2
if not exist "../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)/Lib/x86/dxguid.lib" goto _notice2
findstr "/c:HAVE_FTOL2_SSE" ..\..\windows-build\libSDL\SDL2-2.0.3\VisualC\SDL_Static\SDL_VS2008.vcproj >NUL

View file

@ -41,8 +41,8 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;;&quot;../../windows-build/PCRE/include&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;USE_SHARED;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;USE_SIM_VIDEO;HAVE_LIBSDL;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;;&quot;../../windows-build/PCRE/include&quot;;&quot;../../windows-build/libpng-1.6.18&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;USE_SHARED;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;USE_SIM_VIDEO;HAVE_LIBSDL;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC;HAVE_LIBPNG"
KeepComments="false"
MinimalRebuild="true"
BasicRuntimeChecks="0"
@ -65,9 +65,9 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/fixed:no"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-StaticD.lib dxguid.lib Imm32.lib Version.lib pcrestaticd.lib pcreposixstaticd.lib"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-StaticD.lib dxguid.lib Imm32.lib Version.lib pcrestaticd.lib pcreposixstaticd.lib libpng16.lib zlib.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;;&quot;../../windows-build/libpng-1.6.18/projects/vstudio 2008/Debug Library&quot;"
GenerateDebugInformation="true"
SubSystem="1"
StackReserveSize="10485760"
@ -130,8 +130,8 @@
FavorSizeOrSpeed="1"
OmitFramePointers="true"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;&quot;../../windows-build/winpcap/Wpdpack/Include&quot;;&quot;../../windows-build/PCRE/include/&quot;;&quot;../../windows-build/pthreads&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/include&quot;;&quot;../../windows-build/PCRE/include&quot;"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;USE_SHARED;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;USE_SIM_VIDEO;HAVE_LIBSDL;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC"
AdditionalIncludeDirectories="./;../;../VAX/;../pdp11/;../../windows-build/winpcap/Wpdpack/Include;../../windows-build/PCRE/include/;../../windows-build/pthreads;../../windows-build/libSDL/SDL2-2.0.3/include;../../windows-build/PCRE/include;../../windows-build/libpng-1.6.18"
PreprocessorDefinitions="USE_INT64;USE_ADDR64;VM_VAX;USE_SHARED;_CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;PTW32_STATIC_LIB;USE_READER_THREAD;USE_SIM_VIDEO;HAVE_LIBSDL;SIM_ASYNCH_IO;SIM_NEED_GIT_COMMIT_ID;HAVE_PCREPOSIX_H;PCRE_STATIC;HAVE_LIBPNG"
KeepComments="false"
StringPooling="true"
RuntimeLibrary="0"
@ -154,9 +154,9 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/fixed:no"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-Static.lib dxguid.lib Imm32.lib Version.lib pcreposixstatic.lib pcrestatic.lib"
AdditionalDependencies="wsock32.lib winmm.lib SDL2-Static.lib dxguid.lib Imm32.lib Version.lib pcreposixstatic.lib pcrestatic.lib libpng16.lib zlib.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;"
AdditionalLibraryDirectories="&quot;../../windows-build/winpcap/Wpdpack/Lib/&quot;;&quot;../../windows-build/libSDL/SDL2-2.0.3/lib/&quot;;&quot;../../windows-build/libSDL/Microsoft DirectX SDK (June 2010)\Lib\x86&quot;;&quot;../../windows-build/PCRE/lib/&quot;;&quot;../../windows-build/libpng-1.6.18/projects/vstudio 2008/Release Library&quot;"
GenerateDebugInformation="false"
SubSystem="1"
StackReserveSize="10485760"

7
scp.c
View file

@ -1669,7 +1669,12 @@ ASSERT failure have several different actions:
" Simulators with Video devices display the simulated video in a window\n"
" on the local system. The contents of that display can be saved in a\n"
" file with the SCREENSHOT command:\n\n"
" SCREENSHOT screenshotfile.bmp\n"
" +SCREENSHOT screenshotfile\n\n"
#if defined(HAVE_LIBPNG)
" which will create a screen shot file called screenshotfile.png\n"
#else
" which will create a screen shot file called screenshotfile.bmp\n"
#endif
#define HLP_SPAWN "*Commands Executing_System_Commands"
"2Executing System Commands\n"
" The simulator can execute operating system commands with the ! (spawn)\n"

View file

@ -28,6 +28,7 @@
*/
#include "sim_video.h"
#include "scp.h"
t_bool vid_active = FALSE;
int32 vid_mouse_xrel;
@ -50,6 +51,174 @@ char vid_release_key[64] = "Ctrl-Right-Shift";
#include <SDL.h>
#include <SDL_thread.h>
#if defined(HAVE_LIBPNG)
/* From: https://github.com/driedfruit/SDL_SavePNG */
/*
* Save an SDL_Surface as a PNG file.
*
* Returns 0 success or -1 on failure, the error message is then retrievable
* via SDL_GetError().
*/
#define SDL_SavePNG(surface, file) \
SDL_SavePNG_RW(surface, SDL_RWFromFile(file, "wb"), 1)
/*
* SDL_SavePNG -- libpng-based SDL_Surface writer.
*
* This code is free software, available under zlib/libpng license.
* http://www.libpng.org/pub/png/src/libpng-LICENSE.txt
*/
#include <SDL.h>
#include <png.h>
#define SUCCESS 0
#define ERROR -1
#define USE_ROW_POINTERS
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define rmask 0xFF000000
#define gmask 0x00FF0000
#define bmask 0x0000FF00
#define amask 0x000000FF
#else
#define rmask 0x000000FF
#define gmask 0x0000FF00
#define bmask 0x00FF0000
#define amask 0xFF000000
#endif
/* libpng callbacks */
static void png_error_SDL(png_structp ctx, png_const_charp str)
{
SDL_SetError("libpng: %s\n", str);
}
static void png_write_SDL(png_structp png_ptr, png_bytep data, png_size_t length)
{
SDL_RWops *rw = (SDL_RWops*)png_get_io_ptr(png_ptr);
SDL_RWwrite(rw, data, sizeof(png_byte), length);
}
static SDL_Surface *SDL_PNGFormatAlpha(SDL_Surface *src)
{
SDL_Surface *surf;
SDL_Rect rect = { 0 };
/* NO-OP for images < 32bpp and 32bpp images that already have Alpha channel */
if (src->format->BitsPerPixel <= 24 || src->format->Amask) {
src->refcount++;
return src;
}
/* Convert 32bpp alpha-less image to 24bpp alpha-less image */
rect.w = src->w;
rect.h = src->h;
surf = SDL_CreateRGBSurface(src->flags, src->w, src->h, 24,
src->format->Rmask, src->format->Gmask, src->format->Bmask, 0);
SDL_LowerBlit(src, &rect, surf, &rect);
return surf;
}
static int SDL_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
{
png_structp png_ptr;
png_infop info_ptr;
png_colorp pal_ptr;
SDL_Palette *pal;
int i, colortype;
#ifdef USE_ROW_POINTERS
png_bytep *row_pointers;
#endif
/* Initialize and do basic error checking */
if (!dst)
{
SDL_SetError("Argument 2 to SDL_SavePNG_RW can't be NULL, expecting SDL_RWops*\n");
return (ERROR);
}
if (!surface)
{
SDL_SetError("Argument 1 to SDL_SavePNG_RW can't be NULL, expecting SDL_Surface*\n");
if (freedst) SDL_RWclose(dst);
return (ERROR);
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, png_error_SDL, NULL); /* err_ptr, err_fn, warn_fn */
if (!png_ptr)
{
SDL_SetError("Unable to png_create_write_struct on %s\n", PNG_LIBPNG_VER_STRING);
if (freedst) SDL_RWclose(dst);
return (ERROR);
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
SDL_SetError("Unable to png_create_info_struct\n");
png_destroy_write_struct(&png_ptr, NULL);
if (freedst) SDL_RWclose(dst);
return (ERROR);
}
if (setjmp(png_jmpbuf(png_ptr))) /* All other errors, see also "png_error_SDL" */
{
png_destroy_write_struct(&png_ptr, &info_ptr);
if (freedst) SDL_RWclose(dst);
return (ERROR);
}
/* Setup our RWops writer */
png_set_write_fn(png_ptr, dst, png_write_SDL, NULL); /* w_ptr, write_fn, flush_fn */
/* Prepare chunks */
colortype = PNG_COLOR_MASK_COLOR;
if (surface->format->BytesPerPixel > 0
&& surface->format->BytesPerPixel <= 8
&& (pal = surface->format->palette))
{
colortype |= PNG_COLOR_MASK_PALETTE;
pal_ptr = (png_colorp)malloc(pal->ncolors * sizeof(png_color));
for (i = 0; i < pal->ncolors; i++) {
pal_ptr[i].red = pal->colors[i].r;
pal_ptr[i].green = pal->colors[i].g;
pal_ptr[i].blue = pal->colors[i].b;
}
png_set_PLTE(png_ptr, info_ptr, pal_ptr, pal->ncolors);
free(pal_ptr);
}
else if (surface->format->BytesPerPixel > 3 || surface->format->Amask)
colortype |= PNG_COLOR_MASK_ALPHA;
png_set_IHDR(png_ptr, info_ptr, surface->w, surface->h, 8, colortype,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
// png_set_packing(png_ptr);
/* Allow BGR surfaces */
if (surface->format->Rmask == bmask
&& surface->format->Gmask == gmask
&& surface->format->Bmask == rmask)
png_set_bgr(png_ptr);
/* Write everything */
png_write_info(png_ptr, info_ptr);
#ifdef USE_ROW_POINTERS
row_pointers = (png_bytep*) malloc(sizeof(png_bytep)*surface->h);
for (i = 0; i < surface->h; i++)
row_pointers[i] = (png_bytep)(Uint8*)surface->pixels + i * surface->pitch;
png_write_image(png_ptr, row_pointers);
free(row_pointers);
#else
for (i = 0; i < surface->h; i++)
png_write_row(png_ptr, (png_bytep)(Uint8*)surface->pixels + i * surface->pitch);
#endif
png_write_end(png_ptr, info_ptr);
/* Done */
png_destroy_write_struct(&png_ptr, &info_ptr);
if (freedst) SDL_RWclose(dst);
return (SUCCESS);
}
#endif /* defined(HAVE_LIBPNG) */
/*
Some platforms (OS X), require that ALL input event processing be
performed by the main thread of the process.
@ -1840,23 +2009,49 @@ return _show_stat;
static t_stat _vid_screenshot (const char *filename)
{
int stat;
char *fullname = NULL;
if (!vid_active) {
sim_printf ("No video display is active\n");
return SCPE_UDIS | SCPE_NOMESSAGE;
}
fullname = malloc (strlen(filename) + 5);
#if SDL_MAJOR_VERSION == 1
SDL_SaveBMP(vid_image, filename);
#if defined(HAVE_LIBPNG)
sprintf (fullname, "%s.png", filename);
stat = SDL_SavePNG(vid_image, fullname);
#else
sprintf (fullname, "%s.bmp", filename);
stat = SDL_SaveBMP(vid_image, fullname);
#endif /* defined(HAVE_LIBPNG) */
#else /* SDL_MAJOR_VERSION != 1 */
if (1) {
SDL_Surface *sshot = sim_end ? SDL_CreateRGBSurface(0, vid_width, vid_height, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000) :
SDL_CreateRGBSurface(0, vid_width, vid_height, 32, 0x0000ff00, 0x000ff000, 0xff000000, 0x000000ff) ;
SDL_RenderReadPixels(vid_renderer, NULL, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch);
SDL_SaveBMP(sshot, filename);
#if defined(HAVE_LIBPNG)
sprintf (fullname, "%s.png", filename);
stat = SDL_SavePNG(sshot, fullname);
#else
sprintf (fullname, "%s.bmp", filename);
stat = SDL_SaveBMP(sshot, fullname);
#endif /* defined(HAVE_LIBPNG) */
SDL_FreeSurface(sshot);
}
#endif
if (stat) {
sim_printf ("Error saving screenshot to %s: %s\n", fullname, SDL_GetError());
free (fullname);
return SCPE_IOERR | SCPE_NOMESSAGE;
}
else {
if (!sim_quiet)
sim_printf ("Screenshot saved to %s\n", fullname);
free (fullname);
return SCPE_OK;
}
}
static t_stat _screenshot_stat;
static const char *_screenshot_filename;