MCPcopy Create free account
hub / github.com/ZDoom/Raze / SaveScreenshot

Function SaveScreenshot

source/core/screenshot.cpp:81–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79
80
81static int SaveScreenshot()
82{
83 PalEntry Palette[256];
84
85 size_t dirlen;
86 FString autoname = Args->CheckValue("-shotdir");
87 if (autoname.IsEmpty())
88 {
89 autoname = screenshot_dir;
90 }
91 dirlen = autoname.Len();
92 if (dirlen == 0)
93 {
94 autoname = M_GetScreenshotsPath();
95 dirlen = autoname.Len();
96 }
97 if (dirlen > 0)
98 {
99 if (autoname[dirlen - 1] != '/' && autoname[dirlen - 1] != '\\')
100 {
101 autoname += '/';
102 }
103 }
104 autoname = NicePath(autoname.GetChars());
105 CreatePath(autoname.GetChars());
106
107 if (**screenshotname) autoname << screenshotname;
108 else autoname << currentGame;
109 autoname << "_%04d.png";
110 FileWriter *fil = opennextfile(autoname.GetChars());
111
112 if (fil == nullptr)
113 {
114 return -1;
115 }
116
117 float gamma;
118 int pitch;
119 ESSType ctype;
120 auto imgBuf = screen->GetScreenshotBuffer(pitch, ctype, gamma);
121 WritePNGfile(fil, imgBuf.Data(), Palette, ctype, screen->GetWidth(), screen->GetHeight(), pitch, gamma);
122 delete fil;
123 Printf("screenshot saved\n");
124 return 0;
125}
126
127CCMD(screenshot)
128{

Callers 1

CCMDFunction · 0.85

Calls 14

NicePathFunction · 0.85
CreatePathFunction · 0.85
opennextfileFunction · 0.85
WritePNGfileFunction · 0.85
PrintfFunction · 0.85
LenMethod · 0.80
M_GetScreenshotsPathFunction · 0.50
CheckValueMethod · 0.45
IsEmptyMethod · 0.45
GetCharsMethod · 0.45
GetScreenshotBufferMethod · 0.45
DataMethod · 0.45

Tested by

no test coverage detected