mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-22 18:31:59 -05:00
Changed screenshot format from BMP to PNG (using LodePNG)
NOTE: The little popup window ("Screenshot saved to disk as") still displays a BMP filename, but it saves a PNG file to disk.
This commit is contained in:
parent
efa7e8fc2b
commit
f305a518b2
5 changed files with 8006 additions and 101 deletions
6260
lodepng/lodepng.c
Normal file
6260
lodepng/lodepng.c
Normal file
File diff suppressed because it is too large
Load diff
1716
lodepng/lodepng.h
Normal file
1716
lodepng/lodepng.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -51,6 +51,7 @@
|
|||
<ClInclude Include="resource.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\lodepng\lodepng.c" />
|
||||
<ClCompile Include="..\src\audio.c" />
|
||||
<ClCompile Include="..\src\climate.c" />
|
||||
<ClCompile Include="..\src\config.c" />
|
||||
|
@ -129,13 +130,13 @@
|
|||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IncludePath>$(SolutionDir)..\sdl\include;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)..\lodepng;$(SolutionDir)..\sdl\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)..\sdl\lib\x86;$(LibraryPath)</LibraryPath>
|
||||
<OutDir>$(SolutionDir)..\build\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\obj\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>$(SolutionDir)..\sdl\include;$(IncludePath)</IncludePath>
|
||||
<IncludePath>$(SolutionDir)..\lodepng;$(SolutionDir)..\sdl\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)..\sdl\lib\x86;$(LibraryPath)</LibraryPath>
|
||||
<OutDir>$(SolutionDir)..\build\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\obj\$(Configuration)\</IntDir>
|
||||
|
|
|
@ -254,6 +254,9 @@
|
|||
<ClCompile Include="..\src\window_about.c">
|
||||
<Filter>Windows</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\lodepng\lodepng.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\openrct2.exe">
|
||||
|
|
123
src/screenshot.c
123
src/screenshot.c
|
@ -25,6 +25,8 @@
|
|||
#include "screenshot.h"
|
||||
#include "strings.h"
|
||||
#include "window_error.h"
|
||||
#include <lodepng.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -52,15 +54,12 @@ void screenshot_check()
|
|||
|
||||
static int screenshot_get_next_path(char *path)
|
||||
{
|
||||
char *placeHolder;
|
||||
|
||||
strcpy(path, RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH_SLASH, char));
|
||||
placeHolder = path + strlen(path);
|
||||
|
||||
int i;
|
||||
for (i = 1; i < 1000; i++) {
|
||||
RCT2_GLOBAL(0x013CE952, uint16) = i;
|
||||
format_string(placeHolder, STR_SCR_BMP, 0x013CE952);
|
||||
|
||||
// Glue together path and filename
|
||||
sprintf(path, "%sSCR%d.PNG", RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH_SLASH, char), i);
|
||||
|
||||
if (GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND)
|
||||
return i;
|
||||
|
@ -69,28 +68,6 @@ static int screenshot_get_next_path(char *path)
|
|||
return -1;
|
||||
}
|
||||
|
||||
// Bitmap header structs, for cross platform purposes
|
||||
typedef struct {
|
||||
uint16 bfType;
|
||||
uint32 bfSize;
|
||||
uint16 bfReserved1;
|
||||
uint16 bfReserved2;
|
||||
uint32 bfOffBits;
|
||||
} BitmapFileHeader;
|
||||
|
||||
typedef struct {
|
||||
uint32 biSize;
|
||||
sint32 biWidth;
|
||||
sint32 biHeight;
|
||||
uint16 biPlanes;
|
||||
uint16 biBitCount;
|
||||
uint32 biCompression;
|
||||
uint32 biSizeImage;
|
||||
sint32 biXPelsPerMeter;
|
||||
sint32 biYPelsPerMeter;
|
||||
uint32 biClrUsed;
|
||||
uint32 biClrImportant;
|
||||
} BitmapInfoHeader;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -98,95 +75,43 @@ typedef struct {
|
|||
*/
|
||||
int screenshot_dump()
|
||||
{
|
||||
BitmapFileHeader header;
|
||||
BitmapInfoHeader info;
|
||||
int i, index, width, height, stride;
|
||||
char path[MAX_PATH] = "";
|
||||
|
||||
int i, x, y, index, width, height, stride;
|
||||
char *buffer, path[MAX_PATH], *row, *dst;
|
||||
HFILE hFile;
|
||||
DWORD bytesWritten;
|
||||
unsigned char r, g, b, a = 255;
|
||||
|
||||
unsigned char* png;
|
||||
size_t pngSize;
|
||||
LodePNGState state;
|
||||
|
||||
// Get a free screenshot path
|
||||
if ((index = screenshot_get_next_path(path)) == -1)
|
||||
return -1;
|
||||
|
||||
// Open file for writing
|
||||
hFile = CreateFile(path, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
return -1;
|
||||
|
||||
// Allocate buffer
|
||||
buffer = malloc(0xFFFF);
|
||||
if (buffer == NULL) {
|
||||
CloseHandle(hFile);
|
||||
return -1;
|
||||
}
|
||||
lodepng_state_init(&state);
|
||||
state.info_raw.colortype = LCT_PALETTE;
|
||||
|
||||
// Get image size
|
||||
width = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16);
|
||||
height = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16);
|
||||
stride = (width + 3) & 0xFFFFFFFC;
|
||||
|
||||
// File header
|
||||
memset(&header, 0, sizeof(header));
|
||||
header.bfType = 0x4D42;
|
||||
header.bfSize = height * stride + 1038;
|
||||
header.bfOffBits = 1038;
|
||||
|
||||
WriteFile(hFile, &header, sizeof(header), &bytesWritten, NULL);
|
||||
if (bytesWritten != sizeof(header)) {
|
||||
CloseHandle(hFile);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
// Info header
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.biSize = sizeof(info);
|
||||
info.biWidth = width;
|
||||
info.biHeight = height;
|
||||
info.biPlanes = 1;
|
||||
info.biBitCount = 8;
|
||||
info.biXPelsPerMeter = 2520;
|
||||
info.biYPelsPerMeter = 2520;
|
||||
info.biClrUsed = 246;
|
||||
|
||||
WriteFile(hFile, &info, sizeof(info), &bytesWritten, NULL);
|
||||
if (bytesWritten != sizeof(info)) {
|
||||
CloseHandle(hFile);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
// Palette
|
||||
memset(buffer, 0, 246 * 4);
|
||||
for (i = 0; i < 246; i++) {
|
||||
buffer[i * 4 + 0] = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 0];
|
||||
buffer[i * 4 + 1] = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 1];
|
||||
buffer[i * 4 + 2] = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 2];
|
||||
b = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 0];
|
||||
g = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 1];
|
||||
r = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 2];
|
||||
|
||||
lodepng_palette_add(&state.info_raw, r, g, b, a);
|
||||
}
|
||||
|
||||
WriteFile(hFile, buffer, 246 * 4, &bytesWritten, NULL);
|
||||
if (bytesWritten != 246 * 4) {
|
||||
CloseHandle(hFile);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
// Image, save upside down
|
||||
rct_drawpixelinfo *dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo);
|
||||
for (y = dpi->height - 1; y >= 0; y--) {
|
||||
row = dpi->bits + y * (dpi->width + dpi->pitch);
|
||||
|
||||
memset(buffer, 0, stride);
|
||||
memcpy(buffer, row, dpi->width);
|
||||
unsigned int error = lodepng_encode(&png, &pngSize, dpi->bits, stride, dpi->height, &state);
|
||||
if (!error) lodepng_save_file(png, pngSize, path);
|
||||
|
||||
WriteFile(hFile, buffer, stride, &bytesWritten, NULL);
|
||||
if (bytesWritten != stride) {
|
||||
CloseHandle(hFile);
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
free(buffer);
|
||||
if (error) fprintf(stderr, "error: %u: %s\n", error, lodepng_error_text(error));
|
||||
|
||||
free(png);
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue