author | convert-repo |
Mon, 07 Apr 2008 16:21:55 +0000 | |
changeset 10076 | dfd70e42c4ae |
parent 8760 | ce0891c412ce |
child 10429 | 1b99254f9607 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1309
diff
changeset
|
4 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
923
diff
changeset
|
5 |
#include "debug.h" |
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
6 |
#include "fileio.h" |
8721
b7971ad9bdd9
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8710
diff
changeset
|
7 |
#include "viewport_func.h" |
b7971ad9bdd9
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8710
diff
changeset
|
8 |
#include "gfx_func.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8745
diff
changeset
|
9 |
#include "core/math_func.hpp" |
430 | 10 |
#include "screenshot.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2121
diff
changeset
|
11 |
#include "variables.h" |
7433
8e410e7ec0d7
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
7425
diff
changeset
|
12 |
#include "blitter/factory.hpp" |
7371
b86b05214afe
(svn r10116) -Fix [FS#850]: remove invalid characters (for the file system) from savegame names. Based on a patch by TheJosh.
rubidium
parents:
7122
diff
changeset
|
13 |
#include "fileio.h" |
8610
17cc343a23dd
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8423
diff
changeset
|
14 |
#include "strings_func.h" |
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8617
diff
changeset
|
15 |
#include "zoom_func.h" |
8626
440dfcd14c4a
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
8619
diff
changeset
|
16 |
#include "core/alloc_func.hpp" |
8628
4e316518420a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8627
diff
changeset
|
17 |
#include "core/endian_func.hpp" |
8635
3bbb6f87fced
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents:
8634
diff
changeset
|
18 |
#include "map_func.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8635
diff
changeset
|
19 |
#include "date_func.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8745
diff
changeset
|
20 |
#include "player_func.h" |
0 | 21 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
22 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
23 |
|
2121
c86a863485ee
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
24 |
char _screenshot_format_name[8]; |
c86a863485ee
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
25 |
uint _num_screenshot_formats; |
c86a863485ee
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
26 |
uint _cur_screenshot_format; |
4184
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
27 |
ScreenshotType current_screenshot_type; |
2121
c86a863485ee
(svn r2631) Move screenshot related variables from variables.h to screenshot.[ch]
tron
parents:
2120
diff
changeset
|
28 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
29 |
/* called by the ScreenShot proc to generate screenshot lines. */ |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
30 |
typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n); |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
31 |
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette); |
0 | 32 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
33 |
struct ScreenshotFormat { |
0 | 34 |
const char *name; |
35 |
const char *extension; |
|
36 |
ScreenshotHandlerProc *proc; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
37 |
}; |
0 | 38 |
|
39 |
//************************************************ |
|
40 |
//*** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) |
|
41 |
//************************************************ |
|
923
865f9716f7f5
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
42 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 43 |
#pragma pack(push, 1) |
44 |
#endif |
|
45 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
46 |
struct BitmapFileHeader { |
0 | 47 |
uint16 type; |
48 |
uint32 size; |
|
49 |
uint32 reserved; |
|
50 |
uint32 off_bits; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
51 |
} GCC_PACK; |
0 | 52 |
assert_compile(sizeof(BitmapFileHeader) == 14); |
53 |
||
923
865f9716f7f5
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
54 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 55 |
#pragma pack(pop) |
56 |
#endif |
|
57 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
58 |
struct BitmapInfoHeader { |
0 | 59 |
uint32 size; |
60 |
int32 width, height; |
|
61 |
uint16 planes, bitcount; |
|
62 |
uint32 compression, sizeimage, xpels, ypels, clrused, clrimp; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
63 |
}; |
0 | 64 |
assert_compile(sizeof(BitmapInfoHeader) == 40); |
65 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
66 |
struct RgbQuad { |
0 | 67 |
byte blue, green, red, reserved; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
68 |
}; |
0 | 69 |
assert_compile(sizeof(RgbQuad) == 4); |
70 |
||
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
71 |
/* generic .BMP writer */ |
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
72 |
static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 73 |
{ |
74 |
BitmapFileHeader bfh; |
|
75 |
BitmapInfoHeader bih; |
|
318
65ebd0cab39b
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
76 |
RgbQuad rq[256]; |
0 | 77 |
FILE *f; |
78 |
uint i, padw; |
|
79 |
uint n, maxlines; |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
80 |
uint pal_size = 0; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
81 |
uint bpp = pixelformat / 8; |
0 | 82 |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
83 |
/* only implemented for 8bit and 32bit images so far. */ |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
84 |
if (pixelformat != 8 && pixelformat != 32) return false; |
0 | 85 |
|
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
86 |
f = fopen(name, "wb"); |
0 | 87 |
if (f == NULL) return false; |
88 |
||
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
89 |
/* each scanline must be aligned on a 32bit boundary */ |
8423
8453e9a0f0b5
(svn r11480) -Codechange: Rename the function ALIGN fitting to the naming style
skidd13
parents:
8418
diff
changeset
|
90 |
padw = Align(w, 4); |
0 | 91 |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
92 |
if (pixelformat == 8) pal_size = sizeof(RgbQuad) * 256; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
93 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
94 |
/* setup the file header */ |
0 | 95 |
bfh.type = TO_LE16('MB'); |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
96 |
bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size + padw * h * bpp); |
0 | 97 |
bfh.reserved = 0; |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
98 |
bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size); |
0 | 99 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
100 |
/* setup the info header */ |
0 | 101 |
bih.size = TO_LE32(sizeof(BitmapInfoHeader)); |
102 |
bih.width = TO_LE32(w); |
|
103 |
bih.height = TO_LE32(h); |
|
104 |
bih.planes = TO_LE16(1); |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
105 |
bih.bitcount = TO_LE16(pixelformat); |
0 | 106 |
bih.compression = 0; |
107 |
bih.sizeimage = 0; |
|
108 |
bih.xpels = 0; |
|
109 |
bih.ypels = 0; |
|
110 |
bih.clrused = 0; |
|
111 |
bih.clrimp = 0; |
|
112 |
||
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
113 |
if (pixelformat == 8) { |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
114 |
/* convert the palette to the windows format */ |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
115 |
for (i = 0; i != 256; i++) { |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
116 |
rq[i].red = palette[i].r; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
117 |
rq[i].green = palette[i].g; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
118 |
rq[i].blue = palette[i].b; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
119 |
rq[i].reserved = 0; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
120 |
} |
0 | 121 |
} |
122 |
||
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
123 |
/* write file header and info header and palette */ |
430 | 124 |
if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false; |
125 |
if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false; |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
126 |
if (pixelformat == 8) if (fwrite(rq, sizeof(rq), 1, f) != 1) return false; |
0 | 127 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
128 |
/* use by default 64k temp memory */ |
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7634
diff
changeset
|
129 |
maxlines = Clamp(65536 / padw, 16, 128); |
0 | 130 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
131 |
/* now generate the bitmap bits */ |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
132 |
void *buff = MallocT<uint8>(padw * maxlines * bpp); // by default generate 128 lines at a time. |
430 | 133 |
if (buff == NULL) { |
134 |
fclose(f); |
|
135 |
return false; |
|
136 |
} |
|
0 | 137 |
memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0 |
138 |
||
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
139 |
/* start at the bottom, since bitmaps are stored bottom up. */ |
0 | 140 |
do { |
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
141 |
/* determine # lines */ |
0 | 142 |
n = min(h, maxlines); |
143 |
h -= n; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
144 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
145 |
/* render the pixels */ |
0 | 146 |
callb(userdata, buff, h, padw, n); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
147 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
148 |
/* write each line */ |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
149 |
while (n) |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
150 |
if (fwrite((uint8 *)buff + (--n) * padw * bpp, padw * bpp, 1, f) != 1) { |
430 | 151 |
free(buff); |
152 |
fclose(f); |
|
153 |
return false; |
|
154 |
} |
|
155 |
} while (h != 0); |
|
0 | 156 |
|
430 | 157 |
free(buff); |
0 | 158 |
fclose(f); |
159 |
||
160 |
return true; |
|
161 |
} |
|
162 |
||
163 |
//******************************************************** |
|
164 |
//*** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG) |
|
165 |
//******************************************************** |
|
166 |
#if defined(WITH_PNG) |
|
167 |
#include <png.h> |
|
168 |
||
169 |
static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message) |
|
170 |
{ |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5559
diff
changeset
|
171 |
DEBUG(misc, 0, "[libpng] error: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 172 |
longjmp(png_ptr->jmpbuf, 1); |
173 |
} |
|
174 |
||
175 |
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) |
|
176 |
{ |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5559
diff
changeset
|
177 |
DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 178 |
} |
179 |
||
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
180 |
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 181 |
{ |
318
65ebd0cab39b
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
182 |
png_color rq[256]; |
0 | 183 |
FILE *f; |
184 |
uint i, y, n; |
|
185 |
uint maxlines; |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
186 |
uint bpp = pixelformat / 8; |
0 | 187 |
png_structp png_ptr; |
188 |
png_infop info_ptr; |
|
189 |
||
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
190 |
/* only implemented for 8bit and 32bit images so far. */ |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
191 |
if (pixelformat != 8 && pixelformat != 32) return false; |
0 | 192 |
|
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
193 |
f = fopen(name, "wb"); |
0 | 194 |
if (f == NULL) return false; |
195 |
||
430 | 196 |
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning); |
0 | 197 |
|
430 | 198 |
if (png_ptr == NULL) { |
0 | 199 |
fclose(f); |
200 |
return false; |
|
201 |
} |
|
202 |
||
203 |
info_ptr = png_create_info_struct(png_ptr); |
|
430 | 204 |
if (info_ptr == NULL) { |
0 | 205 |
png_destroy_write_struct(&png_ptr, (png_infopp)NULL); |
206 |
fclose(f); |
|
207 |
return false; |
|
208 |
} |
|
209 |
||
210 |
if (setjmp(png_jmpbuf(png_ptr))) { |
|
211 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
212 |
fclose(f); |
|
213 |
return false; |
|
214 |
} |
|
215 |
||
216 |
png_init_io(png_ptr, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
217 |
|
0 | 218 |
png_set_filter(png_ptr, 0, PNG_FILTER_NONE); |
219 |
||
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
220 |
png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB, |
430 | 221 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
0 | 222 |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
223 |
if (pixelformat == 8) { |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
224 |
/* convert the palette to the .PNG format. */ |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
225 |
for (i = 0; i != 256; i++) { |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
226 |
rq[i].red = palette[i].r; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
227 |
rq[i].green = palette[i].g; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
228 |
rq[i].blue = palette[i].b; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
229 |
} |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
230 |
|
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
231 |
png_set_PLTE(png_ptr, info_ptr, rq, 256); |
0 | 232 |
} |
233 |
||
234 |
png_write_info(png_ptr, info_ptr); |
|
235 |
png_set_flush(png_ptr, 512); |
|
236 |
||
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
237 |
if (pixelformat == 32) { |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
238 |
png_color_8 sig_bit; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
239 |
|
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
240 |
/* Save exact color/alpha resolution */ |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
241 |
sig_bit.alpha = 0; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
242 |
sig_bit.blue = 8; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
243 |
sig_bit.green = 8; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
244 |
sig_bit.red = 8; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
245 |
sig_bit.gray = 8; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
246 |
png_set_sBIT(png_ptr, info_ptr, &sig_bit); |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
247 |
|
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
248 |
#ifdef TTD_LITTLE_ENDIAN |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
249 |
png_set_bgr(png_ptr); |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
250 |
png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
251 |
#else |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
252 |
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
253 |
#endif |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
254 |
} |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
255 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
256 |
/* use by default 64k temp memory */ |
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7634
diff
changeset
|
257 |
maxlines = Clamp(65536 / w, 16, 128); |
0 | 258 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
259 |
/* now generate the bitmap bits */ |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
260 |
void *buff = MallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time. |
430 | 261 |
if (buff == NULL) { |
262 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
263 |
fclose(f); |
|
264 |
return false; |
|
265 |
} |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
266 |
memset(buff, 0, w * maxlines * bpp); |
0 | 267 |
|
268 |
y = 0; |
|
269 |
do { |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
270 |
/* determine # lines to write */ |
0 | 271 |
n = min(h - y, maxlines); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
272 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
273 |
/* render the pixels into the buffer */ |
0 | 274 |
callb(userdata, buff, y, w, n); |
275 |
y += n; |
|
276 |
||
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
277 |
/* write them to png */ |
430 | 278 |
for (i = 0; i != n; i++) |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
279 |
png_write_row(png_ptr, (png_bytep)buff + i * w * bpp); |
0 | 280 |
} while (y != h); |
281 |
||
282 |
png_write_end(png_ptr, info_ptr); |
|
283 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
284 |
||
430 | 285 |
free(buff); |
0 | 286 |
fclose(f); |
287 |
return true; |
|
288 |
} |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
289 |
#endif /* WITH_PNG */ |
0 | 290 |
|
291 |
||
292 |
//************************************************ |
|
293 |
//*** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX) |
|
294 |
//************************************************ |
|
295 |
||
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
296 |
struct PcxHeader { |
0 | 297 |
byte manufacturer; |
298 |
byte version; |
|
299 |
byte rle; |
|
300 |
byte bpp; |
|
301 |
uint32 unused; |
|
302 |
uint16 xmax, ymax; |
|
303 |
uint16 hdpi, vdpi; |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6916
diff
changeset
|
304 |
byte pal_small[16 * 3]; |
0 | 305 |
byte reserved; |
306 |
byte planes; |
|
307 |
uint16 pitch; |
|
308 |
uint16 cpal; |
|
309 |
uint16 width; |
|
310 |
uint16 height; |
|
311 |
byte filler[54]; |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
312 |
}; |
0 | 313 |
assert_compile(sizeof(PcxHeader) == 128); |
314 |
||
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
315 |
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
0 | 316 |
{ |
317 |
FILE *f; |
|
318 |
uint maxlines; |
|
319 |
uint y; |
|
320 |
PcxHeader pcx; |
|
4019
96c633a49ff4
(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
|
321 |
bool success; |
0 | 322 |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
323 |
if (pixelformat == 32) { |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
324 |
DEBUG(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick an other format."); |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
325 |
return false; |
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
326 |
} |
0 | 327 |
if (pixelformat != 8 || w == 0) |
328 |
return false; |
|
329 |
||
5167
2b9d61386688
(svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents:
4912
diff
changeset
|
330 |
f = fopen(name, "wb"); |
0 | 331 |
if (f == NULL) return false; |
332 |
||
333 |
memset(&pcx, 0, sizeof(pcx)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
334 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
335 |
/* setup pcx header */ |
0 | 336 |
pcx.manufacturer = 10; |
337 |
pcx.version = 5; |
|
338 |
pcx.rle = 1; |
|
339 |
pcx.bpp = 8; |
|
430 | 340 |
pcx.xmax = TO_LE16(w - 1); |
341 |
pcx.ymax = TO_LE16(h - 1); |
|
0 | 342 |
pcx.hdpi = TO_LE16(320); |
343 |
pcx.vdpi = TO_LE16(320); |
|
344 |
||
345 |
pcx.planes = 1; |
|
346 |
pcx.cpal = TO_LE16(1); |
|
347 |
pcx.width = pcx.pitch = TO_LE16(w); |
|
348 |
pcx.height = TO_LE16(h); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
349 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
350 |
/* write pcx header */ |
430 | 351 |
if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) { |
352 |
fclose(f); |
|
353 |
return false; |
|
354 |
} |
|
0 | 355 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
356 |
/* use by default 64k temp memory */ |
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7634
diff
changeset
|
357 |
maxlines = Clamp(65536 / w, 16, 128); |
0 | 358 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
359 |
/* now generate the bitmap bits */ |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
360 |
uint8 *buff = MallocT<uint8>(w * maxlines); // by default generate 128 lines at a time. |
430 | 361 |
if (buff == NULL) { |
362 |
fclose(f); |
|
363 |
return false; |
|
364 |
} |
|
365 |
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 |
|
0 | 366 |
|
367 |
y = 0; |
|
368 |
do { |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
369 |
/* determine # lines to write */ |
430 | 370 |
uint n = min(h - y, maxlines); |
371 |
uint i; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
372 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
373 |
/* render the pixels into the buffer */ |
0 | 374 |
callb(userdata, buff, y, w, n); |
375 |
y += n; |
|
376 |
||
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
377 |
/* write them to pcx */ |
430 | 378 |
for (i = 0; i != n; i++) { |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
379 |
const uint8 *bufp = buff + i * w; |
2004 | 380 |
byte runchar = bufp[0]; |
381 |
uint runcount = 1; |
|
382 |
uint j; |
|
0 | 383 |
|
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
384 |
/* for each pixel... */ |
2004 | 385 |
for (j = 1; j < w; j++) { |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
386 |
uint8 ch = bufp[j]; |
2004 | 387 |
|
0 | 388 |
if (ch != runchar || runcount >= 0x3f) { |
430 | 389 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
390 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
391 |
free(buff); |
|
392 |
fclose(f); |
|
393 |
return false; |
|
394 |
} |
|
395 |
if (fputc(runchar, f) == EOF) { |
|
396 |
free(buff); |
|
397 |
fclose(f); |
|
398 |
return false; |
|
399 |
} |
|
0 | 400 |
runcount = 0; |
401 |
runchar = ch; |
|
402 |
} |
|
403 |
runcount++; |
|
404 |
} |
|
405 |
||
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
406 |
/* write remaining bytes.. */ |
430 | 407 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
408 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
409 |
free(buff); |
|
410 |
fclose(f); |
|
411 |
return false; |
|
412 |
} |
|
413 |
if (fputc(runchar, f) == EOF) { |
|
414 |
free(buff); |
|
415 |
fclose(f); |
|
416 |
return false; |
|
417 |
} |
|
0 | 418 |
} |
419 |
} while (y != h); |
|
420 |
||
430 | 421 |
free(buff); |
422 |
||
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
423 |
/* write 8-bit color palette */ |
430 | 424 |
if (fputc(12, f) == EOF) { |
425 |
fclose(f); |
|
426 |
return false; |
|
427 |
} |
|
1991
f3d5e35731a2
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1891
diff
changeset
|
428 |
|
4019
96c633a49ff4
(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 |
if (sizeof(*palette) == 3) { |
96c633a49ff4
(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 |
success = fwrite(palette, 256 * sizeof(*palette), 1, f) == 1; |
96c633a49ff4
(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
|
431 |
} else { |
96c633a49ff4
(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 |
/* If the palette is word-aligned, copy it to a temporary byte array */ |
4079
30cac8061fa2
(svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents:
4019
diff
changeset
|
433 |
byte tmp[256 * 3]; |
4019
96c633a49ff4
(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 |
uint i; |
4079
30cac8061fa2
(svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents:
4019
diff
changeset
|
435 |
|
4019
96c633a49ff4
(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 |
for (i = 0; i < 256; i++) { |
96c633a49ff4
(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 + 0] = palette[i].r; |
96c633a49ff4
(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 |
tmp[i * 3 + 1] = palette[i].g; |
96c633a49ff4
(svn r5249) - Add code to copy the palette to a temporary byte aligned array when making a PCX screenshot, if the palette array is not byte aligned.
peter1138
parents:
3329
diff
changeset
|
439 |
tmp[i * 3 + 2] = palette[i].b; |
96c633a49ff4
(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 |
} |
4079
30cac8061fa2
(svn r5394) Allocate a small, fixed-size array on the stack instead of malloc()ing it
tron
parents:
4019
diff
changeset
|
441 |
success = fwrite(tmp, sizeof(tmp), 1, f) == 1; |
430 | 442 |
} |
4019
96c633a49ff4
(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 |
|
0 | 444 |
fclose(f); |
445 |
||
4019
96c633a49ff4
(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
|
446 |
return success; |
0 | 447 |
} |
448 |
||
449 |
//************************************************ |
|
450 |
//*** GENERIC SCREENSHOT CODE |
|
451 |
//************************************************ |
|
452 |
||
453 |
static const ScreenshotFormat _screenshot_formats[] = { |
|
454 |
#if defined(WITH_PNG) |
|
455 |
{"PNG", "png", &MakePNGImage}, |
|
456 |
#endif |
|
4360
07fb51363337
(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
|
457 |
{"BMP", "bmp", &MakeBmpImage}, |
0 | 458 |
{"PCX", "pcx", &MakePCXImage}, |
459 |
}; |
|
460 |
||
6573 | 461 |
void InitializeScreenshotFormats() |
0 | 462 |
{ |
430 | 463 |
int i, j; |
464 |
for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++) |
|
465 |
if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) { |
|
466 |
j = i; |
|
467 |
break; |
|
468 |
} |
|
0 | 469 |
_cur_screenshot_format = j; |
470 |
_num_screenshot_formats = lengthof(_screenshot_formats); |
|
4185
50a4d6493690
(svn r5627) Fix (r5626) : Forgot to rename one instance make_screenshot to current_screenshot_type
belugas
parents:
4184
diff
changeset
|
471 |
current_screenshot_type = SC_NONE; |
0 | 472 |
} |
473 |
||
474 |
const char *GetScreenshotFormatDesc(int i) |
|
475 |
{ |
|
476 |
return _screenshot_formats[i].name; |
|
477 |
} |
|
478 |
||
479 |
void SetScreenshotFormat(int i) |
|
480 |
{ |
|
481 |
_cur_screenshot_format = i; |
|
482 |
strcpy(_screenshot_format_name, _screenshot_formats[i].extension); |
|
483 |
} |
|
484 |
||
6916
e87d54a598ea
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents:
6574
diff
changeset
|
485 |
/* screenshot generator that dumps the current video buffer */ |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
486 |
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n) |
0 | 487 |
{ |
7433
8e410e7ec0d7
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
7425
diff
changeset
|
488 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
8e410e7ec0d7
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
7425
diff
changeset
|
489 |
void *src = blitter->MoveTo(_screen.dst_ptr, 0, y); |
7481
699607d457a0
(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:
7433
diff
changeset
|
490 |
blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch); |
0 | 491 |
} |
492 |
||
8745
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
493 |
/** generate a large piece of the world |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
494 |
* @param userdata Viewport area to draw |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
495 |
* @param buf Videobuffer with same bitdepth as current blitter |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
496 |
* @param y First line to render |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
497 |
* @param pitch Pitch of the videobuffer |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
498 |
* @param n Number of lines to render |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
499 |
*/ |
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
500 |
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n) |
0 | 501 |
{ |
4522 | 502 |
ViewPort *vp = (ViewPort *)userdata; |
0 | 503 |
DrawPixelInfo dpi, *old_dpi; |
504 |
int wx, left; |
|
505 |
||
8745
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
506 |
/* We are no longer rendering to the screen */ |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
507 |
DrawPixelInfo old_screen = _screen; |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
508 |
bool old_disable_anim = _screen_disable_anim; |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
509 |
|
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
510 |
_screen.dst_ptr = buf; |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
511 |
_screen.width = pitch; |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
512 |
_screen.height = n; |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
513 |
_screen.pitch = pitch; |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
514 |
_screen_disable_anim = true; |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
515 |
|
0 | 516 |
old_dpi = _cur_dpi; |
517 |
_cur_dpi = &dpi; |
|
518 |
||
519 |
dpi.dst_ptr = buf; |
|
520 |
dpi.height = n; |
|
521 |
dpi.width = vp->width; |
|
522 |
dpi.pitch = pitch; |
|
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
7111
diff
changeset
|
523 |
dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
0 | 524 |
dpi.left = 0; |
525 |
dpi.top = y; |
|
526 |
||
8745
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
527 |
/* Render viewport in blocks of 1600 pixels width */ |
0 | 528 |
left = 0; |
529 |
while (vp->width - left != 0) { |
|
530 |
wx = min(vp->width - left, 1600); |
|
531 |
left += wx; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
532 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
533 |
ViewportDoDraw(vp, |
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
534 |
ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left, |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
535 |
ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top, |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
536 |
ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left, |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
537 |
ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top |
0 | 538 |
); |
539 |
} |
|
540 |
||
541 |
_cur_dpi = old_dpi; |
|
8745
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
542 |
|
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
543 |
/* Switch back to rendering to the screen */ |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
544 |
_screen = old_screen; |
0c897b4e651e
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8721
diff
changeset
|
545 |
_screen_disable_anim = old_disable_anim; |
0 | 546 |
} |
547 |
||
548 |
static char *MakeScreenshotName(const char *ext) |
|
549 |
{ |
|
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
550 |
static char filename[MAX_PATH]; |
0 | 551 |
int serial; |
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
552 |
size_t len; |
0 | 553 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4522
diff
changeset
|
554 |
if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_player == PLAYER_SPECTATOR) { |
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
555 |
ttd_strlcpy(_screenshot_name, "screenshot", lengthof(_screenshot_name)); |
0 | 556 |
} else { |
7554
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7481
diff
changeset
|
557 |
SetDParam(0, _local_player); |
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7481
diff
changeset
|
558 |
SetDParam(1, _date); |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4848
diff
changeset
|
559 |
GetString(_screenshot_name, STR_4004, lastof(_screenshot_name)); |
0 | 560 |
} |
561 |
||
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
562 |
/* Add extension to screenshot file */ |
7371
b86b05214afe
(svn r10116) -Fix [FS#850]: remove invalid characters (for the file system) from savegame names. Based on a patch by TheJosh.
rubidium
parents:
7122
diff
changeset
|
563 |
SanitizeFilename(_screenshot_name); |
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
564 |
len = strlen(_screenshot_name); |
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
565 |
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); |
0 | 566 |
|
7425
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
567 |
for (serial = 1;; serial++) { |
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
568 |
snprintf(filename, lengthof(filename), "%s%s", _personal_dir, _screenshot_name); |
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
569 |
if (!FileExists(filename)) break; |
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
570 |
/* If file exists try another one with same name, but just with a higher index */ |
350b9265b7a2
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents:
7374
diff
changeset
|
571 |
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%d.%s", serial, ext); |
0 | 572 |
} |
573 |
||
574 |
return filename; |
|
575 |
} |
|
576 |
||
4184
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
577 |
void SetScreenshotType(ScreenshotType t) |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
578 |
{ |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
579 |
current_screenshot_type = t; |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
580 |
} |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
581 |
|
6573 | 582 |
bool IsScreenshotRequested() |
4184
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
583 |
{ |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
584 |
return (current_screenshot_type != SC_NONE); |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
585 |
} |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
586 |
|
6573 | 587 |
static bool MakeSmallScreenshot() |
0 | 588 |
{ |
589 |
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
590 |
return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); |
0 | 591 |
} |
592 |
||
6573 | 593 |
static bool MakeWorldScreenshot() |
0 | 594 |
{ |
595 |
ViewPort vp; |
|
596 |
const ScreenshotFormat *sf; |
|
597 |
||
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
7111
diff
changeset
|
598 |
vp.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
0 | 599 |
vp.left = 0; |
600 |
vp.top = 0; |
|
4184
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
601 |
vp.virtual_left = -(int)MapMaxX() * TILE_PIXELS; |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
602 |
vp.virtual_top = 0; |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
603 |
vp.virtual_width = (MapMaxX() + MapMaxY()) * TILE_PIXELS; |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
604 |
vp.width = vp.virtual_width; |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
605 |
vp.virtual_height = (MapMaxX() + MapMaxY()) * TILE_PIXELS >> 1; |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
606 |
vp.height = vp.virtual_height; |
0 | 607 |
|
608 |
sf = _screenshot_formats + _cur_screenshot_format; |
|
7374
54c06f06ecc8
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
7371
diff
changeset
|
609 |
return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); |
0 | 610 |
} |
4184
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
611 |
|
6573 | 612 |
bool MakeScreenshot() |
4184
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
613 |
{ |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
614 |
switch (current_screenshot_type) { |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
615 |
case SC_VIEWPORT: |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
616 |
UndrawMouseCursor(); |
5559
10610f5e6e38
(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
|
617 |
DrawDirtyBlocks(); |
4184
f38abcb8b18d
(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; |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
619 |
return MakeSmallScreenshot(); |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
620 |
case SC_WORLD: |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
621 |
current_screenshot_type = SC_NONE; |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
622 |
return MakeWorldScreenshot(); |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
623 |
default: return false; |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
624 |
} |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
625 |
} |
f38abcb8b18d
(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism
belugas
parents:
4079
diff
changeset
|
626 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5559
diff
changeset
|
627 |
|
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5559
diff
changeset
|
628 |