44 bool MakeImage(
const char *name,
ScreenshotCallback *callb,
void *userdata, uint w, uint h,
int pixelformat,
const Colour *palette)
override
51 if (pixelformat == 32) {
52 Debug(misc, 0,
"Can't convert a 32bpp screenshot to PCX format. Please pick another format.");
55 if (pixelformat != 8 || w == 0)
return false;
58 if (!of.has_value())
return false;
61 memset(&pcx, 0,
sizeof(pcx));
64 pcx.manufacturer = 10;
68 pcx.xmax = TO_LE16(w - 1);
69 pcx.ymax = TO_LE16(h - 1);
70 pcx.hdpi = TO_LE16(320);
71 pcx.vdpi = TO_LE16(320);
74 pcx.cpal = TO_LE16(1);
75 pcx.width = pcx.pitch = TO_LE16(w);
76 pcx.height = TO_LE16(h);
79 if (fwrite(&pcx,
sizeof(pcx), 1, f) != 1) {
84 maxlines =
Clamp(65536 / w, 16, 128);
87 std::vector<uint8_t> buff(
static_cast<size_t>(w) * maxlines);
92 uint n = std::min(h - y, maxlines);
96 callb(userdata, buff.data(), y, w, n);
100 for (i = 0; i != n; i++) {
101 const uint8_t *bufp = buff.data() + i * w;
102 uint8_t runchar = bufp[0];
107 for (j = 1; j < w; j++) {
108 uint8_t ch = bufp[j];
110 if (ch != runchar || runcount >= 0x3f) {
111 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
112 if (fputc(0xC0 | runcount, f) == EOF) {
116 if (fputc(runchar, f) == EOF) {
126 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
127 if (fputc(0xC0 | runcount, f) == EOF) {
131 if (fputc(runchar, f) == EOF) {
138 if (fputc(12, f) == EOF) {
143 uint8_t tmp[256 * 3];
145 for (uint i = 0; i < 256; i++) {
146 tmp[i * 3 + 0] = palette[i].r;
147 tmp[i * 3 + 1] = palette[i].g;
148 tmp[i * 3 + 2] = palette[i].b;
150 success = fwrite(tmp,
sizeof(tmp), 1, f) == 1;
#define Debug(category, level, format_string,...)
Output a line of debugging information.
void(void *userdata, void *buf, uint y, uint pitch, uint n) ScreenshotCallback
Callback function signature for generating lines of pixel data to be written to the screenshot file.