diff options
Diffstat (limited to 'src/mbgl/annotation/sprite_image.cpp')
-rw-r--r-- | src/mbgl/annotation/sprite_image.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mbgl/annotation/sprite_image.cpp b/src/mbgl/annotation/sprite_image.cpp new file mode 100644 index 0000000000..9cfe9c9fc8 --- /dev/null +++ b/src/mbgl/annotation/sprite_image.cpp @@ -0,0 +1,27 @@ +#include <mbgl/annotation/sprite_image.hpp> + +#include <mbgl/util/exception.hpp> + +#include <cmath> + +namespace mbgl { + +SpriteImage::SpriteImage(const uint16_t width_, + const uint16_t height_, + const float ratio_, + std::string&& data_) + : width(width_), + height(height_), + ratio(ratio_), + pixelWidth(std::ceil(width * ratio)), + pixelHeight(std::ceil(height * ratio)), + data(std::move(data_)) { + const size_t size = pixelWidth * pixelHeight * 4; + if (size == 0) { + throw util::SpriteImageException("Sprite image dimensions may not be zero"); + } else if (size != data.size()) { + throw util::SpriteImageException("Sprite image pixel count mismatch"); + } +} + +} // namespace mbgl |