OpenTTD Source  12.0-beta2
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 "blitter/factory.hpp"
16 #include "zoom_func.h"
17 #include "core/endian_func.hpp"
18 #include "saveload/saveload.h"
19 #include "company_base.h"
20 #include "company_func.h"
21 #include "strings_func.h"
22 #include "error.h"
23 #include "textbuf_gui.h"
24 #include "window_gui.h"
25 #include "window_func.h"
26 #include "tile_map.h"
27 #include "landscape.h"
28 #include "video/video_driver.hpp"
29 
30 #include "table/strings.h"
31 
32 #include "safeguards.h"
33 
34 static const char * const SCREENSHOT_NAME = "screenshot";
35 static const char * const HEIGHTMAP_NAME = "heightmap";
36 
40 static char _screenshot_name[128];
41 char _full_screenshot_name[MAX_PATH];
43 
52 typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n);
53 
65 typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
66 
69  const char *extension;
71 };
72 
73 #define MKCOLOUR(x) TO_LE32X(x)
74 
75 /*************************************************
76  **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
77  *************************************************/
78 
80 PACK(struct BitmapFileHeader {
81  uint16 type;
82  uint32 size;
83  uint32 reserved;
84  uint32 off_bits;
85 });
86 static_assert(sizeof(BitmapFileHeader) == 14);
87 
90  uint32 size;
91  int32 width, height;
92  uint16 planes, bitcount;
93  uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
94 };
95 static_assert(sizeof(BitmapInfoHeader) == 40);
96 
98 struct RgbQuad {
99  byte blue, green, red, reserved;
100 };
101 static_assert(sizeof(RgbQuad) == 4);
102 
115 static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
116 {
117  uint bpp; // bytes per pixel
118  switch (pixelformat) {
119  case 8: bpp = 1; break;
120  /* 32bpp mode is saved as 24bpp BMP */
121  case 32: bpp = 3; break;
122  /* Only implemented for 8bit and 32bit images so far */
123  default: return false;
124  }
125 
126  FILE *f = fopen(name, "wb");
127  if (f == nullptr) return false;
128 
129  /* Each scanline must be aligned on a 32bit boundary */
130  uint bytewidth = Align(w * bpp, 4); // bytes per line in file
131 
132  /* Size of palette. Only present for 8bpp mode */
133  uint pal_size = pixelformat == 8 ? sizeof(RgbQuad) * 256 : 0;
134 
135  /* Setup the file header */
136  BitmapFileHeader bfh;
137  bfh.type = TO_LE16('MB');
138  bfh.size = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size + bytewidth * h);
139  bfh.reserved = 0;
140  bfh.off_bits = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size);
141 
142  /* Setup the info header */
143  BitmapInfoHeader bih;
144  bih.size = TO_LE32(sizeof(BitmapInfoHeader));
145  bih.width = TO_LE32(w);
146  bih.height = TO_LE32(h);
147  bih.planes = TO_LE16(1);
148  bih.bitcount = TO_LE16(bpp * 8);
149  bih.compression = 0;
150  bih.sizeimage = 0;
151  bih.xpels = 0;
152  bih.ypels = 0;
153  bih.clrused = 0;
154  bih.clrimp = 0;
155 
156  /* Write file header and info header */
157  if (fwrite(&bfh, sizeof(bfh), 1, f) != 1 || fwrite(&bih, sizeof(bih), 1, f) != 1) {
158  fclose(f);
159  return false;
160  }
161 
162  if (pixelformat == 8) {
163  /* Convert the palette to the windows format */
164  RgbQuad rq[256];
165  for (uint i = 0; i < 256; i++) {
166  rq[i].red = palette[i].r;
167  rq[i].green = palette[i].g;
168  rq[i].blue = palette[i].b;
169  rq[i].reserved = 0;
170  }
171  /* Write the palette */
172  if (fwrite(rq, sizeof(rq), 1, f) != 1) {
173  fclose(f);
174  return false;
175  }
176  }
177 
178  /* Try to use 64k of memory, store between 16 and 128 lines */
179  uint maxlines = Clamp(65536 / (w * pixelformat / 8), 16, 128); // number of lines per iteration
180 
181  uint8 *buff = MallocT<uint8>(maxlines * w * pixelformat / 8); // buffer which is rendered to
182  uint8 *line = AllocaM(uint8, bytewidth); // one line, stored to file
183  memset(line, 0, bytewidth);
184 
185  /* Start at the bottom, since bitmaps are stored bottom up */
186  do {
187  uint n = std::min(h, maxlines);
188  h -= n;
189 
190  /* Render the pixels */
191  callb(userdata, buff, h, w, n);
192 
193  /* Write each line */
194  while (n-- != 0) {
195  if (pixelformat == 8) {
196  /* Move to 'line', leave last few pixels in line zeroed */
197  memcpy(line, buff + n * w, w);
198  } else {
199  /* Convert from 'native' 32bpp to BMP-like 24bpp.
200  * Works for both big and little endian machines */
201  Colour *src = ((Colour *)buff) + n * w;
202  byte *dst = line;
203  for (uint i = 0; i < w; i++) {
204  dst[i * 3 ] = src[i].b;
205  dst[i * 3 + 1] = src[i].g;
206  dst[i * 3 + 2] = src[i].r;
207  }
208  }
209  /* Write to file */
210  if (fwrite(line, bytewidth, 1, f) != 1) {
211  free(buff);
212  fclose(f);
213  return false;
214  }
215  }
216  } while (h != 0);
217 
218  free(buff);
219  fclose(f);
220 
221  return true;
222 }
223 
224 /*********************************************************
225  **** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG)
226  *********************************************************/
227 #if defined(WITH_PNG)
228 #include <png.h>
229 
230 #ifdef PNG_TEXT_SUPPORTED
231 #include "rev.h"
232 #include "newgrf_config.h"
233 #include "ai/ai_info.hpp"
234 #include "company_base.h"
235 #include "base_media_base.h"
236 #endif /* PNG_TEXT_SUPPORTED */
237 
238 static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
239 {
240  Debug(misc, 0, "[libpng] error: {} - {}", message, (const char *)png_get_error_ptr(png_ptr));
241  longjmp(png_jmpbuf(png_ptr), 1);
242 }
243 
244 static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
245 {
246  Debug(misc, 1, "[libpng] warning: {} - {}", message, (const char *)png_get_error_ptr(png_ptr));
247 }
248 
261 static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
262 {
263  png_color rq[256];
264  FILE *f;
265  uint i, y, n;
266  uint maxlines;
267  uint bpp = pixelformat / 8;
268  png_structp png_ptr;
269  png_infop info_ptr;
270 
271  /* only implemented for 8bit and 32bit images so far. */
272  if (pixelformat != 8 && pixelformat != 32) return false;
273 
274  f = fopen(name, "wb");
275  if (f == nullptr) return false;
276 
277  png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, const_cast<char *>(name), png_my_error, png_my_warning);
278 
279  if (png_ptr == nullptr) {
280  fclose(f);
281  return false;
282  }
283 
284  info_ptr = png_create_info_struct(png_ptr);
285  if (info_ptr == nullptr) {
286  png_destroy_write_struct(&png_ptr, (png_infopp)nullptr);
287  fclose(f);
288  return false;
289  }
290 
291  if (setjmp(png_jmpbuf(png_ptr))) {
292  png_destroy_write_struct(&png_ptr, &info_ptr);
293  fclose(f);
294  return false;
295  }
296 
297  png_init_io(png_ptr, f);
298 
299  png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
300 
301  png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB,
302  PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
303 
304 #ifdef PNG_TEXT_SUPPORTED
305  /* Try to add some game metadata to the PNG screenshot so
306  * it's more useful for debugging and archival purposes. */
307  png_text_struct text[2];
308  memset(text, 0, sizeof(text));
309  text[0].key = const_cast<char *>("Software");
310  text[0].text = const_cast<char *>(_openttd_revision);
311  text[0].text_length = strlen(_openttd_revision);
312  text[0].compression = PNG_TEXT_COMPRESSION_NONE;
313 
314  char buf[8192];
315  char *p = buf;
316  p += seprintf(p, lastof(buf), "Graphics set: %s (%u)\n", BaseGraphics::GetUsedSet()->name.c_str(), BaseGraphics::GetUsedSet()->version);
317  p = strecpy(p, "NewGRFs:\n", lastof(buf));
318  for (const GRFConfig *c = _game_mode == GM_MENU ? nullptr : _grfconfig; c != nullptr; c = c->next) {
319  p += seprintf(p, lastof(buf), "%08X ", BSWAP32(c->ident.grfid));
320  p = md5sumToString(p, lastof(buf), c->ident.md5sum);
321  p += seprintf(p, lastof(buf), " %s\n", c->filename);
322  }
323  p = strecpy(p, "\nCompanies:\n", lastof(buf));
324  for (const Company *c : Company::Iterate()) {
325  if (c->ai_info == nullptr) {
326  p += seprintf(p, lastof(buf), "%2i: Human\n", (int)c->index);
327  } else {
328  p += seprintf(p, lastof(buf), "%2i: %s (v%d)\n", (int)c->index, c->ai_info->GetName(), c->ai_info->GetVersion());
329  }
330  }
331  text[1].key = const_cast<char *>("Description");
332  text[1].text = buf;
333  text[1].text_length = p - buf;
334  text[1].compression = PNG_TEXT_COMPRESSION_zTXt;
335  png_set_text(png_ptr, info_ptr, text, 2);
336 #endif /* PNG_TEXT_SUPPORTED */
337 
338  if (pixelformat == 8) {
339  /* convert the palette to the .PNG format. */
340  for (i = 0; i != 256; i++) {
341  rq[i].red = palette[i].r;
342  rq[i].green = palette[i].g;
343  rq[i].blue = palette[i].b;
344  }
345 
346  png_set_PLTE(png_ptr, info_ptr, rq, 256);
347  }
348 
349  png_write_info(png_ptr, info_ptr);
350  png_set_flush(png_ptr, 512);
351 
352  if (pixelformat == 32) {
353  png_color_8 sig_bit;
354 
355  /* Save exact colour/alpha resolution */
356  sig_bit.alpha = 0;
357  sig_bit.blue = 8;
358  sig_bit.green = 8;
359  sig_bit.red = 8;
360  sig_bit.gray = 8;
361  png_set_sBIT(png_ptr, info_ptr, &sig_bit);
362 
363 #if TTD_ENDIAN == TTD_LITTLE_ENDIAN
364  png_set_bgr(png_ptr);
365  png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
366 #else
367  png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
368 #endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */
369  }
370 
371  /* use by default 64k temp memory */
372  maxlines = Clamp(65536 / w, 16, 128);
373 
374  /* now generate the bitmap bits */
375  void *buff = CallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time.
376 
377  y = 0;
378  do {
379  /* determine # lines to write */
380  n = std::min(h - y, maxlines);
381 
382  /* render the pixels into the buffer */
383  callb(userdata, buff, y, w, n);
384  y += n;
385 
386  /* write them to png */
387  for (i = 0; i != n; i++) {
388  png_write_row(png_ptr, (png_bytep)buff + i * w * bpp);
389  }
390  } while (y != h);
391 
392  png_write_end(png_ptr, info_ptr);
393  png_destroy_write_struct(&png_ptr, &info_ptr);
394 
395  free(buff);
396  fclose(f);
397  return true;
398 }
399 #endif /* WITH_PNG */
400 
401 
402 /*************************************************
403  **** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX)
404  *************************************************/
405 
407 struct PcxHeader {
408  byte manufacturer;
409  byte version;
410  byte rle;
411  byte bpp;
412  uint32 unused;
413  uint16 xmax, ymax;
414  uint16 hdpi, vdpi;
415  byte pal_small[16 * 3];
416  byte reserved;
417  byte planes;
418  uint16 pitch;
419  uint16 cpal;
420  uint16 width;
421  uint16 height;
422  byte filler[54];
423 };
424 static_assert(sizeof(PcxHeader) == 128);
425 
438 static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
439 {
440  FILE *f;
441  uint maxlines;
442  uint y;
443  PcxHeader pcx;
444  bool success;
445 
446  if (pixelformat == 32) {
447  Debug(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick another format.");
448  return false;
449  }
450  if (pixelformat != 8 || w == 0) return false;
451 
452  f = fopen(name, "wb");
453  if (f == nullptr) return false;
454 
455  memset(&pcx, 0, sizeof(pcx));
456 
457  /* setup pcx header */
458  pcx.manufacturer = 10;
459  pcx.version = 5;
460  pcx.rle = 1;
461  pcx.bpp = 8;
462  pcx.xmax = TO_LE16(w - 1);
463  pcx.ymax = TO_LE16(h - 1);
464  pcx.hdpi = TO_LE16(320);
465  pcx.vdpi = TO_LE16(320);
466 
467  pcx.planes = 1;
468  pcx.cpal = TO_LE16(1);
469  pcx.width = pcx.pitch = TO_LE16(w);
470  pcx.height = TO_LE16(h);
471 
472  /* write pcx header */
473  if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) {
474  fclose(f);
475  return false;
476  }
477 
478  /* use by default 64k temp memory */
479  maxlines = Clamp(65536 / w, 16, 128);
480 
481  /* now generate the bitmap bits */
482  uint8 *buff = CallocT<uint8>(w * maxlines); // by default generate 128 lines at a time.
483 
484  y = 0;
485  do {
486  /* determine # lines to write */
487  uint n = std::min(h - y, maxlines);
488  uint i;
489 
490  /* render the pixels into the buffer */
491  callb(userdata, buff, y, w, n);
492  y += n;
493 
494  /* write them to pcx */
495  for (i = 0; i != n; i++) {
496  const uint8 *bufp = buff + i * w;
497  byte runchar = bufp[0];
498  uint runcount = 1;
499  uint j;
500 
501  /* for each pixel... */
502  for (j = 1; j < w; j++) {
503  uint8 ch = bufp[j];
504 
505  if (ch != runchar || runcount >= 0x3f) {
506  if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
507  if (fputc(0xC0 | runcount, f) == EOF) {
508  free(buff);
509  fclose(f);
510  return false;
511  }
512  }
513  if (fputc(runchar, f) == EOF) {
514  free(buff);
515  fclose(f);
516  return false;
517  }
518  runcount = 0;
519  runchar = ch;
520  }
521  runcount++;
522  }
523 
524  /* write remaining bytes.. */
525  if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
526  if (fputc(0xC0 | runcount, f) == EOF) {
527  free(buff);
528  fclose(f);
529  return false;
530  }
531  }
532  if (fputc(runchar, f) == EOF) {
533  free(buff);
534  fclose(f);
535  return false;
536  }
537  }
538  } while (y != h);
539 
540  free(buff);
541 
542  /* write 8-bit colour palette */
543  if (fputc(12, f) == EOF) {
544  fclose(f);
545  return false;
546  }
547 
548  /* Palette is word-aligned, copy it to a temporary byte array */
549  byte tmp[256 * 3];
550 
551  for (uint i = 0; i < 256; i++) {
552  tmp[i * 3 + 0] = palette[i].r;
553  tmp[i * 3 + 1] = palette[i].g;
554  tmp[i * 3 + 2] = palette[i].b;
555  }
556  success = fwrite(tmp, sizeof(tmp), 1, f) == 1;
557 
558  fclose(f);
559 
560  return success;
561 }
562 
563 /*************************************************
564  **** GENERIC SCREENSHOT CODE
565  *************************************************/
566 
569 #if defined(WITH_PNG)
570  {"png", &MakePNGImage},
571 #endif
572  {"bmp", &MakeBMPImage},
573  {"pcx", &MakePCXImage},
574 };
575 
578 {
580 }
581 
584 {
585  uint j = 0;
586  for (uint i = 0; i < lengthof(_screenshot_formats); i++) {
588  j = i;
589  break;
590  }
591  }
594 }
595 
600 static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
601 {
603  void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
604  blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch);
605 }
606 
615 static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
616 {
617  Viewport *vp = (Viewport *)userdata;
618  DrawPixelInfo dpi, *old_dpi;
619  int wx, left;
620 
621  /* We are no longer rendering to the screen */
622  DrawPixelInfo old_screen = _screen;
623  bool old_disable_anim = _screen_disable_anim;
624 
625  _screen.dst_ptr = buf;
626  _screen.width = pitch;
627  _screen.height = n;
628  _screen.pitch = pitch;
629  _screen_disable_anim = true;
630 
631  old_dpi = _cur_dpi;
632  _cur_dpi = &dpi;
633 
634  dpi.dst_ptr = buf;
635  dpi.height = n;
636  dpi.width = vp->width;
637  dpi.pitch = pitch;
638  dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT;
639  dpi.left = 0;
640  dpi.top = y;
641 
642  /* Render viewport in blocks of 1600 pixels width */
643  left = 0;
644  while (vp->width - left != 0) {
645  wx = std::min(vp->width - left, 1600);
646  left += wx;
647 
648  ViewportDoDraw(vp,
649  ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left,
650  ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top,
651  ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
652  ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top
653  );
654  }
655 
656  _cur_dpi = old_dpi;
657 
658  /* Switch back to rendering to the screen */
659  _screen = old_screen;
660  _screen_disable_anim = old_disable_anim;
661 }
662 
670 static const char *MakeScreenshotName(const char *default_fn, const char *ext, bool crashlog = false)
671 {
672  bool generate = StrEmpty(_screenshot_name);
673 
674  if (generate) {
675  if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
677  } else {
679  }
680  }
681 
682  /* Add extension to screenshot file */
683  size_t len = strlen(_screenshot_name);
684  seprintf(&_screenshot_name[len], lastof(_screenshot_name), ".%s", ext);
685 
686  const char *screenshot_dir = crashlog ? _personal_dir.c_str() : FiosGetScreenshotDir();
687 
688  for (uint serial = 1;; serial++) {
690  /* We need more characters than MAX_PATH -> end with error */
691  _full_screenshot_name[0] = '\0';
692  break;
693  }
694  if (!generate) break; // allow overwriting of non-automatic filenames
695  if (!FileExists(_full_screenshot_name)) break;
696  /* If file exists try another one with same name, but just with a higher index */
697  seprintf(&_screenshot_name[len], lastof(_screenshot_name) - len, "#%u.%s", serial, ext);
698  }
699 
700  return _full_screenshot_name;
701 }
702 
704 static bool MakeSmallScreenshot(bool crashlog)
705 {
707  return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension, crashlog), CurrentScreenCallback, nullptr, _screen.width, _screen.height,
709 }
710 
718 void SetupScreenshotViewport(ScreenshotType t, Viewport *vp, uint32 width, uint32 height)
719 {
720  switch(t) {
721  case SC_VIEWPORT:
722  case SC_CRASHLOG: {
723  assert(width == 0 && height == 0);
724 
727  vp->virtual_top = w->viewport->virtual_top;
730 
731  /* Compute pixel coordinates */
732  vp->left = 0;
733  vp->top = 0;
734  vp->width = _screen.width;
735  vp->height = _screen.height;
736  vp->overlay = w->viewport->overlay;
737  break;
738  }
739  case SC_WORLD: {
740  assert(width == 0 && height == 0);
741 
742  /* Determine world coordinates of screenshot */
744 
745  TileIndex north_tile = _settings_game.construction.freeform_edges ? TileXY(1, 1) : TileXY(0, 0);
746  TileIndex south_tile = MapSize() - 1;
747 
748  /* We need to account for a hill or high building at tile 0,0. */
749  int extra_height_top = TilePixelHeight(north_tile) + 150;
750  /* If there is a hill at the bottom don't create a large black area. */
751  int reclaim_height_bottom = TilePixelHeight(south_tile);
752 
753  vp->virtual_left = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, 0).x;
754  vp->virtual_top = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, extra_height_top).y;
755  vp->virtual_width = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, 0).x - vp->virtual_left + 1;
756  vp->virtual_height = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, reclaim_height_bottom).y - vp->virtual_top + 1;
757 
758  /* Compute pixel coordinates */
759  vp->left = 0;
760  vp->top = 0;
761  vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
762  vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
763  vp->overlay = nullptr;
764  break;
765  }
766  default: {
768 
770  vp->virtual_left = w->viewport->virtual_left;
771  vp->virtual_top = w->viewport->virtual_top;
772 
773  if (width == 0 || height == 0) {
774  vp->virtual_width = w->viewport->virtual_width;
775  vp->virtual_height = w->viewport->virtual_height;
776  } else {
777  vp->virtual_width = width << vp->zoom;
778  vp->virtual_height = height << vp->zoom;
779  }
780 
781  /* Compute pixel coordinates */
782  vp->left = 0;
783  vp->top = 0;
784  vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
785  vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
786  vp->overlay = nullptr;
787  break;
788  }
789  }
790 }
791 
799 static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32 width = 0, uint32 height = 0)
800 {
801  Viewport vp;
802  SetupScreenshotViewport(t, &vp, width, height);
803 
807 }
808 
818 static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
819 {
820  byte *buf = (byte *)buffer;
821  while (n > 0) {
822  TileIndex ti = TileXY(MapMaxX(), y);
823  for (uint x = MapMaxX(); true; x--) {
824  *buf = 256 * TileHeight(ti) / (1 + _heightmap_highest_peak);
825  buf++;
826  if (x == 0) break;
827  ti = TILE_ADDXY(ti, -1, 0);
828  }
829  y++;
830  n--;
831  }
832 }
833 
838 bool MakeHeightmapScreenshot(const char *filename)
839 {
840  Colour palette[256];
841  for (uint i = 0; i < lengthof(palette); i++) {
842  palette[i].a = 0xff;
843  palette[i].r = i;
844  palette[i].g = i;
845  palette[i].b = i;
846  }
847 
849  for (TileIndex tile = 0; tile < MapSize(); tile++) {
850  uint h = TileHeight(tile);
852  }
853 
855  return sf->proc(filename, HeightmapCallback, nullptr, MapSizeX(), MapSizeY(), 8, palette);
856 }
857 
859 
865 static void ScreenshotConfirmationCallback(Window *w, bool confirmed)
866 {
867  if (confirmed) MakeScreenshot(_confirmed_screenshot_type, {});
868 }
869 
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 ? MapSizeX() : vp.width);
883  uint64_t height = (heightmap_or_minimap ? MapSizeY() : vp.height);
884 
885  if (width * height > 8192 * 8192) {
886  /* Ask for confirmation */
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 width, uint32 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  UndrawMouseCursor();
913  DrawDirtyBlocks();
914  }
915 
916  _screenshot_name[0] = '\0';
917  if (!name.empty()) strecpy(_screenshot_name, name.c_str(), lastof(_screenshot_name));
918 
919  bool ret;
920  switch (t) {
921  case SC_VIEWPORT:
922  ret = MakeSmallScreenshot(false);
923  break;
924 
925  case SC_CRASHLOG:
926  ret = MakeSmallScreenshot(true);
927  break;
928 
929  case SC_ZOOMEDIN:
930  case SC_DEFAULTZOOM:
931  ret = MakeLargeWorldScreenshot(t, width, height);
932  break;
933 
934  case SC_WORLD:
935  ret = MakeLargeWorldScreenshot(t);
936  break;
937 
938  case SC_HEIGHTMAP: {
941  break;
942  }
943 
944  case SC_MINIMAP:
946  break;
947 
948  default:
949  NOT_REACHED();
950  }
951 
952  if (ret) {
953  if (t == SC_HEIGHTMAP) {
956  ShowErrorMessage(STR_MESSAGE_HEIGHTMAP_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
957  } else {
959  ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
960  }
961  } else {
962  ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, WL_ERROR);
963  }
964 
965  return ret;
966 }
967 
978 bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
979 {
980  if (t == SC_CRASHLOG) {
981  /* Video buffer might or might not be locked. */
983 
984  return RealMakeScreenshot(t, name, width, height);
985  }
986 
987  VideoDriver::GetInstance()->QueueOnMainThread([=] { // Capture by value to not break scope.
988  RealMakeScreenshot(t, name, width, height);
989  });
990 
991  return true;
992 }
993 
994 
1002 {
1003  Owner o;
1004 
1005  if (IsTileType(tile, MP_VOID)) {
1006  return OWNER_END;
1007  } else {
1008  switch (GetTileType(tile)) {
1009  case MP_INDUSTRY: o = OWNER_DEITY; break;
1010  case MP_HOUSE: o = OWNER_TOWN; break;
1011  default: o = GetTileOwner(tile); break;
1012  /* FIXME: For MP_ROAD there are multiple owners.
1013  * GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
1014  * even if there are no ROADTYPE_ROAD bits on the tile.
1015  */
1016  }
1017 
1018  return o;
1019  }
1020 }
1021 
1022 static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
1023 {
1024  /* Fill with the company colours */
1025  byte owner_colours[OWNER_END + 1];
1026  for (const Company *c : Company::Iterate()) {
1027  owner_colours[c->index] = MKCOLOUR(_colour_gradient[c->colour][5]);
1028  }
1029 
1030  /* Fill with some special colours */
1031  owner_colours[OWNER_TOWN] = PC_DARK_RED;
1032  owner_colours[OWNER_NONE] = PC_GRASS_LAND;
1033  owner_colours[OWNER_WATER] = PC_WATER;
1034  owner_colours[OWNER_DEITY] = PC_DARK_GREY; // industry
1035  owner_colours[OWNER_END] = PC_BLACK;
1036 
1037  uint32 *ubuf = (uint32 *)buf;
1038  uint num = (pitch * n);
1039  for (uint i = 0; i < num; i++) {
1040  uint row = y + (int)(i / pitch);
1041  uint col = (MapSizeX() - 1) - (i % pitch);
1042 
1043  TileIndex tile = TileXY(col, row);
1044  Owner o = GetMinimapOwner(tile);
1045  byte val = owner_colours[o];
1046 
1047  uint32 colour_buf = 0;
1048  colour_buf = (_cur_palette.palette[val].b << 0);
1049  colour_buf |= (_cur_palette.palette[val].g << 8);
1050  colour_buf |= (_cur_palette.palette[val].r << 16);
1051 
1052  *ubuf = colour_buf;
1053  ubuf++; // Skip alpha
1054  }
1055 }
1056 
1061 {
1063  return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), MinimapScreenCallback, nullptr, MapSizeX(), MapSizeY(), 32, _cur_palette.palette);
1064 }
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:98
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:718
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:1001
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:407
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:196
HeightmapCallback
static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
Callback for generating a heightmap.
Definition: screenshot.cpp:818
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:37
BitmapInfoHeader
BMP Info Header (stored in little endian)
Definition: screenshot.cpp:89
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:214
newgrf_config.h
ScreenshotFormat::extension
const char * extension
File extension.
Definition: screenshot.cpp:69
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:52
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:838
InitializeScreenshotFormats
void InitializeScreenshotFormats()
Initialize screenshot format information on startup, with _screenshot_format_name filled from the loa...
Definition: screenshot.cpp:583
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:858
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:40
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:43
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:65
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:345
ScreenshotFormat
Screenshot format information.
Definition: screenshot.cpp:68
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:1557
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:52
_num_screenshot_formats
uint _num_screenshot_formats
Number of available screenshot formats.
Definition: screenshot.cpp:38
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:600
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:670
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:190
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:70
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:129
LargeWorldCallback
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
generate a large piece of the world
Definition: screenshot.cpp:615
_screenshot_formats
static const ScreenshotFormat _screenshot_formats[]
Available screenshot formats.
Definition: screenshot.cpp:568
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:1267
MakeLargeWorldScreenshot
static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32 width=0, uint32 height=0)
Make a screenshot of the map.
Definition: screenshot.cpp:799
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:115
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:438
HEIGHTMAP_NAME
static const char *const HEIGHTMAP_NAME
Default filename of a saved heightmap.
Definition: screenshot.cpp:35
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:261
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:704
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:41
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:219
MakeMinimapWorldScreenshot
bool MakeMinimapWorldScreenshot()
Make a minimap screenshot.
Definition: screenshot.cpp:1060
MakeScreenshot
bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 height)
Schedule making a screenshot.
Definition: screenshot.cpp:978
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:48
_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:39
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:577
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:876
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:577
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:191
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:34
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:42
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:905
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:593
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:865
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