1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Merge with master

This commit is contained in:
Duncan Frost
2014-05-01 21:17:00 +01:00
6 changed files with 8057 additions and 11 deletions

6260
lodepng/lodepng.c Normal file

File diff suppressed because it is too large Load Diff

1716
lodepng/lodepng.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -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>

View File

@@ -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">

View File

@@ -18,6 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include <lodepng.h>
#include <stdio.h>
#include <windows.h>
#include "addresses.h"
#include "gfx.h"
@@ -26,6 +28,16 @@
#include "strings.h"
#include "window_error.h"
enum {
SCREENSHOT_FORMAT_BMP,
SCREENSHOT_FORMAT_PNG
};
int gScreenshotFormat = SCREENSHOT_FORMAT_BMP;
static int screenshot_dump_bmp();
static int screenshot_dump_png();
/**
*
* rct2: 0x006E3AEC
@@ -50,17 +62,14 @@ void screenshot_check()
}
}
static int screenshot_get_next_path(char *path)
static int screenshot_get_next_path(char *path, char *extension)
{
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%s", RCT2_ADDRESS(RCT2_ADDRESS_APP_PATH_SLASH, char), i, extension);
if (GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND)
return i;
@@ -69,6 +78,18 @@ static int screenshot_get_next_path(char *path)
return -1;
}
int screenshot_dump()
{
switch (gScreenshotFormat) {
case SCREENSHOT_FORMAT_BMP:
return screenshot_dump_bmp();
case SCREENSHOT_FORMAT_PNG:
return screenshot_dump_png();
default:
return -1;
}
}
// Bitmap header structs, for cross platform purposes
typedef struct {
uint16 bfType;
@@ -96,7 +117,7 @@ typedef struct {
*
* rct2: 0x00683D20
*/
int screenshot_dump()
int screenshot_dump_bmp()
{
BitmapFileHeader header;
BitmapInfoHeader info;
@@ -107,7 +128,7 @@ int screenshot_dump()
DWORD bytesWritten;
// Get a free screenshot path
if ((index = screenshot_get_next_path(path)) == -1)
if ((index = screenshot_get_next_path(path, ".bmp")) == -1)
return -1;
// Open file for writing
@@ -188,5 +209,48 @@ int screenshot_dump()
CloseHandle(hFile);
free(buffer);
return index;
}
int screenshot_dump_png()
{
int i, index, width, height, stride;
char path[MAX_PATH] = "";
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, ".png")) == -1)
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;
for (i = 0; i < 246; i++) {
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);
}
rct_drawpixelinfo *dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo);
unsigned int error = lodepng_encode(&png, &pngSize, dpi->bits, stride, dpi->height, &state);
if (!error) lodepng_save_file(png, pngSize, path);
if (error) fprintf(stderr, "error: %u: %s\n", error, lodepng_error_text(error));
free(png);
return index;
}

View File

@@ -21,6 +21,8 @@
#ifndef _SCREENSHOT_H_
#define _SCREENSHOT_H_
extern int gScreenshotFormat;
void screenshot_check();
int screenshot_dump();