| 79 | |
| 80 | |
| 81 | static 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 | |
| 127 | CCMD(screenshot) |
| 128 | { |
no test coverage detected