summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry/dem_data.hpp
blob: 817d3cc9c9f8124f8d4c7469f1ba781b176be3fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once

#include <mbgl/math/clamp.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/tileset.hpp>

#include <memory>
#include <array>
#include <cassert>
#include <vector>

namespace mbgl {

class DEMData {
public:
    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) {
        reinterpret_cast<int32_t*>(image.data.get())[idx(x, y)] = value + 65536;
    }

    int32_t get(const int32_t x, const int32_t y) const {
        return reinterpret_cast<const int32_t*>(image.data.get())[idx(x, y)] - 65536;
    }

    const PremultipliedImage* getImage() const {
        return &image;
    }

    const int32_t dim;
    const int32_t border;
    const int32_t stride;


    private:
        PremultipliedImage image;

        size_t idx(const int32_t x, const int32_t y) const {
            assert(x >= -border);
            assert(x < dim + border);
            assert(y >= -border);
            assert(y < dim + border);
            return (y + border) * stride + (x + border);
        }

};

} // namespace mbgl