OpenTTD Source: src/screenshot.cpp Source File

OpenTTD Source 14.1

screenshot.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "core/backup_type.hpp"
12 #include "fileio_func.h"
13 #include "viewport_func.h"
14 #include "gfx_func.h"
15 #include "screenshot.h"
16 #include "screenshot_gui.h"
17 #include "blitter/factory.hpp"
18 #include "zoom_func.h"
19 #include "core/endian_func.hpp"
20 #include "saveload/saveload.h"
21 #include "company_base.h"
22 #include "company_func.h"
23 #include "strings_func.h"
24 #include "error.h"
25 #include "textbuf_gui.h"
26 #include "window_gui.h"
27 #include "window_func.h"
28 #include "tile_map.h"
29 #include "landscape.h"
30 #include "video/video_driver.hpp"
31 #include "smallmap_gui.h"
32
33 #include "table/strings.h"
34
35 #include "safeguards.h"
36
37 static const char * const SCREENSHOT_NAME = "screenshot";
38 static const char * const HEIGHTMAP_NAME = "heightmap";
39
40 std::string _screenshot_format_name;
41 uint _num_screenshot_formats;
42 uint _cur_screenshot_format;
43 static std::string _screenshot_name;
44 std::string _full_screenshot_path;
45 uint _heightmap_highest_peak;
46
55 typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n);
56
68 typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
69
71 struct ScreenshotFormat {
72 const char *extension;
73 ScreenshotHandlerProc *proc;
74 };
75
76 #define MKCOLOUR(x) TO_LE32X(x)
77
78 /*************************************************
79 **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
80 *************************************************/
81
83 PACK(struct BitmapFileHeader {
84 uint16_t type;
85 uint32_t size;
86 uint32_t reserved;
87 uint32_t off_bits;
88 });
89 static_assert(sizeof(BitmapFileHeader) == 14);
90
92 struct BitmapInfoHeader {
93 uint32_t size;
94 int32_t width, height;
95 uint16_t planes, bitcount;
96 uint32_t compression, sizeimage, xpels, ypels, clrused, clrimp;
97 };
98 static_assert(sizeof(BitmapInfoHeader) == 40);
99
101 struct RgbQuad {
102 byte blue, green, red, reserved;
103 };
104 static_assert(sizeof(RgbQuad) == 4);
105
118 static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
119 {
120 uint bpp; // bytes per pixel
121 switch (pixelformat) {
122 case 8: bpp = 1; break;
123 /* 32bpp mode is saved as 24bpp BMP */
124 case 32: bpp = 3; break;
125 /* Only implemented for 8bit and 32bit images so far */
126 default: return false;
127 }
128
129 FILE *f = fopen(name, "wb");
130 if (f == nullptr) return false;
131
132 /* Each scanline must be aligned on a 32bit boundary */
133 uint bytewidth = Align(w * bpp, 4); // bytes per line in file
134
135 /* Size of palette. Only present for 8bpp mode */
136 uint pal_size = pixelformat == 8 ? sizeof(RgbQuad) * 256 : 0;
137
138 /* Setup the file header */
139 BitmapFileHeader bfh;
140 bfh.type = TO_LE16('MB');
141 bfh.size = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size + static_cast<size_t>(bytewidth) * h);
142 bfh.reserved = 0;
143 bfh.off_bits = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size);
144
145 /* Setup the info header */
146 BitmapInfoHeader bih;
147 bih.size = TO_LE32(sizeof(BitmapInfoHeader));
148 bih.width = TO_LE32(w);
149 bih.height = TO_LE32(h);
150 bih.planes = TO_LE16(1);
151 bih.bitcount = TO_LE16(bpp * 8);
152 bih.compression = 0;
153 bih.sizeimage = 0;
154 bih.xpels = 0;
155 bih.ypels = 0;
156 bih.clrused = 0;
157 bih.clrimp = 0;
158
159 /* Write file header and info header */
160 if (fwrite(&bfh, sizeof(bfh), 1, f) != 1 || fwrite(&bih, sizeof(bih), 1, f) != 1) {
161 fclose(f);
162 return false;
163 }
164
165 if (pixelformat == 8) {
166 /* Convert the palette to the windows format */
167 RgbQuad rq[256];
168 for (uint i = 0; i < 256; i++) {
169 rq[i].red = palette[i].r;
170 rq[i].green = palette[i].g;
171 rq[i].blue = palette[i].b;
172 rq[i].reserved = 0;
173 }
174 /* Write the palette */
175 if (fwrite(rq, sizeof(rq), 1, f) != 1) {
176 fclose(f);
177 return false;
178 }
179 }
180
181 /* Try to use 64k of memory, store between 16 and 128 lines */
182 uint maxlines = Clamp(65536 / (w * pixelformat / 8), 16, 128); // number of lines per iteration
183
184 uint8_t *buff = MallocT<uint8_t>(maxlines * w * pixelformat / 8); // buffer which is rendered to
185 uint8_t *line = CallocT<uint8_t>(bytewidth); // one line, stored to file
186
187 /* Start at the bottom, since bitmaps are stored bottom up */
188 do {
189 uint n = std::min(h, maxlines);
190 h -= n;
191
192 /* Render the pixels */
193 callb(userdata, buff, h, w, n);
194
195 /* Write each line */
196 while (n-- != 0) {
197 if (pixelformat == 8) {
198 /* Move to 'line', leave last few pixels in line zeroed */
199 memcpy(line, buff + n * w, w);
200 } else {
201 /* Convert from 'native' 32bpp to BMP-like 24bpp.
202 * Works for both big and little endian machines */
203 Colour *src = ((Colour *)buff) + n * w;
204 byte *dst = line;
205 for (uint i = 0; i < w; i++) {
206 dst[i * 3 ] = src[i].b;
207 dst[i * 3 + 1] = src[i].g;
208 dst[i * 3 + 2] = src[i].r;
209 }
210 }
211 /* Write to file */
212 if (fwrite(line, bytewidth, 1, f) != 1) {
213 free(line);
214 free(buff);
215 fclose(f);
216 return false;
217 }
218 }
219 } while (h != 0);
220
221 free(line);
222 free(buff);
223 fclose(f);
224
225 return true;
226 }
227
228 /*********************************************************
229 **** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG)
230 *********************************************************/
231 #if defined(WITH_PNG)
232 #include <png.h>
233
234 #ifdef PNG_TEXT_SUPPORTED
235 #include "rev.h"
236 #include "newgrf_config.h"
237 #include "ai/ai_info.hpp"
238 #include "company_base.h"
239 #include "base_media_base.h"
240 #endif /* PNG_TEXT_SUPPORTED */
241
242 static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
243 {
244 Debug(misc, 0, "[libpng] error: {} - {}", message, (const char *)png_get_error_ptr(png_ptr));
245 longjmp(png_jmpbuf(png_ptr), 1);
246 }
247
248 static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
249 {
250 Debug(misc, 1, "[libpng] warning: {} - {}", message, (const char *)png_get_error_ptr(png_ptr));
251 }
252
265 static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
266 {
267 png_color rq[256];
268 FILE *f;
269 uint i, y, n;
270 uint maxlines;
271 uint bpp = pixelformat / 8;
272 png_structp png_ptr;
273 png_infop info_ptr;
274
275 /* only implemented for 8bit and 32bit images so far. */
276 if (pixelformat != 8 && pixelformat != 32) return false;
277
278 f = fopen(name, "wb");
279 if (f == nullptr) return false;
280
281 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, const_cast<char *>(name), png_my_error, png_my_warning);
282
283 if (png_ptr == nullptr) {
284 fclose(f);
285 return false;
286 }
287
288 info_ptr = png_create_info_struct(png_ptr);
289 if (info_ptr == nullptr) {
290 png_destroy_write_struct(&png_ptr, (png_infopp)nullptr);
291 fclose(f);
292 return false;
293 }
294
295 if (setjmp(png_jmpbuf(png_ptr))) {
296 png_destroy_write_struct(&png_ptr, &info_ptr);
297 fclose(f);
298 return false;
299 }
300
301 png_init_io(png_ptr, f);
302
303 png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
304
305 png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB,
306 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
307
308 #ifdef PNG_TEXT_SUPPORTED
309 /* Try to add some game metadata to the PNG screenshot so
310 * it's more useful for debugging and archival purposes. */
311 png_text_struct text[2];
312 memset(text, 0, sizeof(text));
313 text[0].key = const_cast<char *>("Software");
314 text[0].text = const_cast<char *>(_openttd_revision);
315 text[0].text_length = strlen(_openttd_revision);
316 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
317
318 std::string message;
319 message.reserve(1024);
320 fmt::format_to(std::back_inserter(message), "Graphics set: {} ({})\n", BaseGraphics::GetUsedSet()->name, BaseGraphics::GetUsedSet()->version);
321 message += "NewGRFs:\n";
322 for (const GRFConfig *c = _game_mode == GM_MENU ? nullptr : _grfconfig; c != nullptr; c = c->next) {
323 fmt::format_to(std::back_inserter(message), "{:08X} {} {}\n", BSWAP32(c->ident.grfid), FormatArrayAsHex(c->ident.md5sum), c->filename);
324 }
325 message += "\nCompanies:\n";
326 for (const Company *c : Company::Iterate()) {
327 if (c->ai_info == nullptr) {
328 fmt::format_to(std::back_inserter(message), "{:2d}: Human\n", (int)c->index);
329 } else {
330 fmt::format_to(std::back_inserter(message), "{:2d}: {} (v{})\n", (int)c->index, c->ai_info->GetName(), c->ai_info->GetVersion());
331 }
332 }
333 text[1].key = const_cast<char *>("Description");
334 text[1].text = const_cast<char *>(message.c_str());
335 text[1].text_length = message.size();
336 text[1].compression = PNG_TEXT_COMPRESSION_zTXt;
337 png_set_text(png_ptr, info_ptr, text, 2);
338 #endif /* PNG_TEXT_SUPPORTED */
339
340 if (pixelformat == 8) {
341 /* convert the palette to the .PNG format. */
342 for (i = 0; i != 256; i++) {
343 rq[i].red = palette[i].r;
344 rq[i].green = palette[i].g;
345 rq[i].blue = palette[i].b;
346 }
347
348 png_set_PLTE(png_ptr, info_ptr, rq, 256);
349 }
350
351 png_write_info(png_ptr, info_ptr);
352 png_set_flush(png_ptr, 512);
353
354 if (pixelformat == 32) {
355 png_color_8 sig_bit;
356
357 /* Save exact colour/alpha resolution */
358 sig_bit.alpha = 0;
359 sig_bit.blue = 8;
360 sig_bit.green = 8;
361 sig_bit.red = 8;
362 sig_bit.gray = 8;
363 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
364
365 #if TTD_ENDIAN == TTD_LITTLE_ENDIAN
366 png_set_bgr(png_ptr);
367 png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
368 #else
369 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
370 #endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */
371 }
372
373 /* use by default 64k temp memory */
374 maxlines = Clamp(65536 / w, 16, 128);
375
376 /* now generate the bitmap bits */
377 void *buff = CallocT<uint8_t>(static_cast<size_t>(w) * maxlines * bpp); // by default generate 128 lines at a time.
378
379 y = 0;
380 do {
381 /* determine # lines to write */
382 n = std::min(h - y, maxlines);
383
384 /* render the pixels into the buffer */
385 callb(userdata, buff, y, w, n);
386 y += n;
387
388 /* write them to png */
389 for (i = 0; i != n; i++) {
390 png_write_row(png_ptr, (png_bytep)buff + i * w * bpp);
391 }
392 } while (y != h);
393
394 png_write_end(png_ptr, info_ptr);
395 png_destroy_write_struct(&png_ptr, &info_ptr);
396
397 free(buff);
398 fclose(f);
399 return true;
400 }
401 #endif /* WITH_PNG */
402
403
404 /*************************************************
405 **** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX)
406 *************************************************/
407
409 struct PcxHeader {
410 byte manufacturer;
411 byte version;
412 byte rle;
413 byte bpp;
414 uint32_t unused;
415 uint16_t xmax, ymax;
416 uint16_t hdpi, vdpi;
417 byte pal_small[16 * 3];
418 byte reserved;
419 byte planes;
420 uint16_t pitch;
421 uint16_t cpal;
422 uint16_t width;
423 uint16_t height;
424 byte filler[54];
425 };
426 static_assert(sizeof(PcxHeader) == 128);
427
440 static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
441 {
442 FILE *f;
443 uint maxlines;
444 uint y;
445 PcxHeader pcx;
446 bool success;
447
448 if (pixelformat == 32) {
449 Debug(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick another format.");
450 return false;
451 }
452 if (pixelformat != 8 || w == 0) return false;
453
454 f = fopen(name, "wb");
455 if (f == nullptr) return false;
456
457 memset(&pcx, 0, sizeof(pcx));
458
459 /* setup pcx header */
460 pcx.manufacturer = 10;
461 pcx.version = 5;
462 pcx.rle = 1;
463 pcx.bpp = 8;
464 pcx.xmax = TO_LE16(w - 1);
465 pcx.ymax = TO_LE16(h - 1);
466 pcx.hdpi = TO_LE16(320);
467 pcx.vdpi = TO_LE16(320);
468
469 pcx.planes = 1;
470 pcx.cpal = TO_LE16(1);
471 pcx.width = pcx.pitch = TO_LE16(w);
472 pcx.height = TO_LE16(h);
473
474 /* write pcx header */
475 if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) {
476 fclose(f);
477 return false;
478 }
479
480 /* use by default 64k temp memory */
481 maxlines = Clamp(65536 / w, 16, 128);
482
483 /* now generate the bitmap bits */
484 uint8_t *buff = CallocT<uint8_t>(static_cast<size_t>(w) * maxlines); // by default generate 128 lines at a time.
485
486 y = 0;
487 do {
488 /* determine # lines to write */
489 uint n = std::min(h - y, maxlines);
490 uint i;
491
492 /* render the pixels into the buffer */
493 callb(userdata, buff, y, w, n);
494 y += n;
495
496 /* write them to pcx */
497 for (i = 0; i != n; i++) {
498 const uint8_t *bufp = buff + i * w;
499 byte runchar = bufp[0];
500 uint runcount = 1;
501 uint j;
502
503 /* for each pixel... */
504 for (j = 1; j < w; j++) {
505 uint8_t ch = bufp[j];
506
507 if (ch != runchar || runcount >= 0x3f) {
508 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
509 if (fputc(0xC0 | runcount, f) == EOF) {
510 free(buff);
511 fclose(f);
512 return false;
513 }
514 }
515 if (fputc(runchar, f) == EOF) {
516 free(buff);
517 fclose(f);
518 return false;
519 }
520 runcount = 0;
521 runchar = ch;
522 }
523 runcount++;
524 }
525
526 /* write remaining bytes.. */
527 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
528 if (fputc(0xC0 | runcount, f) == EOF) {
529 free(buff);
530 fclose(f);
531 return false;
532 }
533 }
534 if (fputc(runchar, f) == EOF) {
535 free(buff);
536 fclose(f);
537 return false;
538 }
539 }
540 } while (y != h);
541
542 free(buff);
543
544 /* write 8-bit colour palette */
545 if (fputc(12, f) == EOF) {
546 fclose(f);
547 return false;
548 }
549
550 /* Palette is word-aligned, copy it to a temporary byte array */
551 byte tmp[256 * 3];
552
553 for (uint i = 0; i < 256; i++) {
554 tmp[i * 3 + 0] = palette[i].r;
555 tmp[i * 3 + 1] = palette[i].g;
556 tmp[i * 3 + 2] = palette[i].b;
557 }
558 success = fwrite(tmp, sizeof(tmp), 1, f) == 1;
559
560 fclose(f);
561
562 return success;
563 }
564
565 /*************************************************
566 **** GENERIC SCREENSHOT CODE
567 *************************************************/
568
570 static const ScreenshotFormat _screenshot_formats[] = {
571 #if defined(WITH_PNG)
572 {"png", &MakePNGImage},
573 #endif
574 {"bmp", &MakeBMPImage},
575 {"pcx", &MakePCXImage},
576 };
577
579 const char *GetCurrentScreenshotExtension()
580 {
581 return _screenshot_formats[_cur_screenshot_format].extension;
582 }
583
585 void InitializeScreenshotFormats()
586 {
587 uint j = 0;
588 for (uint i = 0; i < lengthof(_screenshot_formats); i++) {
589 if (_screenshot_format_name.compare(_screenshot_formats[i].extension) == 0) {
590 j = i;
591 break;
592 }
593 }
594 _cur_screenshot_format = j;
595 _num_screenshot_formats = lengthof(_screenshot_formats);
596 }
597
602 static void CurrentScreenCallback(void *, void *buf, uint y, uint pitch, uint n)
603 {
604 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
605 void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
606 blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch);
607 }
608
617 static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
618 {
619 Viewport *vp = (Viewport *)userdata;
620 DrawPixelInfo dpi;
621 int wx, left;
622
623 /* We are no longer rendering to the screen */
624 DrawPixelInfo old_screen = _screen;
625 bool old_disable_anim = _screen_disable_anim;
626
627 _screen.dst_ptr = buf;
628 _screen.width = pitch;
629 _screen.height = n;
630 _screen.pitch = pitch;
631 _screen_disable_anim = true;
632
633 AutoRestoreBackup dpi_backup(_cur_dpi, &dpi);
634
635 dpi.dst_ptr = buf;
636 dpi.height = n;
637 dpi.width = vp->width;
638 dpi.pitch = pitch;
639 dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT;
640 dpi.left = 0;
641 dpi.top = y;
642
643 /* Render viewport in blocks of 1600 pixels width */
644 left = 0;
645 while (vp->width - left != 0) {
646 wx = std::min(vp->width - left, 1600);
647 left += wx;
648
649 ViewportDoDraw(vp,
650 ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left,
651 ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top,
652 ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
653 ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top
654 );
655 }
656
657 /* Switch back to rendering to the screen */
658 _screen = old_screen;
659 _screen_disable_anim = old_disable_anim;
660 }
661
669 static const char *MakeScreenshotName(const char *default_fn, const char *ext, bool crashlog = false)
670 {
671 bool generate = _screenshot_name.empty();
672
673 if (generate) {
674 if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
675 _screenshot_name = default_fn;
676 } else {
677 _screenshot_name = GenerateDefaultSaveName();
678 }
679 }
680
681 /* Handle user-specified filenames ending in # with automatic numbering */
682 if (_screenshot_name.ends_with("#")) {
683 generate = true;
684 _screenshot_name.pop_back();
685 }
686
687 size_t len = _screenshot_name.size();
688 /* Add extension to screenshot file */
689 _screenshot_name += fmt::format(".{}", ext);
690
691 const char *screenshot_dir = crashlog ? _personal_dir.c_str() : FiosGetScreenshotDir();
692
693 for (uint serial = 1;; serial++) {
694 _full_screenshot_path = fmt::format("{}{}", screenshot_dir, _screenshot_name);
695
696 if (!generate) break; // allow overwriting of non-automatic filenames
697 if (!FileExists(_full_screenshot_path)) break;
698 /* If file exists try another one with same name, but just with a higher index */
699 _screenshot_name.erase(len);
700 _screenshot_name += fmt::format("#{}.{}", serial, ext);
701 }
702
703 return _full_screenshot_path.c_str();
704 }
705
707 static bool MakeSmallScreenshot(bool crashlog)
708 {
709 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
710 return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension, crashlog), CurrentScreenCallback, nullptr, _screen.width, _screen.height,
711 BlitterFactory::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
712 }
713
721 void SetupScreenshotViewport(ScreenshotType t, Viewport *vp, uint32_t width, uint32_t height)
722 {
723 switch(t) {
724 case SC_VIEWPORT:
725 case SC_CRASHLOG: {
726 assert(width == 0 && height == 0);
727
728 Window *w = GetMainWindow();
729 vp->virtual_left = w->viewport->virtual_left;
730 vp->virtual_top = w->viewport->virtual_top;
731 vp->virtual_width = w->viewport->virtual_width;
732 vp->virtual_height = w->viewport->virtual_height;
733
734 /* Compute pixel coordinates */
735 vp->left = 0;
736 vp->top = 0;
737 vp->width = _screen.width;
738 vp->height = _screen.height;
739 vp->overlay = w->viewport->overlay;
740 break;
741 }
742 case SC_WORLD: {
743 assert(width == 0 && height == 0);
744
745 /* Determine world coordinates of screenshot */
746 vp->zoom = ZOOM_LVL_WORLD_SCREENSHOT;
747
748 TileIndex north_tile = _settings_game.construction.freeform_edges ? TileXY(1, 1) : TileXY(0, 0);
749 TileIndex south_tile = Map::Size() - 1;
750
751 /* We need to account for a hill or high building at tile 0,0. */
752 int extra_height_top = TilePixelHeight(north_tile) + 150;
753 /* If there is a hill at the bottom don't create a large black area. */
754 int reclaim_height_bottom = TilePixelHeight(south_tile);
755
756 vp->virtual_left = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, 0).x;
757 vp->virtual_top = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, extra_height_top).y;
758 vp->virtual_width = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, 0).x - vp->virtual_left + 1;
759 vp->virtual_height = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, reclaim_height_bottom).y - vp->virtual_top + 1;
760
761 /* Compute pixel coordinates */
762 vp->left = 0;
763 vp->top = 0;
764 vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
765 vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
766 vp->overlay = nullptr;
767 break;
768 }
769 default: {
770 vp->zoom = (t == SC_ZOOMEDIN) ? _settings_client.gui.zoom_min : ZOOM_LVL_VIEWPORT;
771
772 Window *w = GetMainWindow();
773 vp->virtual_left = w->viewport->virtual_left;
774 vp->virtual_top = w->viewport->virtual_top;
775
776 if (width == 0 || height == 0) {
777 vp->virtual_width = w->viewport->virtual_width;
778 vp->virtual_height = w->viewport->virtual_height;
779 } else {
780 vp->virtual_width = width << vp->zoom;
781 vp->virtual_height = height << vp->zoom;
782 }
783
784 /* Compute pixel coordinates */
785 vp->left = 0;
786 vp->top = 0;
787 vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
788 vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
789 vp->overlay = nullptr;
790 break;
791 }
792 }
793 }
794
802 static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32_t width = 0, uint32_t height = 0)
803 {
804 Viewport vp;
805 SetupScreenshotViewport(t, &vp, width, height);
806
807 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
808 return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), LargeWorldCallback, &vp, vp.width, vp.height,
809 BlitterFactory::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
810 }
811
819 static void HeightmapCallback(void *, void *buffer, uint y, uint, uint n)
820 {
821 byte *buf = (byte *)buffer;
822 while (n > 0) {
823 TileIndex ti = TileXY(Map::MaxX(), y);
824 for (uint x = Map::MaxX(); true; x--) {
825 *buf = 256 * TileHeight(ti) / (1 + _heightmap_highest_peak);
826 buf++;
827 if (x == 0) break;
828 ti = TILE_ADDXY(ti, -1, 0);
829 }
830 y++;
831 n--;
832 }
833 }
834
839 bool MakeHeightmapScreenshot(const char *filename)
840 {
841 Colour palette[256];
842 for (uint i = 0; i < lengthof(palette); i++) {
843 palette[i].a = 0xff;
844 palette[i].r = i;
845 palette[i].g = i;
846 palette[i].b = i;
847 }
848
849 _heightmap_highest_peak = 0;
850 for (TileIndex tile = 0; tile < Map::Size(); tile++) {
851 uint h = TileHeight(tile);
852 _heightmap_highest_peak = std::max(h, _heightmap_highest_peak);
853 }
854
855 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
856 return sf->proc(filename, HeightmapCallback, nullptr, Map::SizeX(), Map::SizeY(), 8, palette);
857 }
858
859 static ScreenshotType _confirmed_screenshot_type;
860
865 static void ScreenshotConfirmationCallback(Window *, bool confirmed)
866 {
867 if (confirmed) MakeScreenshot(_confirmed_screenshot_type, {});
868 }
869
876 void MakeScreenshotWithConfirm(ScreenshotType t)
877 {
878 Viewport vp;
879 SetupScreenshotViewport(t, &vp);
880
881 bool heightmap_or_minimap = t == SC_HEIGHTMAP || t == SC_MINIMAP;
882 uint64_t width = (heightmap_or_minimap ? Map::SizeX() : vp.width);
883 uint64_t height = (heightmap_or_minimap ? Map::SizeY() : vp.height);
884
885 if (width * height > 8192 * 8192) {
886 /* Ask for confirmation */
887 _confirmed_screenshot_type = t;
888 SetDParam(0, width);
889 SetDParam(1, height);
890 ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback);
891 } else {
892 /* Less than 64M pixels, just do it */
893 MakeScreenshot(t, {});
894 }
895 }
896
905 static bool RealMakeScreenshot(ScreenshotType t, std::string name, uint32_t width, uint32_t height)
906 {
907 if (t == SC_VIEWPORT) {
908 /* First draw the dirty parts of the screen and only then change the name
909 * of the screenshot. This way the screenshot will always show the name
910 * of the previous screenshot in the 'successful' message instead of the
911 * name of the new screenshot (or an empty name). */
912 SetScreenshotWindowVisibility(true);
913 UndrawMouseCursor();
914 DrawDirtyBlocks();
915 SetScreenshotWindowVisibility(false);
916 }
917
918 _screenshot_name = name;
919
920 bool ret;
921 switch (t) {
922 case SC_VIEWPORT:
923 ret = MakeSmallScreenshot(false);
924 break;
925
926 case SC_CRASHLOG:
927 ret = MakeSmallScreenshot(true);
928 break;
929
930 case SC_ZOOMEDIN:
931 case SC_DEFAULTZOOM:
932 ret = MakeLargeWorldScreenshot(t, width, height);
933 break;
934
935 case SC_WORLD:
936 ret = MakeLargeWorldScreenshot(t);
937 break;
938
939 case SC_HEIGHTMAP: {
940 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
941 ret = MakeHeightmapScreenshot(MakeScreenshotName(HEIGHTMAP_NAME, sf->extension));
942 break;
943 }
944
945 case SC_MINIMAP:
946 ret = MakeMinimapWorldScreenshot();
947 break;
948
949 default:
950 NOT_REACHED();
951 }
952
953 if (ret) {
954 if (t == SC_HEIGHTMAP) {
955 SetDParamStr(0, _screenshot_name);
956 SetDParam(1, _heightmap_highest_peak);
957 ShowErrorMessage(STR_MESSAGE_HEIGHTMAP_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
958 } else {
959 SetDParamStr(0, _screenshot_name);
960 ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
961 }
962 } else {
963 ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, WL_ERROR);
964 }
965
966 return ret;
967 }
968
979 bool MakeScreenshot(ScreenshotType t, std::string name, uint32_t width, uint32_t height)
980 {
981 if (t == SC_CRASHLOG) {
982 /* Video buffer might or might not be locked. */
983 VideoDriver::VideoBufferLocker lock;
984
985 return RealMakeScreenshot(t, name, width, height);
986 }
987
988 VideoDriver::GetInstance()->QueueOnMainThread([=] { // Capture by value to not break scope.
989 RealMakeScreenshot(t, name, width, height);
990 });
991
992 return true;
993 }
994
995
996 static void MinimapScreenCallback(void *, void *buf, uint y, uint pitch, uint n)
997 {
998 uint32_t *ubuf = (uint32_t *)buf;
999 uint num = (pitch * n);
1000 for (uint i = 0; i < num; i++) {
1001 uint row = y + (int)(i / pitch);
1002 uint col = (Map::SizeX() - 1) - (i % pitch);
1003
1004 TileIndex tile = TileXY(col, row);
1005 byte val = GetSmallMapOwnerPixels(tile, GetTileType(tile), IncludeHeightmap::Never) & 0xFF;
1006
1007 uint32_t colour_buf = 0;
1008 colour_buf = (_cur_palette.palette[val].b << 0);
1009 colour_buf |= (_cur_palette.palette[val].g << 8);
1010 colour_buf |= (_cur_palette.palette[val].r << 16);
1011
1012 *ubuf = colour_buf;
1013 ubuf++; // Skip alpha
1014 }
1015 }
1016
1020 bool MakeMinimapWorldScreenshot()
1021 {
1022 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
1023 return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), MinimapScreenCallback, nullptr, Map::SizeX(), Map::SizeY(), 32, _cur_palette.palette);
1024 }
_cur_palette
Palette _cur_palette
Current palette.
Definition: palette.cpp:24
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
RgbQuad
Format of palette data in BMP header.
Definition: screenshot.cpp:101
factory.hpp
FormatArrayAsHex
std::string FormatArrayAsHex(std::span< const byte > data)
Format a byte array into a continuous hex string.
Definition: string.cpp:88
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
Definition: misc_gui.cpp:1231
ScreenshotType
ScreenshotType
Type of requested screenshot.
Definition: screenshot.h:18
_personal_dir
std::string _personal_dir
custom directory for personal settings, saves, newgrf, etc.
Definition: fileio.cpp:966
endian_func.hpp
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
PcxHeader
Definition of a PCX file header.
Definition: screenshot.cpp:409
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:25
smallmap_gui.h
Map::MaxX
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:297
company_base.h
lock
std::mutex lock
synchronization for playback status fields
Definition: win32_m.cpp:35
Blitter
How all blitters should look like.
Definition: base.hpp:29
Viewport::width
int width
Screen width of the viewport.
Definition: viewport_type.h:25
SC_HEIGHTMAP
@ SC_HEIGHTMAP
Heightmap of the world.
Definition: screenshot.h:24
HeightmapCallback
static void HeightmapCallback(void *, void *buffer, uint y, uint, uint n)
Callback for generating a heightmap.
Definition: screenshot.cpp:819
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:312
Viewport::height
int height
Screen height of the viewport.
Definition: viewport_type.h:26
Blitter::GetScreenDepth
virtual uint8_t GetScreenDepth()=0
Get the screen depth this blitter works for.
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition: viewport_type.h:24
_screenshot_format_name
std::string _screenshot_format_name
Extension of the current screenshot format (corresponds with _cur_screenshot_format).
Definition: screenshot.cpp:40
screenshot_gui.h
BitmapInfoHeader
BMP Info Header (stored in little endian)
Definition: screenshot.cpp:92
saveload.h
zoom_func.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
fileio_func.h
base_media_base.h
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
ScreenshotConfirmationCallback
static void ScreenshotConfirmationCallback(Window *, bool confirmed)
Callback on the confirmation window for huge screenshots.
Definition: screenshot.cpp:865
SC_ZOOMEDIN
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:21
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
newgrf_config.h
ScreenshotFormat::extension
const char * extension
File extension.
Definition: screenshot.cpp:72
Viewport::virtual_top
int virtual_top
Virtual top coordinate.
Definition: viewport_type.h:29
MakeHeightmapScreenshot
bool MakeHeightmapScreenshot(const char *filename)
Make a heightmap of the current map.
Definition: screenshot.cpp:839
InitializeScreenshotFormats
void InitializeScreenshotFormats()
Initialize screenshot format information on startup, with _screenshot_format_name filled from the loa...
Definition: screenshot.cpp:585
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
textbuf_gui.h
ai_info.hpp
screenshot.h
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
gfx_func.h
_confirmed_screenshot_type
static ScreenshotType _confirmed_screenshot_type
Screenshot type the current query is about to confirm.
Definition: screenshot.cpp:859
window_gui.h
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
tile_map.h
BSWAP32
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:345
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:147
Viewport::virtual_left
int virtual_left
Virtual left coordinate.
Definition: viewport_type.h:28
free
void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:382
_screen_disable_anim
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
Definition: gfx.cpp:45
Viewport::left
int left
Screen coordinate left edge of the viewport.
Definition: viewport_type.h:23
Palette::palette
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:324
FileExists
bool FileExists(const std::string &filename)
Test whether the given filename exists.
Definition: fileio.cpp:141
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:138
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
safeguards.h
GenerateDefaultSaveName
std::string GenerateDefaultSaveName()
Get the default name for a savegame or screenshot.
Definition: saveload.cpp:3169
ScreenshotHandlerProc
bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Function signature for a screenshot generation routine for one of the available formats.
Definition: screenshot.cpp:68
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:303
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:382
PACK
PACK(struct BitmapFileHeader { uint16_t type;uint32_t size;uint32_t reserved;uint32_t off_bits;})
BMP File Header (stored in little endian)
ScreenshotFormat
Screenshot format information.
Definition: screenshot.cpp:71
DrawDirtyBlocks
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
Definition: gfx.cpp:1416
ScreenshotCallback
void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
Callback function signature for generating lines of pixel data to be written to the screenshot file.
Definition: screenshot.cpp:55
_num_screenshot_formats
uint _num_screenshot_formats
Number of available screenshot formats.
Definition: screenshot.cpp:41
MakeScreenshotName
static const char * MakeScreenshotName(const char *default_fn, const char *ext, bool crashlog=false)
Construct a pathname for a screenshot file.
Definition: screenshot.cpp:669
Viewport::virtual_width
int virtual_width
width << zoom
Definition: viewport_type.h:30
ZOOM_LVL_WORLD_SCREENSHOT
@ ZOOM_LVL_WORLD_SCREENSHOT
Default zoom level for the world screen shot.
Definition: zoom_type.h:39
error.h
VideoDriver::QueueOnMainThread
void QueueOnMainThread(std::function< void()> &&func)
Queue a function to be called on the main thread with game state lock held and video buffer locked.
Definition: video_driver.hpp:189
stdafx.h
ZOOM_LVL_VIEWPORT
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.
Definition: zoom_type.h:31
landscape.h
ScreenshotFormat::proc
ScreenshotHandlerProc * proc
Function for writing the screenshot.
Definition: screenshot.cpp:73
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:201
viewport_func.h
Blitter::CopyImageToBuffer
virtual void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)=0
Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp.
Colour
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:159
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:157
Map::SizeX
static debug_inline uint SizeX()
Get the size of the map along the X.
Definition: map_func.h:270
LargeWorldCallback
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
generate a large piece of the world
Definition: screenshot.cpp:617
_screenshot_formats
static const ScreenshotFormat _screenshot_formats[]
Available screenshot formats.
Definition: screenshot.cpp:570
TilePixelHeight
uint TilePixelHeight(Tile tile)
Returns the height of a tile in pixels.
Definition: tile_map.h:72
SetScreenshotWindowVisibility
void SetScreenshotWindowVisibility(bool hide)
Set the visibility of the screenshot window when taking a screenshot.
Definition: screenshot_gui.cpp:80
rev.h
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
MakeBMPImage
static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Generic .BMP writer.
Definition: screenshot.cpp:118
strings_func.h
UnScaleByZoom
int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:34
SC_WORLD
@ SC_WORLD
World screenshot.
Definition: screenshot.h:23
MakePCXImage
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Generic .PCX file image writer.
Definition: screenshot.cpp:440
HEIGHTMAP_NAME
static const char *const HEIGHTMAP_NAME
Default filename of a saved heightmap.
Definition: screenshot.cpp:38
SetupScreenshotViewport
void SetupScreenshotViewport(ScreenshotType t, Viewport *vp, uint32_t width, uint32_t height)
Configure a Viewport for rendering (a part of) the map into a screenshot.
Definition: screenshot.cpp:721
Blitter::MoveTo
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
Map::Size
static debug_inline uint Size()
Get the size of the map.
Definition: map_func.h:288
video_driver.hpp
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
GetMainWindow
Window * GetMainWindow()
Get the main window, i.e.
Definition: window.cpp:1128
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:174
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:153
RealMakeScreenshot
static bool RealMakeScreenshot(ScreenshotType t, std::string name, uint32_t width, uint32_t height)
Make a screenshot.
Definition: screenshot.cpp:905
MakePNGImage
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Generic .PNG file image writer.
Definition: screenshot.cpp:265
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
SC_DEFAULTZOOM
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
Definition: screenshot.h:22
MakeSmallScreenshot
static bool MakeSmallScreenshot(bool crashlog)
Make a screenshot of the current screen.
Definition: screenshot.cpp:707
company_func.h
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:26
MakeMinimapWorldScreenshot
bool MakeMinimapWorldScreenshot()
Make a minimap screenshot.
Definition: screenshot.cpp:1020
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:480
_grfconfig
GRFConfig * _grfconfig
First item in list of current GRF set up.
Definition: newgrf_config.cpp:164
_cur_screenshot_format
uint _cur_screenshot_format
Index of the currently selected screenshot format in _screenshot_formats.
Definition: screenshot.cpp:42
window_func.h
GetCurrentScreenshotExtension
const char * GetCurrentScreenshotExtension()
Get filename extension of current screenshot file format.
Definition: screenshot.cpp:579
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:385
TileHeight
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition: tile_map.h:29
SC_VIEWPORT
@ SC_VIEWPORT
Screenshot of viewport.
Definition: screenshot.h:19
MakeScreenshotWithConfirm
void MakeScreenshotWithConfirm(ScreenshotType t)
Make a screenshot.
Definition: screenshot.cpp:876
_screenshot_name
static std::string _screenshot_name
Filename of the screenshot file.
Definition: screenshot.cpp:43
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:619
Window
Data structure for an opened window.
Definition: window_gui.h:267
SC_CRASHLOG
@ SC_CRASHLOG
Raw screenshot from blitter buffer.
Definition: screenshot.h:20
BaseMedia< GraphicsSet >::GetUsedSet
static const GraphicsSet * GetUsedSet()
Return the used set.
Definition: base_media_func.h:394
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
IncludeHeightmap::Never
@ Never
Never include the heightmap.
Viewport::virtual_height
int virtual_height
height << zoom
Definition: viewport_type.h:31
MakeScreenshot
bool MakeScreenshot(ScreenshotType t, std::string name, uint32_t width, uint32_t height)
Schedule making a screenshot.
Definition: screenshot.cpp:979
SC_MINIMAP
@ SC_MINIMAP
Minimap screenshot.
Definition: screenshot.h:25
SCREENSHOT_NAME
static const char *const SCREENSHOT_NAME
Default filename of a saved screenshot.
Definition: screenshot.cpp:37
Company
Definition: company_base.h:129
ScaleByZoom
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:22
MakeLargeWorldScreenshot
static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32_t width=0, uint32_t height=0)
Make a screenshot of the map.
Definition: screenshot.cpp:802
_heightmap_highest_peak
uint _heightmap_highest_peak
When saving a heightmap, this contains the highest peak on the map.
Definition: screenshot.cpp:45
VideoDriver::VideoBufferLocker
Helper struct to ensure the video buffer is locked and ready for drawing.
Definition: video_driver.hpp:212
GetSmallMapOwnerPixels
uint32_t GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap)
Return the colour a tile would be displayed with in the small map in mode "Owner".
Definition: smallmap_gui.cpp:582
Align
constexpr T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Definition: math_func.hpp:37
Colour::a
uint8_t a
colour channels in LE order
Definition: gfx_type.h:167
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
Map::SizeY
static uint SizeY()
Get the size of the map along the Y.
Definition: map_func.h:279
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:635
RemapCoords
Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Definition: landscape.h:82
CurrentScreenCallback
static void CurrentScreenCallback(void *, void *buf, uint y, uint pitch, uint n)
Callback of the screenshot generator that dumps the current video buffer.
Definition: screenshot.cpp:602
_full_screenshot_path
std::string _full_screenshot_path
Pathname of the screenshot file.
Definition: screenshot.cpp:44
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
FiosGetScreenshotDir
const char * FiosGetScreenshotDir()
Get the directory for screenshots.
Definition: fios.cpp:597
backup_type.hpp