author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9551 | 6f60dca6c566 |
child 10039 | 1f236afd6cd1 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8264
diff
changeset
|
3 |
/** @file screenshot.cpp The creation of screenshots! */ |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8264
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1309
diff
changeset
|
6 |
#include "openttd.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
923
diff
changeset
|
7 |
#include "debug.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" |
8225
cd84a95b6630
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8214
diff
changeset
|
9 |
#include "viewport_func.h" |
cd84a95b6630
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8214
diff
changeset
|
10 |
#include "gfx_func.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8249
diff
changeset
|
11 |
#include "core/math_func.hpp" |
430 | 12 |
#include "screenshot.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2121
diff
changeset
|
13 |
#include "variables.h" |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6929
diff
changeset
|
14 |
#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
|
15 |
#include "fileio.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
7927
diff
changeset
|
16 |
#include "strings_func.h" |
8123
ce31d2843a95
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8121
diff
changeset
|
17 |
#include "zoom_func.h" |
8130
d2eb7d04f6e1
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
8123
diff
changeset
|
18 |
#include "core/alloc_func.hpp" |
8132
f4c7a8e4f25a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8131
diff
changeset
|
19 |
#include "core/endian_func.hpp" |
8139
4e91c448c409
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents:
8138
diff
changeset
|
20 |
#include "map_func.h" |
8140
0d0d8c94f84b
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8139
diff
changeset
|
21 |
#include "date_func.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8249
diff
changeset
|
22 |
#include "player_func.h" |
0 | 23 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
24 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
25 |
|
2121
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
26 |
char _screenshot_format_name[8]; |
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
27 |
uint _num_screenshot_formats; |
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
28 |
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
|
29 |
ScreenshotType current_screenshot_type; |
2121
267f7d75d036
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
30 |
|
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
|
31 |
/* 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
|
32 |
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
|
33 |
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette); |
0 | 34 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
35 |
struct ScreenshotFormat { |
0 | 36 |
const char *name; |
37 |
const char *extension; |
|
38 |
ScreenshotHandlerProc *proc; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
39 |
}; |
0 | 40 |
|
41 |
//************************************************ |
|
42 |
//*** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) |
|
43 |
//************************************************ |
|
923
fc5230f75a91
(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(push, 1) |
46 |
#endif |
|
47 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
48 |
struct BitmapFileHeader { |
0 | 49 |
uint16 type; |
50 |
uint32 size; |
|
51 |
uint32 reserved; |
|
52 |
uint32 off_bits; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
53 |
} GCC_PACK; |
0 | 54 |
assert_compile(sizeof(BitmapFileHeader) == 14); |
55 |
||
923
fc5230f75a91
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
56 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 57 |
#pragma pack(pop) |
58 |
#endif |
|
59 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
60 |
struct BitmapInfoHeader { |
0 | 61 |
uint32 size; |
62 |
int32 width, height; |
|
63 |
uint16 planes, bitcount; |
|
64 |
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
|
65 |
}; |
0 | 66 |
assert_compile(sizeof(BitmapInfoHeader) == 40); |
67 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
68 |
struct RgbQuad { |
0 | 69 |
byte blue, green, red, reserved; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
70 |
}; |
0 | 71 |
assert_compile(sizeof(RgbQuad) == 4); |
72 |
||
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
|
73 |
/* 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
|
74 |
static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 75 |
{ |
76 |
BitmapFileHeader bfh; |
|
77 |
BitmapInfoHeader bih; |
|
318
648afd1ab9a7
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
78 |
RgbQuad rq[256]; |
0 | 79 |
FILE *f; |
80 |
uint i, padw; |
|
81 |
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
|
82 |
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
|
83 |
uint bpp = pixelformat / 8; |
0 | 84 |
|
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
|
85 |
/* 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
|
86 |
if (pixelformat != 8 && pixelformat != 32) return false; |
0 | 87 |
|
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
88 |
f = fopen(name, "wb"); |
0 | 89 |
if (f == NULL) return false; |
90 |
||
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
|
91 |
/* 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
|
92 |
padw = Align(w, 4); |
0 | 93 |
|
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 |
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
|
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 file header */ |
0 | 97 |
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
|
98 |
bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size + padw * h * bpp); |
0 | 99 |
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
|
100 |
bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size); |
0 | 101 |
|
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
|
102 |
/* setup the info header */ |
0 | 103 |
bih.size = TO_LE32(sizeof(BitmapInfoHeader)); |
104 |
bih.width = TO_LE32(w); |
|
105 |
bih.height = TO_LE32(h); |
|
106 |
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
|
107 |
bih.bitcount = TO_LE16(pixelformat); |
0 | 108 |
bih.compression = 0; |
109 |
bih.sizeimage = 0; |
|
110 |
bih.xpels = 0; |
|
111 |
bih.ypels = 0; |
|
112 |
bih.clrused = 0; |
|
113 |
bih.clrimp = 0; |
|
114 |
||
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
|
115 |
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
|
116 |
/* 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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
} |
0 | 123 |
} |
124 |
||
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
|
125 |
/* write file header and info header and palette */ |
430 | 126 |
if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false; |
127 |
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
|
128 |
if (pixelformat == 8) if (fwrite(rq, sizeof(rq), 1, f) != 1) return false; |
0 | 129 |
|
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
|
130 |
/* 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
|
131 |
maxlines = Clamp(65536 / padw, 16, 128); |
0 | 132 |
|
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
|
133 |
/* 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
|
134 |
void *buff = MallocT<uint8>(padw * maxlines * bpp); // by default generate 128 lines at a time. |
430 | 135 |
if (buff == NULL) { |
136 |
fclose(f); |
|
137 |
return false; |
|
138 |
} |
|
0 | 139 |
memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0 |
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 |
/* start at the bottom, since bitmaps are stored bottom up. */ |
0 | 142 |
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
|
143 |
/* determine # lines */ |
0 | 144 |
n = min(h, maxlines); |
145 |
h -= n; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
146 |
|
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
|
147 |
/* render the pixels */ |
0 | 148 |
callb(userdata, buff, h, padw, n); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
149 |
|
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
|
150 |
/* write each line */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
151 |
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
|
152 |
if (fwrite((uint8 *)buff + (--n) * padw * bpp, padw * bpp, 1, f) != 1) { |
430 | 153 |
free(buff); |
154 |
fclose(f); |
|
155 |
return false; |
|
156 |
} |
|
157 |
} while (h != 0); |
|
0 | 158 |
|
430 | 159 |
free(buff); |
0 | 160 |
fclose(f); |
161 |
||
162 |
return true; |
|
163 |
} |
|
164 |
||
165 |
//******************************************************** |
|
166 |
//*** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG) |
|
167 |
//******************************************************** |
|
168 |
#if defined(WITH_PNG) |
|
169 |
#include <png.h> |
|
170 |
||
171 |
static void PNGAPI png_my_error(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, 0, "[libpng] error: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 174 |
longjmp(png_ptr->jmpbuf, 1); |
175 |
} |
|
176 |
||
177 |
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) |
|
178 |
{ |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
179 |
DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 180 |
} |
181 |
||
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
182 |
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 183 |
{ |
318
648afd1ab9a7
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
184 |
png_color rq[256]; |
0 | 185 |
FILE *f; |
186 |
uint i, y, n; |
|
187 |
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
|
188 |
uint bpp = pixelformat / 8; |
0 | 189 |
png_structp png_ptr; |
190 |
png_infop info_ptr; |
|
191 |
||
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
|
192 |
/* 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
|
193 |
if (pixelformat != 8 && pixelformat != 32) return false; |
0 | 194 |
|
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
195 |
f = fopen(name, "wb"); |
0 | 196 |
if (f == NULL) return false; |
197 |
||
430 | 198 |
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning); |
0 | 199 |
|
430 | 200 |
if (png_ptr == NULL) { |
0 | 201 |
fclose(f); |
202 |
return false; |
|
203 |
} |
|
204 |
||
205 |
info_ptr = png_create_info_struct(png_ptr); |
|
430 | 206 |
if (info_ptr == NULL) { |
0 | 207 |
png_destroy_write_struct(&png_ptr, (png_infopp)NULL); |
208 |
fclose(f); |
|
209 |
return false; |
|
210 |
} |
|
211 |
||
212 |
if (setjmp(png_jmpbuf(png_ptr))) { |
|
213 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
214 |
fclose(f); |
|
215 |
return false; |
|
216 |
} |
|
217 |
||
218 |
png_init_io(png_ptr, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
219 |
|
0 | 220 |
png_set_filter(png_ptr, 0, PNG_FILTER_NONE); |
221 |
||
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
|
222 |
png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB, |
430 | 223 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
0 | 224 |
|
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
|
225 |
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
|
226 |
/* 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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
} |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
232 |
|
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 |
png_set_PLTE(png_ptr, info_ptr, rq, 256); |
0 | 234 |
} |
235 |
||
236 |
png_write_info(png_ptr, info_ptr); |
|
237 |
png_set_flush(png_ptr, 512); |
|
238 |
||
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
|
239 |
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
|
240 |
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
|
241 |
|
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 |
/* 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
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
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
|
248 |
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
|
249 |
|
9543
a60fb4bacc66
(svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz
parents:
9111
diff
changeset
|
250 |
#if TTD_ENDIAN == TTD_LITTLE_ENDIAN |
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
|
251 |
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
|
252 |
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
|
253 |
#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
|
254 |
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); |
9543
a60fb4bacc66
(svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz
parents:
9111
diff
changeset
|
255 |
#endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */ |
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 |
} |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6875
diff
changeset
|
257 |
|
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
|
258 |
/* 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
|
259 |
maxlines = Clamp(65536 / w, 16, 128); |
0 | 260 |
|
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
|
261 |
/* 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
|
262 |
void *buff = MallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time. |
430 | 263 |
if (buff == NULL) { |
264 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
265 |
fclose(f); |
|
266 |
return false; |
|
267 |
} |
|
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
|
268 |
memset(buff, 0, w * maxlines * bpp); |
0 | 269 |
|
270 |
y = 0; |
|
271 |
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
|
272 |
/* determine # lines to write */ |
0 | 273 |
n = min(h - y, maxlines); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
274 |
|
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
|
275 |
/* render the pixels into the buffer */ |
0 | 276 |
callb(userdata, buff, y, w, n); |
277 |
y += n; |
|
278 |
||
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
|
279 |
/* write them to png */ |
430 | 280 |
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
|
281 |
png_write_row(png_ptr, (png_bytep)buff + i * w * bpp); |
0 | 282 |
} while (y != h); |
283 |
||
284 |
png_write_end(png_ptr, info_ptr); |
|
285 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
286 |
||
430 | 287 |
free(buff); |
0 | 288 |
fclose(f); |
289 |
return true; |
|
290 |
} |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
291 |
#endif /* WITH_PNG */ |
0 | 292 |
|
293 |
||
294 |
//************************************************ |
|
295 |
//*** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX) |
|
296 |
//************************************************ |
|
297 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
298 |
struct PcxHeader { |
0 | 299 |
byte manufacturer; |
300 |
byte version; |
|
301 |
byte rle; |
|
302 |
byte bpp; |
|
303 |
uint32 unused; |
|
304 |
uint16 xmax, ymax; |
|
305 |
uint16 hdpi, vdpi; |
|
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6420
diff
changeset
|
306 |
byte pal_small[16 * 3]; |
0 | 307 |
byte reserved; |
308 |
byte planes; |
|
309 |
uint16 pitch; |
|
310 |
uint16 cpal; |
|
311 |
uint16 width; |
|
312 |
uint16 height; |
|
313 |
byte filler[54]; |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
314 |
}; |
0 | 315 |
assert_compile(sizeof(PcxHeader) == 128); |
316 |
||
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
317 |
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 318 |
{ |
319 |
FILE *f; |
|
320 |
uint maxlines; |
|
321 |
uint y; |
|
322 |
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
|
323 |
bool success; |
0 | 324 |
|
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
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
} |
0 | 329 |
if (pixelformat != 8 || w == 0) |
330 |
return false; |
|
331 |
||
5167
12c46fb7eccf
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
332 |
f = fopen(name, "wb"); |
0 | 333 |
if (f == NULL) return false; |
334 |
||
335 |
memset(&pcx, 0, sizeof(pcx)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
336 |
|
6420
456c275f3313
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6248
diff
changeset
|
337 |
/* setup pcx header */ |
0 | 338 |
pcx.manufacturer = 10; |
339 |
pcx.version = 5; |
|
340 |
pcx.rle = 1; |
|
341 |
pcx.bpp = 8; |
|
430 | 342 |
pcx.xmax = TO_LE16(w - 1); |
343 |
pcx.ymax = TO_LE16(h - 1); |
|
0 | 344 |
pcx.hdpi = TO_LE16(320); |
345 |
pcx.vdpi = TO_LE16(320); |
|
346 |
||
347 |
pcx.planes = 1; |
|
348 |
pcx.cpal = TO_LE16(1); |
|
349 |
pcx.width = pcx.pitch = TO_LE16(w); |
|
350 |
pcx.height = TO_LE16(h); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
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 |
/* write pcx header */ |
430 | 353 |
if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) { |
354 |
fclose(f); |
|
355 |
return false; |
|
356 |
} |
|
0 | 357 |
|
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
|
358 |
/* 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
|
359 |
maxlines = Clamp(65536 / w, 16, 128); |
0 | 360 |
|
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
|
361 |
/* 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
|
362 |
uint8 *buff = MallocT<uint8>(w * maxlines); // by default generate 128 lines at a time. |
430 | 363 |
if (buff == NULL) { |
364 |
fclose(f); |
|
365 |
return false; |
|
366 |
} |
|
367 |
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 |
|
0 | 368 |
|
369 |
y = 0; |
|
370 |
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
|
371 |
/* determine # lines to write */ |
430 | 372 |
uint n = min(h - y, maxlines); |
373 |
uint i; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
374 |
|
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
|
375 |
/* render the pixels into the buffer */ |
0 | 376 |
callb(userdata, buff, y, w, n); |
377 |
y += n; |
|
378 |
||
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
|
379 |
/* write them to pcx */ |
430 | 380 |
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
|
381 |
const uint8 *bufp = buff + i * w; |
2004 | 382 |
byte runchar = bufp[0]; |
383 |
uint runcount = 1; |
|
384 |
uint j; |
|
0 | 385 |
|
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
|
386 |
/* for each pixel... */ |
2004 | 387 |
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
|
388 |
uint8 ch = bufp[j]; |
2004 | 389 |
|
0 | 390 |
if (ch != runchar || runcount >= 0x3f) { |
430 | 391 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
392 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
393 |
free(buff); |
|
394 |
fclose(f); |
|
395 |
return false; |
|
396 |
} |
|
397 |
if (fputc(runchar, f) == EOF) { |
|
398 |
free(buff); |
|
399 |
fclose(f); |
|
400 |
return false; |
|
401 |
} |
|
0 | 402 |
runcount = 0; |
403 |
runchar = ch; |
|
404 |
} |
|
405 |
runcount++; |
|
406 |
} |
|
407 |
||
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
|
408 |
/* write remaining bytes.. */ |
430 | 409 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
410 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
411 |
free(buff); |
|
412 |
fclose(f); |
|
413 |
return false; |
|
414 |
} |
|
415 |
if (fputc(runchar, f) == EOF) { |
|
416 |
free(buff); |
|
417 |
fclose(f); |
|
418 |
return false; |
|
419 |
} |
|
0 | 420 |
} |
421 |
} while (y != h); |
|
422 |
||
430 | 423 |
free(buff); |
424 |
||
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
|
425 |
/* write 8-bit color palette */ |
430 | 426 |
if (fputc(12, f) == EOF) { |
427 |
fclose(f); |
|
428 |
return false; |
|
429 |
} |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
430 |
|
9551
6f60dca6c566
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents:
9543
diff
changeset
|
431 |
/* Palette is word-aligned, copy it to a temporary byte array */ |
6f60dca6c566
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents:
9543
diff
changeset
|
432 |
byte tmp[256 * 3]; |
4079
0baf04d1b0aa
(svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents:
4019
diff
changeset
|
433 |
|
9551
6f60dca6c566
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents:
9543
diff
changeset
|
434 |
for (uint i = 0; i < 256; i++) { |
6f60dca6c566
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents:
9543
diff
changeset
|
435 |
tmp[i * 3 + 0] = palette[i].r; |
6f60dca6c566
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents:
9543
diff
changeset
|
436 |
tmp[i * 3 + 1] = palette[i].g; |
6f60dca6c566
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents:
9543
diff
changeset
|
437 |
tmp[i * 3 + 2] = palette[i].b; |
430 | 438 |
} |
9551
6f60dca6c566
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz
parents:
9543
diff
changeset
|
439 |
success = fwrite(tmp, sizeof(tmp), 1, f) == 1; |
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
|
440 |
|
0 | 441 |
fclose(f); |
442 |
||
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
|
443 |
return success; |
0 | 444 |
} |
445 |
||
446 |
//************************************************ |
|
447 |
//*** GENERIC SCREENSHOT CODE |
|
448 |
//************************************************ |
|
449 |
||
450 |
static const ScreenshotFormat _screenshot_formats[] = { |
|
451 |
#if defined(WITH_PNG) |
|
452 |
{"PNG", "png", &MakePNGImage}, |
|
453 |
#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
|
454 |
{"BMP", "bmp", &MakeBmpImage}, |
0 | 455 |
{"PCX", "pcx", &MakePCXImage}, |
456 |
}; |
|
457 |
||
6247 | 458 |
void InitializeScreenshotFormats() |
0 | 459 |
{ |
430 | 460 |
int i, j; |
461 |
for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++) |
|
462 |
if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) { |
|
463 |
j = i; |
|
464 |
break; |
|
465 |
} |
|
0 | 466 |
_cur_screenshot_format = j; |
467 |
_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
|
468 |
current_screenshot_type = SC_NONE; |
0 | 469 |
} |
470 |
||
471 |
const char *GetScreenshotFormatDesc(int i) |
|
472 |
{ |
|
473 |
return _screenshot_formats[i].name; |
|
474 |
} |
|
475 |
||
476 |
void SetScreenshotFormat(int i) |
|
477 |
{ |
|
478 |
_cur_screenshot_format = i; |
|
479 |
strcpy(_screenshot_format_name, _screenshot_formats[i].extension); |
|
480 |
} |
|
481 |
||
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
|
482 |
/* 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
|
483 |
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n) |
0 | 484 |
{ |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6929
diff
changeset
|
485 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6929
diff
changeset
|
486 |
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
|
487 |
blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch); |
0 | 488 |
} |
489 |
||
8249
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
490 |
/** generate a large piece of the world |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
491 |
* @param userdata Viewport area to draw |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
492 |
* @param buf Videobuffer with same bitdepth as current blitter |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
493 |
* @param y First line to render |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
494 |
* @param pitch Pitch of the videobuffer |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
495 |
* @param n Number of lines to render |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
496 |
*/ |
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
|
497 |
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n) |
0 | 498 |
{ |
4522 | 499 |
ViewPort *vp = (ViewPort *)userdata; |
0 | 500 |
DrawPixelInfo dpi, *old_dpi; |
501 |
int wx, left; |
|
502 |
||
8249
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
503 |
/* We are no longer rendering to the screen */ |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
504 |
DrawPixelInfo old_screen = _screen; |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
505 |
bool old_disable_anim = _screen_disable_anim; |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
506 |
|
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
507 |
_screen.dst_ptr = buf; |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
508 |
_screen.width = pitch; |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
509 |
_screen.height = n; |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
510 |
_screen.pitch = pitch; |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
511 |
_screen_disable_anim = true; |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
512 |
|
0 | 513 |
old_dpi = _cur_dpi; |
514 |
_cur_dpi = &dpi; |
|
515 |
||
516 |
dpi.dst_ptr = buf; |
|
517 |
dpi.height = n; |
|
518 |
dpi.width = vp->width; |
|
519 |
dpi.pitch = pitch; |
|
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6615
diff
changeset
|
520 |
dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
0 | 521 |
dpi.left = 0; |
522 |
dpi.top = y; |
|
523 |
||
8249
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
524 |
/* Render viewport in blocks of 1600 pixels width */ |
0 | 525 |
left = 0; |
526 |
while (vp->width - left != 0) { |
|
527 |
wx = min(vp->width - left, 1600); |
|
528 |
left += wx; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
529 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
530 |
ViewportDoDraw(vp, |
6626
207875b9069a
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
6624
diff
changeset
|
531 |
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
|
532 |
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
|
533 |
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
|
534 |
ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top |
0 | 535 |
); |
536 |
} |
|
537 |
||
538 |
_cur_dpi = old_dpi; |
|
8249
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
539 |
|
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
540 |
/* Switch back to rendering to the screen */ |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
541 |
_screen = old_screen; |
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8225
diff
changeset
|
542 |
_screen_disable_anim = old_disable_anim; |
0 | 543 |
} |
544 |
||
545 |
static char *MakeScreenshotName(const char *ext) |
|
546 |
{ |
|
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
547 |
static char filename[MAX_PATH]; |
0 | 548 |
int serial; |
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
549 |
size_t len; |
0 | 550 |
|
4848
45f848b46222
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4522
diff
changeset
|
551 |
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
|
552 |
ttd_strlcpy(_screenshot_name, "screenshot", lengthof(_screenshot_name)); |
0 | 553 |
} else { |
7058
8105bb13ce3d
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
6985
diff
changeset
|
554 |
SetDParam(0, _local_player); |
8105bb13ce3d
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
6985
diff
changeset
|
555 |
SetDParam(1, _date); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
556 |
GetString(_screenshot_name, STR_4004, lastof(_screenshot_name)); |
0 | 557 |
} |
558 |
||
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
559 |
/* 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
|
560 |
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
|
561 |
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
|
562 |
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); |
0 | 563 |
|
6929
56470c1b8a66
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
6878
diff
changeset
|
564 |
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
|
565 |
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
|
566 |
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
|
567 |
/* 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
|
568 |
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%d.%s", serial, ext); |
0 | 569 |
} |
570 |
||
571 |
return filename; |
|
572 |
} |
|
573 |
||
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
574 |
void SetScreenshotType(ScreenshotType t) |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
575 |
{ |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
576 |
current_screenshot_type = t; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
577 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
578 |
|
6247 | 579 |
bool IsScreenshotRequested() |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
580 |
{ |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
581 |
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
|
582 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
583 |
|
6247 | 584 |
static bool MakeSmallScreenshot() |
0 | 585 |
{ |
586 |
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
|
587 |
return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); |
0 | 588 |
} |
589 |
||
6247 | 590 |
static bool MakeWorldScreenshot() |
0 | 591 |
{ |
592 |
ViewPort vp; |
|
593 |
const ScreenshotFormat *sf; |
|
594 |
||
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6615
diff
changeset
|
595 |
vp.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
0 | 596 |
vp.left = 0; |
597 |
vp.top = 0; |
|
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
598 |
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
|
599 |
vp.virtual_top = 0; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
600 |
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
|
601 |
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
|
602 |
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
|
603 |
vp.height = vp.virtual_height; |
0 | 604 |
|
605 |
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
|
606 |
return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); |
0 | 607 |
} |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
608 |
|
6247 | 609 |
bool MakeScreenshot() |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
610 |
{ |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
611 |
switch (current_screenshot_type) { |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
612 |
case SC_VIEWPORT: |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
613 |
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
|
614 |
DrawDirtyBlocks(); |
4184
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
615 |
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
|
616 |
return MakeSmallScreenshot(); |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
617 |
case SC_WORLD: |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
618 |
current_screenshot_type = SC_NONE; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
619 |
return MakeWorldScreenshot(); |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
620 |
default: return false; |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
621 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
622 |
} |
541f819f2125
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
623 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
624 |
|
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5371
diff
changeset
|
625 |