Mercurial > hg > openttd
annotate src/screenshot.cpp @ 17564:d5ff867052a5 draft
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
author | frosch <frosch@openttd.org> |
---|---|
date | Sat, 16 Apr 2011 16:45:35 +0000 (2011-04-16) |
parents | c62cecf4dade |
children | f1feece6fa62 |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
9 |
9111
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
8264
diff
changeset
|
10 /** @file screenshot.cpp The creation of screenshots! */ |
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
8264
diff
changeset
|
11 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
10039
6301378f3e0f
(svn r14199) -Codechange: split fileio.h into fileio_type.h and fileio_func.h so not everything that includes saveload.h needs to include everything else too.
rubidium <rubidium@openttd.org>
parents:
9551
diff
changeset
|
13 #include "fileio_func.h" |
8225
0e48dd14a0d8
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium <rubidium@openttd.org>
parents:
8214
diff
changeset
|
14 #include "viewport_func.h" |
0e48dd14a0d8
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium <rubidium@openttd.org>
parents:
8214
diff
changeset
|
15 #include "gfx_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
16 #include "screenshot.h" |
6937
b6cf3513b2c4
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight <truelight@openttd.org>
parents:
6929
diff
changeset
|
17 #include "blitter/factory.hpp" |
8123
c26c28875749
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium <rubidium@openttd.org>
parents:
8121
diff
changeset
|
18 #include "zoom_func.h" |
8132
07f1dd54eb1a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium <rubidium@openttd.org>
parents:
8131
diff
changeset
|
19 #include "core/endian_func.hpp" |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10533
diff
changeset
|
20 #include "saveload/saveload.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
21 #include "company_func.h" |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
22 #include "strings_func.h" |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
23 #include "gui.h" |
15829
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
24 #include "window_gui.h" |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
25 #include "window_func.h" |
16954
c42d3f94eb23
(svn r21690) -Fix: the top of a tall building standing on a hill at the top of the map could be cut off in a giant screenshot
yexo <yexo@openttd.org>
parents:
16824
diff
changeset
|
26 #include "tile_map.h" |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
27 |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
28 #include "table/strings.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
29 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
30 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
31 char _screenshot_format_name[8]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
32 uint _num_screenshot_formats; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
33 uint _cur_screenshot_format; |
14083
32a19322a6f8
(svn r18630) -Fix [FS#3419]: when making a screenshot the name of the previous screenshot went missing in the 'successful screenshot' message
rubidium <rubidium@openttd.org>
parents:
14004
diff
changeset
|
34 static char _screenshot_name[128]; |
13631
9d22db56efe5
(svn r18155) -Codechange: in MakeScreenshotName(), don't return pointer to local static variable - use global one instead
smatz <smatz@openttd.org>
parents:
13557
diff
changeset
|
35 char _full_screenshot_name[MAX_PATH]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
36 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
37 /* called by the ScreenShot proc to generate screenshot lines. */ |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
38 typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n); |
13553
4e6941a541e0
(svn r18075) -Codechange: let ScreenshotHandlerProc() accept 'name' as 'const char \*'
smatz <smatz@openttd.org>
parents:
13537
diff
changeset
|
39 typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
40 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
41 struct ScreenshotFormat { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
42 const char *name; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
43 const char *extension; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
44 ScreenshotHandlerProc *proc; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
45 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
46 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
47 /************************************************* |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
48 **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
49 *************************************************/ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
50 #if defined(_MSC_VER) || defined(__WATCOMC__) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
51 #pragma pack(push, 1) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
52 #endif |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
53 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
54 /** BMP File Header (stored in little endian) */ |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
55 struct BitmapFileHeader { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
56 uint16 type; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
57 uint32 size; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
58 uint32 reserved; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
59 uint32 off_bits; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
60 } GCC_PACK; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
61 assert_compile(sizeof(BitmapFileHeader) == 14); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
62 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
63 #if defined(_MSC_VER) || defined(__WATCOMC__) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
64 #pragma pack(pop) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
65 #endif |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
66 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
67 /** BMP Info Header (stored in little endian) */ |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
68 struct BitmapInfoHeader { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
69 uint32 size; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
70 int32 width, height; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
71 uint16 planes, bitcount; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
72 uint32 compression, sizeimage, xpels, ypels, clrused, clrimp; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
73 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
74 assert_compile(sizeof(BitmapInfoHeader) == 40); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
75 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
76 /** Format of palette data in BMP header */ |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
77 struct RgbQuad { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
78 byte blue, green, red, reserved; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
79 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
80 assert_compile(sizeof(RgbQuad) == 4); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
81 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
82 /** |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
83 * Generic .BMP writer |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
84 * @param name file name including extension |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
85 * @param callb callback used for gathering rendered image |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
86 * @param userdata parameters forwarded to #callb |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
87 * @param w width in pixels |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
88 * @param h height in pixels |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
89 * @param pixelformat bits per pixel |
13537
cd0f89ae820c
(svn r18058) -Fix: typos in parameter names
rubidium <rubidium@openttd.org>
parents:
13434
diff
changeset
|
90 * @param palette colour palette (for 8bpp mode) |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
91 * @return was everything ok? |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
92 */ |
13554
cb9446883abb
(svn r18076) -Codechange: rename MakeBmpImage() to MakeBMPImage()
smatz <smatz@openttd.org>
parents:
13553
diff
changeset
|
93 static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
94 { |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
95 uint bpp; // bytes per pixel |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
96 switch (pixelformat) { |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
97 case 8: bpp = 1; break; |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
98 /* 32bpp mode is saved as 24bpp BMP */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
99 case 32: bpp = 3; break; |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
100 /* Only implemented for 8bit and 32bit images so far */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
101 default: return false; |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
102 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
103 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
104 FILE *f = fopen(name, "wb"); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
105 if (f == NULL) return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
106 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
107 /* Each scanline must be aligned on a 32bit boundary */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
108 uint bytewidth = Align(w * bpp, 4); // bytes per line in file |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
109 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
110 /* Size of palette. Only present for 8bpp mode */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
111 uint pal_size = pixelformat == 8 ? sizeof(RgbQuad) * 256 : 0; |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
112 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
113 /* Setup the file header */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
114 BitmapFileHeader bfh; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
115 bfh.type = TO_LE16('MB'); |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
116 bfh.size = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size + bytewidth * h); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
117 bfh.reserved = 0; |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
118 bfh.off_bits = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
119 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
120 /* Setup the info header */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
121 BitmapInfoHeader bih; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
122 bih.size = TO_LE32(sizeof(BitmapInfoHeader)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
123 bih.width = TO_LE32(w); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
124 bih.height = TO_LE32(h); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
125 bih.planes = TO_LE16(1); |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
126 bih.bitcount = TO_LE16(bpp * 8); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
127 bih.compression = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
128 bih.sizeimage = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
129 bih.xpels = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
130 bih.ypels = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
131 bih.clrused = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
132 bih.clrimp = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
133 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
134 /* Write file header and info header */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
135 if (fwrite(&bfh, sizeof(bfh), 1, f) != 1 || fwrite(&bih, sizeof(bih), 1, f) != 1) { |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
136 fclose(f); |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
137 return false; |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
138 } |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
139 |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
140 if (pixelformat == 8) { |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
141 /* Convert the palette to the windows format */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
142 RgbQuad rq[256]; |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
143 for (uint i = 0; i < 256; i++) { |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
144 rq[i].red = palette[i].r; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
145 rq[i].green = palette[i].g; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
146 rq[i].blue = palette[i].b; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
147 rq[i].reserved = 0; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
148 } |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
149 /* Write the palette */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
150 if (fwrite(rq, sizeof(rq), 1, f) != 1) { |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
151 fclose(f); |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
152 return false; |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
153 } |
13432
e8ec1469192b
(svn r17941) -Fix: close BMP file when making screenshot fails
smatz <smatz@openttd.org>
parents:
13430
diff
changeset
|
154 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
155 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
156 /* Try to use 64k of memory, store between 16 and 128 lines */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
157 uint maxlines = Clamp(65536 / (w * pixelformat / 8), 16, 128); // number of lines per iteration |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
158 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
159 uint8 *buff = MallocT<uint8>(maxlines * w * pixelformat / 8); // buffer which is rendered to |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
160 uint8 *line = AllocaM(uint8, bytewidth); // one line, stored to file |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
161 memset(line, 0, bytewidth); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
162 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
163 /* Start at the bottom, since bitmaps are stored bottom up */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
164 do { |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
165 uint n = min(h, maxlines); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
166 h -= n; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
167 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
168 /* Render the pixels */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
169 callb(userdata, buff, h, w, n); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
170 |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
171 /* Write each line */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
172 while (n-- != 0) { |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
173 if (pixelformat == 8) { |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
174 /* Move to 'line', leave last few pixels in line zeroed */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
175 memcpy(line, buff + n * w, w); |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
176 } else { |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
177 /* Convert from 'native' 32bpp to BMP-like 24bpp. |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
178 * Works for both big and little endian machines */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
179 Colour *src = ((Colour *)buff) + n * w; |
14126
7bca289f89b7
(svn r18673) -Fix (r17943): Deja vu: 3 byte structs are padded to a word on ARM.
peter1138 <peter1138@openttd.org>
parents:
14083
diff
changeset
|
180 byte *dst = line; |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
181 for (uint i = 0; i < w; i++) { |
14126
7bca289f89b7
(svn r18673) -Fix (r17943): Deja vu: 3 byte structs are padded to a word on ARM.
peter1138 <peter1138@openttd.org>
parents:
14083
diff
changeset
|
182 dst[i * 3 ] = src[i].b; |
7bca289f89b7
(svn r18673) -Fix (r17943): Deja vu: 3 byte structs are padded to a word on ARM.
peter1138 <peter1138@openttd.org>
parents:
14083
diff
changeset
|
183 dst[i * 3 + 1] = src[i].g; |
7bca289f89b7
(svn r18673) -Fix (r17943): Deja vu: 3 byte structs are padded to a word on ARM.
peter1138 <peter1138@openttd.org>
parents:
14083
diff
changeset
|
184 dst[i * 3 + 2] = src[i].r; |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
185 } |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
186 } |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
187 /* Write to file */ |
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
188 if (fwrite(line, bytewidth, 1, f) != 1) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
189 free(buff); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
190 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
191 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
192 } |
13434
241713c5c665
(svn r17943) -Change: use 24bpp BMP format instead of 32bpp for screenshots. Saves space and is supported by more image viewers
smatz <smatz@openttd.org>
parents:
13432
diff
changeset
|
193 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
194 } while (h != 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
195 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
196 free(buff); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
197 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
198 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
199 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
200 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
201 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
202 /********************************************************* |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
203 **** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG) |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
204 *********************************************************/ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
205 #if defined(WITH_PNG) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
206 #include <png.h> |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
207 |
16820
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
208 #ifdef PNG_TEXT_SUPPORTED |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
209 #include "rev.h" |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
210 #include "newgrf_config.h" |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
211 #include "ai/ai_info.hpp" |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
212 #include "company_base.h" |
16824
9d47c26bc1f1
(svn r21558) -Codechange: add the graphics set and its version to the screenshot metadata as well
rubidium <rubidium@openttd.org>
parents:
16820
diff
changeset
|
213 #include "base_media_base.h" |
16820
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
214 #endif /* PNG_TEXT_SUPPORTED */ |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
215 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
216 static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
217 { |
13553
4e6941a541e0
(svn r18075) -Codechange: let ScreenshotHandlerProc() accept 'name' as 'const char \*'
smatz <smatz@openttd.org>
parents:
13537
diff
changeset
|
218 DEBUG(misc, 0, "[libpng] error: %s - %s", message, (const char *)png_get_error_ptr(png_ptr)); |
14205
c0ea5d87de2e
(svn r18756) -Codechange: direct accesses to png_*_struct members are deprecated
glx <glx@openttd.org>
parents:
14136
diff
changeset
|
219 longjmp(png_jmpbuf(png_ptr), 1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
220 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
221 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
222 static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
223 { |
13553
4e6941a541e0
(svn r18075) -Codechange: let ScreenshotHandlerProc() accept 'name' as 'const char \*'
smatz <smatz@openttd.org>
parents:
13537
diff
changeset
|
224 DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (const char *)png_get_error_ptr(png_ptr)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
225 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
226 |
13553
4e6941a541e0
(svn r18075) -Codechange: let ScreenshotHandlerProc() accept 'name' as 'const char \*'
smatz <smatz@openttd.org>
parents:
13537
diff
changeset
|
227 static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
228 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
229 png_color rq[256]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
230 FILE *f; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
231 uint i, y, n; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
232 uint maxlines; |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
233 uint bpp = pixelformat / 8; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
234 png_structp png_ptr; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
235 png_infop info_ptr; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
236 |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
237 /* only implemented for 8bit and 32bit images so far. */ |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
238 if (pixelformat != 8 && pixelformat != 32) return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
239 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
240 f = fopen(name, "wb"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
241 if (f == NULL) return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
242 |
13553
4e6941a541e0
(svn r18075) -Codechange: let ScreenshotHandlerProc() accept 'name' as 'const char \*'
smatz <smatz@openttd.org>
parents:
13537
diff
changeset
|
243 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (void *)name, png_my_error, png_my_warning); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
244 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
245 if (png_ptr == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
246 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
247 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
248 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
249 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
250 info_ptr = png_create_info_struct(png_ptr); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
251 if (info_ptr == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
252 png_destroy_write_struct(&png_ptr, (png_infopp)NULL); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
253 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
254 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
255 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
256 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
257 if (setjmp(png_jmpbuf(png_ptr))) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
258 png_destroy_write_struct(&png_ptr, &info_ptr); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
259 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
261 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
262 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
263 png_init_io(png_ptr, f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
264 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
265 png_set_filter(png_ptr, 0, PNG_FILTER_NONE); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
266 |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
267 png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
268 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
269 |
16820
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
270 #ifdef PNG_TEXT_SUPPORTED |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
271 /* Try to add some game metadata to the PNG screenshot so |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
272 * it's more useful for debugging and archival purposes. */ |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
273 png_text_struct text[2]; |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
274 memset(text, 0, sizeof(text)); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
275 text[0].key = const_cast<char *>("Software"); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
276 text[0].text = const_cast<char *>(_openttd_revision); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
277 text[0].text_length = strlen(_openttd_revision); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
278 text[0].compression = PNG_TEXT_COMPRESSION_NONE; |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
279 |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
280 char buf[2048]; |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
281 char *p = buf; |
16824
9d47c26bc1f1
(svn r21558) -Codechange: add the graphics set and its version to the screenshot metadata as well
rubidium <rubidium@openttd.org>
parents:
16820
diff
changeset
|
282 p += seprintf(p, lastof(buf), "Graphics set: %s (%u)\n", BaseGraphics::GetUsedSet()->name, BaseGraphics::GetUsedSet()->version); |
9d47c26bc1f1
(svn r21558) -Codechange: add the graphics set and its version to the screenshot metadata as well
rubidium <rubidium@openttd.org>
parents:
16820
diff
changeset
|
283 p = strecpy(p, "NewGRFs:\n", lastof(buf)); |
16820
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
284 for (const GRFConfig *c = _grfconfig; c != NULL; c = c->next) { |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
285 p += seprintf(p, lastof(buf), "%08X ", BSWAP32(c->ident.grfid)); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
286 p = md5sumToString(p, lastof(buf), c->ident.md5sum); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
287 p += seprintf(p, lastof(buf), " %s\n", c->filename); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
288 } |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
289 p = strecpy(p, "\nCompanies:\n", lastof(buf)); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
290 const Company *c; |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
291 FOR_ALL_COMPANIES(c) { |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
292 if (c->ai_info == NULL) { |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
293 p += seprintf(p, lastof(buf), "%2i: Human\n", (int)c->index); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
294 } else { |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
295 #ifdef ENABLE_AI |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
296 p += seprintf(p, lastof(buf), "%2i: %s (v%d)\n", (int)c->index, c->ai_info->GetName(), c->ai_info->GetVersion()); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
297 #endif /* ENABLE_AI */ |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
298 } |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
299 } |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
300 text[1].key = const_cast<char *>("Description"); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
301 text[1].text = buf; |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
302 text[1].text_length = p - buf; |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
303 text[1].compression = PNG_TEXT_COMPRESSION_zTXt; |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
304 png_set_text(png_ptr, info_ptr, text, 2); |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
305 #endif /* PNG_TEXT_SUPPORTED */ |
acd43b314092
(svn r21553) -Feature-ish: store the used OpenTTD version, NewGRFs and AIs in the screenshot file
rubidium <rubidium@openttd.org>
parents:
15829
diff
changeset
|
306 |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
307 if (pixelformat == 8) { |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
308 /* convert the palette to the .PNG format. */ |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
309 for (i = 0; i != 256; i++) { |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
310 rq[i].red = palette[i].r; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
311 rq[i].green = palette[i].g; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
312 rq[i].blue = palette[i].b; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
313 } |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
314 |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
315 png_set_PLTE(png_ptr, info_ptr, rq, 256); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
316 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
317 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
318 png_write_info(png_ptr, info_ptr); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
319 png_set_flush(png_ptr, 512); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
320 |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
321 if (pixelformat == 32) { |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
322 png_color_8 sig_bit; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
323 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
324 /* Save exact colour/alpha resolution */ |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
325 sig_bit.alpha = 0; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
326 sig_bit.blue = 8; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
327 sig_bit.green = 8; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
328 sig_bit.red = 8; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
329 sig_bit.gray = 8; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
330 png_set_sBIT(png_ptr, info_ptr, &sig_bit); |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
331 |
9543
a3ed5df19561
(svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz <smatz@openttd.org>
parents:
9111
diff
changeset
|
332 #if TTD_ENDIAN == TTD_LITTLE_ENDIAN |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
333 png_set_bgr(png_ptr); |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
334 png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
335 #else |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
336 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); |
9543
a3ed5df19561
(svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz <smatz@openttd.org>
parents:
9111
diff
changeset
|
337 #endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */ |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
338 } |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
339 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
340 /* use by default 64k temp memory */ |
7922
ff1975ced735
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents:
7138
diff
changeset
|
341 maxlines = Clamp(65536 / w, 16, 128); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
342 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
343 /* now generate the bitmap bits */ |
11216
dc1618a3d6fa
(svn r15569) -Codechange: replace MallocT + memset( 0 ) calls by CallocT
smatz <smatz@openttd.org>
parents:
11215
diff
changeset
|
344 void *buff = CallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
345 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
346 y = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
347 do { |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
348 /* determine # lines to write */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
349 n = min(h - y, maxlines); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
350 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
351 /* render the pixels into the buffer */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
352 callb(userdata, buff, y, w, n); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
353 y += n; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
354 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
355 /* write them to png */ |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15397
diff
changeset
|
356 for (i = 0; i != n; i++) { |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
357 png_write_row(png_ptr, (png_bytep)buff + i * w * bpp); |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15397
diff
changeset
|
358 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
359 } while (y != h); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
360 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
361 png_write_end(png_ptr, info_ptr); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
362 png_destroy_write_struct(&png_ptr, &info_ptr); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
363 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
364 free(buff); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
365 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
366 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
367 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
368 #endif /* WITH_PNG */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
369 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
370 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
371 /************************************************* |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
372 **** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX) |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
373 *************************************************/ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
374 |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
375 struct PcxHeader { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
376 byte manufacturer; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
377 byte version; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
378 byte rle; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
379 byte bpp; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
380 uint32 unused; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
381 uint16 xmax, ymax; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
382 uint16 hdpi, vdpi; |
6491
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6420
diff
changeset
|
383 byte pal_small[16 * 3]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
384 byte reserved; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
385 byte planes; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
386 uint16 pitch; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
387 uint16 cpal; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
388 uint16 width; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
389 uint16 height; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
390 byte filler[54]; |
6248
0789677a15a0
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium <rubidium@openttd.org>
parents:
6247
diff
changeset
|
391 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
392 assert_compile(sizeof(PcxHeader) == 128); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
393 |
13553
4e6941a541e0
(svn r18075) -Codechange: let ScreenshotHandlerProc() accept 'name' as 'const char \*'
smatz <smatz@openttd.org>
parents:
13537
diff
changeset
|
394 static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
395 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
396 FILE *f; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
397 uint maxlines; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
398 uint y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
399 PcxHeader pcx; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
400 bool success; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
401 |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
402 if (pixelformat == 32) { |
14136
54dfd3720fa1
(svn r18683) -Fix: it's not an other
rubidium <rubidium@openttd.org>
parents:
14126
diff
changeset
|
403 DEBUG(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick another format."); |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
404 return false; |
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
405 } |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15397
diff
changeset
|
406 if (pixelformat != 8 || w == 0) return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
407 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
408 f = fopen(name, "wb"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
409 if (f == NULL) return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
410 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
411 memset(&pcx, 0, sizeof(pcx)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
412 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
413 /* setup pcx header */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
414 pcx.manufacturer = 10; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
415 pcx.version = 5; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
416 pcx.rle = 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
417 pcx.bpp = 8; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
418 pcx.xmax = TO_LE16(w - 1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
419 pcx.ymax = TO_LE16(h - 1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
420 pcx.hdpi = TO_LE16(320); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
421 pcx.vdpi = TO_LE16(320); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
422 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
423 pcx.planes = 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
424 pcx.cpal = TO_LE16(1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
425 pcx.width = pcx.pitch = TO_LE16(w); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
426 pcx.height = TO_LE16(h); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
427 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
428 /* write pcx header */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
429 if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
430 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
431 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
432 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
433 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
434 /* use by default 64k temp memory */ |
7922
ff1975ced735
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13 <skidd13@openttd.org>
parents:
7138
diff
changeset
|
435 maxlines = Clamp(65536 / w, 16, 128); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
436 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
437 /* now generate the bitmap bits */ |
11216
dc1618a3d6fa
(svn r15569) -Codechange: replace MallocT + memset( 0 ) calls by CallocT
smatz <smatz@openttd.org>
parents:
11215
diff
changeset
|
438 uint8 *buff = CallocT<uint8>(w * maxlines); // by default generate 128 lines at a time. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
439 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
440 y = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
441 do { |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
442 /* determine # lines to write */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
443 uint n = min(h - y, maxlines); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
444 uint i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
445 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
446 /* render the pixels into the buffer */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
447 callb(userdata, buff, y, w, n); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
448 y += n; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
449 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
450 /* write them to pcx */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
451 for (i = 0; i != n; i++) { |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
452 const uint8 *bufp = buff + i * w; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
453 byte runchar = bufp[0]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
454 uint runcount = 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
455 uint j; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
456 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
457 /* for each pixel... */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
458 for (j = 1; j < w; j++) { |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
459 uint8 ch = bufp[j]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
460 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
461 if (ch != runchar || runcount >= 0x3f) { |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15397
diff
changeset
|
462 if (runcount > 1 || (runchar & 0xC0) == 0xC0) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
463 if (fputc(0xC0 | runcount, f) == EOF) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
464 free(buff); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
465 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
466 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
467 } |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15397
diff
changeset
|
468 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
469 if (fputc(runchar, f) == EOF) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
470 free(buff); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
471 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
472 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
473 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
474 runcount = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
475 runchar = ch; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
476 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
477 runcount++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
478 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
479 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
480 /* write remaining bytes.. */ |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15397
diff
changeset
|
481 if (runcount > 1 || (runchar & 0xC0) == 0xC0) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
482 if (fputc(0xC0 | runcount, f) == EOF) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
483 free(buff); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
484 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
485 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
486 } |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15397
diff
changeset
|
487 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
488 if (fputc(runchar, f) == EOF) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
489 free(buff); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
490 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
491 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
492 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
493 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
494 } while (y != h); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
495 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
496 free(buff); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
497 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
498 /* write 8-bit colour palette */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
499 if (fputc(12, f) == EOF) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
500 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
501 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
502 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
503 |
9551
8849c20f82c0
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz <smatz@openttd.org>
parents:
9543
diff
changeset
|
504 /* Palette is word-aligned, copy it to a temporary byte array */ |
8849c20f82c0
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz <smatz@openttd.org>
parents:
9543
diff
changeset
|
505 byte tmp[256 * 3]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
506 |
9551
8849c20f82c0
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz <smatz@openttd.org>
parents:
9543
diff
changeset
|
507 for (uint i = 0; i < 256; i++) { |
8849c20f82c0
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz <smatz@openttd.org>
parents:
9543
diff
changeset
|
508 tmp[i * 3 + 0] = palette[i].r; |
8849c20f82c0
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz <smatz@openttd.org>
parents:
9543
diff
changeset
|
509 tmp[i * 3 + 1] = palette[i].g; |
8849c20f82c0
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz <smatz@openttd.org>
parents:
9543
diff
changeset
|
510 tmp[i * 3 + 2] = palette[i].b; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
511 } |
9551
8849c20f82c0
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
smatz <smatz@openttd.org>
parents:
9543
diff
changeset
|
512 success = fwrite(tmp, sizeof(tmp), 1, f) == 1; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
513 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
514 fclose(f); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
515 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
516 return success; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
517 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
518 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
519 /************************************************* |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
520 **** GENERIC SCREENSHOT CODE |
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11230
diff
changeset
|
521 *************************************************/ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
522 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
523 static const ScreenshotFormat _screenshot_formats[] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
524 #if defined(WITH_PNG) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
525 {"PNG", "png", &MakePNGImage}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
526 #endif |
13554
cb9446883abb
(svn r18076) -Codechange: rename MakeBmpImage() to MakeBMPImage()
smatz <smatz@openttd.org>
parents:
13553
diff
changeset
|
527 {"BMP", "bmp", &MakeBMPImage}, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
528 {"PCX", "pcx", &MakePCXImage}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
529 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
530 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
5609
diff
changeset
|
531 void InitializeScreenshotFormats() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
532 { |
15397
921747297c8c
(svn r20040) -Codechange: some coding style + using proper types
rubidium <rubidium@openttd.org>
parents:
14645
diff
changeset
|
533 uint j = 0; |
921747297c8c
(svn r20040) -Codechange: some coding style + using proper types
rubidium <rubidium@openttd.org>
parents:
14645
diff
changeset
|
534 for (uint i = 0; i < lengthof(_screenshot_formats); i++) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
535 if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
536 j = i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
537 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
538 } |
15397
921747297c8c
(svn r20040) -Codechange: some coding style + using proper types
rubidium <rubidium@openttd.org>
parents:
14645
diff
changeset
|
539 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
540 _cur_screenshot_format = j; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
541 _num_screenshot_formats = lengthof(_screenshot_formats); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
542 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
543 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
544 const char *GetScreenshotFormatDesc(int i) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
545 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
546 return _screenshot_formats[i].name; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
547 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
548 |
15397
921747297c8c
(svn r20040) -Codechange: some coding style + using proper types
rubidium <rubidium@openttd.org>
parents:
14645
diff
changeset
|
549 void SetScreenshotFormat(uint i) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
550 { |
15397
921747297c8c
(svn r20040) -Codechange: some coding style + using proper types
rubidium <rubidium@openttd.org>
parents:
14645
diff
changeset
|
551 assert(i < _num_screenshot_formats); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
552 _cur_screenshot_format = i; |
11644
7980a47b17cb
(svn r16024) -Codechange: harden string copying on places where it's possible
rubidium <rubidium@openttd.org>
parents:
11368
diff
changeset
|
553 strecpy(_screenshot_format_name, _screenshot_formats[i].extension, lastof(_screenshot_format_name)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
554 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
555 |
6420
080aae477331
(svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas <belugas@openttd.org>
parents:
6248
diff
changeset
|
556 /* screenshot generator that dumps the current video buffer */ |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
557 static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
558 { |
6937
b6cf3513b2c4
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight <truelight@openttd.org>
parents:
6929
diff
changeset
|
559 Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
b6cf3513b2c4
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight <truelight@openttd.org>
parents:
6929
diff
changeset
|
560 void *src = blitter->MoveTo(_screen.dst_ptr, 0, y); |
6985
d438abfd7ab1
(svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight <truelight@openttd.org>
parents:
6937
diff
changeset
|
561 blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
562 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
563 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
564 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15604
diff
changeset
|
565 * generate a large piece of the world |
8249
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
566 * @param userdata Viewport area to draw |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
567 * @param buf Videobuffer with same bitdepth as current blitter |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
568 * @param y First line to render |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
569 * @param pitch Pitch of the videobuffer |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
570 * @param n Number of lines to render |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
571 */ |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
572 static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
573 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
574 ViewPort *vp = (ViewPort *)userdata; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
575 DrawPixelInfo dpi, *old_dpi; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
576 int wx, left; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
577 |
8249
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
578 /* We are no longer rendering to the screen */ |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
579 DrawPixelInfo old_screen = _screen; |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
580 bool old_disable_anim = _screen_disable_anim; |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
581 |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
582 _screen.dst_ptr = buf; |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
583 _screen.width = pitch; |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
584 _screen.height = n; |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
585 _screen.pitch = pitch; |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
586 _screen_disable_anim = true; |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
587 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
588 old_dpi = _cur_dpi; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
589 _cur_dpi = &dpi; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
590 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
591 dpi.dst_ptr = buf; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
592 dpi.height = n; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
593 dpi.width = vp->width; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
594 dpi.pitch = pitch; |
6624
bf5d7b24a7ab
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight <truelight@openttd.org>
parents:
6615
diff
changeset
|
595 dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
596 dpi.left = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
597 dpi.top = y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
598 |
8249
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
599 /* Render viewport in blocks of 1600 pixels width */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
600 left = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
601 while (vp->width - left != 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
602 wx = min(vp->width - left, 1600); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
603 left += wx; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
604 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
605 ViewportDoDraw(vp, |
6626
f940341a80f0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents:
6624
diff
changeset
|
606 ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left, |
f940341a80f0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents:
6624
diff
changeset
|
607 ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top, |
f940341a80f0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents:
6624
diff
changeset
|
608 ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left, |
f940341a80f0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents:
6624
diff
changeset
|
609 ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
610 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
611 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
612 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
613 _cur_dpi = old_dpi; |
8249
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
614 |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
615 /* Switch back to rendering to the screen */ |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
616 _screen = old_screen; |
f495acdca6b5
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch <frosch@openttd.org>
parents:
8225
diff
changeset
|
617 _screen_disable_anim = old_disable_anim; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
618 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
619 |
13553
4e6941a541e0
(svn r18075) -Codechange: let ScreenshotHandlerProc() accept 'name' as 'const char \*'
smatz <smatz@openttd.org>
parents:
13537
diff
changeset
|
620 static const char *MakeScreenshotName(const char *ext) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
621 { |
13557
b25cd3063c06
(svn r18079) -Codechange: allow overwriting of screenshots with user-supplied filenames
smatz <smatz@openttd.org>
parents:
13554
diff
changeset
|
622 bool generate = StrEmpty(_screenshot_name); |
b25cd3063c06
(svn r18079) -Codechange: allow overwriting of screenshots with user-supplied filenames
smatz <smatz@openttd.org>
parents:
13554
diff
changeset
|
623 |
b25cd3063c06
(svn r18079) -Codechange: allow overwriting of screenshots with user-supplied filenames
smatz <smatz@openttd.org>
parents:
13554
diff
changeset
|
624 if (generate) { |
13429
abbeb6735538
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
smatz <smatz@openttd.org>
parents:
13428
diff
changeset
|
625 if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) { |
abbeb6735538
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
smatz <smatz@openttd.org>
parents:
13428
diff
changeset
|
626 strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name)); |
abbeb6735538
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
smatz <smatz@openttd.org>
parents:
13428
diff
changeset
|
627 } else { |
abbeb6735538
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
smatz <smatz@openttd.org>
parents:
13428
diff
changeset
|
628 GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name)); |
abbeb6735538
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
smatz <smatz@openttd.org>
parents:
13428
diff
changeset
|
629 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
630 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
631 |
6929
bb43858bed10
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium <rubidium@openttd.org>
parents:
6878
diff
changeset
|
632 /* Add extension to screenshot file */ |
13429
abbeb6735538
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
smatz <smatz@openttd.org>
parents:
13428
diff
changeset
|
633 size_t len = strlen(_screenshot_name); |
6929
bb43858bed10
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium <rubidium@openttd.org>
parents:
6878
diff
changeset
|
634 snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
635 |
13429
abbeb6735538
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
smatz <smatz@openttd.org>
parents:
13428
diff
changeset
|
636 for (uint serial = 1;; serial++) { |
13631
9d22db56efe5
(svn r18155) -Codechange: in MakeScreenshotName(), don't return pointer to local static variable - use global one instead
smatz <smatz@openttd.org>
parents:
13557
diff
changeset
|
637 if (snprintf(_full_screenshot_name, lengthof(_full_screenshot_name), "%s%s", _personal_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) { |
13427
88c7b199de2b
(svn r17936) -Fix: deadlock when trying to create screenshot with too long name (including path)
smatz <smatz@openttd.org>
parents:
13401
diff
changeset
|
638 /* We need more characters than MAX_PATH -> end with error */ |
13631
9d22db56efe5
(svn r18155) -Codechange: in MakeScreenshotName(), don't return pointer to local static variable - use global one instead
smatz <smatz@openttd.org>
parents:
13557
diff
changeset
|
639 _full_screenshot_name[0] = '\0'; |
13427
88c7b199de2b
(svn r17936) -Fix: deadlock when trying to create screenshot with too long name (including path)
smatz <smatz@openttd.org>
parents:
13401
diff
changeset
|
640 break; |
88c7b199de2b
(svn r17936) -Fix: deadlock when trying to create screenshot with too long name (including path)
smatz <smatz@openttd.org>
parents:
13401
diff
changeset
|
641 } |
13557
b25cd3063c06
(svn r18079) -Codechange: allow overwriting of screenshots with user-supplied filenames
smatz <smatz@openttd.org>
parents:
13554
diff
changeset
|
642 if (!generate) break; // allow overwriting of non-automatic filenames |
13631
9d22db56efe5
(svn r18155) -Codechange: in MakeScreenshotName(), don't return pointer to local static variable - use global one instead
smatz <smatz@openttd.org>
parents:
13557
diff
changeset
|
643 if (!FileExists(_full_screenshot_name)) break; |
6929
bb43858bed10
(svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium <rubidium@openttd.org>
parents:
6878
diff
changeset
|
644 /* If file exists try another one with same name, but just with a higher index */ |
13429
abbeb6735538
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
smatz <smatz@openttd.org>
parents:
13428
diff
changeset
|
645 snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%u.%s", serial, ext); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
646 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
647 |
13631
9d22db56efe5
(svn r18155) -Codechange: in MakeScreenshotName(), don't return pointer to local static variable - use global one instead
smatz <smatz@openttd.org>
parents:
13557
diff
changeset
|
648 return _full_screenshot_name; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
649 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
650 |
15829
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
651 /** Make a screenshot of the current screen. */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
5609
diff
changeset
|
652 static bool MakeSmallScreenshot() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
653 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
654 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
655 return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
656 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
657 |
15829
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
658 /** Make a zoomed-in screenshot of the currently visible area. */ |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
659 static bool MakeZoomedInScreenshot() |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
660 { |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
661 Window *w = FindWindowById(WC_MAIN_WINDOW, 0); |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
662 ViewPort vp; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
663 |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
664 vp.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
665 vp.left = w->viewport->left; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
666 vp.top = w->viewport->top; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
667 vp.virtual_left = w->viewport->virtual_left; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
668 vp.virtual_top = w->viewport->virtual_top; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
669 vp.virtual_width = w->viewport->virtual_width; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
670 vp.width = vp.virtual_width; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
671 vp.virtual_height = w->viewport->virtual_height; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
672 vp.height = vp.virtual_height; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
673 |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
674 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
675 return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
676 } |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
677 |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
678 /** Make a screenshot of the whole map. */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
5609
diff
changeset
|
679 static bool MakeWorldScreenshot() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
680 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
681 ViewPort vp; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
682 const ScreenshotFormat *sf; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
683 |
16954
c42d3f94eb23
(svn r21690) -Fix: the top of a tall building standing on a hill at the top of the map could be cut off in a giant screenshot
yexo <yexo@openttd.org>
parents:
16824
diff
changeset
|
684 /* We need to account for a hill or high building at tile 0,0. */ |
c42d3f94eb23
(svn r21690) -Fix: the top of a tall building standing on a hill at the top of the map could be cut off in a giant screenshot
yexo <yexo@openttd.org>
parents:
16824
diff
changeset
|
685 int extra_height_top = TileHeight(0) * TILE_HEIGHT + 150; |
c42d3f94eb23
(svn r21690) -Fix: the top of a tall building standing on a hill at the top of the map could be cut off in a giant screenshot
yexo <yexo@openttd.org>
parents:
16824
diff
changeset
|
686 /* If there is a hill at the bottom don't create a large black area. */ |
c42d3f94eb23
(svn r21690) -Fix: the top of a tall building standing on a hill at the top of the map could be cut off in a giant screenshot
yexo <yexo@openttd.org>
parents:
16824
diff
changeset
|
687 int reclaim_height_bottom = TileHeight(MapSize() - 1) * TILE_HEIGHT; |
c42d3f94eb23
(svn r21690) -Fix: the top of a tall building standing on a hill at the top of the map could be cut off in a giant screenshot
yexo <yexo@openttd.org>
parents:
16824
diff
changeset
|
688 |
6624
bf5d7b24a7ab
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight <truelight@openttd.org>
parents:
6615
diff
changeset
|
689 vp.zoom = ZOOM_LVL_WORLD_SCREENSHOT; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
690 vp.left = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
691 vp.top = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
692 vp.virtual_left = -(int)MapMaxX() * TILE_PIXELS; |
16954
c42d3f94eb23
(svn r21690) -Fix: the top of a tall building standing on a hill at the top of the map could be cut off in a giant screenshot
yexo <yexo@openttd.org>
parents:
16824
diff
changeset
|
693 vp.virtual_top = -extra_height_top; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
694 vp.virtual_width = (MapMaxX() + MapMaxY()) * TILE_PIXELS; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
695 vp.width = vp.virtual_width; |
16954
c42d3f94eb23
(svn r21690) -Fix: the top of a tall building standing on a hill at the top of the map could be cut off in a giant screenshot
yexo <yexo@openttd.org>
parents:
16824
diff
changeset
|
696 vp.virtual_height = ((MapMaxX() + MapMaxY()) * TILE_PIXELS >> 1) + extra_height_top - reclaim_height_bottom; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
697 vp.height = vp.virtual_height; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
698 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
699 sf = _screenshot_formats + _cur_screenshot_format; |
6878
385dce807566
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight <truelight@openttd.org>
parents:
6875
diff
changeset
|
700 return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
701 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
702 |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
703 /** |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
704 * Make an actual screenshot. |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
705 * @param t the type of screenshot to make. |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
706 * @param name the name to give to the screenshot. |
15604
ca959eb5d431
(svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
707 * @return true iff the screenshow was made successfully |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
708 */ |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
709 bool MakeScreenshot(ScreenshotType t, const char *name) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
710 { |
14083
32a19322a6f8
(svn r18630) -Fix [FS#3419]: when making a screenshot the name of the previous screenshot went missing in the 'successful screenshot' message
rubidium <rubidium@openttd.org>
parents:
14004
diff
changeset
|
711 if (t == SC_VIEWPORT) { |
32a19322a6f8
(svn r18630) -Fix [FS#3419]: when making a screenshot the name of the previous screenshot went missing in the 'successful screenshot' message
rubidium <rubidium@openttd.org>
parents:
14004
diff
changeset
|
712 /* First draw the dirty parts of the screen and only then change the name |
32a19322a6f8
(svn r18630) -Fix [FS#3419]: when making a screenshot the name of the previous screenshot went missing in the 'successful screenshot' message
rubidium <rubidium@openttd.org>
parents:
14004
diff
changeset
|
713 * of the screenshot. This way the screenshot will always show the name |
15604
ca959eb5d431
(svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents:
15552
diff
changeset
|
714 * of the previous screenshot in the 'successful' message instead of the |
14083
32a19322a6f8
(svn r18630) -Fix [FS#3419]: when making a screenshot the name of the previous screenshot went missing in the 'successful screenshot' message
rubidium <rubidium@openttd.org>
parents:
14004
diff
changeset
|
715 * name of the new screenshot (or an empty name). */ |
32a19322a6f8
(svn r18630) -Fix [FS#3419]: when making a screenshot the name of the previous screenshot went missing in the 'successful screenshot' message
rubidium <rubidium@openttd.org>
parents:
14004
diff
changeset
|
716 UndrawMouseCursor(); |
32a19322a6f8
(svn r18630) -Fix [FS#3419]: when making a screenshot the name of the previous screenshot went missing in the 'successful screenshot' message
rubidium <rubidium@openttd.org>
parents:
14004
diff
changeset
|
717 DrawDirtyBlocks(); |
32a19322a6f8
(svn r18630) -Fix [FS#3419]: when making a screenshot the name of the previous screenshot went missing in the 'successful screenshot' message
rubidium <rubidium@openttd.org>
parents:
14004
diff
changeset
|
718 } |
32a19322a6f8
(svn r18630) -Fix [FS#3419]: when making a screenshot the name of the previous screenshot went missing in the 'successful screenshot' message
rubidium <rubidium@openttd.org>
parents:
14004
diff
changeset
|
719 |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
720 _screenshot_name[0] = '\0'; |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
721 if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_name)); |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
722 |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
723 bool ret; |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
724 switch (t) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
725 case SC_VIEWPORT: |
13632
26e73974b916
(svn r18156) -Add: crash screenshot, created from blitter buffer
smatz <smatz@openttd.org>
parents:
13631
diff
changeset
|
726 case SC_RAW: |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
727 ret = MakeSmallScreenshot(); |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
728 break; |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
729 |
15829
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
730 case SC_ZOOMEDIN: |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
731 ret = MakeZoomedInScreenshot(); |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
732 break; |
d894e15249fb
(svn r20508) -Add [FS#3973]: A new screenshot type that makes a zoomed-in screenshot of the visible viewport. (Eddi)
michi_cc <michi_cc@openttd.org>
parents:
15620
diff
changeset
|
733 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
734 case SC_WORLD: |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
735 ret = MakeWorldScreenshot(); |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
736 break; |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
737 |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
738 default: |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
739 NOT_REACHED(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
740 } |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
741 |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
742 if (ret) { |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
743 SetDParamStr(0, _screenshot_name); |
14645
b7a22979b84e
(svn r19224) -Codechange: change parameters passed to ShowErrorMessage() a bit
smatz <smatz@openttd.org>
parents:
14205
diff
changeset
|
744 ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING); |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
745 } else { |
14645
b7a22979b84e
(svn r19224) -Codechange: change parameters passed to ShowErrorMessage() a bit
smatz <smatz@openttd.org>
parents:
14205
diff
changeset
|
746 ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, WL_ERROR); |
14004
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
747 } |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
748 |
96fa151f99f9
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
rubidium <rubidium@openttd.org>
parents:
13632
diff
changeset
|
749 return ret; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
750 } |