diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-10-26 15:22:31 -0700 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-10-27 18:30:58 -0700 |
commit | 62b56b799a7d4fcd1a8f151eed878054b862da5b (patch) | |
tree | 34d510a69f9dd1bca30e9b137feffbd1eb6495d0 /include/mbgl/util/image.hpp | |
parent | ef8017198ce8f0bd79ba5a5ed31e35a16e3433bb (diff) | |
download | qtlocation-mapboxgl-62b56b799a7d4fcd1a8f151eed878054b862da5b.tar.gz |
[core] change std::array<uint16_t, 2> to mbgl::Size
Diffstat (limited to 'include/mbgl/util/image.hpp')
-rw-r--r-- | include/mbgl/util/image.hpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp index 795d1f9d1a..3dbab27f41 100644 --- a/include/mbgl/util/image.hpp +++ b/include/mbgl/util/image.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/util/noncopyable.hpp> +#include <mbgl/util/size.hpp> #include <string> #include <memory> @@ -18,39 +19,38 @@ class Image : private util::noncopyable { public: Image() = default; - Image(uint16_t w, uint16_t h) - : width(w), - height(h), - data(std::make_unique<uint8_t[]>(size())) {} + Image(Size size_) + : size(std::move(size_)), + data(std::make_unique<uint8_t[]>(bytes())) {} - Image(uint16_t w, uint16_t h, std::unique_ptr<uint8_t[]> data_) - : width(w), - height(h), + Image(Size size_, std::unique_ptr<uint8_t[]> data_) + : size(std::move(size_)), data(std::move(data_)) {} Image(Image&& o) - : width(o.width), - height(o.height), + : size(o.size), data(std::move(o.data)) {} Image& operator=(Image&& o) { - width = o.width; - height = o.height; + size = o.size; data = std::move(o.data); return *this; } 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()); + return size == rhs.size && + std::equal(data.get(), data.get() + bytes(), rhs.data.get(), + rhs.data.get() + rhs.bytes()); } - size_t stride() const { return static_cast<size_t>(width) * 4; } - size_t size() const { return static_cast<size_t>(width) * height * 4; } + bool valid() const { + return size && data.get() != nullptr; + } + + size_t stride() const { return static_cast<size_t>(size.width) * 4; } + size_t bytes() const { return stride() * size.height; } - uint16_t width = 0; - uint16_t height = 0; + Size size; std::unique_ptr<uint8_t[]> data; }; |