OpenTTD Source  12.2
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 
31 #include "table/strings.h"
32 
33 #include "safeguards.h"
34 
35 static const char * const SCREENSHOT_NAME = "screenshot";
36 static const char * const HEIGHTMAP_NAME = "heightmap";
37 
41 static char _screenshot_name[128];
42 char _full_screenshot_name[MAX_PATH];
44 
53 typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n);
54 
66 typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
67 
70  const char *extension;
72 };
73 
74 #define MKCOLOUR(x) TO_LE32X(x)
75 
76 /*************************************************
77  **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
78  *************************************************/
79 
81 PACK(struct BitmapFileHeader {
82  uint16 type;
83  uint32 size;
84  uint32 reserved;
85  uint32 off_bits;
86 });
87 static_assert(sizeof(BitmapFileHeader) == 14);
88 
91  uint32 size;
92  int32 width, height;
93  uint16 planes, bitcount;
94  uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
95 };
96 static_assert(sizeof(BitmapInfoHeader) == 40);
97 
99 struct RgbQuad {
100  byte blue, green, red, reserved;
101 };
102 static_assert(sizeof(RgbQuad) == 4);
103 
116 static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
117 {
118  uint bpp; // bytes per pixel
119  switch (pixelformat) {
120  case 8: bpp = 1; break;
121  /* 32bpp mode is saved as 24bpp BMP */
122  case 32: bpp = 3; break;
123  /* Only implemented for 8bit and 32bit images so far */
124  default: return false;
125  }
126 
127  FILE *f = fopen(name, "wb");
128  if (f == nullptr) return false;
129 
130  /* Each scanline must be aligned on a 32bit boundary */
131  uint bytewidth = Align(w * bpp, 4); // bytes per line in file
132 
133  /* Size of palette. Only present for 8bpp mode */
134  uint pal_size = pixelformat == 8 ? sizeof(RgbQuad) * 256 : 0;
135 
136  /* Setup the file header */
137  BitmapFileHeader bfh;
138  bfh.type = TO_LE16('MB');
139  bfh.size = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size + bytewidth * h);
140  bfh.reserved = 0;
141  bfh.off_bits = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size);
142 
143  /* Setup the info header */
144  BitmapInfoHeader bih;
145  bih.size = TO_LE32(sizeof(BitmapInfoHeader));
146  bih.width = TO_LE32(w);
147  bih.height = TO_LE32(h);
148  bih.planes = TO_LE16(1);
149  bih.bitcount = TO_LE16(bpp * 8);
150  bih.compression = 0;
151  bih.sizeimage = 0;
152  bih.xpels = 0;
153  bih.ypels = 0;
154  bih.clrused = 0;
155  bih.clrimp = 0;
156 
157  /* Write file header and info header */
158  if (fwrite(&bfh, sizeof(bfh), 1, f) != 1 || fwrite(&bih, sizeof(bih), 1, f) != 1) {
159  fclose(f);
160  return false;
161  }
162 
163  if (pixelformat == 8) {
164  /* Convert the palette to the windows format */
165  RgbQuad rq[256];
166  for (uint i = 0; i < 256; i++) {
167  rq[i].red = palette[i].r;
168  rq[i].green = palette[i].g;
169  rq[i].blue = palette[i].b;
170  rq[i].reserved = 0;
171  }
172  /* Write the palette */
173  if (fwrite(rq, sizeof(rq), 1, f) != 1) {
174  fclose(f);
175  return false;
176  }
177  }
178 
179  /* Try to use 64k of memory, store between 16 and 128 lines */
180  uint maxlines = Clamp(65536 / (w * pixelformat / 8), 16, 128); // number of lines per iteration
181 
182  uint8 *buff = MallocT<uint8>(maxlines * w * pixelformat / 8); // buffer which is rendered to
183  uint8 *line = AllocaM(uint8, bytewidth); // one line, stored to file
184  memset(line, 0, bytewidth);
185 
186  /* Start at the bottom, since bitmaps are stored bottom up */
187  do {
188  uint n = std::min(h, maxlines);
189  h -= n;
190 
191  /* Render the pixels */
192  callb(userdata, buff, h, w, n);
193 
194  /* Write each line */
195  while (n-- != 0) {
196  if (pixelformat == 8) {
197  /* Move to 'line', leave last few pixels in line zeroed */
198  memcpy(line, buff + n * w, w);
199  } else {
200  /* Convert from 'native' 32bpp to BMP-like 24bpp.
201  * Works for both big and little endian machines */
202  Colour *src = ((Colour *)buff) + n * w;
203  byte *dst = line;
204  for (uint i = 0; i < w; i++) {
205  dst[i * 3 ] = src[i].b;
206  dst[i * 3 + 1] = src[i].g;
207  dst[i * 3 + 2] = src[i].r;
208  }
209  }
210  /* Write to file */
211  if (fwrite(line, bytewidth, 1, f) != 1) {
212  free(buff);
213  fclose(f);
214  return false;
215  }
216  }
217  } while (h != 0);
218 
219  free(buff);
220  fclose(f);
221 
222  return true;
223 }
224 
225 /*********************************************************
226  **** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG)
227  *********************************************************/
228 #if defined(WITH_PNG)
229 #include <png.h>
230 
231 #ifdef PNG_TEXT_SUPPORTED
232 #include "rev.h"
233 #include "newgrf_config.h"
234 #include "ai/ai_info.hpp"
235 #include "company_base.h"
236 #include "base_media_base.h"
237 #endif /* PNG_TEXT_SUPPORTED */
238 
239 static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
240 {
241  Debug(misc, 0, "[libpng] error: {} - {}", message, (const char *)png_get_error_ptr(png_ptr));
242  longjmp(png_jmpbuf(png_ptr), 1);
243 }
244 
245 static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
246 {
247  Debug(misc, 1, "[libpng] warning: {} - {}", message, (const char *)png_get_error_ptr(png_ptr));
248 }
249 
262 static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
263 {
264  png_color rq[256];
265  FILE *f;
266  uint i, y, n;
267  uint maxlines;
268  uint bpp = pixelformat / 8;
269  png_structp png_ptr;
270  png_infop info_ptr;
271 
272  /* only implemented for 8bit and 32bit images so far. */
273  if (pixelformat != 8 && pixelformat != 32) return false;
274 
275  f = fopen(name, "wb");
276  if (f == nullptr) return false;
277 
278  png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, const_cast<char *>(name), png_my_error, png_my_warning);
279 
280  if (png_ptr == nullptr) {
281  fclose(f);
282  return false;
283  }
284 
285  info_ptr = png_create_info_struct(png_ptr);
286  if (info_ptr == nullptr) {
287  png_destroy_write_struct(&png_ptr, (png_infopp)nullptr);
288  fclose(f);
289  return false;
290  }
291 
292  if (setjmp(png_jmpbuf(png_ptr))) {
293  png_destroy_write_struct(&png_ptr, &info_ptr);
294  fclose(f);
295  return false;
296  }
297 
298  png_init_io(png_ptr, f);
299 
300  png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
301 
302  png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB,
303  PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
304 
305 #ifdef PNG_TEXT_SUPPORTED
306  /* Try to add some game metadata to the PNG screenshot so
307  * it's more useful for debugging and archival purposes. */
308  png_text_struct text[2];
309  memset(text, 0, sizeof(text));
310  text[0].key = const_cast<char *>("Software");
311  text[0].text = const_cast<char *>(_openttd_revision);
312  text[0].text_length = strlen(_openttd_revision);
313  text[0].compression = PNG_TEXT_COMPRESSION_NONE;
314 
315  char buf[8192];
316  char *p = buf;
317  p += seprintf(p, lastof(buf), "Graphics set: %s (%u)\n", BaseGraphics::GetUsedSet()->name.c_str(), BaseGraphics::GetUsedSet()->version);
318  p = strecpy(p, "NewGRFs:\n", lastof(buf));
319  for (const GRFConfig *c = _game_mode == GM_MENU ? nullptr : _grfconfig; c != nullptr; c = c->next) {
320  p += seprintf(p, lastof(buf), "%08X ", BSWAP32(c->ident.grfid));
321  p = md5sumToString(p, lastof(buf), c->ident.md5sum);
322  p += seprintf(p, lastof(buf), " %s\n", c->filename);
323  }
324  p = strecpy(p, "\nCompanies:\n", lastof(buf));
325  for (const Company *c : Company::Iterate()) {
326  if (c->ai_info == nullptr) {
327  p += seprintf(p, lastof(buf), "%2i: Human\n", (int)c->index);
328  } else {
329  p += seprintf(p, lastof(buf), "%2i: %s (v%d)\n", (int)c->index, c->ai_info->GetName(), c->ai_info->GetVersion());
330  }
331  }
332  text[1].key = const_cast<char *>("Description");
333  text[1].text = buf;
334  text[1].text_length = p - buf;
335  text[1].compression = PNG_TEXT_COMPRESSION_zTXt;
336  png_set_text(png_ptr, info_ptr, text, 2);
337 #endif /* PNG_TEXT_SUPPORTED */
338 
339  if (pixelformat == 8) {
340  /* convert the palette to the .PNG format. */
341  for (i = 0; i != 256; i++) {
342  rq[i].red = palette[i].r;
343  rq[i].green = palette[i].g;
344  rq[i].blue = palette[i].b;
345  }
346 
347  png_set_PLTE(png_ptr, info_ptr, rq, 256);
348  }
349 
350  png_write_info(png_ptr, info_ptr);
351  png_set_flush(png_ptr, 512);
352 
353  if (pixelformat == 32) {
354  png_color_8 sig_bit;
355 
356  /* Save exact colour/alpha resolution */
357  sig_bit.alpha = 0;
358  sig_bit.blue = 8;
359  sig_bit.green = 8;
360  sig_bit.red = 8;
361  sig_bit.gray = 8;
362  png_set_sBIT(png_ptr, info_ptr, &sig_bit);
363 
364 #if TTD_ENDIAN == TTD_LITTLE_ENDIAN
365  png_set_bgr(png_ptr);
366  png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
367 #else
368  png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
369 #endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */
370  }
371 
372  /* use by default 64k temp memory */
373  maxlines = Clamp(65536 / w, 16, 128);
374 
375  /* now generate the bitmap bits */
376  void *buff = CallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time.
377 
378  y = 0;
379  do {
380  /* determine # lines to write */
381  n = std::min(h - y, maxlines);
382 
383  /* render the pixels into the buffer */
384  callb(userdata, buff, y, w, n);
385  y += n;
386 
387  /* write them to png */
388  for (i = 0; i != n; i++) {
389  png_write_row(png_ptr, (png_bytep)buff + i * w * bpp);
390  }
391  } while (y != h);
392 
393  png_write_end(png_ptr, info_ptr);
394  png_destroy_write_struct(&png_ptr, &info_ptr);
395 
396  free(buff);
397  fclose(f);
398  return true;
399 }
400 #endif /* WITH_PNG */
401 
402 
403 /*************************************************
404  **** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX)
405  *************************************************/
406 
408 struct PcxHeader {
409  byte manufacturer;
410  byte version;
411  byte rle;
412  byte bpp;
413  uint32 unused;
414  uint16 xmax, ymax;
415  uint16 hdpi, vdpi;
416  byte pal_small[16 * 3];
417  byte reserved;
418  byte planes;
419  uint16 pitch;
420  uint16 cpal;
421  uint16 width;
422  uint16 height;
423  byte filler[54];
424 };
425 static_assert(sizeof(PcxHeader) == 128);
426 
439 static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
440 {
441  FILE *f;
442  uint maxlines;
443  uint y;
444  PcxHeader pcx;
445  bool success;
446 
447  if (pixelformat == 32) {
448  Debug(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick another format.");
449  return false;
450  }
451  if (pixelformat != 8 || w == 0) return false;
452 
453  f = fopen(name, "wb");
454  if (f == nullptr) return false;
455 
456  memset(&pcx, 0, sizeof(pcx));
457 
458  /* setup pcx header */
459  pcx.manufacturer = 10;
460  pcx.version = 5;
461  pcx.rle = 1;
462  pcx.bpp = 8;
463  pcx.xmax = TO_LE16(w - 1);
464  pcx.ymax = TO_LE16(h - 1);
465  pcx.hdpi = TO_LE16(320);
466  pcx.vdpi = TO_LE16(320);
467 
468  pcx.planes = 1;
469  pcx.cpal = TO_LE16(1);
470  pcx.width = pcx.pitch = TO_LE16(w);
471  pcx.height = TO_LE16(h);
472 
473  /* write pcx header */
474  if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) {
475  fclose(f);
476  return false;
477  }
478 
479  /* use by default 64k temp memory */
480  maxlines = Clamp(65536 / w, 16, 128);
481 
482  /* now generate the bitmap bits */
483  uint8 *buff = CallocT<uint8>(w * maxlines); // by default generate 128 lines at a time.
484 
485  y = 0;
486  do {
487  /* determine # lines to write */
488  uint n = std::min(h - y, maxlines);
489  uint i;
490 
491  /* render the pixels into the buffer */
492  callb(userdata, buff, y, w, n);
493  y += n;
494 
495  /* write them to pcx */
496  for (i = 0; i != n; i++) {
497  const uint8 *bufp = buff + i * w;
498  byte runchar = bufp[0];
499  uint runcount = 1;
500  uint j;
501 
502  /* for each pixel... */
503  for (j = 1; j < w; j++) {
504  uint8 ch = bufp[j];
505 
506  if (ch != runchar || runcount >= 0x3f) {
507  if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
508  if (fputc(0xC0 | runcount, f) == EOF) {
509  free(buff);
510  fclose(f);
511  return false;
512  }
513  }
514  if (fputc(runchar, f) == EOF) {
515  free(buff);
516  fclose(f);
517  return false;
518  }
519  runcount = 0;
520  runchar = ch;
521  }
522  runcount++;
523  }
524 
525  /* write remaining bytes.. */
526  if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
527  if (fputc(0xC0 | runcount, f) == EOF) {
528  free(buff);
529  fclose(f);
530  return false;
531  }
532  }
533  if (fputc(runchar, f) == EOF) {
534  free(buff);
535  fclose(f);
536  return false;
537  }
538  }
539  } while (y != h);
540 
541  free(buff);
542 
543  /* write 8-bit colour palette */
544  if (fputc(12, f) == EOF) {
545  fclose(f);
546  return false;
547  }
548 
549  /* Palette is word-aligned, copy it to a temporary byte array */
550  byte tmp[256 * 3];
551 
552  for (uint i = 0; i < 256; i++) {
553  tmp[i * 3 + 0] = palette[i].r;
554  tmp[i * 3 + 1] = palette[i].g;
555  tmp[i * 3 + 2] = palette[i].b;
556  }
557  success = fwrite(tmp, sizeof(tmp), 1, f) == 1;
558 
559  fclose(f);
560 
561  return success;
562 }
563 
564 /*************************************************
565  **** GENERIC SCREENSHOT CODE
566  *************************************************/
567 
570 #if defined(WITH_PNG)
571  {"png", &MakePNGImage},
572 #endif
573  {"bmp", &MakeBMPImage},
574  {"pcx", &MakePCXImage},
575 };
576 
579 {
581 }
582 
585 {
586  uint j = 0;
587  for (uint i = 0; i < lengthof(_screenshot_formats); i++) {
589  j = i;
590  break;
591  }
592  }
595 }
596 
601 static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
602 {
604  void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
605  blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch);
606 }
607 
616 static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
617 {
618  Viewport *vp = (Viewport *)userdata;
619  DrawPixelInfo dpi, *old_dpi;
620  int wx, left;
621 
622  /* We are no longer rendering to the screen */
623  DrawPixelInfo old_screen = _screen;
624  bool old_disable_anim = _screen_disable_anim;
625 
626  _screen.dst_ptr = buf;
627  _screen.width = pitch;
628  _screen.height = n;
629  _screen.pitch = pitch;
630  _screen_disable_anim = true;
631 
632  old_dpi = _cur_dpi;
633  _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  _cur_dpi = old_dpi;
658 
659  /* Switch back to rendering to the screen */
660  _screen = old_screen;
661  _screen_disable_anim = old_disable_anim;
662 }
663 
671 static const char *MakeScreenshotName(const char *default_fn, const char *ext, bool crashlog = false)
672 {
673  bool generate = StrEmpty(_screenshot_name);
674 
675  if (generate) {
676  if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
678  } else {
680  }
681  }
682 
683  /* Add extension to screenshot file */
684  size_t len = strlen(_screenshot_name);
685  seprintf(&_screenshot_name[len], lastof(_screenshot_name), ".%s", ext);
686 
687  const char *screenshot_dir = crashlog ? _personal_dir.c_str() : FiosGetScreenshotDir();
688 
689  for (uint serial = 1;; serial++) {
691  /* We need more characters than MAX_PATH -> end with error */
692  _full_screenshot_name[0] = '\0';
693  break;
694  }
695  if (!generate) break; // allow overwriting of non-automatic filenames
696  if (!FileExists(_full_screenshot_name)) break;
697  /* If file exists try another one with same name, but just with a higher index */
698  seprintf(&_screenshot_name[len], lastof(_screenshot_name) - len, "#%u.%s", serial, ext);
699  }
700 
701  return _full_screenshot_name;
702 }
703 
705 static bool MakeSmallScreenshot(bool crashlog)
706 {
708  return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension, crashlog), CurrentScreenCallback, nullptr, _screen.width, _screen.height,
710 }
711 
719 void SetupScreenshotViewport(ScreenshotType t, Viewport *vp, uint32 width, uint32 height)
720 {
721  switch(t) {
722  case SC_VIEWPORT:
723  case SC_CRASHLOG: {
724  assert(width == 0 && height == 0);
725 
728  vp->virtual_top = w->viewport->virtual_top;
731 
732  /* Compute pixel coordinates */
733  vp->left = 0;
734  vp->top = 0;
735  vp->width = _screen.width;
736  vp->height = _screen.height;
737  vp->overlay = w->viewport->overlay;
738  break;
739  }
740  case SC_WORLD: {
741  assert(width == 0 && height == 0);
742 
743  /* Determine world coordinates of screenshot */
745 
746  TileIndex north_tile = _settings_game.construction.freeform_edges ? TileXY(1, 1) : TileXY(0, 0);
747  TileIndex south_tile = MapSize() - 1;
748 
749  /* We need to account for a hill or high building at tile 0,0. */
750  int extra_height_top = TilePixelHeight(north_tile) + 150;
751  /* If there is a hill at the bottom don't create a large black area. */
752  int reclaim_height_bottom = TilePixelHeight(south_tile);
753 
754  vp->virtual_left = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, 0).x;
755  vp->virtual_top = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, extra_height_top).y;
756  vp->virtual_width = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, 0).x - vp->virtual_left + 1;
757  vp->virtual_height = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, reclaim_height_bottom).y - vp->virtual_top + 1;
758 
759  /* Compute pixel coordinates */
760  vp->left = 0;
761  vp->top = 0;
762  vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
763  vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
764  vp->overlay = nullptr;
765  break;
766  }
767  default: {
769 
771  vp->virtual_left = w->viewport->virtual_left;
772  vp->virtual_top = w->viewport->virtual_top;
773 
774  if (width == 0 || height == 0) {
775  vp->virtual_width = w->viewport->virtual_width;
776  vp->virtual_height = w->viewport->virtual_height;
777  } else {
778  vp->virtual_width = width << vp->zoom;
779  vp->virtual_height = height << vp->zoom;
780  }
781 
782  /* Compute pixel coordinates */
783  vp->left = 0;
784  vp->top = 0;
785  vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
786  vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
787  vp->overlay = nullptr;
788  break;
789  }
790  }
791 }
792 
800 static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32 width = 0, uint32 height = 0)
801 {
802  Viewport vp;
803  SetupScreenshotViewport(t, &vp, width, height);
804 
808 }
809 
819 static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
820 {
821  byte *buf = (byte *)buffer;
822  while (n > 0) {
823  TileIndex ti = TileXY(MapMaxX(), y);
824  for (uint x = MapMaxX(); 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 
850  for (TileIndex tile = 0; tile < MapSize(); tile++) {
851  uint h = TileHeight(tile);
853  }
854 
856  return sf->proc(filename, HeightmapCallback, nullptr, MapSizeX(), MapSizeY(), 8, palette);
857 }
858 
860 
866 static void ScreenshotConfirmationCallback(Window *w, bool confirmed)
867 {
868  if (confirmed) MakeScreenshot(_confirmed_screenshot_type, {});
869 }
870 
878 {
879  Viewport vp;
880  SetupScreenshotViewport(t, &vp);
881 
882  bool heightmap_or_minimap = t == SC_HEIGHTMAP || t == SC_MINIMAP;
883  uint64_t width = (heightmap_or_minimap ? MapSizeX() : vp.width);
884  uint64_t height = (heightmap_or_minimap ? MapSizeY() : vp.height);
885 
886  if (width * height > 8192 * 8192) {
887  /* Ask for confirmation */
889  SetDParam(0, width);
890  SetDParam(1, height);
891  ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback);
892  } else {
893  /* Less than 64M pixels, just do it */
894  MakeScreenshot(t, {});
895  }
896 }
897 
906 static bool RealMakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
907 {
908  if (t == SC_VIEWPORT) {
909  /* First draw the dirty parts of the screen and only then change the name
910  * of the screenshot. This way the screenshot will always show the name
911  * of the previous screenshot in the 'successful' message instead of the
912  * name of the new screenshot (or an empty name). */
914  UndrawMouseCursor();
915  DrawDirtyBlocks();
917  }
918 
919  _screenshot_name[0] = '\0';
920  if (!name.empty()) strecpy(_screenshot_name, name.c_str(), lastof(_screenshot_name));
921 
922  bool ret;
923  switch (t) {
924  case SC_VIEWPORT:
925  ret = MakeSmallScreenshot(false);
926  break;
927 
928  case SC_CRASHLOG:
929  ret = MakeSmallScreenshot(true);
930  break;
931 
932  case SC_ZOOMEDIN:
933  case SC_DEFAULTZOOM:
934  ret = MakeLargeWorldScreenshot(t, width, height);
935  break;
936 
937  case SC_WORLD:
938  ret = MakeLargeWorldScreenshot(t);
939  break;
940 
941  case SC_HEIGHTMAP: {
944  break;
945  }
946 
947  case SC_MINIMAP:
949  break;
950 
951  default:
952  NOT_REACHED();
953  }
954 
955  if (ret) {
956  if (t == SC_HEIGHTMAP) {
959  ShowErrorMessage(STR_MESSAGE_HEIGHTMAP_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
960  } else {
962  ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
963  }
964  } else {
965  ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, WL_ERROR);
966  }
967 
968  return ret;
969 }
970 
981 bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
982 {
983  if (t == SC_CRASHLOG) {
984  /* Video buffer might or might not be locked. */
986 
987  return RealMakeScreenshot(t, name, width, height);
988  }
989 
990  VideoDriver::GetInstance()->QueueOnMainThread([=] { // Capture by value to not break scope.
991  RealMakeScreenshot(t, name, width, height);
992  });
993 
994  return true;
995 }
996 
997 
1005 {
1006  Owner o;
1007 
1008  if (IsTileType(tile, MP_VOID)) {
1009  return OWNER_END;
1010  } else {
1011  switch (GetTileType(tile)) {
1012  case MP_INDUSTRY: o = OWNER_DEITY; break;
1013  case MP_HOUSE: o = OWNER_TOWN; break;
1014  default: o = GetTileOwner(tile); break;
1015  /* FIXME: For MP_ROAD there are multiple owners.
1016  * GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
1017  * even if there are no ROADTYPE_ROAD bits on the tile.
1018  */
1019  }
1020 
1021  return o;
1022  }
1023 }
1024 
1025 static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
1026 {
1027  /* Fill with the company colours */
1028  byte owner_colours[OWNER_END + 1];
1029  for (const Company *c : Company::Iterate()) {
1030  owner_colours[c->index] = MKCOLOUR(_colour_gradient[c->colour][5]);
1031  }
1032 
1033  /* Fill with some special colours */
1034  owner_colours[OWNER_TOWN] = PC_DARK_RED;
1035  owner_colours[OWNER_NONE] = PC_GRASS_LAND;
1036  owner_colours[OWNER_WATER] = PC_WATER;
1037  owner_colours[OWNER_DEITY] = PC_DARK_GREY; // industry
1038  owner_colours[OWNER_END] = PC_BLACK;
1039 
1040  uint32 *ubuf = (uint32 *)buf;
1041  uint num = (pitch * n);
1042  for (uint i = 0; i < num; i++) {
1043  uint row = y + (int)(i / pitch);
1044  uint col = (MapSizeX() - 1) - (i % pitch);
1045 
1046  TileIndex tile = TileXY(col, row);
1047  Owner o = GetMinimapOwner(tile);
1048  byte val = owner_colours[o];
1049 
1050  uint32 colour_buf = 0;
1051  colour_buf = (_cur_palette.palette[val].b << 0);
1052  colour_buf |= (_cur_palette.palette[val].g << 8);
1053  colour_buf |= (_cur_palette.palette[val].r << 16);
1054 
1055  *ubuf = colour_buf;
1056  ubuf++; // Skip alpha
1057  }
1058 }
1059 
1064 {
1066  return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), MinimapScreenCallback, nullptr, MapSizeX(), MapSizeY(), 32, _cur_palette.palette);
1067 }
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition: tile_type.h:49
RgbQuad
Format of palette data in BMP header.
Definition: screenshot.cpp:99
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
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:719
GetMinimapOwner
static Owner GetMinimapOwner(TileIndex tile)
Return the owner of a tile to display it with in the small map in mode "Owner".
Definition: screenshot.cpp:1004
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:408
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:23
PC_DARK_RED
static const uint8 PC_DARK_RED
Dark red palette colour.
Definition: gfx_func.h:198
HeightmapCallback
static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
Callback for generating a heightmap.
Definition: screenshot.cpp:819
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:321
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:1146
_screenshot_format_name
std::string _screenshot_format_name
Extension of the current screenshot format (corresponds with _cur_screenshot_format).
Definition: screenshot.cpp:38
screenshot_gui.h
BitmapInfoHeader
BMP Info Header (stored in little endian)
Definition: screenshot.cpp:90
saveload.h
zoom_func.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
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:52
SC_ZOOMEDIN
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:21
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:54
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
PC_GRASS_LAND
static const uint8 PC_GRASS_LAND
Dark green palette colour for grass land.
Definition: gfx_func.h:216
newgrf_config.h
ScreenshotFormat::extension
const char * extension
File extension.
Definition: screenshot.cpp:70
Viewport::virtual_top
int virtual_top
Virtual top coordinate.
Definition: viewport_type.h:29
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:53
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:839
InitializeScreenshotFormats
void InitializeScreenshotFormats()
Initialize screenshot format information on startup, with _screenshot_format_name filled from the loa...
Definition: screenshot.cpp:584
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:383
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:859
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:41
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:44
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:314
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:53
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:66
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:346
ScreenshotFormat
Screenshot format information.
Definition: screenshot.cpp:69
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:64
DrawDirtyBlocks
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
Definition: gfx.cpp:1619
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:53
_num_screenshot_formats
uint _num_screenshot_formats
Number of available screenshot formats.
Definition: screenshot.cpp:39
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:601
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:671
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:43
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:187
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
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:192
ZOOM_LVL_VIEWPORT
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.
Definition: zoom_type.h:35
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:71
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:199
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)
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
GenerateDefaultSaveName
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
Definition: saveload.cpp:3360
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
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:131
LargeWorldCallback
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
generate a large piece of the world
Definition: screenshot.cpp:616
_screenshot_formats
static const ScreenshotFormat _screenshot_formats[]
Available screenshot formats.
Definition: screenshot.cpp:569
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:1268
MakeLargeWorldScreenshot
static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32 width=0, uint32 height=0)
Make a screenshot of the map.
Definition: screenshot.cpp:800
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:116
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:439
HEIGHTMAP_NAME
static const char *const HEIGHTMAP_NAME
Default filename of a saved heightmap.
Definition: screenshot.cpp:36
Colour::a
uint8 a
colour channels in LE order
Definition: gfx_type.h:171
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:53
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
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
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:262
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:535
SC_DEFAULTZOOM
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
Definition: screenshot.h:22
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:43
MakeSmallScreenshot
static bool MakeSmallScreenshot(bool crashlog)
Make a screenshot of the current screen.
Definition: screenshot.cpp:705
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:42
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
PC_WATER
static const uint8 PC_WATER
Dark blue palette colour for water.
Definition: gfx_func.h:221
MakeMinimapWorldScreenshot
bool MakeMinimapWorldScreenshot()
Make a minimap screenshot.
Definition: screenshot.cpp:1063
MakeScreenshot
bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
Schedule making a screenshot.
Definition: screenshot.cpp:981
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:49
_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:40
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:578
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
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:877
OWNER_END
@ OWNER_END
Last + 1 owner.
Definition: company_type.h:28
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:578
Window
Data structure for an opened window.
Definition: window_gui.h:279
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:553
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
PC_DARK_GREY
static const uint8 PC_DARK_GREY
Dark grey palette colour.
Definition: gfx_func.h:193
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:112
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:460
SCREENSHOT_NAME
static const char *const SCREENSHOT_NAME
Default filename of a saved screenshot.
Definition: screenshot.cpp:35
Company
Definition: company_base.h:115
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
_heightmap_highest_peak
uint _heightmap_highest_peak
When saving a heightmap, this contains the highest peak on the map.
Definition: screenshot.cpp:43
VideoDriver::VideoBufferLocker
Helper struct to ensure the video buffer is locked and ready for drawing.
Definition: video_driver.hpp:207
RealMakeScreenshot
static bool RealMakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
Make a screenshot.
Definition: screenshot.cpp:906
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
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:296
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:594
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:866
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