OpenTTD Source: src/screenshot.cpp File Reference

OpenTTD Source 14.0-beta1

Data Structures | Macros | Typedefs | Functions | Variables
screenshot.cpp File Reference
`#include "stdafx.h"`
`#include "core/backup_type.hpp"`
`#include "fileio_func.h"`
`#include "viewport_func.h"`
`#include "gfx_func.h"`
`#include "screenshot.h"`
`#include "screenshot_gui.h"`
`#include "blitter/factory.hpp"`
`#include "zoom_func.h"`
`#include "core/endian_func.hpp"`
`#include "saveload/saveload.h"`
`#include "company_base.h"`
`#include "company_func.h"`
`#include "strings_func.h"`
`#include "error.h"`
`#include "textbuf_gui.h"`
`#include "window_gui.h"`
`#include "window_func.h"`
`#include "tile_map.h"`
`#include "landscape.h"`
`#include "video/video_driver.hpp"`
`#include "smallmap_gui.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`
`#include <png.h>`

Go to the source code of this file.

## Data Structures
struct | ScreenshotFormat
| Screenshot format information. More...
struct | BitmapInfoHeader
| BMP Info Header (stored in little endian) More...
struct | RgbQuad
| Format of palette data in BMP header. More...
struct | PcxHeader
| Definition of a PCX file header. More...

## Macros
#define | MKCOLOUR(x) TO_LE32X(x)

## Typedefs
typedef 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. More...
typedef 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. More...

## Functions
| PACK (struct BitmapFileHeader { uint16_t type;uint32_t size;uint32_t reserved;uint32_t off_bits;})
| BMP File Header (stored in little endian)
static bool | MakeBMPImage (const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
| Generic .BMP writer. More...
static void PNGAPI | png_my_error (png_structp png_ptr, png_const_charp message)
static void PNGAPI | png_my_warning (png_structp png_ptr, png_const_charp message)
static bool | MakePNGImage (const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
| Generic .PNG file image writer. More...
static bool | MakePCXImage (const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
| Generic .PCX file image writer. More...
const char * | GetCurrentScreenshotExtension ()
| Get filename extension of current screenshot file format.
void | InitializeScreenshotFormats ()
| Initialize screenshot format information on startup, with _screenshot_format_name filled from the loadsave code.
static void | CurrentScreenCallback (void *, void *buf, uint y, uint pitch, uint n)
| Callback of the screenshot generator that dumps the current video buffer. More...
static void | LargeWorldCallback (void *userdata, void *buf, uint y, uint pitch, uint n)
| generate a large piece of the world More...
static const char * | MakeScreenshotName (const char *default_fn, const char *ext, bool crashlog=false)
| Construct a pathname for a screenshot file. More...
static bool | MakeSmallScreenshot (bool crashlog)
| Make a screenshot of the current screen.
void | SetupScreenshotViewport (ScreenshotType t, Viewport *vp, uint32_t width, uint32_t height)
| Configure a Viewport for rendering (a part of) the map into a screenshot. More...
static bool | MakeLargeWorldScreenshot (ScreenshotType t, uint32_t width=0, uint32_t height=0)
| Make a screenshot of the map. More...
static void | HeightmapCallback (void *, void *buffer, uint y, uint, uint n)
| Callback for generating a heightmap. More...
bool | MakeHeightmapScreenshot (const char *filename)
| Make a heightmap of the current map. More...
static void | ScreenshotConfirmationCallback (Window *, bool confirmed)
| Callback on the confirmation window for huge screenshots. More...
void | MakeScreenshotWithConfirm (ScreenshotType t)
| Make a screenshot. More...
static bool | RealMakeScreenshot (ScreenshotType t, std::string name, uint32_t width, uint32_t height)
| Make a screenshot. More...
bool | MakeScreenshot (ScreenshotType t, std::string name, uint32_t width, uint32_t height)
| Schedule making a screenshot. More...
static void | MinimapScreenCallback (void *, void *buf, uint y, uint pitch, uint n)
bool | MakeMinimapWorldScreenshot ()
| Make a minimap screenshot.

## Variables
static const char *const | SCREENSHOT_NAME = "screenshot"
| Default filename of a saved screenshot.
static const char *const | HEIGHTMAP_NAME = "heightmap"
| Default filename of a saved heightmap.
std::string | _screenshot_format_name
| Extension of the current screenshot format (corresponds with _cur_screenshot_format).
uint | _num_screenshot_formats
| Number of available screenshot formats.
uint | _cur_screenshot_format
| Index of the currently selected screenshot format in _screenshot_formats.
static std::string | _screenshot_name
| Filename of the screenshot file.
std::string | _full_screenshot_path
| Pathname of the screenshot file.
uint | _heightmap_highest_peak
| When saving a heightmap, this contains the highest peak on the map.
static const ScreenshotFormat | _screenshot_formats []
| Available screenshot formats. More...
static ScreenshotType | _confirmed_screenshot_type
| Screenshot type the current query is about to confirm.

## Detailed Description

The creation of screenshots!

Definition in file screenshot.cpp.

## Typedef Documentation

## ◆ ScreenshotCallback

typedef 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.

Parameters

  userdata | Pointer to user data.
  buf | Destination buffer.
  y | Line number of the first line to write.
  pitch | Number of pixels to write (1 byte for 8bpp, 4 bytes for 32bpp).

See also
  Colour

Parameters

  n | Number of lines to write.

Definition at line 55 of file screenshot.cpp.

## ◆ ScreenshotHandlerProc

typedef 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.

Parameters

  name | Filename, including extension.
  callb | Callback function for generating lines of pixels.
  userdata | User data, passed on to callb.
  w | Width of the image in pixels.
  h | Height of the image in pixels.
  pixelformat | Bits per pixel (bpp), either 8 or 32.
  palette | Colour palette (for 8bpp images).

Returns
  File was written successfully.

Definition at line 68 of file screenshot.cpp.

## Function Documentation

## ◆ CurrentScreenCallback()

static void CurrentScreenCallback | ( | void * | ,
|  | void * | buf,
|  | uint | y,
|  | uint | pitch,
|  | uint | n
| ) |  |
| static

Callback of the screenshot generator that dumps the current video buffer.

See also
  ScreenshotCallback

Definition at line 602 of file screenshot.cpp.

Referenced by MakeSmallScreenshot().

## ◆ HeightmapCallback()

static void HeightmapCallback | ( | void * | ,
|  | void * | buffer,
|  | uint | y,
|  | uint | ,
|  | uint | n
| ) |  |
| static

Callback for generating a heightmap.

Supports 8bpp grayscale only.

Parameters

  buffer | Destination buffer.
  y | Line number of the first line to write.
  n | Number of lines to write.

See also
  ScreenshotCallback

Definition at line 819 of file screenshot.cpp.

Referenced by MakeHeightmapScreenshot().

## ◆ LargeWorldCallback()

static void LargeWorldCallback | ( | void * | userdata,
|  | void * | buf,
|  | uint | y,
|  | uint | pitch,
|  | uint | n
| ) |  |
| static

generate a large piece of the world

Parameters

  userdata | Viewport area to draw
  buf | Videobuffer with same bitdepth as current blitter
  y | First line to render
  pitch | Pitch of the videobuffer
  n | Number of lines to render

Definition at line 617 of file screenshot.cpp.

Referenced by MakeLargeWorldScreenshot().

## ◆ MakeBMPImage()

static bool MakeBMPImage | ( | const char * | name,
|  | ScreenshotCallback * | callb,
|  | void * | userdata,
|  | uint | w,
|  | uint | h,
|  | int | pixelformat,
|  | const Colour * | palette
| ) |  |
| static

Generic .BMP writer.

Parameters

  name | file name including extension
  callb | callback used for gathering rendered image
  userdata | parameters forwarded to callb
  w | width in pixels
  h | height in pixels
  pixelformat | bits per pixel
  palette | colour palette (for 8bpp mode)

Returns
  was everything ok?

See also
  ScreenshotHandlerProc

Definition at line 118 of file screenshot.cpp.

References Align().

## ◆ MakeHeightmapScreenshot()

bool MakeHeightmapScreenshot | ( | const char * | filename | ) |

Make a heightmap of the current map.

Parameters

  filename | Filename to use for saving.

Definition at line 839 of file screenshot.cpp.

References _cur_screenshot_format, _heightmap_highest_peak, _screenshot_formats, Colour::a, HeightmapCallback(), lengthof, ScreenshotFormat::proc, Map::Size(), Map::SizeX(), Map::SizeY(), and TileHeight().

## ◆ MakeLargeWorldScreenshot()

static bool MakeLargeWorldScreenshot | ( | ScreenshotType | t,
|  | uint32_t | width = `0`,
|  | uint32_t | height = `0`
| ) |  |
| static

Make a screenshot of the map.

Parameters

  t | Screenshot type: World or viewport screenshot
  width | the width of the screenshot of, or 0 for current viewport width.
  height | the height of the screenshot of, or 0 for current viewport height.

Returns
  true on success

Definition at line 802 of file screenshot.cpp.

References _cur_palette, _cur_screenshot_format, _screenshot_formats, ScreenshotFormat::extension, BlitterFactory::GetCurrentBlitter(), Blitter::GetScreenDepth(), Viewport::height, LargeWorldCallback(), MakeScreenshotName(), Palette::palette, ScreenshotFormat::proc, SCREENSHOT_NAME, SetupScreenshotViewport(), and Viewport::width.

## ◆ MakePCXImage()

static bool MakePCXImage | ( | const char * | name,
|  | ScreenshotCallback * | callb,
|  | void * | userdata,
|  | uint | w,
|  | uint | h,
|  | int | pixelformat,
|  | const Colour * | palette
| ) |  |
| static

Generic .PCX file image writer.

Parameters

  name | Filename, including extension.
  callb | Callback function for generating lines of pixels.
  userdata | User data, passed on to callb.
  w | Width of the image in pixels.
  h | Height of the image in pixels.
  pixelformat | Bits per pixel (bpp), either 8 or 32.
  palette | Colour palette (for 8bpp images).

Returns
  File was written successfully.

See also
  ScreenshotHandlerProc

Definition at line 440 of file screenshot.cpp.

## ◆ MakePNGImage()

static bool MakePNGImage | ( | const char * | name,
|  | ScreenshotCallback * | callb,
|  | void * | userdata,
|  | uint | w,
|  | uint | h,
|  | int | pixelformat,
|  | const Colour * | palette
| ) |  |
| static

Generic .PNG file image writer.

Parameters

  name | Filename, including extension.
  callb | Callback function for generating lines of pixels.
  userdata | User data, passed on to callb.
  w | Width of the image in pixels.
  h | Height of the image in pixels.
  pixelformat | Bits per pixel (bpp), either 8 or 32.
  palette | Colour palette (for 8bpp images).

Returns
  File was written successfully.

See also
  ScreenshotHandlerProc

Definition at line 265 of file screenshot.cpp.

## ◆ MakeScreenshot()

bool MakeScreenshot | ( | ScreenshotType | t,
|  | std::string | name,
|  | uint32_t | width,
|  | uint32_t | height
| ) |  |

Schedule making a screenshot.

Unconditionally take a screenshot of the requested type.

Parameters

  t | the type of screenshot to make.
  name | the name to give to the screenshot.
  width | the width of the screenshot of, or 0 for current viewport width (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM).
  height | the height of the screenshot of, or 0 for current viewport height (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM).

Returns
  true iff the screenshot was successfully made.

See also
  MakeScreenshotWithConfirm

Definition at line 979 of file screenshot.cpp.

References VideoDriver::GetInstance(), lock, VideoDriver::QueueOnMainThread(), RealMakeScreenshot(), and SC_CRASHLOG.

Referenced by MakeScreenshotWithConfirm(), and ScreenshotConfirmationCallback().

## ◆ MakeScreenshotName()

static const char* MakeScreenshotName | ( | const char * | default_fn,
|  | const char * | ext,
|  | bool | crashlog = `false`
| ) |  |
| static

Construct a pathname for a screenshot file.

Parameters

  default_fn | Default filename.
  ext | Extension to use.
  crashlog | Create path for crash.png

Returns
  Pathname for a screenshot file.

Definition at line 669 of file screenshot.cpp.

References _screenshot_name.

Referenced by MakeLargeWorldScreenshot(), MakeMinimapWorldScreenshot(), and MakeSmallScreenshot().

## ◆ MakeScreenshotWithConfirm()

void MakeScreenshotWithConfirm | ( | ScreenshotType | t | ) |

Make a screenshot.

Ask for confirmation first if the screenshot will be huge.

Parameters

  t | Screenshot type: World, defaultzoom, heightmap or viewport screenshot

See also
  MakeScreenshot

Definition at line 876 of file screenshot.cpp.

References _confirmed_screenshot_type, Viewport::height, MakeScreenshot(), SC_HEIGHTMAP, SC_MINIMAP, ScreenshotConfirmationCallback(), SetDParam(), SetupScreenshotViewport(), ShowQuery(), Map::SizeX(), Map::SizeY(), and Viewport::width.

## ◆ RealMakeScreenshot()

static bool RealMakeScreenshot | ( | ScreenshotType | t,
|  | std::string | name,
|  | uint32_t | width,
|  | uint32_t | height
| ) |  |
| static

Make a screenshot.

Parameters

  t | the type of screenshot to make.
  name | the name to give to the screenshot.
  width | the width of the screenshot of, or 0 for current viewport width (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM).
  height | the height of the screenshot of, or 0 for current viewport height (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM).

Returns
  true iff the screenshot was made successfully

Definition at line 905 of file screenshot.cpp.

References SC_VIEWPORT, and SetScreenshotWindowVisibility().

Referenced by MakeScreenshot().

## ◆ ScreenshotConfirmationCallback()

static void ScreenshotConfirmationCallback | ( | Window * | ,
|  | bool | confirmed
| ) |  |
| static

Callback on the confirmation window for huge screenshots.

Parameters

  confirmed | true on confirmation

Definition at line 865 of file screenshot.cpp.

References _confirmed_screenshot_type, and MakeScreenshot().

Referenced by MakeScreenshotWithConfirm().

## ◆ SetupScreenshotViewport()

void SetupScreenshotViewport | ( | ScreenshotType | t,
|  | Viewport * | vp,
|  | uint32_t | width,
|  | uint32_t | height
| ) |  |

Configure a Viewport for rendering (a part of) the map into a screenshot.

Parameters

  | t | Screenshot type
  | width | the width of the screenshot, or 0 for current viewport width (needs to be 0 with SC_VIEWPORT, SC_CRASHLOG, and SC_WORLD).
  | height | the height of the screenshot, or 0 for current viewport height (needs to be 0 with SC_VIEWPORT, SC_CRASHLOG, and SC_WORLD).
  [out] | vp | Result viewport

Definition at line 721 of file screenshot.cpp.

References GetMainWindow(), Viewport::left, SC_CRASHLOG, SC_VIEWPORT, Viewport::top, Window::viewport, Viewport::virtual_height, Viewport::virtual_left, Viewport::virtual_top, Viewport::virtual_width, and Viewport::width.

Referenced by MakeLargeWorldScreenshot(), and MakeScreenshotWithConfirm().

## Variable Documentation

## ◆ _screenshot_formats

const ScreenshotFormat _screenshot_formats[]
| static

Initial value:
= {
{"png", &MakePNGImage},
{"bmp", &MakeBMPImage},
{"pcx", &MakePCXImage},
}

Available screenshot formats.

Definition at line 570 of file screenshot.cpp.

Referenced by GetCurrentScreenshotExtension(), InitializeScreenshotFormats(), MakeHeightmapScreenshot(), MakeLargeWorldScreenshot(), MakeMinimapWorldScreenshot(), and MakeSmallScreenshot().

MakeBMPImage
static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Generic .BMP writer.
Definition: screenshot.cpp:118
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
MakePNGImage
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Generic .PNG file image writer.
Definition: screenshot.cpp:265