46 bool MakeImage(
const char *name,
ScreenshotCallback *callb,
void *userdata, uint w, uint h,
int pixelformat,
const Colour *palette)
override
49 switch (pixelformat) {
50 case 8: bpp = 1;
break;
52 case 32: bpp = 3;
break;
54 default:
return false;
58 if (!of.has_value())
return false;
62 uint bytewidth =
Align(w * bpp, 4);
65 uint pal_size = pixelformat == 8 ?
sizeof(
RgbQuad) * 256 : 0;
69 bfh.type = TO_LE16(
'MB');
70 bfh.size = TO_LE32(
sizeof(BitmapFileHeader) +
sizeof(
BitmapInfoHeader) + pal_size +
static_cast<size_t>(bytewidth) * h);
72 bfh.off_bits = TO_LE32(
sizeof(BitmapFileHeader) +
sizeof(
BitmapInfoHeader) + pal_size);
77 bih.width = TO_LE32(w);
78 bih.height = TO_LE32(h);
79 bih.planes = TO_LE16(1);
80 bih.bitcount = TO_LE16(bpp * 8);
89 if (fwrite(&bfh,
sizeof(bfh), 1, f) != 1 || fwrite(&bih,
sizeof(bih), 1, f) != 1) {
93 if (pixelformat == 8) {
96 for (uint i = 0; i < 256; i++) {
97 rq[i].red = palette[i].r;
98 rq[i].green = palette[i].g;
99 rq[i].blue = palette[i].b;
103 if (fwrite(rq,
sizeof(rq), 1, f) != 1) {
109 uint maxlines =
Clamp(65536 / (w * pixelformat / 8), 16, 128);
111 std::vector<uint8_t> buff(maxlines * w * pixelformat / 8);
112 std::vector<uint8_t> line(bytewidth);
116 uint n = std::min(h, maxlines);
120 callb(userdata, buff.data(), h, w, n);
124 if (pixelformat == 8) {
126 memcpy(line.data(), buff.data() + n * w, w);
130 Colour *src = ((Colour *)buff.data()) + n * w;
131 uint8_t *dst = line.data();
132 for (uint i = 0; i < w; i++) {
133 dst[i * 3 ] = src[i].b;
134 dst[i * 3 + 1] = src[i].g;
135 dst[i * 3 + 2] = src[i].r;
139 if (fwrite(line.data(), bytewidth, 1, f) != 1) {
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.