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 /src/mbgl/sprite | |
parent | ef8017198ce8f0bd79ba5a5ed31e35a16e3433bb (diff) | |
download | qtlocation-mapboxgl-62b56b799a7d4fcd1a8f151eed878054b862da5b.tar.gz |
[core] change std::array<uint16_t, 2> to mbgl::Size
Diffstat (limited to 'src/mbgl/sprite')
-rw-r--r-- | src/mbgl/sprite/sprite_atlas.cpp | 13 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_image.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_parser.cpp | 19 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_parser.hpp | 8 |
4 files changed, 22 insertions, 20 deletions
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp index 198b0a6c57..f8417c3372 100644 --- a/src/mbgl/sprite/sprite_atlas.cpp +++ b/src/mbgl/sprite/sprite_atlas.cpp @@ -128,7 +128,7 @@ void SpriteAtlas::_setSprite(const std::string& name, auto it = sprites.find(name); if (it != sprites.end()) { // There is already a sprite with that name in our store. - if ((it->second->image.width != sprite->image.width || it->second->image.height != sprite->image.height)) { + if (it->second->image.size != sprite->image.size) { Log::Warning(Event::Sprite, "Can't change sprite dimensions for '%s'", name.c_str()); return; } @@ -164,8 +164,8 @@ std::shared_ptr<const SpriteImage> SpriteAtlas::getSprite(const std::string& nam Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(const SpriteImage& spriteImage) { - const uint16_t pixel_width = std::ceil(spriteImage.image.width / pixelRatio); - const uint16_t pixel_height = std::ceil(spriteImage.image.height / pixelRatio); + const uint16_t pixel_width = std::ceil(spriteImage.image.size.width / pixelRatio); + const uint16_t pixel_height = std::ceil(spriteImage.image.size.height / pixelRatio); // Increase to next number divisible by 4, but at least 1. // This is so we can scale down the texture coordinates and pack them @@ -275,9 +275,10 @@ void SpriteAtlas::copy(const Holder& holder, const SpritePatternMode mode) { const int padding = 1; - copyBitmap(srcData, uint32_t(holder.spriteImage->image.width), 0, 0, - dstData, pixelWidth, (holder.pos.x + padding) * pixelRatio, (holder.pos.y + padding) * pixelRatio, pixelWidth * pixelHeight, - uint32_t(holder.spriteImage->image.width), uint32_t(holder.spriteImage->image.height), mode); + copyBitmap(srcData, holder.spriteImage->image.size.width, 0, 0, dstData, pixelWidth, + (holder.pos.x + padding) * pixelRatio, (holder.pos.y + padding) * pixelRatio, + pixelWidth * pixelHeight, holder.spriteImage->image.size.width, + holder.spriteImage->image.size.height, mode); dirtyFlag = true; } diff --git a/src/mbgl/sprite/sprite_image.cpp b/src/mbgl/sprite/sprite_image.cpp index d7e422ed1d..1579d9d89e 100644 --- a/src/mbgl/sprite/sprite_image.cpp +++ b/src/mbgl/sprite/sprite_image.cpp @@ -13,7 +13,7 @@ SpriteImage::SpriteImage(PremultipliedImage&& image_, pixelRatio(pixelRatio_), sdf(sdf_) { - if (image.size() == 0) { + if (!image.valid()) { throw util::SpriteImageException("Sprite image dimensions may not be zero"); } else if (pixelRatio <= 0) { throw util::SpriteImageException("Sprite pixelRatio may not be <= 0"); diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp index 34b1d875b6..8d9b35cb77 100644 --- a/src/mbgl/sprite/sprite_parser.cpp +++ b/src/mbgl/sprite/sprite_parser.cpp @@ -13,30 +13,31 @@ namespace mbgl { SpriteImagePtr createSpriteImage(const PremultipliedImage& image, - const uint16_t srcX, - const uint16_t srcY, - const uint16_t width, - const uint16_t height, + const uint32_t srcX, + const uint32_t srcY, + const uint32_t width, + const uint32_t height, const double ratio, const bool sdf) { // Disallow invalid parameter configurations. if (width <= 0 || height <= 0 || width > 1024 || height > 1024 || ratio <= 0 || ratio > 10 || - srcX + width > image.width || srcY + height > image.height) { + srcX >= image.size.width || srcY >= image.size.height || + srcX + width > image.size.width || srcY + height > image.size.height) { Log::Error(Event::Sprite, "Can't create sprite with invalid metrics"); return nullptr; } - PremultipliedImage dstImage(width, height); + PremultipliedImage dstImage({ width, height }); auto srcData = reinterpret_cast<const uint32_t*>(image.data.get()); auto dstData = reinterpret_cast<uint32_t*>(dstImage.data.get()); // Copy from the source image into our individual sprite image - for (uint16_t y = 0; y < height; ++y) { + for (uint32_t y = 0; y < height; ++y) { const auto dstRow = y * width; - const auto srcRow = (y + srcY) * image.width + srcX; - for (uint16_t x = 0; x < width; ++x) { + const auto srcRow = (y + srcY) * image.size.width + srcX; + for (uint32_t x = 0; x < width; ++x) { dstData[dstRow + x] = srcData[srcRow + x]; } } diff --git a/src/mbgl/sprite/sprite_parser.hpp b/src/mbgl/sprite/sprite_parser.hpp index 6a564ce330..4a63d4858a 100644 --- a/src/mbgl/sprite/sprite_parser.hpp +++ b/src/mbgl/sprite/sprite_parser.hpp @@ -17,10 +17,10 @@ using SpriteImagePtr = std::shared_ptr<const SpriteImage>; // Extracts an individual image from a spritesheet from the given location. SpriteImagePtr createSpriteImage(const PremultipliedImage&, - uint16_t srcX, - uint16_t srcY, - uint16_t srcWidth, - uint16_t srcHeight, + uint32_t srcX, + uint32_t srcY, + uint32_t srcWidth, + uint32_t srcHeight, double ratio, bool sdf); |