summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-09-13 11:07:38 -0400
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-09-13 22:17:41 +0300
commitcda418198f17df87962e1797e024714eaceadcd7 (patch)
treec4d0b9bd696ca3416be7888357afe09f62815b91 /include
parent366a69785a2fffd0713897f53647cf18b7a0c645 (diff)
downloadqtlocation-mapboxgl-cda418198f17df87962e1797e024714eaceadcd7.tar.gz
[core] Clear atlasImage rect for a removed pattern
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/image.hpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp
index cb28f3da8d..4887058f79 100644
--- a/include/mbgl/util/image.hpp
+++ b/include/mbgl/util/image.hpp
@@ -5,6 +5,7 @@
#include <mbgl/util/size.hpp>
#include <string>
+#include <cstring>
#include <memory>
#include <algorithm>
@@ -91,6 +92,31 @@ public:
operator=(std::move(newImage));
}
+ // Clears the rect area specified by `pt` and `size` from `dstImage`.
+ static void clear(Image& dstImg, const Point<uint32_t>& pt, const Size& size) {
+ if (size.isEmpty()) {
+ return;
+ }
+
+ if (!dstImg.valid()) {
+ throw std::invalid_argument("invalid destination for image clear");
+ }
+
+ if (size.width > dstImg.size.width ||
+ size.height > dstImg.size.height ||
+ pt.x > dstImg.size.width - size.width ||
+ pt.y > dstImg.size.height - size.height) {
+ throw std::out_of_range("out of range destination coordinates for image clear");
+ }
+
+ uint8_t* dstData = dstImg.data.get();
+
+ for (uint32_t y = 0; y < size.height; y++) {
+ const std::size_t dstOffset = (pt.y + y) * dstImg.stride() + pt.x * channels;
+ std::memset(dstData + dstOffset, 0, size.width * channels);
+ }
+ }
+
// 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.