102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference |
GitLab repository
Toggle main menu visibility
Loading...
Searching...
No Matches
screenshots.c
Go to the documentation of this file.
1
#include "
pcdogs/graphics/constants.h
"
2
#include "
pcdogs/graphics/functions.h
"
3
#include "
pcdogs/image/globals.h
"
4
#include "
pcdogs/image/types.h
"
5
#include "
pcdogs/platform/enums.h
"
6
#include "
pcdogs/platform/functions.h
"
7
#include "
pcdogs/platform/globals.h
"
8
#include "
pcdogs/runtime/enums.h
"
9
#include "
pcdogs/runtime/functions.h
"
10
#include "
pcdogs/runtime/types.h
"
11
12
// Original pcdogs.exe: 0x418b90
13
void
Graphics_TakeScreenshot
(
void
)
14
{
15
char
path[260];
16
int32_t number = 0;
17
18
for
(;;)
19
{
20
String_FormatCRTString
(path,
"sshot%03d.bmp"
, number);
21
struct
File_Handle
*existing =
CRT_fopen
(path,
"rb"
);
22
if
(!existing)
23
break
;
24
25
++number;
26
CRT_fclose
(existing);
27
}
28
29
String_FormatCRTString
(path,
"sshot%03d.bmp"
, number);
30
File_SaveScreenshot
(path);
31
}
32
33
// Original pcdogs.exe: 0x418bf0
34
uint8_t *
Graphics_ConvertSurface565ToBGR24
(IDirectDrawSurface7 *surface)
35
{
36
DDSURFACEDESC2 desc = {0};
37
desc.dwSize =
sizeof
(desc);
38
surface->lpVtbl->Lock(surface, NULL, &desc, DDLOCK_WAIT, NULL);
39
40
const
uint16_t *pixels = desc.lpSurface;
41
const
int32_t pitch = desc.lPitch / (int32_t)
sizeof
(*pixels);
42
uint8_t *output = &
g_screenshotBuffer
;
43
44
/* Retail starts at source row 480 and ends at row 1. */
45
for
(int32_t y =
GRAPHICS_DEFAULT_HEIGHT
; y > 0; --y)
46
{
47
const
uint16_t *row = pixels + y * pitch;
48
for
(int32_t x = 0; x <
GRAPHICS_DEFAULT_WIDTH
; ++x)
49
{
50
*output++ = (uint8_t)((row[x] & 31) << 3);
51
*output++ = (uint8_t)(((row[x] >> 5) & 63) << 2);
52
*output++ = (uint8_t)((row[x] >> 11) << 3);
53
}
54
}
55
56
return
&
g_screenshotBuffer
;
57
}
58
59
// Original pcdogs.exe: 0x418ce0
60
void
File_SaveScreenshot
(
const
char
*path)
61
{
62
BITMAPINFOHEADER *info = LocalAlloc(
LMEM_ZEROINIT
,
sizeof
(*info));
63
info->biSize =
sizeof
(*info);
64
info->biWidth =
GRAPHICS_DEFAULT_WIDTH
;
65
info->biHeight =
GRAPHICS_DEFAULT_HEIGHT
;
66
info->biPlanes = 1;
67
info->biBitCount = 24;
68
info->biCompression = 0;
69
/* The BMP headers declare half the size of the pixel data written below. */
70
info->biSizeImage =
GRAPHICS_DEFAULT_WIDTH
*
GRAPHICS_DEFAULT_HEIGHT
* 3 / 2;
71
info->biClrImportant = 0;
72
73
Graphics_ConvertSurface565ToBGR24
(
g_ddrawBackBuffer
);
74
DDraw_UnlockSurface
(
g_ddrawBackBuffer
);
75
HANDLE file = CreateFileA(path, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_NONE
, NULL,
76
CREATE_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
, NULL);
77
if
(file == INVALID_HANDLE_VALUE)
78
return
;
79
80
struct
PCDOGS_BitmapFileHeader
header = {
81
.bfType = 0x4d42,
82
.bfSize =
sizeof
(header) + info->biSize + info->biSizeImage,
83
.bfOffBits =
sizeof
(header) + info->biSize};
84
DWORD written;
85
if
(WriteFile(file, &header,
sizeof
(header), &written, NULL) &&
86
WriteFile(file, info,
sizeof
(*info), &written, NULL) &&
87
WriteFile(file, &
g_screenshotBuffer
,
GRAPHICS_DEFAULT_WIDTH
*
GRAPHICS_DEFAULT_HEIGHT
* 3, &written, NULL))
88
CloseHandle(file);
89
}
constants.h
GRAPHICS_DEFAULT_WIDTH
#define GRAPHICS_DEFAULT_WIDTH
Definition
constants.h:25
GRAPHICS_DEFAULT_HEIGHT
#define GRAPHICS_DEFAULT_HEIGHT
Definition
constants.h:26
functions.h
globals.h
types.h
enums.h
functions.h
DDraw_UnlockSurface
HRESULT DDraw_UnlockSurface(IDirectDrawSurface7 *surface)
Definition
graphics_surfaces.c:605
globals.h
g_ddrawBackBuffer
#define g_ddrawBackBuffer
Definition
globals.h:222
enums.h
FILE_SHARE_NONE
#define FILE_SHARE_NONE
Definition
enums.h:202
CREATE_ALWAYS
@ CREATE_ALWAYS
Definition
enums.h:44
FILE_ATTRIBUTE_NORMAL
#define FILE_ATTRIBUTE_NORMAL
Definition
enums.h:80
functions.h
CRT_fclose
int32_t CRT_fclose(struct File_Handle *stream)
Definition
stdio.c:80
CRT_fopen
struct File_Handle * CRT_fopen(char const *filename, char const *mode)
Definition
stdio.c:134
String_FormatCRTString
int32_t String_FormatCRTString(char *buffer, char const *format,...)
Definition
formatting.c:18
types.h
File_SaveScreenshot
void File_SaveScreenshot(const char *path)
Definition
screenshots.c:60
Graphics_TakeScreenshot
void Graphics_TakeScreenshot(void)
Definition
screenshots.c:13
Graphics_ConvertSurface565ToBGR24
uint8_t * Graphics_ConvertSurface565ToBGR24(IDirectDrawSurface7 *surface)
Definition
screenshots.c:34
File_Handle
Definition
types.h:228
PCDOGS_BitmapFileHeader
Definition
types.h:68
g_screenshotBuffer
#define g_screenshotBuffer
Definition
values.h:804
LMEM_ZEROINIT
#define LMEM_ZEROINIT
Definition
win32_memory.h:74
src
graphics
screenshots.c
Generated by
1.17.0