summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2011-05-28 13:54:18 +0000
committeralberth <alberth@openttd.org>2011-05-28 13:54:18 +0000
commitbe048e05f2535458aeef5024ff1c61da183a7836 (patch)
tree1e3db57bee4d99492efdf09dd4bc942fd1d06835
parent64745b4d0d94db4a4d36805ab8a768bf3b01dec1 (diff)
downloadopenttd-be048e05f2535458aeef5024ff1c61da183a7836.tar.xz
(svn r22509) -Add: Save heightmap.
-rw-r--r--src/screenshot.cpp49
-rw-r--r--src/screenshot.h10
2 files changed, 55 insertions, 4 deletions
diff --git a/src/screenshot.cpp b/src/screenshot.cpp
index d22c85b5f..87cc143cd 100644
--- a/src/screenshot.cpp
+++ b/src/screenshot.cpp
@@ -28,6 +28,7 @@
#include "table/strings.h"
static const char * const SCREENSHOT_NAME = "screenshot"; ///< Default filename of a saved screenshot.
+static const char * const HEIGHTMAP_NAME = "heightmap"; ///< Default filename of a saved heightmap.
char _screenshot_format_name[8]; ///< Extension of the current screenshot format (corresponds with #_cur_screenshot_format).
uint _num_screenshot_formats; ///< Number of available screenshot formats.
@@ -771,6 +772,48 @@ static bool MakeWorldScreenshot()
}
/**
+ * Callback for generating a heightmap. Supports 8bpp grayscale only.
+ * @param userdata Pointer to user data.
+ * @param buf Destination buffer.
+ * @param y Line number of the first line to write.
+ * @param pitch Number of pixels to write (1 byte for 8bpp, 4 bytes for 32bpp). @see Colour
+ * @param n Number of lines to write.
+ * @see ScreenshotCallback
+ */
+static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
+{
+ byte *buf = (byte *)buffer;
+ while (n > 0) {
+ TileIndex ti = TileXY(MapMaxX(), y);
+ for (uint x = MapMaxX(); true; x--) {
+ *buf = 16 * TileHeight(ti);
+ buf++;
+ if (x == 0) break;
+ ti = TILE_ADDXY(ti, -1, 0);
+ }
+ y++;
+ n--;
+ }
+}
+
+/**
+ * Make a heightmap of the current map.
+ * @param filename Filename to use for saving.
+ */
+bool MakeHeightmapScreenshot(const char *filename)
+{
+ Colour palette[256];
+ for (uint i = 0; i < lengthof(palette); i++) {
+ palette[i].a = 0xff;
+ palette[i].r = i;
+ palette[i].g = i;
+ palette[i].b = i;
+ }
+ const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
+ return sf->proc(filename, HeightmapCallback, NULL, MapSizeX(), MapSizeY(), 8, palette);
+}
+
+/**
* Make an actual screenshot.
* @param t the type of screenshot to make.
* @param name the name to give to the screenshot.
@@ -805,6 +848,12 @@ bool MakeScreenshot(ScreenshotType t, const char *name)
ret = MakeWorldScreenshot();
break;
+ case SC_HEIGHTMAP: {
+ const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
+ ret = MakeHeightmapScreenshot(MakeScreenshotName(HEIGHTMAP_NAME, sf->extension));
+ break;
+ }
+
default:
NOT_REACHED();
}
diff --git a/src/screenshot.h b/src/screenshot.h
index 21271214c..acd694f2b 100644
--- a/src/screenshot.h
+++ b/src/screenshot.h
@@ -19,12 +19,14 @@ void SetScreenshotFormat(uint i);
/** Type of requested screenshot */
enum ScreenshotType {
- SC_VIEWPORT, ///< Screenshot of viewport
- SC_RAW, ///< Raw screenshot from blitter buffer
- SC_ZOOMEDIN, ///< Zoomed in screenshot of the visible area
- SC_WORLD, ///< World screenshot
+ SC_VIEWPORT, ///< Screenshot of viewport.
+ SC_RAW, ///< Raw screenshot from blitter buffer.
+ SC_ZOOMEDIN, ///< Zoomed in screenshot of the visible area.
+ SC_WORLD, ///< World screenshot.
+ SC_HEIGHTMAP, ///< Heightmap of the world.
};
+bool MakeHeightmapScreenshot(const char *filename);
bool MakeScreenshot(ScreenshotType t, const char *name);
extern char _screenshot_format_name[8];