The creation of screenshots! More...
#include "stdafx.h"#include "fileio_func.h"#include "viewport_func.h"#include "gfx_func.h"#include "screenshot.h"#include "blitter/factory.hpp"#include "zoom_func.h"#include "core/endian_func.hpp"#include "saveload/saveload.h"#include "company_func.h"#include "strings_func.h"#include "error.h"#include "window_gui.h"#include "window_func.h"#include "tile_map.h"#include "table/strings.h"#include <png.h>Go to the source code of this file.
Data Structures | |
| struct | ScreenshotFormat |
| Screenshot format information. More... | |
| struct | BitmapFileHeader |
| BMP File Header (stored in little endian). 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... | |
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. | |
| 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. | |
Functions | |
| assert_compile (sizeof(BitmapFileHeader)==14) | |
| assert_compile (sizeof(BitmapInfoHeader)==40) | |
| assert_compile (sizeof(RgbQuad)==4) | |
| static bool | MakeBMPImage (const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
| Generic .BMP writer. | |
| 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. | |
| assert_compile (sizeof(PcxHeader)==128) | |
| static bool | MakePCXImage (const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
| Generic .PCX file image writer. | |
| 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. | |
| const char * | GetScreenshotFormatDesc (int i) |
| Give descriptive name of the screenshot format. | |
| bool | GetScreenshotFormatSupports_32bpp (int i) |
| Determine whether a certain screenshot format support 32bpp images. | |
| void | SetScreenshotFormat (uint i) |
| Set the screenshot format to use. | |
| static void | CurrentScreenCallback (void *userdata, void *buf, uint y, uint pitch, uint n) |
| Callback of the screenshot generator that dumps the current video buffer. | |
| static void | LargeWorldCallback (void *userdata, void *buf, uint y, uint pitch, uint n) |
| generate a large piece of the world | |
| static const char * | MakeScreenshotName (const char *default_fn, const char *ext) |
| Construct a pathname for a screenshot file. | |
| static bool | MakeSmallScreenshot () |
| Make a screenshot of the current screen. | |
| static bool | MakeZoomedInScreenshot (ZoomLevel zl) |
| Make a zoomed-in screenshot of the currently visible area. | |
| static bool | MakeWorldScreenshot () |
| Make a screenshot of the whole map. | |
| static void | HeightmapCallback (void *userdata, void *buffer, uint y, uint pitch, uint n) |
| Callback for generating a heightmap. | |
| bool | MakeHeightmapScreenshot (const char *filename) |
| Make a heightmap of the current map. | |
| bool | MakeScreenshot (ScreenshotType t, const char *name) |
| Make an actual 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. | |
| char | _screenshot_format_name [8] |
| 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 char | _screenshot_name [128] |
| Filename of the screenshot file. | |
| char | _full_screenshot_name [MAX_PATH] |
| Pathname of the screenshot file. | |
| struct BitmapFileHeader | GCC_PACK |
| BMP File Header (stored in little endian). | |
| static const ScreenshotFormat | _screenshot_formats [] |
| Available screenshot formats. | |
The creation of screenshots!
Definition in file screenshot.cpp.
| 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.
| 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). |
| n | Number of lines to write. |
Definition at line 47 of file screenshot.cpp.
| 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.
| 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). |
Definition at line 60 of file screenshot.cpp.
| static void CurrentScreenCallback | ( | void * | userdata, | |
| void * | buf, | |||
| uint | y, | |||
| uint | pitch, | |||
| uint | n | |||
| ) | [static] |
Callback of the screenshot generator that dumps the current video buffer.
Definition at line 634 of file screenshot.cpp.
References Blitter::CopyImageToBuffer(), BlitterFactoryBase::GetCurrentBlitter(), and Blitter::MoveTo().
Referenced by MakeSmallScreenshot().
| const char* GetCurrentScreenshotExtension | ( | ) |
Get filename extension of current screenshot file format.
Definition at line 580 of file screenshot.cpp.
References _cur_screenshot_format, and ScreenshotFormat::extension.
Referenced by FiosMakeHeightmapName().
| const char* GetScreenshotFormatDesc | ( | int | i | ) |
Give descriptive name of the screenshot format.
| i | Number of the screenshot format. |
Definition at line 604 of file screenshot.cpp.
References ScreenshotFormat::name.
Referenced by FormatString().
| bool GetScreenshotFormatSupports_32bpp | ( | int | i | ) |
Determine whether a certain screenshot format support 32bpp images.
| i | Number of the screenshot format. |
Definition at line 614 of file screenshot.cpp.
References ScreenshotFormat::supports_32bpp.
Referenced by GameOptionsWindow::BuildDropDownList().
| static void HeightmapCallback | ( | void * | userdata, | |
| void * | buffer, | |||
| uint | y, | |||
| uint | pitch, | |||
| uint | n | |||
| ) | [static] |
Callback for generating a heightmap.
Supports 8bpp grayscale only.
| 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). |
| n | Number of lines to write. |
Definition at line 798 of file screenshot.cpp.
References MapMaxX(), TILE_ADDXY, TileHeight(), and TileXY().
Referenced by MakeHeightmapScreenshot().
| void InitializeScreenshotFormats | ( | ) |
Initialize screenshot format information on startup, with _screenshot_format_name filled from the loadsave code.
Definition at line 586 of file screenshot.cpp.
References _cur_screenshot_format, _num_screenshot_formats, _screenshot_format_name, and lengthof.
| static void LargeWorldCallback | ( | void * | userdata, | |
| void * | buf, | |||
| uint | y, | |||
| uint | pitch, | |||
| uint | n | |||
| ) | [static] |
generate a large piece of the world
| 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 649 of file screenshot.cpp.
References _screen_disable_anim, ViewPort::left, min(), ScaleByZoom(), ViewPort::top, ViewPort::virtual_left, ViewPort::virtual_top, ViewPort::width, and ViewPort::zoom.
Referenced by MakeWorldScreenshot(), and MakeZoomedInScreenshot().
| static bool MakeBMPImage | ( | const char * | name, | |
| ScreenshotCallback * | callb, | |||
| void * | userdata, | |||
| uint | w, | |||
| uint | h, | |||
| int | pixelformat, | |||
| const Colour * | palette | |||
| ) | [static] |
Generic .BMP writer.
| 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) |
Definition at line 117 of file screenshot.cpp.
| bool MakeHeightmapScreenshot | ( | const char * | filename | ) |
Make a heightmap of the current map.
| filename | Filename to use for saving. |
Definition at line 818 of file screenshot.cpp.
References _cur_screenshot_format, Colour::a, HeightmapCallback(), lengthof, MapSizeX(), MapSizeY(), and ScreenshotFormat::proc.
Referenced by MakeScreenshot().
| 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.
| 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). |
Definition at line 441 of file screenshot.cpp.
| 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.
| 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). |
Definition at line 263 of file screenshot.cpp.
References _grfconfig, BSWAP32(), Clamp(), free(), ScriptInfo::GetName(), BaseMedia< GraphicsSet >::GetUsedSet(), ScriptInfo::GetVersion(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, lastof, md5sumToString(), min(), GRFConfig::next, png_my_error(), png_my_warning(), seprintf(), and strecpy().
| bool MakeScreenshot | ( | ScreenshotType | t, | |
| const char * | name | |||
| ) |
Make an actual screenshot.
| t | the type of screenshot to make. | |
| name | the name to give to the screenshot. |
Definition at line 837 of file screenshot.cpp.
References _cur_screenshot_format, _screenshot_name, _settings_client, DrawDirtyBlocks(), ScreenshotFormat::extension, ClientSettings::gui, HEIGHTMAP_NAME, INVALID_STRING_ID, lastof, MakeHeightmapScreenshot(), MakeScreenshotName(), MakeSmallScreenshot(), MakeWorldScreenshot(), MakeZoomedInScreenshot(), SC_DEFAULTZOOM, SC_HEIGHTMAP, SC_RAW, SC_VIEWPORT, SC_WORLD, SC_ZOOMEDIN, SetDParamStr(), ShowErrorMessage(), strecpy(), WL_ERROR, WL_WARNING, ZOOM_LVL_VIEWPORT, and GUISettings::zoom_min.
Referenced by CrashLog::WriteScreenshot().
| static const char* MakeScreenshotName | ( | const char * | default_fn, | |
| const char * | ext | |||
| ) | [static] |
Construct a pathname for a screenshot file.
| default_fn | Default filename. | |
| ext | Extension to use. |
Definition at line 703 of file screenshot.cpp.
References _full_screenshot_name, _local_company, _personal_dir, _screenshot_name, COMPANY_SPECTATOR, FileExists(), GenerateDefaultSaveName(), lastof, lengthof, strecpy(), and StrEmpty().
Referenced by MakeScreenshot(), MakeSmallScreenshot(), MakeWorldScreenshot(), and MakeZoomedInScreenshot().
| static bool MakeSmallScreenshot | ( | ) | [static] |
Make a screenshot of the current screen.
Definition at line 735 of file screenshot.cpp.
References _cur_palette, _cur_screenshot_format, CurrentScreenCallback(), ScreenshotFormat::extension, BlitterFactoryBase::GetCurrentBlitter(), Blitter::GetScreenDepth(), MakeScreenshotName(), Palette::palette, ScreenshotFormat::proc, and SCREENSHOT_NAME.
Referenced by MakeScreenshot().
| static bool MakeWorldScreenshot | ( | ) | [static] |
Make a screenshot of the whole map.
Definition at line 764 of file screenshot.cpp.
References _cur_palette, _cur_screenshot_format, ScreenshotFormat::extension, BlitterFactoryBase::GetCurrentBlitter(), Blitter::GetScreenDepth(), ViewPort::height, LargeWorldCallback(), ViewPort::left, MakeScreenshotName(), MapMaxX(), MapMaxY(), MapSize(), Palette::palette, ScreenshotFormat::proc, SCREENSHOT_NAME, TILE_PIXELS, TilePixelHeight(), ViewPort::top, ViewPort::virtual_height, ViewPort::virtual_left, ViewPort::virtual_top, ViewPort::virtual_width, ViewPort::width, and ViewPort::zoom.
Referenced by MakeScreenshot().
| static bool MakeZoomedInScreenshot | ( | ZoomLevel | zl | ) | [static] |
Make a zoomed-in screenshot of the currently visible area.
Definition at line 743 of file screenshot.cpp.
References _cur_palette, _cur_screenshot_format, ScreenshotFormat::extension, FindWindowById(), BlitterFactoryBase::GetCurrentBlitter(), Blitter::GetScreenDepth(), ViewPort::height, LargeWorldCallback(), ViewPort::left, MakeScreenshotName(), Palette::palette, ScreenshotFormat::proc, SCREENSHOT_NAME, ViewPort::top, UnScaleByZoom(), Window::viewport, ViewPort::virtual_height, ViewPort::virtual_left, ViewPort::virtual_top, ViewPort::virtual_width, WC_MAIN_WINDOW, ViewPort::width, and ViewPort::zoom.
Referenced by MakeScreenshot().
| void SetScreenshotFormat | ( | uint | i | ) |
Set the screenshot format to use.
| i | Number of the format. |
Definition at line 623 of file screenshot.cpp.
References _cur_screenshot_format, _num_screenshot_formats, _screenshot_format_name, lastof, and strecpy().
Referenced by GameOptionsWindow::OnDropdownSelect().
const ScreenshotFormat _screenshot_formats[] [static] |
{
{"PNG", "png", &MakePNGImage, true},
{"BMP", "bmp", &MakeBMPImage, true},
{"PCX", "pcx", &MakePCXImage, false},
}
Available screenshot formats.
Definition at line 571 of file screenshot.cpp.
1.7.1