summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry
diff options
context:
space:
mode:
authorMolly Lloyd <mollymerp@users.noreply.github.com>2018-02-14 13:17:55 -0800
committerGitHub <noreply@github.com>2018-02-14 13:17:55 -0800
commit8a283b030629abb00367929d047731c3974bc3d6 (patch)
tree4016b561a3ab52e4ce12e65b4307f0b626124120 /src/mbgl/geometry
parenta386cac452b333d3e9656efd04e98035cd6b1c57 (diff)
downloadqtlocation-mapboxgl-8a283b030629abb00367929d047731c3974bc3d6.tar.gz
[core] add support for mapzen terrarium (#11154)
* add support for mapzen terrarium * Encoding --> DEMEncoding, avoid if statement when unpacking elevation values * add Terrarium test * update submodule * remove redundant checks
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r--src/mbgl/geometry/dem_data.cpp16
-rw-r--r--src/mbgl/geometry/dem_data.hpp3
2 files changed, 16 insertions, 3 deletions
diff --git a/src/mbgl/geometry/dem_data.cpp b/src/mbgl/geometry/dem_data.cpp
index 78134dadc1..7fa98950ea 100644
--- a/src/mbgl/geometry/dem_data.cpp
+++ b/src/mbgl/geometry/dem_data.cpp
@@ -3,7 +3,7 @@
namespace mbgl {
-DEMData::DEMData(const PremultipliedImage& _image):
+DEMData::DEMData(const PremultipliedImage& _image, Tileset::DEMEncoding encoding):
dim(_image.size.height),
border(std::max<int32_t>(std::ceil(_image.size.height / 2), 1)),
stride(dim + 2 * border),
@@ -13,13 +13,25 @@ DEMData::DEMData(const PremultipliedImage& _image):
throw std::runtime_error("raster-dem tiles must be square.");
}
+ auto decodeMapbox = [] (const uint8_t r, const uint8_t g, const uint8_t b){
+ // https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb
+ return (r * 256 * 256 + g * 256 + b)/10 - 10000;
+ };
+
+ auto decodeTerrarium = [] (const uint8_t r, const uint8_t g, const uint8_t b){
+ // https://aws.amazon.com/public-datasets/terrain/
+ return ((r * 256 + g + b / 256) - 32768);
+ };
+
+ auto decodeRGB = encoding == Tileset::DEMEncoding::Terrarium ? decodeTerrarium : decodeMapbox;
+
std::memset(image.data.get(), 0, image.bytes());
for (int32_t y = 0; y < dim; y++) {
for (int32_t x = 0; x < dim; x++) {
const int32_t i = y * dim + x;
const int32_t j = i * 4;
- set(x, y, (_image.data[j] * 256 * 256 + _image.data[j+1] * 256 + _image.data[j+2])/10 - 10000);
+ set(x, y, decodeRGB(_image.data[j], _image.data[j+1], _image.data[j+2]));
}
}
diff --git a/src/mbgl/geometry/dem_data.hpp b/src/mbgl/geometry/dem_data.hpp
index 507a51661d..817d3cc9c9 100644
--- a/src/mbgl/geometry/dem_data.hpp
+++ b/src/mbgl/geometry/dem_data.hpp
@@ -2,6 +2,7 @@
#include <mbgl/math/clamp.hpp>
#include <mbgl/util/image.hpp>
+#include <mbgl/util/tileset.hpp>
#include <memory>
#include <array>
@@ -12,7 +13,7 @@ namespace mbgl {
class DEMData {
public:
- DEMData(const PremultipliedImage& image);
+ DEMData(const PremultipliedImage& image, Tileset::DEMEncoding encoding);
void backfillBorder(const DEMData& borderTileData, int8_t dx, int8_t dy);
void set(const int32_t x, const int32_t y, const int32_t value) {