1 #pragma once
2 
3 #include <mbgl/math/clamp.hpp>
4 #include <mbgl/util/image.hpp>
5 #include <mbgl/util/tileset.hpp>
6 
7 #include <memory>
8 #include <array>
9 #include <cassert>
10 #include <vector>
11 
12 namespace mbgl {
13 
14 class DEMData {
15 public:
16     DEMData(const PremultipliedImage& image, Tileset::DEMEncoding encoding);
17     void backfillBorder(const DEMData& borderTileData, int8_t dx, int8_t dy);
18 
set(const int32_t x,const int32_t y,const int32_t value)19     void set(const int32_t x, const int32_t y, const int32_t value) {
20         reinterpret_cast<int32_t*>(image.data.get())[idx(x, y)] = value + 65536;
21     }
22 
get(const int32_t x,const int32_t y) const23     int32_t get(const int32_t x, const int32_t y) const {
24         return reinterpret_cast<const int32_t*>(image.data.get())[idx(x, y)] - 65536;
25     }
26 
getImage() const27     const PremultipliedImage* getImage() const {
28         return &image;
29     }
30 
31     const int32_t dim;
32     const int32_t border;
33     const int32_t stride;
34 
35 
36     private:
37         PremultipliedImage image;
38 
idx(const int32_t x,const int32_t y) const39         size_t idx(const int32_t x, const int32_t y) const {
40             assert(x >= -border);
41             assert(x < dim + border);
42             assert(y >= -border);
43             assert(y < dim + border);
44             return (y + border) * stride + (x + border);
45         }
46 
47 };
48 
49 } // namespace mbgl
50