author | Darkvater |
Sun, 29 Jan 2006 10:50:27 +0000 | |
changeset 2911 | 592a60af08a7 |
parent 2791 | f8ffac7515d4 |
child 3260 | 7d22aa47de3b |
child 9956 | 341e963c63c4 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 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" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
6 |
#include "functions.h" |
1309
dab90d4cbf2d
(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
8aa8100b0b22
(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" |
10 |
#include "viewport.h" |
|
11 |
#include "player.h" |
|
430 | 12 |
#include "screenshot.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2121
diff
changeset
|
13 |
#include "variables.h" |
0 | 14 |
|
2121
c86a863485ee
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
15 |
char _screenshot_format_name[8]; |
c86a863485ee
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
16 |
uint _num_screenshot_formats; |
c86a863485ee
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
17 |
uint _cur_screenshot_format; |
c86a863485ee
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
18 |
|
0 | 19 |
// called by the ScreenShot proc to generate screenshot lines. |
2120 | 20 |
typedef void ScreenshotCallback(void *userdata, Pixel *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
|
21 |
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette); |
0 | 22 |
|
23 |
typedef struct { |
|
24 |
const char *name; |
|
25 |
const char *extension; |
|
26 |
ScreenshotHandlerProc *proc; |
|
27 |
} ScreenshotFormat; |
|
28 |
||
29 |
//************************************************ |
|
30 |
//*** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) |
|
31 |
//************************************************ |
|
923
865f9716f7f5
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
32 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 33 |
#pragma pack(push, 1) |
34 |
#endif |
|
35 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
36 |
typedef struct BitmapFileHeader { |
0 | 37 |
uint16 type; |
38 |
uint32 size; |
|
39 |
uint32 reserved; |
|
40 |
uint32 off_bits; |
|
41 |
} GCC_PACK BitmapFileHeader; |
|
42 |
assert_compile(sizeof(BitmapFileHeader) == 14); |
|
43 |
||
923
865f9716f7f5
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
44 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 45 |
#pragma pack(pop) |
46 |
#endif |
|
47 |
||
48 |
typedef struct BitmapInfoHeader { |
|
49 |
uint32 size; |
|
50 |
int32 width, height; |
|
51 |
uint16 planes, bitcount; |
|
52 |
uint32 compression, sizeimage, xpels, ypels, clrused, clrimp; |
|
53 |
} BitmapInfoHeader; |
|
54 |
assert_compile(sizeof(BitmapInfoHeader) == 40); |
|
55 |
||
56 |
typedef struct RgbQuad { |
|
57 |
byte blue, green, red, reserved; |
|
58 |
} RgbQuad; |
|
59 |
assert_compile(sizeof(RgbQuad) == 4); |
|
60 |
||
61 |
// 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
|
62 |
static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 63 |
{ |
64 |
BitmapFileHeader bfh; |
|
65 |
BitmapInfoHeader bih; |
|
318
65ebd0cab39b
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
66 |
RgbQuad rq[256]; |
2062 | 67 |
Pixel *buff; |
0 | 68 |
FILE *f; |
69 |
uint i, padw; |
|
70 |
uint n, maxlines; |
|
71 |
||
72 |
// only implemented for 8bit images so far. |
|
73 |
if (pixelformat != 8) |
|
74 |
return false; |
|
75 |
||
76 |
f = fopen(name, "wb"); |
|
77 |
if (f == NULL) return false; |
|
78 |
||
79 |
// each scanline must be aligned on a 32bit boundary |
|
2398
70de6626d65f
(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
|
80 |
padw = ALIGN(w, 4); |
0 | 81 |
|
82 |
// setup the file header |
|
83 |
bfh.type = TO_LE16('MB'); |
|
84 |
bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + sizeof(RgbQuad) * 256 + padw * h); |
|
85 |
bfh.reserved = 0; |
|
86 |
bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + sizeof(RgbQuad) * 256); |
|
87 |
||
88 |
// setup the info header |
|
89 |
bih.size = TO_LE32(sizeof(BitmapInfoHeader)); |
|
90 |
bih.width = TO_LE32(w); |
|
91 |
bih.height = TO_LE32(h); |
|
92 |
bih.planes = TO_LE16(1); |
|
93 |
bih.bitcount = TO_LE16(8); |
|
94 |
bih.compression = 0; |
|
95 |
bih.sizeimage = 0; |
|
96 |
bih.xpels = 0; |
|
97 |
bih.ypels = 0; |
|
98 |
bih.clrused = 0; |
|
99 |
bih.clrimp = 0; |
|
100 |
||
101 |
// convert the palette to the windows format |
|
430 | 102 |
for (i = 0; i != 256; i++) { |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
103 |
rq[i].red = palette[i].r; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
104 |
rq[i].green = palette[i].g; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
105 |
rq[i].blue = palette[i].b; |
0 | 106 |
rq[i].reserved = 0; |
107 |
} |
|
108 |
||
109 |
// write file header and info header and palette |
|
430 | 110 |
if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false; |
111 |
if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false; |
|
112 |
if (fwrite(rq, sizeof(rq), 1, f) != 1) return false; |
|
0 | 113 |
|
114 |
// use by default 64k temp memory |
|
115 |
maxlines = clamp(65536 / padw, 16, 128); |
|
116 |
||
117 |
// now generate the bitmap bits |
|
430 | 118 |
buff = malloc(padw * maxlines); // by default generate 128 lines at a time. |
119 |
if (buff == NULL) { |
|
120 |
fclose(f); |
|
121 |
return false; |
|
122 |
} |
|
0 | 123 |
memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0 |
124 |
||
125 |
// start at the bottom, since bitmaps are stored bottom up. |
|
126 |
do { |
|
127 |
// determine # lines |
|
128 |
n = min(h, maxlines); |
|
129 |
h -= n; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
130 |
|
0 | 131 |
// render the pixels |
132 |
callb(userdata, buff, h, padw, n); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
133 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
134 |
// write each line |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
135 |
while (n) |
430 | 136 |
if (fwrite(buff + (--n) * padw, padw, 1, f) != 1) { |
137 |
free(buff); |
|
138 |
fclose(f); |
|
139 |
return false; |
|
140 |
} |
|
141 |
} while (h != 0); |
|
0 | 142 |
|
430 | 143 |
free(buff); |
0 | 144 |
fclose(f); |
145 |
||
146 |
return true; |
|
147 |
} |
|
148 |
||
149 |
//******************************************************** |
|
150 |
//*** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG) |
|
151 |
//******************************************************** |
|
152 |
#if defined(WITH_PNG) |
|
153 |
#include <png.h> |
|
154 |
||
155 |
static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message) |
|
156 |
{ |
|
2013
1b80954e9594
(svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents:
2004
diff
changeset
|
157 |
DEBUG(misc, 0) ("ERROR(libpng): %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 158 |
longjmp(png_ptr->jmpbuf, 1); |
159 |
} |
|
160 |
||
161 |
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) |
|
162 |
{ |
|
2013
1b80954e9594
(svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents:
2004
diff
changeset
|
163 |
DEBUG(misc, 0) ("WARNING(libpng): %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 164 |
} |
165 |
||
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
166 |
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 167 |
{ |
318
65ebd0cab39b
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
168 |
png_color rq[256]; |
2062 | 169 |
Pixel *buff; |
0 | 170 |
FILE *f; |
171 |
uint i, y, n; |
|
172 |
uint maxlines; |
|
173 |
png_structp png_ptr; |
|
174 |
png_infop info_ptr; |
|
175 |
||
176 |
// only implemented for 8bit images so far. |
|
177 |
if (pixelformat != 8) |
|
178 |
return false; |
|
179 |
||
180 |
f = fopen(name, "wb"); |
|
181 |
if (f == NULL) return false; |
|
182 |
||
430 | 183 |
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning); |
0 | 184 |
|
430 | 185 |
if (png_ptr == NULL) { |
0 | 186 |
fclose(f); |
187 |
return false; |
|
188 |
} |
|
189 |
||
190 |
info_ptr = png_create_info_struct(png_ptr); |
|
430 | 191 |
if (info_ptr == NULL) { |
0 | 192 |
png_destroy_write_struct(&png_ptr, (png_infopp)NULL); |
193 |
fclose(f); |
|
194 |
return false; |
|
195 |
} |
|
196 |
||
197 |
if (setjmp(png_jmpbuf(png_ptr))) { |
|
198 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
199 |
fclose(f); |
|
200 |
return false; |
|
201 |
} |
|
202 |
||
203 |
png_init_io(png_ptr, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
204 |
|
0 | 205 |
png_set_filter(png_ptr, 0, PNG_FILTER_NONE); |
206 |
||
430 | 207 |
png_set_IHDR(png_ptr, info_ptr, w, h, pixelformat, PNG_COLOR_TYPE_PALETTE, |
208 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
|
0 | 209 |
|
210 |
// convert the palette to the .PNG format. |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
211 |
for (i = 0; i != 256; i++) { |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
212 |
rq[i].red = palette[i].r; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
213 |
rq[i].green = palette[i].g; |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
214 |
rq[i].blue = palette[i].b; |
0 | 215 |
} |
216 |
||
217 |
png_set_PLTE(png_ptr, info_ptr, rq, 256); |
|
218 |
png_write_info(png_ptr, info_ptr); |
|
219 |
png_set_flush(png_ptr, 512); |
|
220 |
||
221 |
// use by default 64k temp memory |
|
222 |
maxlines = clamp(65536 / w, 16, 128); |
|
223 |
||
224 |
// now generate the bitmap bits |
|
430 | 225 |
buff = malloc(w * maxlines); // by default generate 128 lines at a time. |
226 |
if (buff == NULL) { |
|
227 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
228 |
fclose(f); |
|
229 |
return false; |
|
230 |
} |
|
0 | 231 |
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 |
232 |
||
233 |
y = 0; |
|
234 |
do { |
|
235 |
// determine # lines to write |
|
236 |
n = min(h - y, maxlines); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
237 |
|
0 | 238 |
// render the pixels into the buffer |
239 |
callb(userdata, buff, y, w, n); |
|
240 |
y += n; |
|
241 |
||
242 |
// write them to png |
|
430 | 243 |
for (i = 0; i != n; i++) |
0 | 244 |
png_write_row(png_ptr, buff + i * w); |
245 |
} while (y != h); |
|
246 |
||
247 |
png_write_end(png_ptr, info_ptr); |
|
248 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
249 |
||
430 | 250 |
free(buff); |
0 | 251 |
fclose(f); |
252 |
return true; |
|
253 |
} |
|
254 |
#endif // WITH_PNG |
|
255 |
||
256 |
||
257 |
//************************************************ |
|
258 |
//*** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX) |
|
259 |
//************************************************ |
|
260 |
||
261 |
typedef struct { |
|
262 |
byte manufacturer; |
|
263 |
byte version; |
|
264 |
byte rle; |
|
265 |
byte bpp; |
|
266 |
uint32 unused; |
|
267 |
uint16 xmax, ymax; |
|
268 |
uint16 hdpi, vdpi; |
|
269 |
byte pal_small[16*3]; |
|
270 |
byte reserved; |
|
271 |
byte planes; |
|
272 |
uint16 pitch; |
|
273 |
uint16 cpal; |
|
274 |
uint16 width; |
|
275 |
uint16 height; |
|
276 |
byte filler[54]; |
|
277 |
} PcxHeader; |
|
278 |
assert_compile(sizeof(PcxHeader) == 128); |
|
279 |
||
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
280 |
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 281 |
{ |
2062 | 282 |
Pixel *buff; |
0 | 283 |
FILE *f; |
284 |
uint maxlines; |
|
285 |
uint y; |
|
286 |
PcxHeader pcx; |
|
287 |
||
288 |
if (pixelformat != 8 || w == 0) |
|
289 |
return false; |
|
290 |
||
291 |
f = fopen(name, "wb"); |
|
292 |
if (f == NULL) return false; |
|
293 |
||
294 |
memset(&pcx, 0, sizeof(pcx)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
295 |
|
0 | 296 |
// setup pcx header |
297 |
pcx.manufacturer = 10; |
|
298 |
pcx.version = 5; |
|
299 |
pcx.rle = 1; |
|
300 |
pcx.bpp = 8; |
|
430 | 301 |
pcx.xmax = TO_LE16(w - 1); |
302 |
pcx.ymax = TO_LE16(h - 1); |
|
0 | 303 |
pcx.hdpi = TO_LE16(320); |
304 |
pcx.vdpi = TO_LE16(320); |
|
305 |
||
306 |
pcx.planes = 1; |
|
307 |
pcx.cpal = TO_LE16(1); |
|
308 |
pcx.width = pcx.pitch = TO_LE16(w); |
|
309 |
pcx.height = TO_LE16(h); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
310 |
|
0 | 311 |
// write pcx header |
430 | 312 |
if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) { |
313 |
fclose(f); |
|
314 |
return false; |
|
315 |
} |
|
0 | 316 |
|
317 |
// use by default 64k temp memory |
|
318 |
maxlines = clamp(65536 / w, 16, 128); |
|
319 |
||
320 |
// now generate the bitmap bits |
|
430 | 321 |
buff = malloc(w * maxlines); // by default generate 128 lines at a time. |
322 |
if (buff == NULL) { |
|
323 |
fclose(f); |
|
324 |
return false; |
|
325 |
} |
|
326 |
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 |
|
0 | 327 |
|
328 |
y = 0; |
|
329 |
do { |
|
330 |
// determine # lines to write |
|
430 | 331 |
uint n = min(h - y, maxlines); |
332 |
uint i; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
333 |
|
0 | 334 |
// render the pixels into the buffer |
335 |
callb(userdata, buff, y, w, n); |
|
336 |
y += n; |
|
337 |
||
338 |
// write them to pcx |
|
430 | 339 |
for (i = 0; i != n; i++) { |
2062 | 340 |
const Pixel* bufp = buff + i * w; |
2004 | 341 |
byte runchar = bufp[0]; |
342 |
uint runcount = 1; |
|
343 |
uint j; |
|
0 | 344 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
345 |
// for each pixel... |
2004 | 346 |
for (j = 1; j < w; j++) { |
2062 | 347 |
Pixel ch = bufp[j]; |
2004 | 348 |
|
0 | 349 |
if (ch != runchar || runcount >= 0x3f) { |
430 | 350 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
351 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
352 |
free(buff); |
|
353 |
fclose(f); |
|
354 |
return false; |
|
355 |
} |
|
356 |
if (fputc(runchar, f) == EOF) { |
|
357 |
free(buff); |
|
358 |
fclose(f); |
|
359 |
return false; |
|
360 |
} |
|
0 | 361 |
runcount = 0; |
362 |
runchar = ch; |
|
363 |
} |
|
364 |
runcount++; |
|
365 |
} |
|
366 |
||
367 |
// write remaining bytes.. |
|
430 | 368 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
369 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
370 |
free(buff); |
|
371 |
fclose(f); |
|
372 |
return false; |
|
373 |
} |
|
374 |
if (fputc(runchar, f) == EOF) { |
|
375 |
free(buff); |
|
376 |
fclose(f); |
|
377 |
return false; |
|
378 |
} |
|
0 | 379 |
} |
380 |
} while (y != h); |
|
381 |
||
430 | 382 |
free(buff); |
383 |
||
0 | 384 |
// write 8-bit color palette |
430 | 385 |
if (fputc(12, f) == EOF) { |
386 |
fclose(f); |
|
387 |
return false; |
|
388 |
} |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
389 |
|
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
390 |
{assert_compile(sizeof(*palette) == 3);} |
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
391 |
if (fwrite(palette, 256 * sizeof(*palette), 1, f) != 1) { |
430 | 392 |
fclose(f); |
393 |
return false; |
|
394 |
} |
|
0 | 395 |
fclose(f); |
396 |
||
397 |
return true; |
|
398 |
} |
|
399 |
||
400 |
//************************************************ |
|
401 |
//*** GENERIC SCREENSHOT CODE |
|
402 |
//************************************************ |
|
403 |
||
404 |
static const ScreenshotFormat _screenshot_formats[] = { |
|
405 |
{"BMP", "bmp", &MakeBmpImage}, |
|
406 |
#if defined(WITH_PNG) |
|
407 |
{"PNG", "png", &MakePNGImage}, |
|
408 |
#endif |
|
409 |
{"PCX", "pcx", &MakePCXImage}, |
|
410 |
}; |
|
411 |
||
430 | 412 |
void InitializeScreenshotFormats(void) |
0 | 413 |
{ |
430 | 414 |
int i, j; |
415 |
for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++) |
|
416 |
if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) { |
|
417 |
j = i; |
|
418 |
break; |
|
419 |
} |
|
0 | 420 |
_cur_screenshot_format = j; |
421 |
_num_screenshot_formats = lengthof(_screenshot_formats); |
|
422 |
} |
|
423 |
||
424 |
const char *GetScreenshotFormatDesc(int i) |
|
425 |
{ |
|
426 |
return _screenshot_formats[i].name; |
|
427 |
} |
|
428 |
||
429 |
void SetScreenshotFormat(int i) |
|
430 |
{ |
|
431 |
_cur_screenshot_format = i; |
|
432 |
strcpy(_screenshot_format_name, _screenshot_formats[i].extension); |
|
433 |
} |
|
434 |
||
435 |
// screenshot generator that dumps the current video buffer |
|
2062 | 436 |
static void CurrentScreenCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n) |
0 | 437 |
{ |
430 | 438 |
for (; n > 0; --n) { |
315
e008762a8689
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
439 |
memcpy(buf, _screen.dst_ptr + y * _screen.pitch, _screen.width); |
e008762a8689
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
440 |
++y; |
e008762a8689
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
441 |
buf += pitch; |
e008762a8689
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
442 |
} |
0 | 443 |
} |
444 |
||
445 |
// generate a large piece of the world |
|
2062 | 446 |
static void LargeWorldCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n) |
0 | 447 |
{ |
448 |
ViewPort *vp = (ViewPort *)userdata; |
|
449 |
DrawPixelInfo dpi, *old_dpi; |
|
450 |
int wx, left; |
|
451 |
||
452 |
old_dpi = _cur_dpi; |
|
453 |
_cur_dpi = &dpi; |
|
454 |
||
455 |
dpi.dst_ptr = buf; |
|
456 |
dpi.height = n; |
|
457 |
dpi.width = vp->width; |
|
458 |
dpi.pitch = pitch; |
|
459 |
dpi.zoom = 0; |
|
460 |
dpi.left = 0; |
|
461 |
dpi.top = y; |
|
462 |
||
463 |
left = 0; |
|
464 |
while (vp->width - left != 0) { |
|
465 |
wx = min(vp->width - left, 1600); |
|
466 |
left += wx; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
467 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
468 |
ViewportDoDraw(vp, |
0 | 469 |
((left - wx - vp->left) << vp->zoom) + vp->virtual_left, |
470 |
((y - vp->top) << vp->zoom) + vp->virtual_top, |
|
471 |
((left - vp->left) << vp->zoom) + vp->virtual_left, |
|
430 | 472 |
(((y + n) - vp->top) << vp->zoom) + vp->virtual_top |
0 | 473 |
); |
474 |
} |
|
475 |
||
476 |
_cur_dpi = old_dpi; |
|
477 |
} |
|
478 |
||
479 |
static char *MakeScreenshotName(const char *ext) |
|
480 |
{ |
|
481 |
static char filename[256]; |
|
482 |
char *base; |
|
483 |
int serial; |
|
484 |
||
2693
4c9f68543198
(svn r3235) - Fix: fix two crashes, one with making a screenshot in the main menu without any game loaded, another when failing to load a scenario in 'New Game'
Darkvater
parents:
2548
diff
changeset
|
485 |
if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_player == OWNER_SPECTATOR) { |
0 | 486 |
sprintf(_screenshot_name, "screenshot"); |
487 |
} else { |
|
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2398
diff
changeset
|
488 |
const Player* p = GetPlayer(_local_player); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
489 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
490 |
SetDParam(1, p->name_2); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
491 |
SetDParam(2, _date); |
0 | 492 |
GetString(_screenshot_name, STR_4004); |
493 |
} |
|
494 |
||
495 |
base = strchr(_screenshot_name, 0); |
|
496 |
base[0] = '.'; strcpy(base + 1, ext); |
|
497 |
||
498 |
serial = 0; |
|
430 | 499 |
for (;;) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
500 |
snprintf(filename, sizeof(filename), "%s%s", _path.personal_dir, _screenshot_name); |
0 | 501 |
if (!FileExists(filename)) |
502 |
break; |
|
503 |
sprintf(base, " #%d.%s", ++serial, ext); |
|
504 |
} |
|
505 |
||
506 |
return filename; |
|
507 |
} |
|
508 |
||
430 | 509 |
bool MakeScreenshot(void) |
0 | 510 |
{ |
511 |
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
|
512 |
return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, 8, _cur_palette); |
0 | 513 |
} |
514 |
||
515 |
bool MakeWorldScreenshot(int left, int top, int width, int height, int zoom) |
|
516 |
{ |
|
517 |
ViewPort vp; |
|
518 |
const ScreenshotFormat *sf; |
|
519 |
||
520 |
vp.zoom = zoom; |
|
521 |
vp.left = 0; |
|
522 |
vp.top = 0; |
|
523 |
vp.virtual_width = width; |
|
524 |
vp.width = width >> zoom; |
|
525 |
vp.virtual_height = height; |
|
526 |
vp.height = height >> zoom; |
|
527 |
vp.virtual_left = left; |
|
528 |
vp.virtual_top = top; |
|
529 |
||
530 |
sf = _screenshot_formats + _cur_screenshot_format; |
|
531 |
return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, 8, _cur_palette); |
|
532 |
} |