OpenTTD Source: src/screenshot.cpp Source File

OpenTTD Source 13.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 "fileio_func.h"
12 #include "viewport_func.h"
13 #include "gfx_func.h"
14 #include "screenshot.h"
15 #include "screenshot_gui.h"
16 #include "blitter/factory.hpp"
17 #include "zoom_func.h"
18 #include "core/endian_func.hpp"
19 #include "saveload/saveload.h"
20 #include "company_base.h"
21 #include "company_func.h"
22 #include "strings_func.h"
23 #include "error.h"
24 #include "textbuf_gui.h"
25 #include "window_gui.h"
26 #include "window_func.h"
27 #include "tile_map.h"
28 #include "landscape.h"
29 #include "video/video_driver.hpp"
30 #include "smallmap_gui.h"
31
32 #include "table/strings.h"
33
34 #include "safeguards.h"
35
36 static const char * const SCREENSHOT_NAME = "screenshot";
37 static const char * const HEIGHTMAP_NAME = "heightmap";
38
39 std::string _screenshot_format_name;
40 uint _num_screenshot_formats;
41 uint _cur_screenshot_format;
42 static char _screenshot_name[128];
43 char _full_screenshot_name[MAX_PATH];
44 uint _heightmap_highest_peak;
45
54 typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n);
55
67 typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
68
70 struct ScreenshotFormat {
71 const char *extension;
72 ScreenshotHandlerProc *proc;
73 };
74
75 #define MKCOLOUR(x) TO_LE32X(x)
76
77 /*************************************************
78 **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
79 *************************************************/
80
82 PACK(struct BitmapFileHeader {
83 uint16 type;
84 uint32 size;
85 uint32 reserved;
86 uint32 off_bits;
87 });
88 static_assert(sizeof(BitmapFileHeader) == 14);
89
91 struct BitmapInfoHeader {
92 uint32 size;
93 int32 width, height;
94 uint16 planes, bitcount;
95 uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
96 };
97 static_assert(sizeof(BitmapInfoHeader) == 40);
98
100 struct RgbQuad {
101 byte blue, green, red, reserved;
102 };
103 static_assert(sizeof(RgbQuad) == 4);
104
117 static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
118 {
119 uint bpp; // bytes per pixel
120 switch (pixelformat) {
121 case 8: bpp = 1; break;
122 /* 32bpp mode is saved as 24bpp BMP */
123 case 32: bpp = 3; break;
124 /* Only implemented for 8bit and 32bit images so far */
125 default: return false;
126 }
127
128 FILE *f = fopen(name, "wb");
129 if (f == nullptr) return false;
130
131 /* Each scanline must be aligned on a 32bit boundary */
132 uint bytewidth = Align(w * bpp, 4); // bytes per line in file
133
134 /* Size of palette. Only present for 8bpp mode */
135 uint pal_size = pixelformat == 8 ? sizeof(RgbQuad) * 256 : 0;
136
137 /* Setup the file header */
138 BitmapFileHeader bfh;
139 bfh.type = TO_LE16('MB');
140 bfh.size = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size + bytewidth * h);
141 bfh.reserved = 0;
142 bfh.off_bits = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size);
143
144 /* Setup the info header */
145 BitmapInfoHeader bih;
146 bih.size = TO_LE32(sizeof(BitmapInfoHeader));
147 bih.width = TO_LE32(w);
148 bih.height = TO_LE32(h);
149 bih.planes = TO_LE16(1);
150 bih.bitcount = TO_LE16(bpp * 8);
151 bih.compression = 0;
152 bih.sizeimage = 0;
153 bih.xpels = 0;
154 bih.ypels = 0;
155 bih.clrused = 0;
156 bih.clrimp = 0;
157
158 /* Write file header and info header */
159 if (fwrite(&bfh, sizeof(bfh), 1, f) != 1 || fwrite(&bih, sizeof(bih), 1, f) != 1) {
160 fclose(f);
161 return false;
162 }
163
164 if (pixelformat == 8) {
165 /* Convert the palette to the windows format */
166 RgbQuad rq[256];
167 for (uint i = 0; i < 256; i++) {
168 rq[i].red = palette[i].r;
169 rq[i].green = palette[i].g;
170 rq[i].blue = palette[i].b;
171 rq[i].reserved = 0;
172 }
173 /* Write the palette */
174 if (fwrite(rq, sizeof(rq), 1, f) != 1) {
175 fclose(f);
176 return false;
177 }
178 }
179
180 /* Try to use 64k of memory, store between 16 and 128 lines */
181 uint maxlines = Clamp(65536 / (w * pixelformat / 8), 16, 128); // number of lines per iteration
182
183 uint8 *buff = MallocT<uint8>(maxlines * w * pixelformat / 8); // buffer which is rendered to
184 uint8 *line = AllocaM(uint8, bytewidth); // one line, stored to file
185 memset(line, 0, bytewidth);
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(buff);
214 fclose(f);
215 return false;
216 }
217 }
218 } while (h != 0);
219
220 free(buff);
221 fclose(f);
222
223 return true;
224 }
225
226 /*********************************************************
227 **** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG)
228 *********************************************************/
229 #if defined(WITH_PNG)
230 #include <png.h>
231
232 #ifdef PNG_TEXT_SUPPORTED
233 #include "rev.h"
234 #include "newgrf_config.h"
235 #include "ai/ai_info.hpp"
236 #include "company_base.h"
237 #include "base_media_base.h"
238 #endif /* PNG_TEXT_SUPPORTED */
239
240 static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
241 {
242 Debug(misc, 0, "[libpng] error: {} - {}", message, (const char *)png_get_error_ptr(png_ptr));
243 longjmp(png_jmpbuf(png_ptr), 1);
244 }
245
246 static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
247 {
248 Debug(misc, 1, "[libpng] warning: {} - {}", message, (const char *)png_get_error_ptr(png_ptr));
249 }
250
263 static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
264 {
265 png_color rq[256];
266 FILE *f;
267 uint i, y, n;
268 uint maxlines;
269 uint bpp = pixelformat / 8;
270 png_structp png_ptr;
271 png_infop info_ptr;
272
273 /* only implemented for 8bit and 32bit images so far. */
274 if (pixelformat != 8 && pixelformat != 32) return false;
275
276 f = fopen(name, "wb");
277 if (f == nullptr) return false;
278
279 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, const_cast<char *>(name), png_my_error, png_my_warning);
280
281 if (png_ptr == nullptr) {
282 fclose(f);
283 return false;
284 }
285
286 info_ptr = png_create_info_struct(png_ptr);
287 if (info_ptr == nullptr) {
288 png_destroy_write_struct(&png_ptr, (png_infopp)nullptr);
289 fclose(f);
290 return false;
291 }
292
293 if (setjmp(png_jmpbuf(png_ptr))) {
294 png_destroy_write_struct(&png_ptr, &info_ptr);
295 fclose(f);
296 return false;
297 }
298
299 png_init_io(png_ptr, f);
300
301 png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
302
303 png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB,
304 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
305
306 #ifdef PNG_TEXT_SUPPORTED
307 /* Try to add some game metadata to the PNG screenshot so
308 * it's more useful for debugging and archival purposes. */
309 png_text_struct text[2];
310 memset(text, 0, sizeof(text));
311 text[0].key = const_cast<char *>("Software");
312 text[0].text = const_cast<char *>(_openttd_revision);
313 text[0].text_length = strlen(_openttd_revision);
314 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
315
316 char buf[8192];
317 char *p = buf;
318 p += seprintf(p, lastof(buf), "Graphics set: %s (%u)\n", BaseGraphics::GetUsedSet()->name.c_str(), BaseGraphics::GetUsedSet()->version);
319 p = strecpy(p, "NewGRFs:\n", lastof(buf));
320 for (const GRFConfig *c = _game_mode == GM_MENU ? nullptr : _grfconfig; c != nullptr; c = c->next) {
321 p += seprintf(p, lastof(buf), "%08X ", BSWAP32(c->ident.grfid));
322 p = md5sumToString(p, lastof(buf), c->ident.md5sum);
323 p += seprintf(p, lastof(buf), " %s\n", c->filename);
324 }
325 p = strecpy(p, "\nCompanies:\n", lastof(buf));
326 for (const Company *c : Company::Iterate()) {
327 if (c->ai_info == nullptr) {
328 p += seprintf(p, lastof(buf), "%2i: Human\n", (int)c->index);
329 } else {
330 p += seprintf(p, lastof(buf), "%2i: %s (v%d)\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 = buf;
335 text[1].text_length = p - buf;
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>(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 unused;
415 uint16 xmax, ymax;
416 uint16 hdpi, vdpi;
417 byte pal_small[16 * 3];
418 byte reserved;
419 byte planes;
420 uint16 pitch;
421 uint16 cpal;
422 uint16 width;
423 uint16 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 *buff = CallocT<uint8>(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 *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 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 *userdata, 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, *old_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 old_dpi = _cur_dpi;
634 _cur_dpi = &dpi;
635
636 dpi.dst_ptr = buf;
637 dpi.height = n;
638 dpi.width = vp->width;
639 dpi.pitch = pitch;
640 dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT;
641 dpi.left = 0;
642 dpi.top = y;
643
644 /* Render viewport in blocks of 1600 pixels width */
645 left = 0;
646 while (vp->width - left != 0) {
647 wx = std::min(vp->width - left, 1600);
648 left += wx;
649
650 ViewportDoDraw(vp,
651 ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left,
652 ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top,
653 ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
654 ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top
655 );
656 }
657
658 _cur_dpi = old_dpi;
659
660 /* Switch back to rendering to the screen */
661 _screen = old_screen;
662 _screen_disable_anim = old_disable_anim;
663 }
664
672 static const char *MakeScreenshotName(const char *default_fn, const char *ext, bool crashlog = false)
673 {
674 bool generate = StrEmpty(_screenshot_name);
675
676 if (generate) {
677 if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
678 strecpy(_screenshot_name, default_fn, lastof(_screenshot_name));
679 } else {
680 GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
681 }
682 }
683
684 size_t len = strlen(_screenshot_name);
685
686 /* Handle user-specified filenames ending in # with automatic numbering */
687 if (StrEndsWith(_screenshot_name, "#")) {
688 generate = true;
689 len -= 1;
690 _screenshot_name[len] = '\0';
691 }
692
693 /* Add extension to screenshot file */
694 seprintf(&_screenshot_name[len], lastof(_screenshot_name), ".%s", ext);
695
696 const char *screenshot_dir = crashlog ? _personal_dir.c_str() : FiosGetScreenshotDir();
697
698 for (uint serial = 1;; serial++) {
699 if (seprintf(_full_screenshot_name, lastof(_full_screenshot_name), "%s%s", screenshot_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) {
700 /* We need more characters than MAX_PATH -> end with error */
701 _full_screenshot_name[0] = '\0';
702 break;
703 }
704 if (!generate) break; // allow overwriting of non-automatic filenames
705 if (!FileExists(_full_screenshot_name)) break;
706 /* If file exists try another one with same name, but just with a higher index */
707 seprintf(&_screenshot_name[len], lastof(_screenshot_name) - len, "#%u.%s", serial, ext);
708 }
709
710 return _full_screenshot_name;
711 }
712
714 static bool MakeSmallScreenshot(bool crashlog)
715 {
716 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
717 return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension, crashlog), CurrentScreenCallback, nullptr, _screen.width, _screen.height,
718 BlitterFactory::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
719 }
720
728 void SetupScreenshotViewport(ScreenshotType t, Viewport *vp, uint32 width, uint32 height)
729 {
730 switch(t) {
731 case SC_VIEWPORT:
732 case SC_CRASHLOG: {
733 assert(width == 0 && height == 0);
734
735 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
736 vp->virtual_left = w->viewport->virtual_left;
737 vp->virtual_top = w->viewport->virtual_top;
738 vp->virtual_width = w->viewport->virtual_width;
739 vp->virtual_height = w->viewport->virtual_height;
740
741 /* Compute pixel coordinates */
742 vp->left = 0;
743 vp->top = 0;
744 vp->width = _screen.width;
745 vp->height = _screen.height;
746 vp->overlay = w->viewport->overlay;
747 break;
748 }
749 case SC_WORLD: {
750 assert(width == 0 && height == 0);
751
752 /* Determine world coordinates of screenshot */
753 vp->zoom = ZOOM_LVL_WORLD_SCREENSHOT;
754
755 TileIndex north_tile = _settings_game.construction.freeform_edges ? TileXY(1, 1) : TileXY(0, 0);
756 TileIndex south_tile = MapSize() - 1;
757
758 /* We need to account for a hill or high building at tile 0,0. */
759 int extra_height_top = TilePixelHeight(north_tile) + 150;
760 /* If there is a hill at the bottom don't create a large black area. */
761 int reclaim_height_bottom = TilePixelHeight(south_tile);
762
763 vp->virtual_left = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, 0).x;
764 vp->virtual_top = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, extra_height_top).y;
765 vp->virtual_width = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, 0).x - vp->virtual_left + 1;
766 vp->virtual_height = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, reclaim_height_bottom).y - vp->virtual_top + 1;
767
768 /* Compute pixel coordinates */
769 vp->left = 0;
770 vp->top = 0;
771 vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
772 vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
773 vp->overlay = nullptr;
774 break;
775 }
776 default: {
777 vp->zoom = (t == SC_ZOOMEDIN) ? _settings_client.gui.zoom_min : ZOOM_LVL_VIEWPORT;
778
779 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
780 vp->virtual_left = w->viewport->virtual_left;
781 vp->virtual_top = w->viewport->virtual_top;
782
783 if (width == 0 || height == 0) {
784 vp->virtual_width = w->viewport->virtual_width;
785 vp->virtual_height = w->viewport->virtual_height;
786 } else {
787 vp->virtual_width = width << vp->zoom;
788 vp->virtual_height = height << vp->zoom;
789 }
790
791 /* Compute pixel coordinates */
792 vp->left = 0;
793 vp->top = 0;
794 vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
795 vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
796 vp->overlay = nullptr;
797 break;
798 }
799 }
800 }
801
809 static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32 width = 0, uint32 height = 0)
810 {
811 Viewport vp;
812 SetupScreenshotViewport(t, &vp, width, height);
813
814 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
815 return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), LargeWorldCallback, &vp, vp.width, vp.height,
816 BlitterFactory::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
817 }
818
828 static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
829 {
830 byte *buf = (byte *)buffer;
831 while (n > 0) {
832 TileIndex ti = TileXY(MapMaxX(), y);
833 for (uint x = MapMaxX(); true; x--) {
834 *buf = 256 * TileHeight(ti) / (1 + _heightmap_highest_peak);
835 buf++;
836 if (x == 0) break;
837 ti = TILE_ADDXY(ti, -1, 0);
838 }
839 y++;
840 n--;
841 }
842 }
843
848 bool MakeHeightmapScreenshot(const char *filename)
849 {
850 Colour palette[256];
851 for (uint i = 0; i < lengthof(palette); i++) {
852 palette[i].a = 0xff;
853 palette[i].r = i;
854 palette[i].g = i;
855 palette[i].b = i;
856 }
857
858 _heightmap_highest_peak = 0;
859 for (TileIndex tile = 0; tile < MapSize(); tile++) {
860 uint h = TileHeight(tile);
861 _heightmap_highest_peak = std::max(h, _heightmap_highest_peak);
862 }
863
864 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
865 return sf->proc(filename, HeightmapCallback, nullptr, MapSizeX(), MapSizeY(), 8, palette);
866 }
867
868 static ScreenshotType _confirmed_screenshot_type;
869
875 static void ScreenshotConfirmationCallback(Window *w, bool confirmed)
876 {
877 if (confirmed) MakeScreenshot(_confirmed_screenshot_type, {});
878 }
879
886 void MakeScreenshotWithConfirm(ScreenshotType t)
887 {
888 Viewport vp;
889 SetupScreenshotViewport(t, &vp);
890
891 bool heightmap_or_minimap = t == SC_HEIGHTMAP || t == SC_MINIMAP;
892 uint64_t width = (heightmap_or_minimap ? MapSizeX() : vp.width);
893 uint64_t height = (heightmap_or_minimap ? MapSizeY() : vp.height);
894
895 if (width * height > 8192 * 8192) {
896 /* Ask for confirmation */
897 _confirmed_screenshot_type = t;
898 SetDParam(0, width);
899 SetDParam(1, height);
900 ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback);
901 } else {
902 /* Less than 64M pixels, just do it */
903 MakeScreenshot(t, {});
904 }
905 }
906
915 static bool RealMakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
916 {
917 if (t == SC_VIEWPORT) {
918 /* First draw the dirty parts of the screen and only then change the name
919 * of the screenshot. This way the screenshot will always show the name
920 * of the previous screenshot in the 'successful' message instead of the
921 * name of the new screenshot (or an empty name). */
922 SetScreenshotWindowVisibility(true);
923 UndrawMouseCursor();
924 DrawDirtyBlocks();
925 SetScreenshotWindowVisibility(false);
926 }
927
928 _screenshot_name[0] = '\0';
929 if (!name.empty()) strecpy(_screenshot_name, name.c_str(), lastof(_screenshot_name));
930
931 bool ret;
932 switch (t) {
933 case SC_VIEWPORT:
934 ret = MakeSmallScreenshot(false);
935 break;
936
937 case SC_CRASHLOG:
938 ret = MakeSmallScreenshot(true);
939 break;
940
941 case SC_ZOOMEDIN:
942 case SC_DEFAULTZOOM:
943 ret = MakeLargeWorldScreenshot(t, width, height);
944 break;
945
946 case SC_WORLD:
947 ret = MakeLargeWorldScreenshot(t);
948 break;
949
950 case SC_HEIGHTMAP: {
951 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
952 ret = MakeHeightmapScreenshot(MakeScreenshotName(HEIGHTMAP_NAME, sf->extension));
953 break;
954 }
955
956 case SC_MINIMAP:
957 ret = MakeMinimapWorldScreenshot();
958 break;
959
960 default:
961 NOT_REACHED();
962 }
963
964 if (ret) {
965 if (t == SC_HEIGHTMAP) {
966 SetDParamStr(0, _screenshot_name);
967 SetDParam(1, _heightmap_highest_peak);
968 ShowErrorMessage(STR_MESSAGE_HEIGHTMAP_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
969 } else {
970 SetDParamStr(0, _screenshot_name);
971 ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
972 }
973 } else {
974 ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, WL_ERROR);
975 }
976
977 return ret;
978 }
979
990 bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
991 {
992 if (t == SC_CRASHLOG) {
993 /* Video buffer might or might not be locked. */
994 VideoDriver::VideoBufferLocker lock;
995
996 return RealMakeScreenshot(t, name, width, height);
997 }
998
999 VideoDriver::GetInstance()->QueueOnMainThread([=] { // Capture by value to not break scope.
1000 RealMakeScreenshot(t, name, width, height);
1001 });
1002
1003 return true;
1004 }
1005
1006
1007 static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
1008 {
1009 uint32 *ubuf = (uint32 *)buf;
1010 uint num = (pitch * n);
1011 for (uint i = 0; i < num; i++) {
1012 uint row = y + (int)(i / pitch);
1013 uint col = (MapSizeX() - 1) - (i % pitch);
1014
1015 TileIndex tile = TileXY(col, row);
1016 byte val = GetSmallMapOwnerPixels(tile, GetTileType(tile), IncludeHeightmap::Never) & 0xFF;
1017
1018 uint32 colour_buf = 0;
1019 colour_buf = (_cur_palette.palette[val].b << 0);
1020 colour_buf |= (_cur_palette.palette[val].g << 8);
1021 colour_buf |= (_cur_palette.palette[val].r << 16);
1022
1023 *ubuf = colour_buf;
1024 ubuf++; // Skip alpha
1025 }
1026 }
1027
1031 bool MakeMinimapWorldScreenshot()
1032 {
1033 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
1034 return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), MinimapScreenCallback, nullptr, MapSizeX(), MapSizeY(), 32, _cur_palette.palette);
1035 }
RgbQuad
Format of palette data in BMP header.
Definition: screenshot.cpp:100
factory.hpp
SetupScreenshotViewport
void SetupScreenshotViewport(ScreenshotType t, Viewport *vp, uint32 width, uint32 height)
Configure a Viewport for rendering (a part of) the map into a screenshot.
Definition: screenshot.cpp:728
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:957
endian_func.hpp
PcxHeader
Definition of a PCX file header.
Definition: screenshot.cpp:409
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:23
smallmap_gui.h
HeightmapCallback
static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
Callback for generating a heightmap.
Definition: screenshot.cpp:828
company_base.h
lock
std::mutex lock
synchronization for playback status fields
Definition: win32_m.cpp:34
Blitter
How all blitters should look like.
Definition: base.hpp:28
TilePixelHeight
static uint TilePixelHeight(TileIndex tile)
Returns the height of a tile in pixels.
Definition: tile_map.h:72
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
RemapCoords
static 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
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:255
Blitter::GetScreenDepth
virtual uint8 GetScreenDepth()=0
Get the screen depth this blitter works for.
Viewport::height
int height
Screen height of the viewport.
Definition: viewport_type.h:26
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition: viewport_type.h:24
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1157
_screenshot_format_name
std::string _screenshot_format_name
Extension of the current screenshot format (corresponds with _cur_screenshot_format).
Definition: screenshot.cpp:39
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
screenshot_gui.h
BitmapInfoHeader
BMP Info Header (stored in little endian)
Definition: screenshot.cpp:91
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
BaseSet::version
uint32 version
The version of this base set.
Definition: base_media_base.h:64
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
SC_ZOOMEDIN
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:21
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
newgrf_config.h
ScreenshotFormat::extension
const char * extension
File extension.
Definition: screenshot.cpp:71
Viewport::virtual_top
int virtual_top
Virtual top coordinate.
Definition: viewport_type.h:29
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
MakeHeightmapScreenshot
bool MakeHeightmapScreenshot(const char *filename)
Make a heightmap of the current map.
Definition: screenshot.cpp:848
InitializeScreenshotFormats
void InitializeScreenshotFormats()
Initialize screenshot format information on startup, with _screenshot_format_name filled from the loa...
Definition: screenshot.cpp:585
textbuf_gui.h
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:377
ai_info.hpp
screenshot.h
gfx_func.h
MapSizeX
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
_confirmed_screenshot_type
static ScreenshotType _confirmed_screenshot_type
Screenshot type the current query is about to confirm.
Definition: screenshot.cpp:868
window_gui.h
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
tile_map.h
_screenshot_name
static char _screenshot_name[128]
Filename of the screenshot file.
Definition: screenshot.cpp:42
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
Align
static T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Definition: math_func.hpp:35
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:155
Viewport::virtual_left
int virtual_left
Virtual left coordinate.
Definition: viewport_type.h:28
_screen_disable_anim
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
Definition: gfx.cpp:46
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:321
FileExists
bool FileExists(const std::string &filename)
Test whether the given filename exists.
Definition: fileio.cpp:122
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:141
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
safeguards.h
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:67
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:354
ScreenshotFormat
Screenshot format information.
Definition: screenshot.cpp:70
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:67
DrawDirtyBlocks
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
Definition: gfx.cpp:1635
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:54
_num_screenshot_formats
uint _num_screenshot_formats
Number of available screenshot formats.
Definition: screenshot.cpp:40
CurrentScreenCallback
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
Callback of the screenshot generator that dumps the current video buffer.
Definition: screenshot.cpp:602
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:672
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:41
error.h
MapSizeY
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
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:190
UnScaleByZoom
static 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
stdafx.h
ZOOM_LVL_VIEWPORT
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.
Definition: zoom_type.h:33
landscape.h
BSWAP32
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:390
ScreenshotFormat::proc
ScreenshotHandlerProc * proc
Function for writing the screenshot.
Definition: screenshot.cpp:72
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:202
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.
PACK
PACK(struct BitmapFileHeader { uint16 type;uint32 size;uint32 reserved;uint32 off_bits;})
BMP File Header (stored in little endian)
StrEndsWith
bool StrEndsWith(const std::string_view str, const std::string_view suffix)
Check whether the given string ends with the given suffix.
Definition: string.cpp:398
GenerateDefaultSaveName
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
Definition: saveload.cpp:3354
Colour
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:163
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:134
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
GetSmallMapOwnerPixels
uint32 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:565
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1266
MakeLargeWorldScreenshot
static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32 width=0, uint32 height=0)
Make a screenshot of the map.
Definition: screenshot.cpp:809
SetScreenshotWindowVisibility
void SetScreenshotWindowVisibility(bool hide)
Set the visibility of the screenshot window when taking a screenshot.
Definition: screenshot_gui.cpp:81
rev.h
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
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:386
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:117
strings_func.h
ScaleByZoom
static 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
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:37
Colour::a
uint8 a
colour channels in LE order
Definition: gfx_type.h:171
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...
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
video_driver.hpp
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:183
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:263
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:554
SC_DEFAULTZOOM
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
Definition: screenshot.h:22
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:44
MakeSmallScreenshot
static bool MakeSmallScreenshot(bool crashlog)
Make a screenshot of the current screen.
Definition: screenshot.cpp:714
company_func.h
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
_full_screenshot_name
char _full_screenshot_name[MAX_PATH]
Pathname of the screenshot file.
Definition: screenshot.cpp:43
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
MakeMinimapWorldScreenshot
bool MakeMinimapWorldScreenshot()
Make a minimap screenshot.
Definition: screenshot.cpp:1031
MakeScreenshot
bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
Schedule making a screenshot.
Definition: screenshot.cpp:990
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:258
_cur_palette
Palette _cur_palette
Current palette.
Definition: gfx.cpp:51
_grfconfig
GRFConfig * _grfconfig
First item in list of current GRF set up.
Definition: newgrf_config.cpp:171
_cur_screenshot_format
uint _cur_screenshot_format
Index of the currently selected screenshot format in _screenshot_formats.
Definition: screenshot.cpp:41
window_func.h
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
GetCurrentScreenshotExtension
const char * GetCurrentScreenshotExtension()
Get filename extension of current screenshot file format.
Definition: screenshot.cpp:579
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
SC_VIEWPORT
@ SC_VIEWPORT
Screenshot of viewport.
Definition: screenshot.h:19
MakeScreenshotWithConfirm
void MakeScreenshotWithConfirm(ScreenshotType t)
Make a screenshot.
Definition: screenshot.cpp:886
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
Window
Data structure for an opened window.
Definition: window_gui.h:213
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:572
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
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:357
IncludeHeightmap::Never
@ Never
Never include the heightmap.
Viewport::virtual_height
int virtual_height
height << zoom
Definition: viewport_type.h:31
SC_MINIMAP
@ SC_MINIMAP
Minimap screenshot.
Definition: screenshot.h:25
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:113
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
SCREENSHOT_NAME
static const char *const SCREENSHOT_NAME
Default filename of a saved screenshot.
Definition: screenshot.cpp:36
Company
Definition: company_base.h:117
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
_heightmap_highest_peak
uint _heightmap_highest_peak
When saving a heightmap, this contains the highest peak on the map.
Definition: screenshot.cpp:44
VideoDriver::VideoBufferLocker
Helper struct to ensure the video buffer is locked and ready for drawing.
Definition: video_driver.hpp:210
RealMakeScreenshot
static bool RealMakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
Make a screenshot.
Definition: screenshot.cpp:915
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
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
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
FiosGetScreenshotDir
const char * FiosGetScreenshotDir()
Get the directory for screenshots.
Definition: fios.cpp:625
ScreenshotConfirmationCallback
static void ScreenshotConfirmationCallback(Window *w, bool confirmed)
Callback on the confirmation window for huge screenshots.
Definition: screenshot.cpp:875
AllocaM
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
Definition: alloc_func.hpp:132