blob: a1c899d239aacd87cbd8776b8ae2ac4a82570f18 (
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
50
51
52
53
|
#ifndef MBGL_UTIL_IMAGE
#define MBGL_UTIL_IMAGE
#include <string>
#include <memory>
#include <algorithm>
namespace mbgl {
enum ImageAlphaMode {
Unassociated,
Premultiplied
};
template <ImageAlphaMode Mode>
class Image {
public:
Image() = default;
Image(size_t w, size_t h)
: width(w),
height(h),
data(std::make_unique<uint8_t[]>(size())) {}
Image(size_t w, size_t h, std::unique_ptr<uint8_t[]> data_)
: width(w),
height(h),
data(std::move(data_)) {}
bool operator==(const Image& rhs) const {
return width == rhs.width && height == rhs.height &&
std::equal(data.get(), data.get() + size(), rhs.data.get(),
rhs.data.get() + rhs.size());
}
size_t stride() const { return width * 4; }
size_t size() const { return width * height * 4; }
size_t width = 0;
size_t height = 0;
std::unique_ptr<uint8_t[]> data;
};
using UnassociatedImage = Image<ImageAlphaMode::Unassociated>;
using PremultipliedImage = Image<ImageAlphaMode::Premultiplied>;
// TODO: don't use std::string for binary data.
PremultipliedImage decodeImage(const std::string&);
std::string encodePNG(const PremultipliedImage&);
} // namespace mbgl
#endif
|