summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2016-01-14 17:11:25 -0800
committerAnsis Brammanis <brammanis@gmail.com>2016-01-19 18:20:54 -0800
commit26faa6a5ade54c0a423aab84106876dc59be868f (patch)
tree16c476ea5bc3d2084cd07e7051eb5d55d10d5be2 /src
parent9b62661b07e86fc1d64e308fde3e15527c1cd8c8 (diff)
downloadqtlocation-mapboxgl-26faa6a5ade54c0a423aab84106876dc59be868f.tar.gz
[core][ios][osx][android] fix icons with non-integer width/height
ref #3031 ref #2198 For example, an icon that has: - a pixel width of 10 - a pixel ratio of 3 - a scaled with of 3.333 is now supported.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/sprite/sprite_image.cpp12
-rw-r--r--src/mbgl/sprite/sprite_parser.cpp23
2 files changed, 14 insertions, 21 deletions
diff --git a/src/mbgl/sprite/sprite_image.cpp b/src/mbgl/sprite/sprite_image.cpp
index d5e4a7828e..e55d676b34 100644
--- a/src/mbgl/sprite/sprite_image.cpp
+++ b/src/mbgl/sprite/sprite_image.cpp
@@ -6,16 +6,16 @@
namespace mbgl {
-SpriteImage::SpriteImage(const uint16_t width_,
- const uint16_t height_,
+SpriteImage::SpriteImage(const uint16_t pixelWidth_,
+ const uint16_t pixelHeight_,
const float pixelRatio_,
std::string&& data_,
bool sdf_)
- : width(width_),
- height(height_),
+ : width(std::ceil(pixelWidth_ / pixelRatio_)),
+ height(std::ceil(pixelHeight_ / pixelRatio_)),
pixelRatio(pixelRatio_),
- pixelWidth(std::ceil(width * pixelRatio)),
- pixelHeight(std::ceil(height * pixelRatio)),
+ pixelWidth(pixelWidth_),
+ pixelHeight(pixelHeight_),
data(std::move(data_)),
sdf(sdf_) {
const size_t size = pixelWidth * pixelHeight * 4;
diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp
index 1aa95310c5..6942d009f3 100644
--- a/src/mbgl/sprite/sprite_parser.cpp
+++ b/src/mbgl/sprite/sprite_parser.cpp
@@ -15,37 +15,30 @@ namespace mbgl {
SpriteImagePtr createSpriteImage(const PremultipliedImage& image,
const uint16_t srcX,
const uint16_t srcY,
- const uint16_t srcWidth,
- const uint16_t srcHeight,
+ const uint16_t width,
+ const uint16_t height,
const double ratio,
const bool sdf) {
// Disallow invalid parameter configurations.
- if (srcWidth == 0 || srcHeight == 0 || ratio <= 0 || ratio > 10 || srcWidth > 1024 ||
- srcHeight > 1024) {
+ if (width == 0 || height == 0 || ratio <= 0 || ratio > 10 || width > 1024 ||
+ height > 1024) {
Log::Warning(Event::Sprite, "Can't create sprite with invalid metrics");
return nullptr;
}
- const uint16_t width = std::ceil(double(srcWidth) / ratio);
- const uint16_t dstWidth = std::ceil(width * ratio);
- assert(dstWidth >= srcWidth);
- const uint16_t height = std::ceil(double(srcHeight) / ratio);
- const uint16_t dstHeight = std::ceil(height * ratio);
- assert(dstHeight >= srcHeight);
-
- std::string data(dstWidth * dstHeight * 4, '\0');
+ std::string data(width * height * 4, '\0');
auto srcData = reinterpret_cast<const uint32_t*>(image.data.get());
auto dstData = reinterpret_cast<uint32_t*>(const_cast<char*>(data.data()));
- const int32_t maxX = std::min(uint32_t(image.width), uint32_t(srcWidth + srcX)) - srcX;
+ const int32_t maxX = std::min(uint32_t(image.width), uint32_t(width + srcX)) - srcX;
assert(maxX <= int32_t(image.width));
- const int32_t maxY = std::min(uint32_t(image.height), uint32_t(srcHeight + srcY)) - srcY;
+ const int32_t maxY = std::min(uint32_t(image.height), uint32_t(height + srcY)) - srcY;
assert(maxY <= int32_t(image.height));
// Copy from the source image into our individual sprite image
for (uint16_t y = 0; y < maxY; ++y) {
- const auto dstRow = y * dstWidth;
+ const auto dstRow = y * width;
const auto srcRow = (y + srcY) * image.width + srcX;
for (uint16_t x = 0; x < maxX; ++x) {
dstData[dstRow + x] = srcData[srcRow + x];