summaryrefslogtreecommitdiff
path: root/src/heightmap.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2016-09-04 12:57:43 +0000
committeralberth <alberth@openttd.org>2016-09-04 12:57:43 +0000
commit597380e099688652e31fd1f406b53dee6b65da90 (patch)
treeac7bdedf8b7fd9d8f096465c3cbb1b41b40f1e78 /src/heightmap.cpp
parentdf9a9f074a55a839a5f311e5c0837342192e720d (diff)
downloadopenttd-597380e099688652e31fd1f406b53dee6b65da90.tar.xz
(svn r27650) -Codechange: Replace SaveOrLoadMode by FileOperation and DetailedFileType.
Diffstat (limited to 'src/heightmap.cpp')
-rw-r--r--src/heightmap.cpp35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/heightmap.cpp b/src/heightmap.cpp
index ec3125728..630dc69d7 100644
--- a/src/heightmap.cpp
+++ b/src/heightmap.cpp
@@ -102,7 +102,7 @@ static void ReadHeightmapPNGImageData(byte *map, png_structp png_ptr, png_infop
* If map == NULL only the size of the PNG is read, otherwise a map
* with grayscale pixels is allocated and assigned to *map.
*/
-static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map)
+static bool ReadHeightmapPNG(const char *filename, uint *x, uint *y, byte **map)
{
FILE *fp;
png_structp png_ptr = NULL;
@@ -232,7 +232,7 @@ static void ReadHeightmapBMPImageData(byte *map, BmpInfo *info, BmpData *data)
* If map == NULL only the size of the BMP is read, otherwise a map
* with grayscale pixels is allocated and assigned to *map.
*/
-static bool ReadHeightmapBMP(char *filename, uint *x, uint *y, byte **map)
+static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, byte **map)
{
FILE *f;
BmpInfo info;
@@ -444,45 +444,56 @@ void FixSlopes()
}
/**
- * Reads the heightmap with the correct file reader
+ * Reads the heightmap with the correct file reader.
+ * @param dft Type of image file.
+ * @param filename Name of the file to load.
+ * @param [out] x Length of the image.
+ * @param [out] y Height of the image.
+ * @param [inout] map If not \c NULL, destination to store the loaded block of image data.
+ * @return Whether loading was successful.
*/
-static bool ReadHeightMap(char *filename, uint *x, uint *y, byte **map)
+static bool ReadHeightMap(DetailedFileType dft, const char *filename, uint *x, uint *y, byte **map)
{
- switch (_file_to_saveload.mode) {
- default: NOT_REACHED();
+ switch (dft) {
+ default:
+ NOT_REACHED();
+
#ifdef WITH_PNG
- case SL_PNG:
+ case DFT_HEIGHTMAP_PNG:
return ReadHeightmapPNG(filename, x, y, map);
#endif /* WITH_PNG */
- case SL_BMP:
+
+ case DFT_HEIGHTMAP_BMP:
return ReadHeightmapBMP(filename, x, y, map);
}
}
/**
* Get the dimensions of a heightmap.
+ * @param dft Type of image file.
* @param filename to query
* @param x dimension x
* @param y dimension y
* @return Returns false if loading of the image failed.
*/
-bool GetHeightmapDimensions(char *filename, uint *x, uint *y)
+bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y)
{
- return ReadHeightMap(filename, x, y, NULL);
+ return ReadHeightMap(dft, filename, x, y, NULL);
}
/**
* Load a heightmap from file and change the map in his current dimensions
* to a landscape representing the heightmap.
* It converts pixels to height. The brighter, the higher.
+ * @param dft Type of image file.
* @param filename of the heightmap file to be imported
*/
-void LoadHeightmap(char *filename)
+void LoadHeightmap(DetailedFileType dft, const char *filename)
{
uint x, y;
byte *map = NULL;
- if (!ReadHeightMap(filename, &x, &y, &map)) {
+ if (!ReadHeightMap(dft, filename, &x, &y, &map)) {
free(map);
return;
}