mirror of https://github.com/OpenRCT2/OpenRCT2.git
fix whizzed screenshots
This commit is contained in:
parent
f4a4df1cb5
commit
fbebd6527b
|
@ -236,7 +236,7 @@ int screenshot_dump_png()
|
||||||
{
|
{
|
||||||
rct_drawpixelinfo *dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo);
|
rct_drawpixelinfo *dpi = RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo);
|
||||||
|
|
||||||
int i, index, width, height, stride;
|
int i, index, width, height, padding;
|
||||||
char path[MAX_PATH] = "";
|
char path[MAX_PATH] = "";
|
||||||
unsigned int error;
|
unsigned int error;
|
||||||
unsigned char r, g, b, a = 255;
|
unsigned char r, g, b, a = 255;
|
||||||
|
@ -256,7 +256,8 @@ int screenshot_dump_png()
|
||||||
// Get image size
|
// Get image size
|
||||||
width = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16);
|
width = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16);
|
||||||
height = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16);
|
height = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16);
|
||||||
stride = (width + 3) & ~3;
|
|
||||||
|
padding = dpi->pitch;
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
b = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 0];
|
b = RCT2_ADDRESS(0x01424680, uint8)[i * 4 + 0];
|
||||||
|
@ -266,7 +267,24 @@ int screenshot_dump_png()
|
||||||
lodepng_palette_add(&state.info_raw, r, g, b, a);
|
lodepng_palette_add(&state.info_raw, r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
error = lodepng_encode(&png, &pngSize, dpi->bits, width, height, &state);
|
uint8* pixels = dpi->bits;
|
||||||
|
|
||||||
|
if (padding > 0) {
|
||||||
|
pixels = malloc(width * height);
|
||||||
|
if (!pixels) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
uint8* src = dpi->bits;
|
||||||
|
uint8* dst = pixels;
|
||||||
|
for (int y = height; y > 0; y--) {
|
||||||
|
for (int x = width; x > 0; x--) {
|
||||||
|
*dst++ = *src++;
|
||||||
|
}
|
||||||
|
src += padding;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
error = lodepng_encode(&png, &pngSize, pixels, width, height, &state);
|
||||||
if (error) {
|
if (error) {
|
||||||
log_error("Unable to save screenshot, %u: %s", lodepng_error_text(error));
|
log_error("Unable to save screenshot, %u: %s", lodepng_error_text(error));
|
||||||
index = -1;
|
index = -1;
|
||||||
|
@ -275,6 +293,9 @@ int screenshot_dump_png()
|
||||||
}
|
}
|
||||||
|
|
||||||
free(png);
|
free(png);
|
||||||
|
if (pixels != dpi->bits) {
|
||||||
|
free(pixels);
|
||||||
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,17 +183,24 @@ void platform_draw()
|
||||||
int pitch;
|
int pitch;
|
||||||
if (SDL_LockTexture(gBufferTexture, NULL, &pixels, &pitch) == 0) {
|
if (SDL_LockTexture(gBufferTexture, NULL, &pixels, &pitch) == 0) {
|
||||||
uint8 *src = (uint8*)_screenBuffer;
|
uint8 *src = (uint8*)_screenBuffer;
|
||||||
|
int padding = pitch - (width * 4);
|
||||||
if (pitch == width * 4) {
|
if (pitch == width * 4) {
|
||||||
uint32 *dst = pixels;
|
uint32 *dst = pixels;
|
||||||
for (int i = width * height; i > 0; i--) *(dst++) = *(uint32 *)(&gPaletteHWMapped[*src++]);
|
for (int i = width * height; i > 0; i--) { *dst++ = *(uint32 *)(&gPaletteHWMapped[*src++]); }
|
||||||
} else
|
} else
|
||||||
if (pitch == (((width * 2) + 3) & ~3)) {
|
if (pitch == (width * 2) + padding) {
|
||||||
uint16 *dst = pixels;
|
uint16 *dst = pixels;
|
||||||
for (int i = width * height; i > 0; i--) *(dst++) = *(uint16 *)(&gPaletteHWMapped[*src++]);
|
for (int y = height; y > 0; y++) {
|
||||||
|
for (int x = width; x > 0; x--) { *dst++ = *(uint16 *)(&gPaletteHWMapped[*src++]); }
|
||||||
|
dst = (uint16*)(((uint8 *)dst) + padding);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
if (pitch == (((width) + 3) & ~3)) {
|
if (pitch == width + padding) {
|
||||||
uint8 *dst = pixels;
|
uint8 *dst = pixels;
|
||||||
for (int i = width * height; i > 0; i--) *(dst++) = *(uint8 *)(&gPaletteHWMapped[*src++]);
|
for (int y = height; y > 0; y++) {
|
||||||
|
for (int x = width; x > 0; x--) { *dst++ = *(uint8 *)(&gPaletteHWMapped[*src++]); }
|
||||||
|
dst += padding;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SDL_UnlockTexture(gBufferTexture);
|
SDL_UnlockTexture(gBufferTexture);
|
||||||
}
|
}
|
||||||
|
@ -797,8 +804,8 @@ static void platform_refresh_screenbuffer(int width, int height, int pitch)
|
||||||
dst += pitch;
|
dst += pitch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newScreenBufferSize - _screenBufferSize > 0)
|
//if (newScreenBufferSize - _screenBufferSize > 0)
|
||||||
memset((uint8*)newScreenBuffer + _screenBufferSize, 0, newScreenBufferSize - _screenBufferSize);
|
// memset((uint8*)newScreenBuffer + _screenBufferSize, 0, newScreenBufferSize - _screenBufferSize);
|
||||||
free(_screenBuffer);
|
free(_screenBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue