From 3270440f234570f1426c442898c2400e36608ebf Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 8 Jun 2017 13:58:46 -0700 Subject: [core] Per-tile glyph/icon atlases --- include/mbgl/util/image.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'include') diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp index a41b8462bd..91bf06d727 100644 --- a/include/mbgl/util/image.hpp +++ b/include/mbgl/util/image.hpp @@ -78,10 +78,27 @@ public: std::fill(data.get(), data.get() + bytes(), value); } + void resize(Size size_) { + if (size == size_) { + return; + } + Image newImage(size_); + newImage.fill(0); + copy(*this, newImage, {0, 0}, {0, 0}, { + std::min(size.width, size_.width), + std::min(size.height, size_.height) + }); + operator=(std::move(newImage)); + } + // Copy image data within `rect` from `src` to the rectangle of the same size at `pt` // in `dst`. If the specified bounds exceed the bounds of the source or destination, // throw `std::out_of_range`. Must not be used to move data within a single Image. static void copy(const Image& srcImg, Image& dstImg, const Point& srcPt, const Point& dstPt, const Size& size) { + if (size.isEmpty()) { + return; + } + if (!srcImg.valid()) { throw std::invalid_argument("invalid source for image copy"); } -- cgit v1.2.1