44 bool MakeImage(std::string_view name,
const ScreenshotCallback &callb, uint w, uint h,
int pixelformat,
const Colour *palette)
override
50 if (pixelformat == 32) {
51 Debug(misc, 0,
"Can't convert a 32bpp screenshot to PCX format. Please pick another format.");
54 if (pixelformat != 8 || w == 0)
return false;
57 if (!of.has_value())
return false;
62 pcx.manufacturer = 10;
66 pcx.xmax = TO_LE16(w - 1);
67 pcx.ymax = TO_LE16(h - 1);
68 pcx.hdpi = TO_LE16(320);
69 pcx.vdpi = TO_LE16(320);
72 pcx.cpal = TO_LE16(1);
73 pcx.width = pcx.pitch = TO_LE16(w);
74 pcx.height = TO_LE16(h);
77 if (fwrite(&pcx,
sizeof(pcx), 1, f) != 1) {
82 maxlines =
Clamp(65536 / w, 16, 128);
85 std::vector<uint8_t> buff(
static_cast<size_t>(w) * maxlines);
90 uint n = std::min(h - y, maxlines);
94 callb(buff.data(), y, w, n);
98 for (i = 0; i != n; i++) {
99 const uint8_t *bufp = buff.data() + i * w;
100 uint8_t runchar = bufp[0];
105 for (j = 1; j < w; j++) {
106 uint8_t ch = bufp[j];
108 if (ch != runchar || runcount >= 0x3f) {
109 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
110 if (fputc(0xC0 | runcount, f) == EOF) {
114 if (fputc(runchar, f) == EOF) {
124 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
125 if (fputc(0xC0 | runcount, f) == EOF) {
129 if (fputc(runchar, f) == EOF) {
136 if (fputc(12, f) == EOF) {
141 uint8_t tmp[256 * 3];
143 for (uint i = 0; i < 256; i++) {
144 tmp[i * 3 + 0] = palette[i].r;
145 tmp[i * 3 + 1] = palette[i].g;
146 tmp[i * 3 + 2] = palette[i].b;
148 success = fwrite(tmp,
sizeof(tmp), 1, f) == 1;
#define Debug(category, level, format_string,...)
Output a line of debugging information.
std::function< void(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.