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