2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-02-06 08:18:00 +00:00
|
|
|
#include "strings.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gfx.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "player.h"
|
2004-11-15 19:25:59 +00:00
|
|
|
#include "screenshot.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-19 06:47:07 +00:00
|
|
|
char _screenshot_format_name[8];
|
|
|
|
uint _num_screenshot_formats;
|
|
|
|
uint _cur_screenshot_format;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// called by the ScreenShot proc to generate screenshot lines.
|
2005-07-19 06:31:39 +00:00
|
|
|
typedef void ScreenshotCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n);
|
2005-06-30 05:27:32 +00:00
|
|
|
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
const char *extension;
|
|
|
|
ScreenshotHandlerProc *proc;
|
|
|
|
} ScreenshotFormat;
|
|
|
|
|
|
|
|
//************************************************
|
|
|
|
//*** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
|
|
|
|
//************************************************
|
2005-01-07 09:28:16 +00:00
|
|
|
#if defined(_MSC_VER) || defined(__WATCOMC__)
|
2004-08-09 17:04:08 +00:00
|
|
|
#pragma pack(push, 1)
|
|
|
|
#endif
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
typedef struct BitmapFileHeader {
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 type;
|
|
|
|
uint32 size;
|
|
|
|
uint32 reserved;
|
|
|
|
uint32 off_bits;
|
|
|
|
} GCC_PACK BitmapFileHeader;
|
|
|
|
assert_compile(sizeof(BitmapFileHeader) == 14);
|
|
|
|
|
2005-01-07 09:28:16 +00:00
|
|
|
#if defined(_MSC_VER) || defined(__WATCOMC__)
|
2004-08-09 17:04:08 +00:00
|
|
|
#pragma pack(pop)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct BitmapInfoHeader {
|
|
|
|
uint32 size;
|
|
|
|
int32 width, height;
|
|
|
|
uint16 planes, bitcount;
|
|
|
|
uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
|
|
|
|
} BitmapInfoHeader;
|
|
|
|
assert_compile(sizeof(BitmapInfoHeader) == 40);
|
|
|
|
|
|
|
|
typedef struct RgbQuad {
|
|
|
|
byte blue, green, red, reserved;
|
|
|
|
} RgbQuad;
|
|
|
|
assert_compile(sizeof(RgbQuad) == 4);
|
|
|
|
|
|
|
|
// generic .BMP writer
|
2005-06-30 05:27:32 +00:00
|
|
|
static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
BitmapFileHeader bfh;
|
|
|
|
BitmapInfoHeader bih;
|
2004-09-27 12:36:59 +00:00
|
|
|
RgbQuad rq[256];
|
2005-07-15 14:16:14 +00:00
|
|
|
Pixel *buff;
|
2004-08-09 17:04:08 +00:00
|
|
|
FILE *f;
|
|
|
|
uint i, padw;
|
|
|
|
uint n, maxlines;
|
|
|
|
|
|
|
|
// only implemented for 8bit images so far.
|
|
|
|
if (pixelformat != 8)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
f = fopen(name, "wb");
|
|
|
|
if (f == NULL) return false;
|
|
|
|
|
|
|
|
// each scanline must be aligned on a 32bit boundary
|
2005-09-08 12:48:26 +00:00
|
|
|
padw = ALIGN(w, 4);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// setup the file header
|
|
|
|
bfh.type = TO_LE16('MB');
|
|
|
|
bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + sizeof(RgbQuad) * 256 + padw * h);
|
|
|
|
bfh.reserved = 0;
|
|
|
|
bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + sizeof(RgbQuad) * 256);
|
|
|
|
|
|
|
|
// setup the info header
|
|
|
|
bih.size = TO_LE32(sizeof(BitmapInfoHeader));
|
|
|
|
bih.width = TO_LE32(w);
|
|
|
|
bih.height = TO_LE32(h);
|
|
|
|
bih.planes = TO_LE16(1);
|
|
|
|
bih.bitcount = TO_LE16(8);
|
|
|
|
bih.compression = 0;
|
|
|
|
bih.sizeimage = 0;
|
|
|
|
bih.xpels = 0;
|
|
|
|
bih.ypels = 0;
|
|
|
|
bih.clrused = 0;
|
|
|
|
bih.clrimp = 0;
|
|
|
|
|
|
|
|
// convert the palette to the windows format
|
2004-11-15 19:25:59 +00:00
|
|
|
for (i = 0; i != 256; i++) {
|
2005-06-30 05:27:32 +00:00
|
|
|
rq[i].red = palette[i].r;
|
|
|
|
rq[i].green = palette[i].g;
|
|
|
|
rq[i].blue = palette[i].b;
|
2004-08-09 17:04:08 +00:00
|
|
|
rq[i].reserved = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// write file header and info header and palette
|
2004-11-15 19:25:59 +00:00
|
|
|
if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false;
|
|
|
|
if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false;
|
|
|
|
if (fwrite(rq, sizeof(rq), 1, f) != 1) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// use by default 64k temp memory
|
|
|
|
maxlines = clamp(65536 / padw, 16, 128);
|
|
|
|
|
|
|
|
// now generate the bitmap bits
|
2004-11-15 19:25:59 +00:00
|
|
|
buff = malloc(padw * maxlines); // by default generate 128 lines at a time.
|
|
|
|
if (buff == NULL) {
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0
|
|
|
|
|
|
|
|
// start at the bottom, since bitmaps are stored bottom up.
|
|
|
|
do {
|
|
|
|
// determine # lines
|
|
|
|
n = min(h, maxlines);
|
|
|
|
h -= n;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// render the pixels
|
|
|
|
callb(userdata, buff, h, padw, n);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
|
|
|
// write each line
|
|
|
|
while (n)
|
2004-11-15 19:25:59 +00:00
|
|
|
if (fwrite(buff + (--n) * padw, padw, 1, f) != 1) {
|
|
|
|
free(buff);
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} while (h != 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-15 19:25:59 +00:00
|
|
|
free(buff);
|
2004-08-09 17:04:08 +00:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//********************************************************
|
|
|
|
//*** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG)
|
|
|
|
//********************************************************
|
|
|
|
#if defined(WITH_PNG)
|
|
|
|
#include <png.h>
|
|
|
|
|
|
|
|
static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
|
|
|
|
{
|
2005-07-05 17:47:10 +00:00
|
|
|
DEBUG(misc, 0) ("ERROR(libpng): %s - %s", message, (char *)png_get_error_ptr(png_ptr));
|
2004-08-09 17:04:08 +00:00
|
|
|
longjmp(png_ptr->jmpbuf, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
|
|
|
|
{
|
2005-07-05 17:47:10 +00:00
|
|
|
DEBUG(misc, 0) ("WARNING(libpng): %s - %s", message, (char *)png_get_error_ptr(png_ptr));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-30 05:27:32 +00:00
|
|
|
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-09-27 12:36:59 +00:00
|
|
|
png_color rq[256];
|
2005-07-15 14:16:14 +00:00
|
|
|
Pixel *buff;
|
2004-08-09 17:04:08 +00:00
|
|
|
FILE *f;
|
|
|
|
uint i, y, n;
|
|
|
|
uint maxlines;
|
|
|
|
png_structp png_ptr;
|
|
|
|
png_infop info_ptr;
|
|
|
|
|
|
|
|
// only implemented for 8bit images so far.
|
|
|
|
if (pixelformat != 8)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
f = fopen(name, "wb");
|
|
|
|
if (f == NULL) return false;
|
|
|
|
|
2004-11-15 19:25:59 +00:00
|
|
|
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-15 19:25:59 +00:00
|
|
|
if (png_ptr == NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
info_ptr = png_create_info_struct(png_ptr);
|
2004-11-15 19:25:59 +00:00
|
|
|
if (info_ptr == NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
|
|
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
png_init_io(png_ptr, f);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
|
|
|
|
|
2004-11-15 19:25:59 +00:00
|
|
|
png_set_IHDR(png_ptr, info_ptr, w, h, pixelformat, PNG_COLOR_TYPE_PALETTE,
|
|
|
|
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// convert the palette to the .PNG format.
|
2005-06-30 05:27:32 +00:00
|
|
|
for (i = 0; i != 256; i++) {
|
|
|
|
rq[i].red = palette[i].r;
|
|
|
|
rq[i].green = palette[i].g;
|
|
|
|
rq[i].blue = palette[i].b;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
png_set_PLTE(png_ptr, info_ptr, rq, 256);
|
|
|
|
png_write_info(png_ptr, info_ptr);
|
|
|
|
png_set_flush(png_ptr, 512);
|
|
|
|
|
|
|
|
// use by default 64k temp memory
|
|
|
|
maxlines = clamp(65536 / w, 16, 128);
|
|
|
|
|
|
|
|
// now generate the bitmap bits
|
2004-11-15 19:25:59 +00:00
|
|
|
buff = malloc(w * maxlines); // by default generate 128 lines at a time.
|
|
|
|
if (buff == NULL) {
|
|
|
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0
|
|
|
|
|
|
|
|
y = 0;
|
|
|
|
do {
|
|
|
|
// determine # lines to write
|
|
|
|
n = min(h - y, maxlines);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// render the pixels into the buffer
|
|
|
|
callb(userdata, buff, y, w, n);
|
|
|
|
y += n;
|
|
|
|
|
|
|
|
// write them to png
|
2004-11-15 19:25:59 +00:00
|
|
|
for (i = 0; i != n; i++)
|
2004-08-09 17:04:08 +00:00
|
|
|
png_write_row(png_ptr, buff + i * w);
|
|
|
|
} while (y != h);
|
|
|
|
|
|
|
|
png_write_end(png_ptr, info_ptr);
|
|
|
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
|
|
|
|
2004-11-15 19:25:59 +00:00
|
|
|
free(buff);
|
2004-08-09 17:04:08 +00:00
|
|
|
fclose(f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // WITH_PNG
|
|
|
|
|
|
|
|
|
|
|
|
//************************************************
|
|
|
|
//*** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX)
|
|
|
|
//************************************************
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
byte manufacturer;
|
|
|
|
byte version;
|
|
|
|
byte rle;
|
|
|
|
byte bpp;
|
|
|
|
uint32 unused;
|
|
|
|
uint16 xmax, ymax;
|
|
|
|
uint16 hdpi, vdpi;
|
|
|
|
byte pal_small[16*3];
|
|
|
|
byte reserved;
|
|
|
|
byte planes;
|
|
|
|
uint16 pitch;
|
|
|
|
uint16 cpal;
|
|
|
|
uint16 width;
|
|
|
|
uint16 height;
|
|
|
|
byte filler[54];
|
|
|
|
} PcxHeader;
|
|
|
|
assert_compile(sizeof(PcxHeader) == 128);
|
|
|
|
|
2005-06-30 05:27:32 +00:00
|
|
|
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-15 14:16:14 +00:00
|
|
|
Pixel *buff;
|
2004-08-09 17:04:08 +00:00
|
|
|
FILE *f;
|
|
|
|
uint maxlines;
|
|
|
|
uint y;
|
|
|
|
PcxHeader pcx;
|
|
|
|
|
|
|
|
if (pixelformat != 8 || w == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
f = fopen(name, "wb");
|
|
|
|
if (f == NULL) return false;
|
|
|
|
|
|
|
|
memset(&pcx, 0, sizeof(pcx));
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// setup pcx header
|
|
|
|
pcx.manufacturer = 10;
|
|
|
|
pcx.version = 5;
|
|
|
|
pcx.rle = 1;
|
|
|
|
pcx.bpp = 8;
|
2004-11-15 19:25:59 +00:00
|
|
|
pcx.xmax = TO_LE16(w - 1);
|
|
|
|
pcx.ymax = TO_LE16(h - 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
pcx.hdpi = TO_LE16(320);
|
|
|
|
pcx.vdpi = TO_LE16(320);
|
|
|
|
|
|
|
|
pcx.planes = 1;
|
|
|
|
pcx.cpal = TO_LE16(1);
|
|
|
|
pcx.width = pcx.pitch = TO_LE16(w);
|
|
|
|
pcx.height = TO_LE16(h);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// write pcx header
|
2004-11-15 19:25:59 +00:00
|
|
|
if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) {
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// use by default 64k temp memory
|
|
|
|
maxlines = clamp(65536 / w, 16, 128);
|
|
|
|
|
|
|
|
// now generate the bitmap bits
|
2004-11-15 19:25:59 +00:00
|
|
|
buff = malloc(w * maxlines); // by default generate 128 lines at a time.
|
|
|
|
if (buff == NULL) {
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
y = 0;
|
|
|
|
do {
|
|
|
|
// determine # lines to write
|
2004-11-15 19:25:59 +00:00
|
|
|
uint n = min(h - y, maxlines);
|
|
|
|
uint i;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// render the pixels into the buffer
|
|
|
|
callb(userdata, buff, y, w, n);
|
|
|
|
y += n;
|
|
|
|
|
|
|
|
// write them to pcx
|
2004-11-15 19:25:59 +00:00
|
|
|
for (i = 0; i != n; i++) {
|
2005-07-15 14:16:14 +00:00
|
|
|
const Pixel* bufp = buff + i * w;
|
2005-07-03 10:22:20 +00:00
|
|
|
byte runchar = bufp[0];
|
|
|
|
uint runcount = 1;
|
|
|
|
uint j;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
// for each pixel...
|
2005-07-03 10:22:20 +00:00
|
|
|
for (j = 1; j < w; j++) {
|
2005-07-15 14:16:14 +00:00
|
|
|
Pixel ch = bufp[j];
|
2005-07-03 10:22:20 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (ch != runchar || runcount >= 0x3f) {
|
2004-11-15 19:25:59 +00:00
|
|
|
if (runcount > 1 || (runchar & 0xC0) == 0xC0)
|
|
|
|
if (fputc(0xC0 | runcount, f) == EOF) {
|
|
|
|
free(buff);
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (fputc(runchar, f) == EOF) {
|
|
|
|
free(buff);
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
runcount = 0;
|
|
|
|
runchar = ch;
|
|
|
|
}
|
|
|
|
runcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// write remaining bytes..
|
2004-11-15 19:25:59 +00:00
|
|
|
if (runcount > 1 || (runchar & 0xC0) == 0xC0)
|
|
|
|
if (fputc(0xC0 | runcount, f) == EOF) {
|
|
|
|
free(buff);
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (fputc(runchar, f) == EOF) {
|
|
|
|
free(buff);
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} while (y != h);
|
|
|
|
|
2004-11-15 19:25:59 +00:00
|
|
|
free(buff);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// write 8-bit color palette
|
2004-11-15 19:25:59 +00:00
|
|
|
if (fputc(12, f) == EOF) {
|
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
2005-06-30 05:27:32 +00:00
|
|
|
|
|
|
|
{assert_compile(sizeof(*palette) == 3);}
|
|
|
|
if (fwrite(palette, 256 * sizeof(*palette), 1, f) != 1) {
|
2004-11-15 19:25:59 +00:00
|
|
|
fclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************
|
|
|
|
//*** GENERIC SCREENSHOT CODE
|
|
|
|
//************************************************
|
|
|
|
|
|
|
|
static const ScreenshotFormat _screenshot_formats[] = {
|
|
|
|
{"BMP", "bmp", &MakeBmpImage},
|
|
|
|
#if defined(WITH_PNG)
|
|
|
|
{"PNG", "png", &MakePNGImage},
|
|
|
|
#endif
|
|
|
|
{"PCX", "pcx", &MakePCXImage},
|
|
|
|
};
|
|
|
|
|
2004-11-15 19:25:59 +00:00
|
|
|
void InitializeScreenshotFormats(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-11-15 19:25:59 +00:00
|
|
|
int i, j;
|
|
|
|
for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++)
|
|
|
|
if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) {
|
|
|
|
j = i;
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
_cur_screenshot_format = j;
|
|
|
|
_num_screenshot_formats = lengthof(_screenshot_formats);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *GetScreenshotFormatDesc(int i)
|
|
|
|
{
|
|
|
|
return _screenshot_formats[i].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetScreenshotFormat(int i)
|
|
|
|
{
|
|
|
|
_cur_screenshot_format = i;
|
|
|
|
strcpy(_screenshot_format_name, _screenshot_formats[i].extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
// screenshot generator that dumps the current video buffer
|
2005-07-15 14:16:14 +00:00
|
|
|
static void CurrentScreenCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-11-15 19:25:59 +00:00
|
|
|
for (; n > 0; --n) {
|
2004-09-25 18:30:19 +00:00
|
|
|
memcpy(buf, _screen.dst_ptr + y * _screen.pitch, _screen.width);
|
|
|
|
++y;
|
|
|
|
buf += pitch;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// generate a large piece of the world
|
2005-07-15 14:16:14 +00:00
|
|
|
static void LargeWorldCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
ViewPort *vp = (ViewPort *)userdata;
|
|
|
|
DrawPixelInfo dpi, *old_dpi;
|
|
|
|
int wx, left;
|
|
|
|
|
|
|
|
old_dpi = _cur_dpi;
|
|
|
|
_cur_dpi = &dpi;
|
|
|
|
|
|
|
|
dpi.dst_ptr = buf;
|
|
|
|
dpi.height = n;
|
|
|
|
dpi.width = vp->width;
|
|
|
|
dpi.pitch = pitch;
|
|
|
|
dpi.zoom = 0;
|
|
|
|
dpi.left = 0;
|
|
|
|
dpi.top = y;
|
|
|
|
|
|
|
|
left = 0;
|
|
|
|
while (vp->width - left != 0) {
|
|
|
|
wx = min(vp->width - left, 1600);
|
|
|
|
left += wx;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
|
|
|
ViewportDoDraw(vp,
|
2004-08-09 17:04:08 +00:00
|
|
|
((left - wx - vp->left) << vp->zoom) + vp->virtual_left,
|
|
|
|
((y - vp->top) << vp->zoom) + vp->virtual_top,
|
|
|
|
((left - vp->left) << vp->zoom) + vp->virtual_left,
|
2004-11-15 19:25:59 +00:00
|
|
|
(((y + n) - vp->top) << vp->zoom) + vp->virtual_top
|
2004-08-09 17:04:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_cur_dpi = old_dpi;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *MakeScreenshotName(const char *ext)
|
|
|
|
{
|
|
|
|
static char filename[256];
|
|
|
|
char *base;
|
|
|
|
int serial;
|
|
|
|
|
2005-11-26 12:45:53 +00:00
|
|
|
if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_player == OWNER_SPECTATOR) {
|
2004-08-09 17:04:08 +00:00
|
|
|
sprintf(_screenshot_name, "screenshot");
|
|
|
|
} else {
|
2005-10-22 06:39:32 +00:00
|
|
|
const Player* p = GetPlayer(_local_player);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
|
|
|
SetDParam(2, _date);
|
2004-08-09 17:04:08 +00:00
|
|
|
GetString(_screenshot_name, STR_4004);
|
|
|
|
}
|
|
|
|
|
|
|
|
base = strchr(_screenshot_name, 0);
|
|
|
|
base[0] = '.'; strcpy(base + 1, ext);
|
|
|
|
|
|
|
|
serial = 0;
|
2004-11-15 19:25:59 +00:00
|
|
|
for (;;) {
|
2004-09-10 19:02:27 +00:00
|
|
|
snprintf(filename, sizeof(filename), "%s%s", _path.personal_dir, _screenshot_name);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!FileExists(filename))
|
|
|
|
break;
|
|
|
|
sprintf(base, " #%d.%s", ++serial, ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2004-11-15 19:25:59 +00:00
|
|
|
bool MakeScreenshot(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
|
2004-09-10 19:02:27 +00:00
|
|
|
return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, 8, _cur_palette);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MakeWorldScreenshot(int left, int top, int width, int height, int zoom)
|
|
|
|
{
|
|
|
|
ViewPort vp;
|
|
|
|
const ScreenshotFormat *sf;
|
|
|
|
|
|
|
|
vp.zoom = zoom;
|
|
|
|
vp.left = 0;
|
|
|
|
vp.top = 0;
|
|
|
|
vp.virtual_width = width;
|
|
|
|
vp.width = width >> zoom;
|
|
|
|
vp.virtual_height = height;
|
|
|
|
vp.height = height >> zoom;
|
|
|
|
vp.virtual_left = left;
|
|
|
|
vp.virtual_top = top;
|
|
|
|
|
|
|
|
sf = _screenshot_formats + _cur_screenshot_format;
|
|
|
|
return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, 8, _cur_palette);
|
|
|
|
}
|