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