screenshot.cpp File Reference

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 "gui.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.
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.
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 *ext)
 Construct a pathname for a screenshot file.
static bool MakeSmallScreenshot ()
 Make a screenshot of the current screen.
static bool MakeZoomedInScreenshot ()
 Make a zoomed-in screenshot of the currently visible area.
static bool MakeWorldScreenshot ()
 Make a screenshot of the whole map.
bool MakeScreenshot (ScreenshotType t, const char *name)
 Make an actual screenshot.

Variables

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.

Detailed Description

The creation of screenshots!

Definition in file screenshot.cpp.


Typedef Documentation

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

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 58 of file screenshot.cpp.


Function Documentation

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.

See also:
ScreenshotCallback

Definition at line 617 of file screenshot.cpp.

References Blitter::CopyImageToBuffer(), BlitterFactoryBase::GetCurrentBlitter(), and Blitter::MoveTo().

Referenced by MakeSmallScreenshot().

const char* GetScreenshotFormatDesc ( int  i  ) 

Give descriptive name of the screenshot format.

Parameters:
i Number of the screenshot format.
Returns:
String constant describing the format.

Definition at line 597 of file screenshot.cpp.

References ScreenshotFormat::name.

Referenced by FormatString().

void InitializeScreenshotFormats (  ) 

Initialize screenshot format information on startup, with _screenshot_format_name filled from the loadsave code.

Definition at line 579 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

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 632 of file screenshot.cpp.

References _screen_disable_anim, ViewPort::left, min(), ScaleByZoom(), ViewPort::top, ViewPort::virtual_left, ViewPort::virtual_top, ViewPort::width, ViewPort::zoom, and ZOOM_LVL_WORLD_SCREENSHOT.

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.

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 114 of file screenshot.cpp.

References Align(), AllocaM, Clamp(), and min().

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.

References Clamp(), DEBUG, and min().

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 260 of file screenshot.cpp.

References _grfconfig, BSWAP32(), Clamp(), ScriptFileInfo::GetName(), BaseMedia< GraphicsSet >::GetUsedSet(), ScriptFileInfo::GetVersion(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, lastof, md5sumToString(), min(), GRFConfig::next, seprintf(), and strecpy().

bool MakeScreenshot ( ScreenshotType  t,
const char *  name 
)

Make an actual screenshot.

Parameters:
t the type of screenshot to make.
name the name to give to the screenshot.
Returns:
true iff the screenshow was made successfully

Definition at line 774 of file screenshot.cpp.

References _screenshot_name, DrawDirtyBlocks(), INVALID_STRING_ID, lastof, MakeSmallScreenshot(), MakeWorldScreenshot(), MakeZoomedInScreenshot(), SC_RAW, SC_VIEWPORT, SC_WORLD, SC_ZOOMEDIN, SetDParamStr(), ShowErrorMessage(), strecpy(), WL_ERROR, and WL_WARNING.

Referenced by CrashLog::WriteScreenshot().

static const char* MakeScreenshotName ( const char *  ext  )  [static]

Construct a pathname for a screenshot file.

Parameters:
ext Extension to use.
Returns:
Pathname for a screenshot file.

Definition at line 685 of file screenshot.cpp.

References _full_screenshot_name, _local_company, _personal_dir, _screenshot_name, COMPANY_SPECTATOR, GenerateDefaultSaveName(), lastof, lengthof, strecpy(), and StrEmpty().

Referenced by MakeSmallScreenshot(), MakeWorldScreenshot(), and MakeZoomedInScreenshot().

static bool MakeSmallScreenshot (  )  [static]
static bool MakeWorldScreenshot (  )  [static]
static bool MakeZoomedInScreenshot (  )  [static]
void SetScreenshotFormat ( uint  i  ) 

Set the screenshot format to use.

Parameters:
i Number of the format.

Definition at line 606 of file screenshot.cpp.

References _cur_screenshot_format, _num_screenshot_formats, _screenshot_format_name, lastof, and strecpy().

Referenced by GameOptionsWindow::OnDropdownSelect().


Variable Documentation

Initial value:
 {

  {"PNG", "png", &MakePNGImage},

  {"BMP", "bmp", &MakeBMPImage},
  {"PCX", "pcx", &MakePCXImage},
}

Available screenshot formats.

Definition at line 570 of file screenshot.cpp.


Generated on Fri May 27 04:20:02 2011 for OpenTTD by  doxygen 1.6.1