1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

support screenshots with 32bit surfaces

This commit is contained in:
FunkyFr3sh 2021-10-02 15:49:58 +02:00
parent 3a3eef6c75
commit 710a1e3bca

View File

@ -75,6 +75,39 @@ static BOOL ss_screenshot_16bit(char* filename, IDirectDrawSurfaceImpl* src)
return !error;
}
static BOOL ss_screenshot_32bit(char* filename, IDirectDrawSurfaceImpl* src)
{
unsigned int error = TRUE;
unsigned int* dst_buf = malloc(src->width * src->height * 4);
if (dst_buf)
{
unsigned int* src_buf = (unsigned int*)dds_GetBuffer(src);
for (int y = 0; y < src->height; y++)
{
int dst_row = y * src->width;
for (int x = 0; x < src->width; x++)
{
unsigned int pixel = src_buf[dst_row + x];
BYTE red = (pixel >> 16) & 0xFF;
BYTE green = (pixel >> 8) & 0xFF;
BYTE blue = pixel & 0xFF;
dst_buf[dst_row + x] = (0xFF << 24) | (blue << 16) | (green << 8) | red;
}
}
error = lodepng_encode32_file(filename, (unsigned char*)dst_buf, src->width, src->height);
free(dst_buf);
}
return !error;
}
BOOL ss_take_screenshot(IDirectDrawSurfaceImpl* src)
{
if (!src || !dds_GetBuffer(src))
@ -110,6 +143,10 @@ BOOL ss_take_screenshot(IDirectDrawSurfaceImpl* src)
{
return ss_screenshot_16bit(filename, src);
}
else if (src->bpp == 32)
{
return ss_screenshot_32bit(filename, src);
}
return FALSE;
}