author | rubidium |
Sat, 22 Dec 2007 23:30:28 +0000 | |
changeset 8121 | 3bc6351e7369 |
parent 8114 | dd6d21dc99c1 |
child 8123 | ce31d2843a95 |
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" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
430
diff
changeset
|
7 |
#include "table/strings.h" |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
8 |
#include "fileio.h" |
0 | 9 |
#include "viewport.h" |
10 |
#include "player.h" |
|
430 | 11 |
#include "screenshot.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2121
diff
changeset
|
12 |
#include "variables.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4185
diff
changeset
|
13 |
#include "date.h" |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
14 |
#include "string.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
15 |
#include "helpers.hpp" |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6929
diff
changeset
|
16 |
#include "blitter/factory.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" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
7927
diff
changeset
|
18 |
#include "strings_func.h" |
0 | 19 |
|
2121
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
20 |
char _screenshot_format_name[8]; |
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
21 |
uint _num_screenshot_formats; |
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
22 |
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
|
23 |
ScreenshotType current_screenshot_type; |
2121
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
24 |
|
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
|
25 |
/* called by the ScreenShot proc to generate screenshot lines. */ |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
26 |
typedef void ScreenshotCallback(void *userdata, void *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
|
27 |
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette); |
0 | 28 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
29 |
struct ScreenshotFormat { |
0 | 30 |
const char *name; |
31 |
const char *extension; |
|
32 |
ScreenshotHandlerProc *proc; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
33 |
}; |
0 | 34 |
|
35 |
//************************************************ |
|
36 |
//*** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) |
|
37 |
//************************************************ |
|
923
fc5230f75a91
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
38 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 39 |
#pragma pack(push, 1) |
40 |
#endif |
|
41 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
42 |
struct BitmapFileHeader { |
0 | 43 |
uint16 type; |
44 |
uint32 size; |
|
45 |
uint32 reserved; |
|
46 |
uint32 off_bits; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
47 |
} GCC_PACK; |
0 | 48 |
assert_compile(sizeof(BitmapFileHeader) == 14); |
49 |
||
923
fc5230f75a91
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
50 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 51 |
#pragma pack(pop) |
52 |
#endif |
|
53 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
54 |
struct BitmapInfoHeader { |
0 | 55 |
uint32 size; |
56 |
int32 width, height; |
|
57 |
uint16 planes, bitcount; |
|
58 |
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
|
59 |
}; |
0 | 60 |
assert_compile(sizeof(BitmapInfoHeader) == 40); |
61 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
62 |
struct RgbQuad { |
0 | 63 |
byte blue, green, red, reserved; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
64 |
}; |
0 | 65 |
assert_compile(sizeof(RgbQuad) == 4); |
66 |
||
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
|
67 |
/* 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
|
68 |
static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 69 |
{ |
70 |
BitmapFileHeader bfh; |
|
71 |
BitmapInfoHeader bih; |
|
318
648afd1ab9a7
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
72 |
RgbQuad rq[256]; |
0 | 73 |
FILE *f; |
74 |
uint i, padw; |
|
75 |
uint n, maxlines; |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
76 |
uint pal_size = 0; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
77 |
uint bpp = pixelformat / 8; |
0 | 78 |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
79 |
/* only implemented for 8bit and 32bit images so far. */ |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
80 |
if (pixelformat != 8 && pixelformat != 32) return false; |
0 | 81 |
|
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
82 |
f = fopen(name, "wb"); |
0 | 83 |
if (f == NULL) return false; |
84 |
||
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
|
85 |
/* each scanline must be aligned on a 32bit boundary */ |
7927
3a3289a049f9
(svn r11480) -Codechange: Rename the function ALIGN fitting to the naming style
skidd13
parents:
7922
diff
changeset
|
86 |
padw = Align(w, 4); |
0 | 87 |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
88 |
if (pixelformat == 8) pal_size = sizeof(RgbQuad) * 256; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
89 |
|
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
|
90 |
/* setup the file header */ |
0 | 91 |
bfh.type = TO_LE16('MB'); |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
92 |
bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size + padw * h * bpp); |
0 | 93 |
bfh.reserved = 0; |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
94 |
bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size); |
0 | 95 |
|
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
|
96 |
/* setup the info header */ |
0 | 97 |
bih.size = TO_LE32(sizeof(BitmapInfoHeader)); |
98 |
bih.width = TO_LE32(w); |
|
99 |
bih.height = TO_LE32(h); |
|
100 |
bih.planes = TO_LE16(1); |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
101 |
bih.bitcount = TO_LE16(pixelformat); |
0 | 102 |
bih.compression = 0; |
103 |
bih.sizeimage = 0; |
|
104 |
bih.xpels = 0; |
|
105 |
bih.ypels = 0; |
|
106 |
bih.clrused = 0; |
|
107 |
bih.clrimp = 0; |
|
108 |
||
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
109 |
if (pixelformat == 8) { |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
110 |
/* convert the palette to the windows format */ |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
111 |
for (i = 0; i != 256; i++) { |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
112 |
rq[i].red = palette[i].r; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
113 |
rq[i].green = palette[i].g; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
114 |
rq[i].blue = palette[i].b; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
115 |
rq[i].reserved = 0; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
116 |
} |
0 | 117 |
} |
118 |
||
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
|
119 |
/* write file header and info header and palette */ |
430 | 120 |
if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false; |
121 |
if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false; |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
122 |
if (pixelformat == 8) if (fwrite(rq, sizeof(rq), 1, f) != 1) return false; |
0 | 123 |
|
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
|
124 |
/* use by default 64k temp memory */ |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7138
diff
changeset
|
125 |
maxlines = Clamp(65536 / padw, 16, 128); |
0 | 126 |
|
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
|
127 |
/* now generate the bitmap bits */ |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
128 |
void *buff = MallocT<uint8>(padw * maxlines * bpp); // by default generate 128 lines at a time. |
430 | 129 |
if (buff == NULL) { |
130 |
fclose(f); |
|
131 |
return false; |
|
132 |
} |
|
0 | 133 |
memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0 |
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 |
/* start at the bottom, since bitmaps are stored bottom up. */ |
0 | 136 |
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
|
137 |
/* determine # lines */ |
0 | 138 |
n = min(h, maxlines); |
139 |
h -= n; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
140 |
|
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
|
141 |
/* render the pixels */ |
0 | 142 |
callb(userdata, buff, h, padw, n); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
143 |
|
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
|
144 |
/* write each line */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
145 |
while (n) |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
146 |
if (fwrite((uint8 *)buff + (--n) * padw * bpp, padw * bpp, 1, f) != 1) { |
430 | 147 |
free(buff); |
148 |
fclose(f); |
|
149 |
return false; |
|
150 |
} |
|
151 |
} while (h != 0); |
|
0 | 152 |
|
430 | 153 |
free(buff); |
0 | 154 |
fclose(f); |
155 |
||
156 |
return true; |
|
157 |
} |
|
158 |
||
159 |
//******************************************************** |
|
160 |
//*** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG) |
|
161 |
//******************************************************** |
|
162 |
#if defined(WITH_PNG) |
|
163 |
#include <png.h> |
|
164 |
||
165 |
static void PNGAPI png_my_error(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, 0, "[libpng] error: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 168 |
longjmp(png_ptr->jmpbuf, 1); |
169 |
} |
|
170 |
||
171 |
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) |
|
172 |
{ |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
173 |
DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 174 |
} |
175 |
||
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
176 |
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 177 |
{ |
318
648afd1ab9a7
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
178 |
png_color rq[256]; |
0 | 179 |
FILE *f; |
180 |
uint i, y, n; |
|
181 |
uint maxlines; |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
182 |
uint bpp = pixelformat / 8; |
0 | 183 |
png_structp png_ptr; |
184 |
png_infop info_ptr; |
|
185 |
||
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
186 |
/* only implemented for 8bit and 32bit images so far. */ |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
187 |
if (pixelformat != 8 && pixelformat != 32) return false; |
0 | 188 |
|
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
189 |
f = fopen(name, "wb"); |
0 | 190 |
if (f == NULL) return false; |
191 |
||
430 | 192 |
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning); |
0 | 193 |
|
430 | 194 |
if (png_ptr == NULL) { |
0 | 195 |
fclose(f); |
196 |
return false; |
|
197 |
} |
|
198 |
||
199 |
info_ptr = png_create_info_struct(png_ptr); |
|
430 | 200 |
if (info_ptr == NULL) { |
0 | 201 |
png_destroy_write_struct(&png_ptr, (png_infopp)NULL); |
202 |
fclose(f); |
|
203 |
return false; |
|
204 |
} |
|
205 |
||
206 |
if (setjmp(png_jmpbuf(png_ptr))) { |
|
207 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
208 |
fclose(f); |
|
209 |
return false; |
|
210 |
} |
|
211 |
||
212 |
png_init_io(png_ptr, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
213 |
|
0 | 214 |
png_set_filter(png_ptr, 0, PNG_FILTER_NONE); |
215 |
||
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
216 |
png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB, |
430 | 217 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
0 | 218 |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
219 |
if (pixelformat == 8) { |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
220 |
/* convert the palette to the .PNG format. */ |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
221 |
for (i = 0; i != 256; i++) { |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
222 |
rq[i].red = palette[i].r; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
223 |
rq[i].green = palette[i].g; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
224 |
rq[i].blue = palette[i].b; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
225 |
} |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
226 |
|
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
227 |
png_set_PLTE(png_ptr, info_ptr, rq, 256); |
0 | 228 |
} |
229 |
||
230 |
png_write_info(png_ptr, info_ptr); |
|
231 |
png_set_flush(png_ptr, 512); |
|
232 |
||
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
233 |
if (pixelformat == 32) { |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
234 |
png_color_8 sig_bit; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
235 |
|
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
236 |
/* Save exact color/alpha resolution */ |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
237 |
sig_bit.alpha = 0; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
238 |
sig_bit.blue = 8; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
239 |
sig_bit.green = 8; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
240 |
sig_bit.red = 8; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
241 |
sig_bit.gray = 8; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
242 |
png_set_sBIT(png_ptr, info_ptr, &sig_bit); |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
243 |
|
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
244 |
#ifdef TTD_LITTLE_ENDIAN |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
245 |
png_set_bgr(png_ptr); |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
246 |
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
247 |
#else |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
248 |
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
249 |
#endif |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
250 |
} |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
251 |
|
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
|
252 |
/* use by default 64k temp memory */ |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7138
diff
changeset
|
253 |
maxlines = Clamp(65536 / w, 16, 128); |
0 | 254 |
|
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
|
255 |
/* now generate the bitmap bits */ |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
256 |
void *buff = MallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time. |
430 | 257 |
if (buff == NULL) { |
258 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
259 |
fclose(f); |
|
260 |
return false; |
|
261 |
} |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
262 |
memset(buff, 0, w * maxlines * bpp); |
0 | 263 |
|
264 |
y = 0; |
|
265 |
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
|
266 |
/* determine # lines to write */ |
0 | 267 |
n = min(h - y, maxlines); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
268 |
|
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
|
269 |
/* render the pixels into the buffer */ |
0 | 270 |
callb(userdata, buff, y, w, n); |
271 |
y += n; |
|
272 |
||
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
|
273 |
/* write them to png */ |
430 | 274 |
for (i = 0; i != n; i++) |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
275 |
png_write_row(png_ptr, (png_bytep)buff + i * w * bpp); |
0 | 276 |
} while (y != h); |
277 |
||
278 |
png_write_end(png_ptr, info_ptr); |
|
279 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
280 |
||
430 | 281 |
free(buff); |
0 | 282 |
fclose(f); |
283 |
return true; |
|
284 |
} |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
285 |
#endif /* WITH_PNG */ |
0 | 286 |
|
287 |
||
288 |
//************************************************ |
|
289 |
//*** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX) |
|
290 |
//************************************************ |
|
291 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
292 |
struct PcxHeader { |
0 | 293 |
byte manufacturer; |
294 |
byte version; |
|
295 |
byte rle; |
|
296 |
byte bpp; |
|
297 |
uint32 unused; |
|
298 |
uint16 xmax, ymax; |
|
299 |
uint16 hdpi, vdpi; |
|
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6420
diff
changeset
|
300 |
byte pal_small[16 * 3]; |
0 | 301 |
byte reserved; |
302 |
byte planes; |
|
303 |
uint16 pitch; |
|
304 |
uint16 cpal; |
|
305 |
uint16 width; |
|
306 |
uint16 height; |
|
307 |
byte filler[54]; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
308 |
}; |
0 | 309 |
assert_compile(sizeof(PcxHeader) == 128); |
310 |
||
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
311 |
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 312 |
{ |
313 |
FILE *f; |
|
314 |
uint maxlines; |
|
315 |
uint y; |
|
316 |
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
|
317 |
bool success; |
0 | 318 |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
319 |
if (pixelformat == 32) { |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
320 |
DEBUG(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick an other format."); |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
321 |
return false; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
322 |
} |
0 | 323 |
if (pixelformat != 8 || w == 0) |
324 |
return false; |
|
325 |
||
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
326 |
f = fopen(name, "wb"); |
0 | 327 |
if (f == NULL) return false; |
328 |
||
329 |
memset(&pcx, 0, sizeof(pcx)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
330 |
|
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
|
331 |
/* setup pcx header */ |
0 | 332 |
pcx.manufacturer = 10; |
333 |
pcx.version = 5; |
|
334 |
pcx.rle = 1; |
|
335 |
pcx.bpp = 8; |
|
430 | 336 |
pcx.xmax = TO_LE16(w - 1); |
337 |
pcx.ymax = TO_LE16(h - 1); |
|
0 | 338 |
pcx.hdpi = TO_LE16(320); |
339 |
pcx.vdpi = TO_LE16(320); |
|
340 |
||
341 |
pcx.planes = 1; |
|
342 |
pcx.cpal = TO_LE16(1); |
|
343 |
pcx.width = pcx.pitch = TO_LE16(w); |
|
344 |
pcx.height = TO_LE16(h); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
345 |
|
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
|
346 |
/* write pcx header */ |
430 | 347 |
if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) { |
348 |
fclose(f); |
|
349 |
return false; |
|
350 |
} |
|
0 | 351 |
|
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
|
352 |
/* use by default 64k temp memory */ |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7138
diff
changeset
|
353 |
maxlines = Clamp(65536 / w, 16, 128); |
0 | 354 |
|
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
|
355 |
/* now generate the bitmap bits */ |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
356 |
uint8 *buff = MallocT<uint8>(w * maxlines); // by default generate 128 lines at a time. |
430 | 357 |
if (buff == NULL) { |
358 |
fclose(f); |
|
359 |
return false; |
|
360 |
} |
|
361 |
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 |
|
0 | 362 |
|
363 |
y = 0; |
|
364 |
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
|
365 |
/* determine # lines to write */ |
430 | 366 |
uint n = min(h - y, maxlines); |
367 |
uint i; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
368 |
|
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
|
369 |
/* render the pixels into the buffer */ |
0 | 370 |
callb(userdata, buff, y, w, n); |
371 |
y += n; |
|
372 |
||
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
|
373 |
/* write them to pcx */ |
430 | 374 |
for (i = 0; i != n; i++) { |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
375 |
const uint8 *bufp = buff + i * w; |
2004 | 376 |
byte runchar = bufp[0]; |
377 |
uint runcount = 1; |
|
378 |
uint j; |
|
0 | 379 |
|
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
|
380 |
/* for each pixel... */ |
2004 | 381 |
for (j = 1; j < w; j++) { |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
382 |
uint8 ch = bufp[j]; |
2004 | 383 |
|
0 | 384 |
if (ch != runchar || runcount >= 0x3f) { |
430 | 385 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
386 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
387 |
free(buff); |
|
388 |
fclose(f); |
|
389 |
return false; |
|
390 |
} |
|
391 |
if (fputc(runchar, f) == EOF) { |
|
392 |
free(buff); |
|
393 |
fclose(f); |
|
394 |
return false; |
|
395 |
} |
|
0 | 396 |
runcount = 0; |
397 |
runchar = ch; |
|
398 |
} |
|
399 |
runcount++; |
|
400 |
} |
|
401 |
||
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
|
402 |
/* write remaining bytes.. */ |
430 | 403 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
404 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
405 |
free(buff); |
|
406 |
fclose(f); |
|
407 |
return false; |
|
408 |
} |
|
409 |
if (fputc(runchar, f) == EOF) { |
|
410 |
free(buff); |
|
411 |
fclose(f); |
|
412 |
return false; |
|
413 |
} |
|
0 | 414 |
} |
415 |
} while (y != h); |
|
416 |
||
430 | 417 |
free(buff); |
418 |
||
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
|
419 |
/* write 8-bit color palette */ |
430 | 420 |
if (fputc(12, f) == EOF) { |
421 |
fclose(f); |
|
422 |
return false; |
|
423 |
} |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
424 |
|
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
|
425 |
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
|
426 |
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
|
427 |
} 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
|
428 |
/* 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
|
429 |
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
|
430 |
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
|
431 |
|
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
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
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
|
436 |
} |
4079
0baf04d1b0aa
(svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents:
4019
diff
changeset
|
437 |
success = fwrite(tmp, sizeof(tmp), 1, f) == 1; |
430 | 438 |
} |
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
|
439 |
|
0 | 440 |
fclose(f); |
441 |
||
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
|
442 |
return success; |
0 | 443 |
} |
444 |
||
445 |
//************************************************ |
|
446 |
//*** GENERIC SCREENSHOT CODE |
|
447 |
//************************************************ |
|
448 |
||
449 |
static const ScreenshotFormat _screenshot_formats[] = { |
|
450 |
#if defined(WITH_PNG) |
|
451 |
{"PNG", "png", &MakePNGImage}, |
|
452 |
#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
|
453 |
{"BMP", "bmp", &MakeBmpImage}, |
0 | 454 |
{"PCX", "pcx", &MakePCXImage}, |
455 |
}; |
|
456 |
||
6247 | 457 |
void InitializeScreenshotFormats() |
0 | 458 |
{ |
430 | 459 |
int i, j; |
460 |
for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++) |
|
461 |
if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) { |
|
462 |
j = i; |
|
463 |
break; |
|
464 |
} |
|
0 | 465 |
_cur_screenshot_format = j; |
466 |
_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
|
467 |
current_screenshot_type = SC_NONE; |
0 | 468 |
} |
469 |
||
470 |
const char *GetScreenshotFormatDesc(int i) |
|
471 |
{ |
|
472 |
return _screenshot_formats[i].name; |
|
473 |
} |
|
474 |
||
475 |
void SetScreenshotFormat(int i) |
|
476 |
{ |
|
477 |
_cur_screenshot_format = i; |
|
478 |
strcpy(_screenshot_format_name, _screenshot_formats[i].extension); |
|
479 |
} |
|
480 |
||
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
|
481 |
/* screenshot generator that dumps the current video buffer */ |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
482 |
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n) |
0 | 483 |
{ |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6929
diff
changeset
|
484 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6929
diff
changeset
|
485 |
void *src = blitter->MoveTo(_screen.dst_ptr, 0, y); |
6985
d50d59dca7c1
(svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents:
6937
diff
changeset
|
486 |
blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch); |
0 | 487 |
} |
488 |
||
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
|
489 |
/* generate a large piece of the world */ |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
490 |
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n) |
0 | 491 |
{ |
4522 | 492 |
ViewPort *vp = (ViewPort *)userdata; |
0 | 493 |
DrawPixelInfo dpi, *old_dpi; |
494 |
int wx, left; |
|
495 |
||
496 |
old_dpi = _cur_dpi; |
|
497 |
_cur_dpi = &dpi; |
|
498 |
||
499 |
dpi.dst_ptr = buf; |
|
500 |
dpi.height = n; |
|
501 |
dpi.width = vp->width; |
|
502 |
dpi.pitch = pitch; |
|
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6615
diff
changeset
|
503 |
dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
0 | 504 |
dpi.left = 0; |
505 |
dpi.top = y; |
|
506 |
||
507 |
left = 0; |
|
508 |
while (vp->width - left != 0) { |
|
509 |
wx = min(vp->width - left, 1600); |
|
510 |
left += wx; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
511 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
512 |
ViewportDoDraw(vp, |
6626
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
513 |
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
|
514 |
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
|
515 |
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
|
516 |
ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top |
0 | 517 |
); |
518 |
} |
|
519 |
||
520 |
_cur_dpi = old_dpi; |
|
521 |
} |
|
522 |
||
523 |
static char *MakeScreenshotName(const char *ext) |
|
524 |
{ |
|
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
525 |
static char filename[MAX_PATH]; |
0 | 526 |
int serial; |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
527 |
size_t len; |
0 | 528 |
|
4848
45f848b46222
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4522
diff
changeset
|
529 |
if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_player == PLAYER_SPECTATOR) { |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
530 |
ttd_strlcpy(_screenshot_name, "screenshot", lengthof(_screenshot_name)); |
0 | 531 |
} else { |
7058
8105bb13ce3d
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
6985
diff
changeset
|
532 |
SetDParam(0, _local_player); |
8105bb13ce3d
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
6985
diff
changeset
|
533 |
SetDParam(1, _date); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
534 |
GetString(_screenshot_name, STR_4004, lastof(_screenshot_name)); |
0 | 535 |
} |
536 |
||
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
537 |
/* Add extension to screenshot file */ |
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
|
538 |
SanitizeFilename(_screenshot_name); |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
539 |
len = strlen(_screenshot_name); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
540 |
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); |
0 | 541 |
|
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
542 |
for (serial = 1;; serial++) { |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
543 |
snprintf(filename, lengthof(filename), "%s%s", _personal_dir, _screenshot_name); |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
544 |
if (!FileExists(filename)) break; |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
545 |
/* If file exists try another one with same name, but just with a higher index */ |
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
546 |
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%d.%s", serial, ext); |
0 | 547 |
} |
548 |
||
549 |
return filename; |
|
550 |
} |
|
551 |
||
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
552 |
void SetScreenshotType(ScreenshotType t) |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
553 |
{ |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
554 |
current_screenshot_type = t; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
555 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
556 |
|
6247 | 557 |
bool IsScreenshotRequested() |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
558 |
{ |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
559 |
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
|
560 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
561 |
|
6247 | 562 |
static bool MakeSmallScreenshot() |
0 | 563 |
{ |
564 |
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
565 |
return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); |
0 | 566 |
} |
567 |
||
6247 | 568 |
static bool MakeWorldScreenshot() |
0 | 569 |
{ |
570 |
ViewPort vp; |
|
571 |
const ScreenshotFormat *sf; |
|
572 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6615
diff
changeset
|
573 |
vp.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
0 | 574 |
vp.left = 0; |
575 |
vp.top = 0; |
|
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
576 |
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
|
577 |
vp.virtual_top = 0; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
578 |
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
|
579 |
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
|
580 |
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
|
581 |
vp.height = vp.virtual_height; |
0 | 582 |
|
583 |
sf = _screenshot_formats + _cur_screenshot_format; |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
584 |
return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); |
0 | 585 |
} |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
586 |
|
6247 | 587 |
bool MakeScreenshot() |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
588 |
{ |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
589 |
switch (current_screenshot_type) { |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
590 |
case SC_VIEWPORT: |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
591 |
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
|
592 |
DrawDirtyBlocks(); |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
593 |
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
|
594 |
return MakeSmallScreenshot(); |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
595 |
case SC_WORLD: |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
596 |
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
|
597 |
return MakeWorldScreenshot(); |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
598 |
default: return false; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
599 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
600 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
601 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
602 |
|
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
603 |