author | rubidium |
Tue, 12 Jun 2007 15:46:34 +0000 | |
changeset 6875 | e517a59b78e5 |
parent 6626 | 207875b9069a |
child 6878 | 5cefd3ac59c7 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1309
diff
changeset
|
4 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
923
diff
changeset
|
5 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1299
diff
changeset
|
7 |
#include "strings.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
430
diff
changeset
|
8 |
#include "table/strings.h" |
0 | 9 |
#include "gfx.h" |
3329
9885789ecaf7
(svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents:
3294
diff
changeset
|
10 |
#include "hal.h" |
0 | 11 |
#include "viewport.h" |
12 |
#include "player.h" |
|
430 | 13 |
#include "screenshot.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2121
diff
changeset
|
14 |
#include "variables.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4185
diff
changeset
|
15 |
#include "date.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
16 |
#include "helpers.hpp" |
6875
e517a59b78e5
(svn r10116) -Fix [FS#850]: remove invalid characters (for the file system) from savegame names. Based on a patch by TheJosh.
rubidium
parents:
6626
diff
changeset
|
17 |
#include "fileio.h" |
0 | 18 |
|
2121
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
19 |
char _screenshot_format_name[8]; |
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
20 |
uint _num_screenshot_formats; |
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
21 |
uint _cur_screenshot_format; |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
22 |
ScreenshotType current_screenshot_type; |
2121
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
23 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
24 |
/* called by the ScreenShot proc to generate screenshot lines. */ |
2120 | 25 |
typedef void ScreenshotCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n); |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
26 |
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette); |
0 | 27 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
28 |
struct ScreenshotFormat { |
0 | 29 |
const char *name; |
30 |
const char *extension; |
|
31 |
ScreenshotHandlerProc *proc; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
32 |
}; |
0 | 33 |
|
34 |
//************************************************ |
|
35 |
//*** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) |
|
36 |
//************************************************ |
|
923
fc5230f75a91
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
37 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 38 |
#pragma pack(push, 1) |
39 |
#endif |
|
40 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
41 |
struct BitmapFileHeader { |
0 | 42 |
uint16 type; |
43 |
uint32 size; |
|
44 |
uint32 reserved; |
|
45 |
uint32 off_bits; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
46 |
} GCC_PACK; |
0 | 47 |
assert_compile(sizeof(BitmapFileHeader) == 14); |
48 |
||
923
fc5230f75a91
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
49 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 50 |
#pragma pack(pop) |
51 |
#endif |
|
52 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
53 |
struct BitmapInfoHeader { |
0 | 54 |
uint32 size; |
55 |
int32 width, height; |
|
56 |
uint16 planes, bitcount; |
|
57 |
uint32 compression, sizeimage, xpels, ypels, clrused, clrimp; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
58 |
}; |
0 | 59 |
assert_compile(sizeof(BitmapInfoHeader) == 40); |
60 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
61 |
struct RgbQuad { |
0 | 62 |
byte blue, green, red, reserved; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
63 |
}; |
0 | 64 |
assert_compile(sizeof(RgbQuad) == 4); |
65 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
66 |
/* generic .BMP writer */ |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
67 |
static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 68 |
{ |
69 |
BitmapFileHeader bfh; |
|
70 |
BitmapInfoHeader bih; |
|
318
648afd1ab9a7
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
71 |
RgbQuad rq[256]; |
0 | 72 |
FILE *f; |
73 |
uint i, padw; |
|
74 |
uint n, maxlines; |
|
75 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
76 |
/* only implemented for 8bit images so far. */ |
0 | 77 |
if (pixelformat != 8) |
78 |
return false; |
|
79 |
||
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
80 |
f = fopen(name, "wb"); |
0 | 81 |
if (f == NULL) return false; |
82 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
83 |
/* each scanline must be aligned on a 32bit boundary */ |
2398
912f16512ce2
(svn r2924) Introduce the ALIGN() macro which aligns values to multiples of a power of 2, for exact semantics see the commment in macros.h
tron
parents:
2186
diff
changeset
|
84 |
padw = ALIGN(w, 4); |
0 | 85 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
86 |
/* setup the file header */ |
0 | 87 |
bfh.type = TO_LE16('MB'); |
88 |
bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + sizeof(RgbQuad) * 256 + padw * h); |
|
89 |
bfh.reserved = 0; |
|
90 |
bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + sizeof(RgbQuad) * 256); |
|
91 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
92 |
/* setup the info header */ |
0 | 93 |
bih.size = TO_LE32(sizeof(BitmapInfoHeader)); |
94 |
bih.width = TO_LE32(w); |
|
95 |
bih.height = TO_LE32(h); |
|
96 |
bih.planes = TO_LE16(1); |
|
97 |
bih.bitcount = TO_LE16(8); |
|
98 |
bih.compression = 0; |
|
99 |
bih.sizeimage = 0; |
|
100 |
bih.xpels = 0; |
|
101 |
bih.ypels = 0; |
|
102 |
bih.clrused = 0; |
|
103 |
bih.clrimp = 0; |
|
104 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
105 |
/* convert the palette to the windows format */ |
430 | 106 |
for (i = 0; i != 256; i++) { |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
107 |
rq[i].red = palette[i].r; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
108 |
rq[i].green = palette[i].g; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
109 |
rq[i].blue = palette[i].b; |
0 | 110 |
rq[i].reserved = 0; |
111 |
} |
|
112 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
113 |
/* write file header and info header and palette */ |
430 | 114 |
if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false; |
115 |
if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false; |
|
116 |
if (fwrite(rq, sizeof(rq), 1, f) != 1) return false; |
|
0 | 117 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
118 |
/* use by default 64k temp memory */ |
0 | 119 |
maxlines = clamp(65536 / padw, 16, 128); |
120 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
121 |
/* now generate the bitmap bits */ |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
122 |
Pixel *buff = MallocT<Pixel>(padw * maxlines); // by default generate 128 lines at a time. |
430 | 123 |
if (buff == NULL) { |
124 |
fclose(f); |
|
125 |
return false; |
|
126 |
} |
|
0 | 127 |
memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0 |
128 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
129 |
/* start at the bottom, since bitmaps are stored bottom up. */ |
0 | 130 |
do { |
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
131 |
/* determine # lines */ |
0 | 132 |
n = min(h, maxlines); |
133 |
h -= n; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
134 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
135 |
/* render the pixels */ |
0 | 136 |
callb(userdata, buff, h, padw, n); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
137 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
138 |
/* write each line */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
139 |
while (n) |
430 | 140 |
if (fwrite(buff + (--n) * padw, padw, 1, f) != 1) { |
141 |
free(buff); |
|
142 |
fclose(f); |
|
143 |
return false; |
|
144 |
} |
|
145 |
} while (h != 0); |
|
0 | 146 |
|
430 | 147 |
free(buff); |
0 | 148 |
fclose(f); |
149 |
||
150 |
return true; |
|
151 |
} |
|
152 |
||
153 |
//******************************************************** |
|
154 |
//*** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG) |
|
155 |
//******************************************************** |
|
156 |
#if defined(WITH_PNG) |
|
157 |
#include <png.h> |
|
158 |
||
159 |
static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message) |
|
160 |
{ |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
161 |
DEBUG(misc, 0, "[libpng] error: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 162 |
longjmp(png_ptr->jmpbuf, 1); |
163 |
} |
|
164 |
||
165 |
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) |
|
166 |
{ |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
167 |
DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 168 |
} |
169 |
||
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
170 |
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 171 |
{ |
318
648afd1ab9a7
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
172 |
png_color rq[256]; |
0 | 173 |
FILE *f; |
174 |
uint i, y, n; |
|
175 |
uint maxlines; |
|
176 |
png_structp png_ptr; |
|
177 |
png_infop info_ptr; |
|
178 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
179 |
/* only implemented for 8bit images so far. */ |
0 | 180 |
if (pixelformat != 8) |
181 |
return false; |
|
182 |
||
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
183 |
f = fopen(name, "wb"); |
0 | 184 |
if (f == NULL) return false; |
185 |
||
430 | 186 |
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning); |
0 | 187 |
|
430 | 188 |
if (png_ptr == NULL) { |
0 | 189 |
fclose(f); |
190 |
return false; |
|
191 |
} |
|
192 |
||
193 |
info_ptr = png_create_info_struct(png_ptr); |
|
430 | 194 |
if (info_ptr == NULL) { |
0 | 195 |
png_destroy_write_struct(&png_ptr, (png_infopp)NULL); |
196 |
fclose(f); |
|
197 |
return false; |
|
198 |
} |
|
199 |
||
200 |
if (setjmp(png_jmpbuf(png_ptr))) { |
|
201 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
202 |
fclose(f); |
|
203 |
return false; |
|
204 |
} |
|
205 |
||
206 |
png_init_io(png_ptr, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
207 |
|
0 | 208 |
png_set_filter(png_ptr, 0, PNG_FILTER_NONE); |
209 |
||
430 | 210 |
png_set_IHDR(png_ptr, info_ptr, w, h, pixelformat, PNG_COLOR_TYPE_PALETTE, |
211 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
|
0 | 212 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
213 |
/* convert the palette to the .PNG format. */ |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
214 |
for (i = 0; i != 256; i++) { |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
215 |
rq[i].red = palette[i].r; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
216 |
rq[i].green = palette[i].g; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
217 |
rq[i].blue = palette[i].b; |
0 | 218 |
} |
219 |
||
220 |
png_set_PLTE(png_ptr, info_ptr, rq, 256); |
|
221 |
png_write_info(png_ptr, info_ptr); |
|
222 |
png_set_flush(png_ptr, 512); |
|
223 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
224 |
/* use by default 64k temp memory */ |
0 | 225 |
maxlines = clamp(65536 / w, 16, 128); |
226 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
227 |
/* now generate the bitmap bits */ |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
228 |
Pixel *buff = MallocT<Pixel>(w * maxlines); // by default generate 128 lines at a time. |
430 | 229 |
if (buff == NULL) { |
230 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
231 |
fclose(f); |
|
232 |
return false; |
|
233 |
} |
|
0 | 234 |
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 |
235 |
||
236 |
y = 0; |
|
237 |
do { |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
238 |
/* determine # lines to write */ |
0 | 239 |
n = min(h - y, maxlines); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
240 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
241 |
/* render the pixels into the buffer */ |
0 | 242 |
callb(userdata, buff, y, w, n); |
243 |
y += n; |
|
244 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
245 |
/* write them to png */ |
430 | 246 |
for (i = 0; i != n; i++) |
0 | 247 |
png_write_row(png_ptr, buff + i * w); |
248 |
} while (y != h); |
|
249 |
||
250 |
png_write_end(png_ptr, info_ptr); |
|
251 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
252 |
||
430 | 253 |
free(buff); |
0 | 254 |
fclose(f); |
255 |
return true; |
|
256 |
} |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
257 |
#endif /* WITH_PNG */ |
0 | 258 |
|
259 |
||
260 |
//************************************************ |
|
261 |
//*** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX) |
|
262 |
//************************************************ |
|
263 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
264 |
struct PcxHeader { |
0 | 265 |
byte manufacturer; |
266 |
byte version; |
|
267 |
byte rle; |
|
268 |
byte bpp; |
|
269 |
uint32 unused; |
|
270 |
uint16 xmax, ymax; |
|
271 |
uint16 hdpi, vdpi; |
|
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6420
diff
changeset
|
272 |
byte pal_small[16 * 3]; |
0 | 273 |
byte reserved; |
274 |
byte planes; |
|
275 |
uint16 pitch; |
|
276 |
uint16 cpal; |
|
277 |
uint16 width; |
|
278 |
uint16 height; |
|
279 |
byte filler[54]; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
280 |
}; |
0 | 281 |
assert_compile(sizeof(PcxHeader) == 128); |
282 |
||
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
283 |
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 284 |
{ |
285 |
FILE *f; |
|
286 |
uint maxlines; |
|
287 |
uint y; |
|
288 |
PcxHeader pcx; |
|
4019
05b2ea531da0
(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
|
289 |
bool success; |
0 | 290 |
|
291 |
if (pixelformat != 8 || w == 0) |
|
292 |
return false; |
|
293 |
||
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
294 |
f = fopen(name, "wb"); |
0 | 295 |
if (f == NULL) return false; |
296 |
||
297 |
memset(&pcx, 0, sizeof(pcx)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
298 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
299 |
/* setup pcx header */ |
0 | 300 |
pcx.manufacturer = 10; |
301 |
pcx.version = 5; |
|
302 |
pcx.rle = 1; |
|
303 |
pcx.bpp = 8; |
|
430 | 304 |
pcx.xmax = TO_LE16(w - 1); |
305 |
pcx.ymax = TO_LE16(h - 1); |
|
0 | 306 |
pcx.hdpi = TO_LE16(320); |
307 |
pcx.vdpi = TO_LE16(320); |
|
308 |
||
309 |
pcx.planes = 1; |
|
310 |
pcx.cpal = TO_LE16(1); |
|
311 |
pcx.width = pcx.pitch = TO_LE16(w); |
|
312 |
pcx.height = TO_LE16(h); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
313 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
314 |
/* write pcx header */ |
430 | 315 |
if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) { |
316 |
fclose(f); |
|
317 |
return false; |
|
318 |
} |
|
0 | 319 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
320 |
/* use by default 64k temp memory */ |
0 | 321 |
maxlines = clamp(65536 / w, 16, 128); |
322 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
323 |
/* now generate the bitmap bits */ |
5609
dc6a58930ba4
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5587
diff
changeset
|
324 |
Pixel *buff = MallocT<Pixel>(w * maxlines); // by default generate 128 lines at a time. |
430 | 325 |
if (buff == NULL) { |
326 |
fclose(f); |
|
327 |
return false; |
|
328 |
} |
|
329 |
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 |
|
0 | 330 |
|
331 |
y = 0; |
|
332 |
do { |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
333 |
/* determine # lines to write */ |
430 | 334 |
uint n = min(h - y, maxlines); |
335 |
uint i; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
336 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
337 |
/* render the pixels into the buffer */ |
0 | 338 |
callb(userdata, buff, y, w, n); |
339 |
y += n; |
|
340 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
341 |
/* write them to pcx */ |
430 | 342 |
for (i = 0; i != n; i++) { |
2062 | 343 |
const Pixel* bufp = buff + i * w; |
2004 | 344 |
byte runchar = bufp[0]; |
345 |
uint runcount = 1; |
|
346 |
uint j; |
|
0 | 347 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
348 |
/* for each pixel... */ |
2004 | 349 |
for (j = 1; j < w; j++) { |
2062 | 350 |
Pixel ch = bufp[j]; |
2004 | 351 |
|
0 | 352 |
if (ch != runchar || runcount >= 0x3f) { |
430 | 353 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
354 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
355 |
free(buff); |
|
356 |
fclose(f); |
|
357 |
return false; |
|
358 |
} |
|
359 |
if (fputc(runchar, f) == EOF) { |
|
360 |
free(buff); |
|
361 |
fclose(f); |
|
362 |
return false; |
|
363 |
} |
|
0 | 364 |
runcount = 0; |
365 |
runchar = ch; |
|
366 |
} |
|
367 |
runcount++; |
|
368 |
} |
|
369 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
370 |
/* write remaining bytes.. */ |
430 | 371 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
372 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
373 |
free(buff); |
|
374 |
fclose(f); |
|
375 |
return false; |
|
376 |
} |
|
377 |
if (fputc(runchar, f) == EOF) { |
|
378 |
free(buff); |
|
379 |
fclose(f); |
|
380 |
return false; |
|
381 |
} |
|
0 | 382 |
} |
383 |
} while (y != h); |
|
384 |
||
430 | 385 |
free(buff); |
386 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
387 |
/* write 8-bit color palette */ |
430 | 388 |
if (fputc(12, f) == EOF) { |
389 |
fclose(f); |
|
390 |
return false; |
|
391 |
} |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
392 |
|
4019
05b2ea531da0
(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
|
393 |
if (sizeof(*palette) == 3) { |
05b2ea531da0
(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
|
394 |
success = fwrite(palette, 256 * sizeof(*palette), 1, f) == 1; |
05b2ea531da0
(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
|
395 |
} else { |
05b2ea531da0
(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
|
396 |
/* If the palette is word-aligned, copy it to a temporary byte array */ |
4079
0baf04d1b0aa
(svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents:
4019
diff
changeset
|
397 |
byte tmp[256 * 3]; |
4019
05b2ea531da0
(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
|
398 |
uint i; |
4079
0baf04d1b0aa
(svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents:
4019
diff
changeset
|
399 |
|
4019
05b2ea531da0
(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
|
400 |
for (i = 0; i < 256; i++) { |
05b2ea531da0
(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
|
401 |
tmp[i * 3 + 0] = palette[i].r; |
05b2ea531da0
(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
|
402 |
tmp[i * 3 + 1] = palette[i].g; |
05b2ea531da0
(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
|
403 |
tmp[i * 3 + 2] = palette[i].b; |
05b2ea531da0
(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
|
404 |
} |
4079
0baf04d1b0aa
(svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents:
4019
diff
changeset
|
405 |
success = fwrite(tmp, sizeof(tmp), 1, f) == 1; |
430 | 406 |
} |
4019
05b2ea531da0
(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
|
407 |
|
0 | 408 |
fclose(f); |
409 |
||
4019
05b2ea531da0
(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
|
410 |
return success; |
0 | 411 |
} |
412 |
||
413 |
//************************************************ |
|
414 |
//*** GENERIC SCREENSHOT CODE |
|
415 |
//************************************************ |
|
416 |
||
417 |
static const ScreenshotFormat _screenshot_formats[] = { |
|
418 |
#if defined(WITH_PNG) |
|
419 |
{"PNG", "png", &MakePNGImage}, |
|
420 |
#endif |
|
4360
290ac179db55
(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
|
421 |
{"BMP", "bmp", &MakeBmpImage}, |
0 | 422 |
{"PCX", "pcx", &MakePCXImage}, |
423 |
}; |
|
424 |
||
6247 | 425 |
void InitializeScreenshotFormats() |
0 | 426 |
{ |
430 | 427 |
int i, j; |
428 |
for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++) |
|
429 |
if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) { |
|
430 |
j = i; |
|
431 |
break; |
|
432 |
} |
|
0 | 433 |
_cur_screenshot_format = j; |
434 |
_num_screenshot_formats = lengthof(_screenshot_formats); |
|
4185
33a0f0f80965
(svn r5627) Fix (r5626) : Forgot to rename one instance make_screenshot to current_screenshot_type
belugas
parents:
4184
diff
changeset
|
435 |
current_screenshot_type = SC_NONE; |
0 | 436 |
} |
437 |
||
438 |
const char *GetScreenshotFormatDesc(int i) |
|
439 |
{ |
|
440 |
return _screenshot_formats[i].name; |
|
441 |
} |
|
442 |
||
443 |
void SetScreenshotFormat(int i) |
|
444 |
{ |
|
445 |
_cur_screenshot_format = i; |
|
446 |
strcpy(_screenshot_format_name, _screenshot_formats[i].extension); |
|
447 |
} |
|
448 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
449 |
/* screenshot generator that dumps the current video buffer */ |
2062 | 450 |
static void CurrentScreenCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n) |
0 | 451 |
{ |
430 | 452 |
for (; n > 0; --n) { |
6615
74ec6e68e831
(svn r9835) -Codechange: use Pixel typedef instead of byte where ever possible
truelight
parents:
6491
diff
changeset
|
453 |
memcpy(buf, _screen.dst_ptr + y * _screen.pitch, _screen.width * sizeof(Pixel)); |
315
6937bce0a9cb
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
454 |
++y; |
6937bce0a9cb
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
455 |
buf += pitch; |
6937bce0a9cb
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
456 |
} |
0 | 457 |
} |
458 |
||
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
459 |
/* generate a large piece of the world */ |
2062 | 460 |
static void LargeWorldCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n) |
0 | 461 |
{ |
4522 | 462 |
ViewPort *vp = (ViewPort *)userdata; |
0 | 463 |
DrawPixelInfo dpi, *old_dpi; |
464 |
int wx, left; |
|
465 |
||
466 |
old_dpi = _cur_dpi; |
|
467 |
_cur_dpi = &dpi; |
|
468 |
||
469 |
dpi.dst_ptr = buf; |
|
470 |
dpi.height = n; |
|
471 |
dpi.width = vp->width; |
|
472 |
dpi.pitch = pitch; |
|
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6615
diff
changeset
|
473 |
dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
0 | 474 |
dpi.left = 0; |
475 |
dpi.top = y; |
|
476 |
||
477 |
left = 0; |
|
478 |
while (vp->width - left != 0) { |
|
479 |
wx = min(vp->width - left, 1600); |
|
480 |
left += wx; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
481 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
482 |
ViewportDoDraw(vp, |
6626
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
483 |
ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left, |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
484 |
ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top, |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
485 |
ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left, |
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
486 |
ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top |
0 | 487 |
); |
488 |
} |
|
489 |
||
490 |
_cur_dpi = old_dpi; |
|
491 |
} |
|
492 |
||
493 |
static char *MakeScreenshotName(const char *ext) |
|
494 |
{ |
|
495 |
static char filename[256]; |
|
496 |
char *base; |
|
497 |
int serial; |
|
498 |
||
4848
45f848b46222
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4522
diff
changeset
|
499 |
if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_player == PLAYER_SPECTATOR) { |
0 | 500 |
sprintf(_screenshot_name, "screenshot"); |
501 |
} else { |
|
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2398
diff
changeset
|
502 |
const Player* p = GetPlayer(_local_player); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
503 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
504 |
SetDParam(1, p->name_2); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
505 |
SetDParam(2, _date); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
506 |
GetString(_screenshot_name, STR_4004, lastof(_screenshot_name)); |
0 | 507 |
} |
508 |
||
6875
e517a59b78e5
(svn r10116) -Fix [FS#850]: remove invalid characters (for the file system) from savegame names. Based on a patch by TheJosh.
rubidium
parents:
6626
diff
changeset
|
509 |
SanitizeFilename(_screenshot_name); |
0 | 510 |
base = strchr(_screenshot_name, 0); |
511 |
base[0] = '.'; strcpy(base + 1, ext); |
|
512 |
||
513 |
serial = 0; |
|
430 | 514 |
for (;;) { |
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5167
diff
changeset
|
515 |
snprintf(filename, sizeof(filename), "%s%s", _paths.personal_dir, _screenshot_name); |
0 | 516 |
if (!FileExists(filename)) |
517 |
break; |
|
518 |
sprintf(base, " #%d.%s", ++serial, ext); |
|
519 |
} |
|
520 |
||
521 |
return filename; |
|
522 |
} |
|
523 |
||
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
524 |
void SetScreenshotType(ScreenshotType t) |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
525 |
{ |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
526 |
current_screenshot_type = t; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
527 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
528 |
|
6247 | 529 |
bool IsScreenshotRequested() |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
530 |
{ |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
531 |
return (current_screenshot_type != SC_NONE); |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
532 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
533 |
|
6247 | 534 |
static bool MakeSmallScreenshot() |
0 | 535 |
{ |
536 |
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
537 |
return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, 8, _cur_palette); |
0 | 538 |
} |
539 |
||
6247 | 540 |
static bool MakeWorldScreenshot() |
0 | 541 |
{ |
542 |
ViewPort vp; |
|
543 |
const ScreenshotFormat *sf; |
|
544 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6615
diff
changeset
|
545 |
vp.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
0 | 546 |
vp.left = 0; |
547 |
vp.top = 0; |
|
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
548 |
vp.virtual_left = -(int)MapMaxX() * TILE_PIXELS; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
549 |
vp.virtual_top = 0; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
550 |
vp.virtual_width = (MapMaxX() + MapMaxY()) * TILE_PIXELS; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
551 |
vp.width = vp.virtual_width; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
552 |
vp.virtual_height = (MapMaxX() + MapMaxY()) * TILE_PIXELS >> 1; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
553 |
vp.height = vp.virtual_height; |
0 | 554 |
|
555 |
sf = _screenshot_formats + _cur_screenshot_format; |
|
556 |
return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, 8, _cur_palette); |
|
557 |
} |
|
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
558 |
|
6247 | 559 |
bool MakeScreenshot() |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
560 |
{ |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
561 |
switch (current_screenshot_type) { |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
562 |
case SC_VIEWPORT: |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
563 |
UndrawMouseCursor(); |
5371
b42f29b9cc7a
(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
|
564 |
DrawDirtyBlocks(); |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
565 |
current_screenshot_type = SC_NONE; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
566 |
return MakeSmallScreenshot(); |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
567 |
case SC_WORLD: |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
568 |
current_screenshot_type = SC_NONE; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
569 |
return MakeWorldScreenshot(); |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
570 |
default: return false; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
571 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
572 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
573 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
574 |
|
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
575 |