src/screenshot.cpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 8760 ce0891c412ce
child 10429 1b99254f9607
permissions -rw-r--r--
update tags
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1309
diff changeset
     4
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 923
diff changeset
     5
#include "debug.h"
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
     6
#include "fileio.h"
8721
b7971ad9bdd9 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8710
diff changeset
     7
#include "viewport_func.h"
b7971ad9bdd9 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8710
diff changeset
     8
#include "gfx_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8745
diff changeset
     9
#include "core/math_func.hpp"
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
    10
#include "screenshot.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2121
diff changeset
    11
#include "variables.h"
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7425
diff changeset
    12
#include "blitter/factory.hpp"
7371
b86b05214afe (svn r10116) -Fix [FS#850]: remove invalid characters (for the file system) from savegame names. Based on a patch by TheJosh.
rubidium
parents: 7122
diff changeset
    13
#include "fileio.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8423
diff changeset
    14
#include "strings_func.h"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
    15
#include "zoom_func.h"
8626
440dfcd14c4a (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8619
diff changeset
    16
#include "core/alloc_func.hpp"
8628
4e316518420a (svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents: 8627
diff changeset
    17
#include "core/endian_func.hpp"
8635
3bbb6f87fced (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8634
diff changeset
    18
#include "map_func.h"
8636
2b158acb649c (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8635
diff changeset
    19
#include "date_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8745
diff changeset
    20
#include "player_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    22
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    23
2121
c86a863485ee (svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents: 2120
diff changeset
    24
char _screenshot_format_name[8];
c86a863485ee (svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents: 2120
diff changeset
    25
uint _num_screenshot_formats;
c86a863485ee (svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents: 2120
diff changeset
    26
uint _cur_screenshot_format;
4184
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
    27
ScreenshotType current_screenshot_type;
2121
c86a863485ee (svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents: 2120
diff changeset
    28
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
    29
/* called by the ScreenShot proc to generate screenshot lines. */
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
    30
typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n);
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1891
diff changeset
    31
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    33
struct ScreenshotFormat {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	const char *name;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	const char *extension;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	ScreenshotHandlerProc *proc;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    37
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
//************************************************
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
//*** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
//************************************************
923
865f9716f7f5 (svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents: 534
diff changeset
    42
#if defined(_MSC_VER) || defined(__WATCOMC__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
#pragma pack(push, 1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    46
struct BitmapFileHeader {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
	uint16 type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	uint32 size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
	uint32 reserved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	uint32 off_bits;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    51
} GCC_PACK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
assert_compile(sizeof(BitmapFileHeader) == 14);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
923
865f9716f7f5 (svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents: 534
diff changeset
    54
#if defined(_MSC_VER) || defined(__WATCOMC__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
#pragma pack(pop)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    58
struct BitmapInfoHeader {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
	uint32 size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	int32 width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	uint16 planes, bitcount;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    63
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
assert_compile(sizeof(BitmapInfoHeader) == 40);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    66
struct RgbQuad {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
	byte blue, green, red, reserved;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    68
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
assert_compile(sizeof(RgbQuad) == 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
    71
/* generic .BMP writer */
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1891
diff changeset
    72
static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	BitmapFileHeader bfh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	BitmapInfoHeader bih;
318
65ebd0cab39b (svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents: 315
diff changeset
    76
	RgbQuad rq[256];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	FILE *f;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
	uint i, padw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
	uint n, maxlines;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
    80
	uint pal_size = 0;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
    81
	uint bpp = pixelformat / 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
    83
	/* only implemented for 8bit and 32bit images so far. */
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
    84
	if (pixelformat != 8 && pixelformat != 32) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4912
diff changeset
    86
	f = fopen(name, "wb");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	if (f == NULL) return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
    89
	/* each scanline must be aligned on a 32bit boundary */
8423
8453e9a0f0b5 (svn r11480) -Codechange: Rename the function ALIGN fitting to the naming style
skidd13
parents: 8418
diff changeset
    90
	padw = Align(w, 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
    92
	if (pixelformat == 8) pal_size = sizeof(RgbQuad) * 256;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
    93
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
    94
	/* setup the file header */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	bfh.type = TO_LE16('MB');
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
    96
	bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size + padw * h * bpp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	bfh.reserved = 0;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
    98
	bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   100
	/* setup the info header */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	bih.size = TO_LE32(sizeof(BitmapInfoHeader));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	bih.width = TO_LE32(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	bih.height = TO_LE32(h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	bih.planes = TO_LE16(1);
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   105
	bih.bitcount = TO_LE16(pixelformat);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	bih.compression = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	bih.sizeimage = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	bih.xpels = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	bih.ypels = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	bih.clrused = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	bih.clrimp = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   113
	if (pixelformat == 8) {
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   114
		/* convert the palette to the windows format */
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   115
		for (i = 0; i != 256; i++) {
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   116
			rq[i].red   = palette[i].r;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   117
			rq[i].green = palette[i].g;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   118
			rq[i].blue  = palette[i].b;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   119
			rq[i].reserved = 0;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   120
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   123
	/* write file header and info header and palette */
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   124
	if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   125
	if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   126
	if (pixelformat == 8) if (fwrite(rq, sizeof(rq), 1, f) != 1) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   128
	/* use by default 64k temp memory */
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7634
diff changeset
   129
	maxlines = Clamp(65536 / padw, 16, 128);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   131
	/* now generate the bitmap bits */
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   132
	void *buff = MallocT<uint8>(padw * maxlines * bpp); // by default generate 128 lines at a time.
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   133
	if (buff == NULL) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   134
		fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   135
		return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   136
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
	memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   139
	/* start at the bottom, since bitmaps are stored bottom up. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	do {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   141
		/* determine # lines */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
		n = min(h, maxlines);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
		h -= n;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   144
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   145
		/* render the pixels */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
		callb(userdata, buff, h, padw, n);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   147
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   148
		/* write each line */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   149
		while (n)
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   150
			if (fwrite((uint8 *)buff + (--n) * padw * bpp, padw * bpp, 1, f) != 1) {
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   151
				free(buff);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   152
				fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   153
				return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   154
			}
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   155
	} while (h != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   157
	free(buff);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
//********************************************************
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
//*** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
//********************************************************
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
#if defined(WITH_PNG)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
#include <png.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
{
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5559
diff changeset
   171
	DEBUG(misc, 0, "[libpng] error: %s - %s", message, (char *)png_get_error_ptr(png_ptr));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	longjmp(png_ptr->jmpbuf, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
{
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5559
diff changeset
   177
	DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1891
diff changeset
   180
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
{
318
65ebd0cab39b (svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents: 315
diff changeset
   182
	png_color rq[256];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	FILE *f;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	uint i, y, n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
	uint maxlines;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   186
	uint bpp = pixelformat / 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	png_structp png_ptr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	png_infop info_ptr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   190
	/* only implemented for 8bit and 32bit images so far. */
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   191
	if (pixelformat != 8 && pixelformat != 32) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4912
diff changeset
   193
	f = fopen(name, "wb");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	if (f == NULL) return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   196
	png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   198
	if (png_ptr == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
		fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	info_ptr = png_create_info_struct(png_ptr);
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   204
	if (info_ptr == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
		png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	if (setjmp(png_jmpbuf(png_ptr))) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
		png_destroy_write_struct(&png_ptr, &info_ptr);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
		fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
	png_init_io(png_ptr, f);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   217
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   220
	png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB,
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   221
		PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   223
	if (pixelformat == 8) {
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   224
		/* convert the palette to the .PNG format. */
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   225
		for (i = 0; i != 256; i++) {
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   226
			rq[i].red   = palette[i].r;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   227
			rq[i].green = palette[i].g;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   228
			rq[i].blue  = palette[i].b;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   229
		}
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   230
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   231
		png_set_PLTE(png_ptr, info_ptr, rq, 256);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	png_write_info(png_ptr, info_ptr);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	png_set_flush(png_ptr, 512);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   237
	if (pixelformat == 32) {
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   238
		png_color_8 sig_bit;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   239
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   240
		/* Save exact color/alpha resolution */
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   241
		sig_bit.alpha = 0;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   242
		sig_bit.blue  = 8;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   243
		sig_bit.green = 8;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   244
		sig_bit.red   = 8;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   245
		sig_bit.gray  = 8;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   246
		png_set_sBIT(png_ptr, info_ptr, &sig_bit);
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   247
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   248
#ifdef TTD_LITTLE_ENDIAN
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   249
		png_set_bgr(png_ptr);
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   250
		png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   251
#else
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   252
		png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   253
#endif
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   254
	}
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   255
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   256
	/* use by default 64k temp memory */
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7634
diff changeset
   257
	maxlines = Clamp(65536 / w, 16, 128);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   259
	/* now generate the bitmap bits */
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   260
	void *buff = MallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time.
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   261
	if (buff == NULL) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   262
		png_destroy_write_struct(&png_ptr, &info_ptr);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   263
		fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   264
		return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   265
	}
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   266
	memset(buff, 0, w * maxlines * bpp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
	do {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   270
		/* determine # lines to write */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
		n = min(h - y, maxlines);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   272
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   273
		/* render the pixels into the buffer */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
		callb(userdata, buff, y, w, n);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
		y += n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   277
		/* write them to png */
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   278
		for (i = 0; i != n; i++)
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   279
			png_write_row(png_ptr, (png_bytep)buff + i * w * bpp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	} while (y != h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	png_write_end(png_ptr, info_ptr);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	png_destroy_write_struct(&png_ptr, &info_ptr);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   285
	free(buff);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
	fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
}
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4261
diff changeset
   289
#endif /* WITH_PNG */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
//************************************************
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
//*** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
//************************************************
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   296
struct PcxHeader {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	byte manufacturer;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	byte version;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	byte rle;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	byte bpp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	uint32 unused;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
	uint16 xmax, ymax;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	uint16 hdpi, vdpi;
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6916
diff changeset
   304
	byte pal_small[16 * 3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	byte reserved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	byte planes;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	uint16 pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
	uint16 cpal;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	uint16 width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	uint16 height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	byte filler[54];
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   312
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
assert_compile(sizeof(PcxHeader) == 128);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1891
diff changeset
   315
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	FILE *f;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
	uint maxlines;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	uint y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	PcxHeader pcx;
4019
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   321
	bool success;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   323
	if (pixelformat == 32) {
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   324
		DEBUG(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick an other format.");
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   325
		return false;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   326
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	if (pixelformat != 8 || w == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4912
diff changeset
   330
	f = fopen(name, "wb");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
	if (f == NULL) return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	memset(&pcx, 0, sizeof(pcx));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   334
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   335
	/* setup pcx header */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	pcx.manufacturer = 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	pcx.version = 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	pcx.rle = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
	pcx.bpp = 8;
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   340
	pcx.xmax = TO_LE16(w - 1);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   341
	pcx.ymax = TO_LE16(h - 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
	pcx.hdpi = TO_LE16(320);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
	pcx.vdpi = TO_LE16(320);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
	pcx.planes = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
	pcx.cpal = TO_LE16(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
	pcx.width = pcx.pitch = TO_LE16(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
	pcx.height = TO_LE16(h);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   349
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   350
	/* write pcx header */
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   351
	if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   352
		fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   353
		return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   354
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   356
	/* use by default 64k temp memory */
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7634
diff changeset
   357
	maxlines = Clamp(65536 / w, 16, 128);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   359
	/* now generate the bitmap bits */
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   360
	uint8 *buff = MallocT<uint8>(w * maxlines); // by default generate 128 lines at a time.
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   361
	if (buff == NULL) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   362
		fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   363
		return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   364
	}
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   365
	memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
	y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	do {
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   369
		/* determine # lines to write */
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   370
		uint n = min(h - y, maxlines);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   371
		uint i;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   372
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   373
		/* render the pixels into the buffer */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
		callb(userdata, buff, y, w, n);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
		y += n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   377
		/* write them to pcx */
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   378
		for (i = 0; i != n; i++) {
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   379
			const uint8 *bufp = buff + i * w;
2004
6b975f28c351 (svn r2512) Small cleanup
tron
parents: 2003
diff changeset
   380
			byte runchar = bufp[0];
6b975f28c351 (svn r2512) Small cleanup
tron
parents: 2003
diff changeset
   381
			uint runcount = 1;
6b975f28c351 (svn r2512) Small cleanup
tron
parents: 2003
diff changeset
   382
			uint j;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   384
			/* for each pixel... */
2004
6b975f28c351 (svn r2512) Small cleanup
tron
parents: 2003
diff changeset
   385
			for (j = 1; j < w; j++) {
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   386
				uint8 ch = bufp[j];
2004
6b975f28c351 (svn r2512) Small cleanup
tron
parents: 2003
diff changeset
   387
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
				if (ch != runchar || runcount >= 0x3f) {
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   389
					if (runcount > 1 || (runchar & 0xC0) == 0xC0)
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   390
						if (fputc(0xC0 | runcount, f) == EOF) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   391
							free(buff);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   392
							fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   393
							return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   394
						}
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   395
					if (fputc(runchar, f) == EOF) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   396
						free(buff);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   397
						fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   398
						return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   399
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
					runcount = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
					runchar = ch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
				runcount++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   406
			/* write remaining bytes.. */
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   407
			if (runcount > 1 || (runchar & 0xC0) == 0xC0)
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   408
				if (fputc(0xC0 | runcount, f) == EOF) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   409
					free(buff);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   410
					fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   411
					return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   412
				}
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   413
			if (fputc(runchar, f) == EOF) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   414
				free(buff);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   415
				fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   416
				return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   417
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	} while (y != h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   421
	free(buff);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   422
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   423
	/* write 8-bit color palette */
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   424
	if (fputc(12, f) == EOF) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   425
		fclose(f);
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   426
		return false;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   427
	}
1991
f3d5e35731a2 (svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents: 1891
diff changeset
   428
4019
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   429
	if (sizeof(*palette) == 3) {
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   430
		success = fwrite(palette, 256 * sizeof(*palette), 1, f) == 1;
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   431
	} else {
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   432
		/* If the palette is word-aligned, copy it to a temporary byte array */
4079
30cac8061fa2 (svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents: 4019
diff changeset
   433
		byte tmp[256 * 3];
4019
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   434
		uint i;
4079
30cac8061fa2 (svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents: 4019
diff changeset
   435
4019
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   436
		for (i = 0; i < 256; i++) {
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   437
			tmp[i * 3 + 0] = palette[i].r;
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   438
			tmp[i * 3 + 1] = palette[i].g;
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   439
			tmp[i * 3 + 2] = palette[i].b;
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   440
		}
4079
30cac8061fa2 (svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents: 4019
diff changeset
   441
		success = fwrite(tmp, sizeof(tmp), 1, f) == 1;
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   442
	}
4019
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   443
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
	fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
4019
96c633a49ff4 (svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents: 3329
diff changeset
   446
	return success;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
//************************************************
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
//*** GENERIC SCREENSHOT CODE
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
//************************************************
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
static const ScreenshotFormat _screenshot_formats[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
#if defined(WITH_PNG)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
	{"PNG", "png", &MakePNGImage},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
#endif
4360
07fb51363337 (svn r6068) -Codechange: Switch PNG and BMP priority for screenshots. This ensures PNG is used by default when available. (hylje)
matthijs
parents: 4300
diff changeset
   457
	{"BMP", "bmp", &MakeBmpImage},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
	{"PCX", "pcx", &MakePCXImage},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5860
diff changeset
   461
void InitializeScreenshotFormats()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
{
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   463
	int i, j;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   464
	for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++)
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   465
		if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) {
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   466
			j = i;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   467
			break;
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
   468
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
	_cur_screenshot_format = j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
	_num_screenshot_formats = lengthof(_screenshot_formats);
4185
50a4d6493690 (svn r5627) Fix (r5626) : Forgot to rename one instance make_screenshot to current_screenshot_type
belugas
parents: 4184
diff changeset
   471
	current_screenshot_type = SC_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
const char *GetScreenshotFormatDesc(int i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
	return _screenshot_formats[i].name;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
void SetScreenshotFormat(int i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
	_cur_screenshot_format = i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	strcpy(_screenshot_format_name, _screenshot_formats[i].extension);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6574
diff changeset
   485
/* screenshot generator that dumps the current video buffer */
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   486
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
{
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7425
diff changeset
   488
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7425
diff changeset
   489
	void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
7481
699607d457a0 (svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents: 7433
diff changeset
   490
	blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
8745
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   493
/** generate a large piece of the world
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   494
 * @param userdata Viewport area to draw
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   495
 * @param buf Videobuffer with same bitdepth as current blitter
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   496
 * @param y First line to render
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   497
 * @param pitch Pitch of the videobuffer
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   498
 * @param n Number of lines to render
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   499
 */
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   500
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
{
4522
3f90e8cf2435 (svn r6347) Undo
tron
parents: 4521
diff changeset
   502
	ViewPort *vp = (ViewPort *)userdata;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
	DrawPixelInfo dpi, *old_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
	int wx, left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
8745
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   506
	/* We are no longer rendering to the screen */
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   507
	DrawPixelInfo old_screen = _screen;
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   508
	bool old_disable_anim = _screen_disable_anim;
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   509
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   510
	_screen.dst_ptr = buf;
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   511
	_screen.width = pitch;
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   512
	_screen.height = n;
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   513
	_screen.pitch = pitch;
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   514
	_screen_disable_anim = true;
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   515
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
	old_dpi = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	_cur_dpi = &dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
	dpi.dst_ptr = buf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
	dpi.height = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
	dpi.width = vp->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	dpi.pitch = pitch;
7120
e31767effc16 (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 7111
diff changeset
   523
	dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
	dpi.left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
	dpi.top = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
8745
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   527
	/* Render viewport in blocks of 1600 pixels width */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
	while (vp->width - left != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
		wx = min(vp->width - left, 1600);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
		left += wx;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   532
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 1
diff changeset
   533
		ViewportDoDraw(vp,
7122
0607a15aedc0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 7120
diff changeset
   534
			ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left,
0607a15aedc0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 7120
diff changeset
   535
			ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top,
0607a15aedc0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 7120
diff changeset
   536
			ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
0607a15aedc0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 7120
diff changeset
   537
			ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	_cur_dpi = old_dpi;
8745
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   542
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   543
	/* Switch back to rendering to the screen */
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   544
	_screen = old_screen;
0c897b4e651e (svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents: 8721
diff changeset
   545
	_screen_disable_anim = old_disable_anim;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
static char *MakeScreenshotName(const char *ext)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
{
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   550
	static char filename[MAX_PATH];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	int serial;
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   552
	size_t len;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4522
diff changeset
   554
	if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_player == PLAYER_SPECTATOR) {
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   555
		ttd_strlcpy(_screenshot_name, "screenshot", lengthof(_screenshot_name));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
	} else {
7554
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7481
diff changeset
   557
		SetDParam(0, _local_player);
076c42f44a83 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7481
diff changeset
   558
		SetDParam(1, _date);
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4848
diff changeset
   559
		GetString(_screenshot_name, STR_4004, lastof(_screenshot_name));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   562
	/* Add extension to screenshot file */
7371
b86b05214afe (svn r10116) -Fix [FS#850]: remove invalid characters (for the file system) from savegame names. Based on a patch by TheJosh.
rubidium
parents: 7122
diff changeset
   563
	SanitizeFilename(_screenshot_name);
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   564
	len = strlen(_screenshot_name);
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   565
	snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   567
	for (serial = 1;; serial++) {
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   568
		snprintf(filename, lengthof(filename), "%s%s", _personal_dir, _screenshot_name);
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   569
		if (!FileExists(filename)) break;
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   570
		/* If file exists try another one with same name, but just with a higher index */
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7374
diff changeset
   571
		snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%d.%s", serial, ext);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
	return filename;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
4184
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   577
void SetScreenshotType(ScreenshotType t)
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   578
{
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   579
	current_screenshot_type = t;
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   580
}
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   581
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5860
diff changeset
   582
bool IsScreenshotRequested()
4184
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   583
{
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   584
	return (current_screenshot_type != SC_NONE);
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   585
}
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   586
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5860
diff changeset
   587
static bool MakeSmallScreenshot()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
	const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   590
	return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5860
diff changeset
   593
static bool MakeWorldScreenshot()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
	ViewPort vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
	const ScreenshotFormat *sf;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
7120
e31767effc16 (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 7111
diff changeset
   598
	vp.zoom = ZOOM_LVL_WORLD_SCREENSHOT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
	vp.left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
	vp.top = 0;
4184
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   601
	vp.virtual_left = -(int)MapMaxX() * TILE_PIXELS;
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   602
	vp.virtual_top = 0;
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   603
	vp.virtual_width = (MapMaxX() + MapMaxY()) * TILE_PIXELS;
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   604
	vp.width = vp.virtual_width;
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   605
	vp.virtual_height = (MapMaxX() + MapMaxY()) * TILE_PIXELS >> 1;
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   606
	vp.height = vp.virtual_height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
	sf = _screenshot_formats + _cur_screenshot_format;
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7371
diff changeset
   609
	return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
}
4184
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   611
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5860
diff changeset
   612
bool MakeScreenshot()
4184
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   613
{
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   614
	switch (current_screenshot_type) {
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   615
		case SC_VIEWPORT:
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   616
			UndrawMouseCursor();
5559
10610f5e6e38 (svn r7556) -Fix(r7153): By handling the KeyEvent sooner in the events loops, the console command "screenshot no_con" did not had time to actually repaint the screen without the console before the screenshot. Forcing a redraw before it ensure that the feature acts as required. (to be ported to 0.5.0)
belugas
parents: 5296
diff changeset
   617
			DrawDirtyBlocks();
4184
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   618
			current_screenshot_type = SC_NONE;
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   619
			return MakeSmallScreenshot();
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   620
		case SC_WORLD:
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   621
			current_screenshot_type = SC_NONE;
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   622
			return MakeWorldScreenshot();
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   623
		default: return false;
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   624
	}
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   625
}
f38abcb8b18d (svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents: 4079
diff changeset
   626
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5559
diff changeset
   627
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5559
diff changeset
   628