summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmark/api/query.benchmark.cpp2
-rw-r--r--include/mbgl/map/map.hpp4
-rw-r--r--include/mbgl/style/image.hpp6
-rwxr-xr-xplatform/android/src/native_map_view.cpp10
-rw-r--r--platform/darwin/src/MGLStyle.mm2
-rw-r--r--platform/glfw/glfw_view.cpp8
-rw-r--r--platform/glfw/glfw_view.hpp2
-rw-r--r--platform/ios/src/MGLMapView.mm2
-rw-r--r--platform/ios/src/UIImage+MGLAdditions.h2
-rw-r--r--platform/ios/src/UIImage+MGLAdditions.mm5
-rw-r--r--platform/macos/src/MGLMapView.mm2
-rw-r--r--platform/macos/src/NSImage+MGLAdditions.h2
-rw-r--r--platform/macos/src/NSImage+MGLAdditions.mm9
-rw-r--r--platform/node/src/node_map.cpp2
-rw-r--r--platform/qt/src/qmapboxgl.cpp7
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp6
-rw-r--r--src/mbgl/annotation/annotation_manager.hpp2
-rw-r--r--src/mbgl/map/map.cpp8
-rw-r--r--src/mbgl/sprite/sprite_atlas.cpp13
-rw-r--r--src/mbgl/sprite/sprite_atlas.hpp6
-rw-r--r--src/mbgl/sprite/sprite_image_collection.cpp4
-rw-r--r--src/mbgl/sprite/sprite_image_collection.hpp1
-rw-r--r--src/mbgl/sprite/sprite_loader.cpp5
-rw-r--r--src/mbgl/sprite/sprite_loader.hpp6
-rw-r--r--src/mbgl/sprite/sprite_loader_observer.hpp7
-rw-r--r--src/mbgl/sprite/sprite_parser.cpp25
-rw-r--r--src/mbgl/sprite/sprite_parser.hpp24
-rw-r--r--src/mbgl/style/image.cpp9
-rw-r--r--src/mbgl/style/image_impl.cpp10
-rw-r--r--src/mbgl/style/image_impl.hpp4
-rw-r--r--src/mbgl/style/style.cpp22
-rw-r--r--src/mbgl/style/style.hpp4
-rw-r--r--test/api/annotations.test.cpp28
-rw-r--r--test/api/query.test.cpp2
-rw-r--r--test/map/map.test.cpp16
-rw-r--r--test/sprite/sprite_atlas.test.cpp22
-rw-r--r--test/sprite/sprite_image_collection.test.cpp10
-rw-r--r--test/sprite/sprite_loader.test.cpp10
-rw-r--r--test/sprite/sprite_parser.test.cpp38
-rw-r--r--test/style/style_image.test.cpp10
-rw-r--r--test/text/quads.test.cpp4
41 files changed, 176 insertions, 185 deletions
diff --git a/benchmark/api/query.benchmark.cpp b/benchmark/api/query.benchmark.cpp
index faf6c4fbe4..cf5e2516de 100644
--- a/benchmark/api/query.benchmark.cpp
+++ b/benchmark/api/query.benchmark.cpp
@@ -25,7 +25,7 @@ public:
map.setStyleJSON(util::read_file("benchmark/fixtures/api/query_style.json"));
map.setLatLngZoom({ 40.726989, -73.992857 }, 15); // Manhattan
- map.addImage("test-icon", std::make_unique<style::Image>(
+ map.addImage(std::make_unique<style::Image>("test-icon",
decodeImage(util::read_file("benchmark/fixtures/api/default_marker.png")), 1.0));
mbgl::benchmark::render(map, view);
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 6b86684faa..00131cc5ea 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -148,7 +148,7 @@ public:
LatLng latLngForPixel(const ScreenCoordinate&) const;
// Annotations
- void addAnnotationImage(const std::string&, std::unique_ptr<style::Image>);
+ void addAnnotationImage(std::unique_ptr<style::Image>);
void removeAnnotationImage(const std::string&);
double getTopOffsetPixelsForAnnotationImage(const std::string&);
@@ -169,7 +169,7 @@ public:
std::unique_ptr<style::Layer> removeLayer(const std::string& layerID);
// Images
- void addImage(const std::string&, std::unique_ptr<style::Image>);
+ void addImage(std::unique_ptr<style::Image>);
void removeImage(const std::string&);
const style::Image* getImage(const std::string&);
diff --git a/include/mbgl/style/image.hpp b/include/mbgl/style/image.hpp
index 528b2ecb95..3877086bd6 100644
--- a/include/mbgl/style/image.hpp
+++ b/include/mbgl/style/image.hpp
@@ -3,12 +3,16 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/immutable.hpp>
+#include <string>
+
namespace mbgl {
namespace style {
class Image {
public:
- Image(PremultipliedImage&&, float pixelRatio, bool sdf = false);
+ Image(std::string id, PremultipliedImage&&, float pixelRatio, bool sdf = false);
+
+ std::string getID() const;
const PremultipliedImage& getImage() const;
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 1e2464f1a0..51ce9c031d 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -735,8 +735,8 @@ void NativeMapView::addAnnotationIcon(JNIEnv& env, jni::String symbol, jint w, j
}
jni::GetArrayRegion(env, *jpixels, 0, size, reinterpret_cast<jbyte*>(premultipliedImage.data.get()));
- map->addAnnotationImage(symbolName,
- std::make_unique<mbgl::style::Image>(std::move(premultipliedImage), float(scale)));
+ map->addAnnotationImage(std::make_unique<mbgl::style::Image>(
+ symbolName, std::move(premultipliedImage), float(scale)));
}
jdouble NativeMapView::getTopOffsetPixelsForAnnotationSymbol(JNIEnv& env, jni::String symbolName) {
@@ -1037,8 +1037,10 @@ void NativeMapView::addImage(JNIEnv& env, jni::String name, jni::jint w, jni::ji
jni::GetArrayRegion(env, *pixels, 0, size, reinterpret_cast<jbyte*>(premultipliedImage.data.get()));
- map->addImage(jni::Make<std::string>(env, name),
- std::make_unique<mbgl::style::Image>(std::move(premultipliedImage), float(scale)));
+ map->addImage(std::make_unique<mbgl::style::Image>(
+ jni::Make<std::string>(env, name),
+ std::move(premultipliedImage),
+ float(scale)));
}
void NativeMapView::removeImage(JNIEnv& env, jni::String name) {
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index 2c54b11634..5f26b4fed2 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -510,7 +510,7 @@ static NSURL *MGLStyleURL_emerald;
format:@"Cannot assign image %@ to a nil name.", image];
}
- self.mapView.mbglMap->addImage([name UTF8String], image.mgl_styleImage);
+ self.mapView.mbglMap->addImage([image mgl_styleImageWithIdentifier:name]);
}
- (void)removeImageForName:(NSString *)name
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index d3a6347110..29cd0dd7c3 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -131,7 +131,7 @@ GLFWView::~GLFWView() {
void GLFWView::setMap(mbgl::Map *map_) {
map = map_;
- map->addAnnotationImage("default_marker", makeImage(22, 22, 1));
+ map->addAnnotationImage(makeImage("default_marker", 22, 22, 1));
}
void GLFWView::updateAssumedState() {
@@ -255,7 +255,7 @@ mbgl::Point<double> GLFWView::makeRandomPoint() const {
}
std::unique_ptr<mbgl::style::Image>
-GLFWView::makeImage(int width, int height, float pixelRatio) {
+GLFWView::makeImage(const std::string& id, int width, int height, float pixelRatio) {
const int r = 255 * (double(std::rand()) / RAND_MAX);
const int g = 255 * (double(std::rand()) / RAND_MAX);
const int b = 255 * (double(std::rand()) / RAND_MAX);
@@ -280,7 +280,7 @@ GLFWView::makeImage(int width, int height, float pixelRatio) {
}
}
- return std::make_unique<mbgl::style::Image>(std::move(image), pixelRatio);
+ return std::make_unique<mbgl::style::Image>(id, std::move(image), pixelRatio);
}
void GLFWView::nextOrientation() {
@@ -297,7 +297,7 @@ void GLFWView::addRandomCustomPointAnnotations(int count) {
for (int i = 0; i < count; i++) {
static int spriteID = 1;
const auto name = std::string{ "marker-" } + mbgl::util::toString(spriteID++);
- map->addAnnotationImage(name, makeImage(22, 22, 1));
+ map->addAnnotationImage(makeImage(name, 22, 22, 1));
spriteIDs.push_back(name);
annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { makeRandomPoint(), name }));
}
diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp
index 77f4f64b01..b5fd5856f4 100644
--- a/platform/glfw/glfw_view.hpp
+++ b/platform/glfw/glfw_view.hpp
@@ -61,7 +61,7 @@ private:
mbgl::Color makeRandomColor() const;
mbgl::Point<double> makeRandomPoint() const;
- static std::unique_ptr<mbgl::style::Image> makeImage(int width, int height, float pixelRatio);
+ static std::unique_ptr<mbgl::style::Image> makeImage(const std::string& id, int width, int height, float pixelRatio);
void nextOrientation();
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index a4c9f5194c..8cba1187ea 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -3449,7 +3449,7 @@ public:
annotationImage.delegate = self;
// add sprite
- _mbglMap->addAnnotationImage(iconIdentifier.UTF8String, annotationImage.image.mgl_styleImage);
+ _mbglMap->addAnnotationImage([annotationImage.image mgl_styleImageWithIdentifier:iconIdentifier]);
// Create a slop area with a “radius” equal in size to the annotation
// image’s alignment rect, allowing the eventual tap to be on any point
diff --git a/platform/ios/src/UIImage+MGLAdditions.h b/platform/ios/src/UIImage+MGLAdditions.h
index 642355d412..0b4cb4c015 100644
--- a/platform/ios/src/UIImage+MGLAdditions.h
+++ b/platform/ios/src/UIImage+MGLAdditions.h
@@ -8,7 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)styleImage;
-- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage;
+- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier;
@end
diff --git a/platform/ios/src/UIImage+MGLAdditions.mm b/platform/ios/src/UIImage+MGLAdditions.mm
index 4ced1e30d5..b10c48a62a 100644
--- a/platform/ios/src/UIImage+MGLAdditions.mm
+++ b/platform/ios/src/UIImage+MGLAdditions.mm
@@ -22,9 +22,10 @@
return self;
}
-- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage {
+- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier {
BOOL isTemplate = self.renderingMode == UIImageRenderingModeAlwaysTemplate;
- return std::make_unique<mbgl::style::Image>(MGLPremultipliedImageFromCGImage(self.CGImage),
+ return std::make_unique<mbgl::style::Image>([identifier UTF8String],
+ MGLPremultipliedImageFromCGImage(self.CGImage),
float(self.scale), isTemplate);
}
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index a36766b745..59951f946d 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -1949,7 +1949,7 @@ public:
return;
}
- _mbglMap->addAnnotationImage(iconIdentifier.UTF8String, annotationImage.image.mgl_styleImage);
+ _mbglMap->addAnnotationImage([annotationImage.image mgl_styleImageWithIdentifier:iconIdentifier]);
// Create a slop area with a “radius” equal to the annotation image’s entire
// size, allowing the eventual click to be on any point within this image.
diff --git a/platform/macos/src/NSImage+MGLAdditions.h b/platform/macos/src/NSImage+MGLAdditions.h
index d3cc80615b..1bcec00e8b 100644
--- a/platform/macos/src/NSImage+MGLAdditions.h
+++ b/platform/macos/src/NSImage+MGLAdditions.h
@@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)image;
-- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage;
+- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier;
@end
diff --git a/platform/macos/src/NSImage+MGLAdditions.mm b/platform/macos/src/NSImage+MGLAdditions.mm
index fee3fe2751..6bb8fca68b 100644
--- a/platform/macos/src/NSImage+MGLAdditions.mm
+++ b/platform/macos/src/NSImage+MGLAdditions.mm
@@ -30,7 +30,7 @@
return self;
}
-- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage {
+- (std::unique_ptr<mbgl::style::Image>)mgl_styleImageWithIdentifier:(NSString *)identifier {
// Create a bitmap image representation from the image, respecting backing
// scale factor and any resizing done on the image at runtime.
// http://www.cocoabuilder.com/archive/cocoa/82430-nsimage-getting-raw-bitmap-data.html#82431
@@ -40,9 +40,10 @@
mbgl::PremultipliedImage cPremultipliedImage({ static_cast<uint32_t>(rep.pixelsWide), static_cast<uint32_t>(rep.pixelsHigh) });
std::copy(rep.bitmapData, rep.bitmapData + cPremultipliedImage.bytes(), cPremultipliedImage.data.get());
- return std::make_unique<mbgl::style::Image>(std::move(cPremultipliedImage),
- (float)(rep.pixelsWide / self.size.width),
- [self isTemplate]);
+ return std::make_unique<mbgl::style::Image>([identifier UTF8String],
+ std::move(cPremultipliedImage),
+ (float)(rep.pixelsWide / self.size.width),
+ [self isTemplate]);
}
@end
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index b174893e78..7261b33740 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -664,7 +664,7 @@ void NodeMap::AddImage(const Nan::FunctionCallbackInfo<v8::Value>& info) {
mbgl::UnassociatedImage cImage({ imageWidth, imageHeight}, std::move(data));
mbgl::PremultipliedImage cPremultipliedImage = mbgl::util::premultiply(std::move(cImage));
- nodeMap->map->addImage(*Nan::Utf8String(info[0]), std::make_unique<mbgl::style::Image>(std::move(cPremultipliedImage), pixelRatio));
+ nodeMap->map->addImage(std::make_unique<mbgl::style::Image>(*Nan::Utf8String(info[0]), std::move(cPremultipliedImage), pixelRatio));
}
void NodeMap::RemoveImage(const Nan::FunctionCallbackInfo<v8::Value>& info) {
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index bfc014dcd0..01471bf733 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -78,7 +78,7 @@ mbgl::Size sanitizedSize(const QSize& size) {
};
};
-std::unique_ptr<mbgl::style::Image> toStyleImage(const QImage &sprite) {
+std::unique_ptr<mbgl::style::Image> toStyleImage(const QString &id, const QImage &sprite) {
const QImage swapped = sprite
.rgbSwapped()
.convertToFormat(QImage::Format_ARGB32_Premultiplied);
@@ -87,6 +87,7 @@ std::unique_ptr<mbgl::style::Image> toStyleImage(const QImage &sprite) {
memcpy(img.get(), swapped.constBits(), swapped.byteCount());
return std::make_unique<mbgl::style::Image>(
+ id.toStdString(),
mbgl::PremultipliedImage(
{ static_cast<uint32_t>(swapped.width()), static_cast<uint32_t>(swapped.height()) },
std::move(img)),
@@ -1027,7 +1028,7 @@ void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &icon)
{
if (icon.isNull()) return;
- d_ptr->mapObj->addAnnotationImage(name.toStdString(), toStyleImage(icon));
+ d_ptr->mapObj->addAnnotationImage(toStyleImage(name, icon));
}
/*!
@@ -1329,7 +1330,7 @@ void QMapboxGL::addImage(const QString &id, const QImage &image)
{
if (image.isNull()) return;
- d_ptr->mapObj->addImage(id.toStdString(), toStyleImage(image));
+ d_ptr->mapObj->addImage(toStyleImage(id, image));
}
/*!
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index 8e75f8e63f..a7f1c69f3b 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -191,9 +191,9 @@ void AnnotationManager::removeTile(AnnotationTile& tile) {
tiles.erase(&tile);
}
-void AnnotationManager::addImage(const std::string& id, std::unique_ptr<style::Image> image) {
- addSpriteImage(spriteImages, id, std::move(image), [&](style::Image& added) {
- spriteAtlas.addImage(id, added.impl);
+void AnnotationManager::addImage(std::unique_ptr<style::Image> image) {
+ addSpriteImage(spriteImages, std::move(image), [&](style::Image& added) {
+ spriteAtlas.addImage(added.impl);
});
}
diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp
index 69232677f9..837827b75c 100644
--- a/src/mbgl/annotation/annotation_manager.hpp
+++ b/src/mbgl/annotation/annotation_manager.hpp
@@ -33,7 +33,7 @@ public:
Update updateAnnotation(const AnnotationID&, const Annotation&, const uint8_t maxZoom);
void removeAnnotation(const AnnotationID&);
- void addImage(const std::string&, std::unique_ptr<style::Image>);
+ void addImage(std::unique_ptr<style::Image>);
void removeImage(const std::string&);
double getTopOffsetPixelsForImage(const std::string&);
SpriteAtlas& getSpriteAtlas() { return spriteAtlas; }
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index c6d3ed9915..e994428bf1 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -788,8 +788,8 @@ LatLng Map::latLngForPixel(const ScreenCoordinate& pixel) const {
#pragma mark - Annotations
-void Map::addAnnotationImage(const std::string& id, std::unique_ptr<style::Image> image) {
- impl->annotationManager->addImage(id, std::move(image));
+void Map::addAnnotationImage(std::unique_ptr<style::Image> image) {
+ impl->annotationManager->addImage(std::move(image));
}
void Map::removeAnnotationImage(const std::string& id) {
@@ -936,13 +936,13 @@ std::unique_ptr<Layer> Map::removeLayer(const std::string& id) {
return removedLayer;
}
-void Map::addImage(const std::string& id, std::unique_ptr<style::Image> image) {
+void Map::addImage(std::unique_ptr<style::Image> image) {
if (!impl->style) {
return;
}
impl->styleMutated = true;
- impl->style->addImage(id, std::move(image));
+ impl->style->addImage(std::move(image));
}
void Map::removeImage(const std::string& id) {
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp
index f677f7bb60..0f4cde56ad 100644
--- a/src/mbgl/sprite/sprite_atlas.cpp
+++ b/src/mbgl/sprite/sprite_atlas.cpp
@@ -42,25 +42,20 @@ SpriteAtlas::SpriteAtlas(Size size_, float pixelRatio_)
SpriteAtlas::~SpriteAtlas() = default;
-void SpriteAtlas::onSpriteLoaded(Images&& result) {
+void SpriteAtlas::onSpriteLoaded() {
markAsLoaded();
-
- for (auto& pair : result) {
- addImage(pair.first, pair.second->impl);
- }
-
for (auto requestor : requestors) {
requestor->onIconsAvailable(buildIconMap());
}
requestors.clear();
}
-void SpriteAtlas::addImage(const std::string& id, Immutable<style::Image::Impl> image_) {
+void SpriteAtlas::addImage(Immutable<style::Image::Impl> image_) {
icons.clear();
- auto it = entries.find(id);
+ auto it = entries.find(image_->id);
if (it == entries.end()) {
- entries.emplace(id, Entry { std::move(image_), {}, {} });
+ entries.emplace(image_->id, Entry { image_, {}, {} });
return;
}
diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp
index 4e03c32b30..bcec26b7ba 100644
--- a/src/mbgl/sprite/sprite_atlas.hpp
+++ b/src/mbgl/sprite/sprite_atlas.hpp
@@ -43,12 +43,10 @@ public:
class SpriteAtlas : public util::noncopyable {
public:
- using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
-
SpriteAtlas(Size, float pixelRatio);
~SpriteAtlas();
- void onSpriteLoaded(Images&&);
+ void onSpriteLoaded();
void markAsLoaded() {
loaded = true;
@@ -61,7 +59,7 @@ public:
void dumpDebugLogs() const;
const style::Image::Impl* getImage(const std::string&) const;
- void addImage(const std::string&, Immutable<style::Image::Impl>);
+ void addImage(Immutable<style::Image::Impl>);
void removeImage(const std::string&);
void getIcons(IconRequestor& requestor);
diff --git a/src/mbgl/sprite/sprite_image_collection.cpp b/src/mbgl/sprite/sprite_image_collection.cpp
index 787ba83db2..ae00a6b146 100644
--- a/src/mbgl/sprite/sprite_image_collection.cpp
+++ b/src/mbgl/sprite/sprite_image_collection.cpp
@@ -3,10 +3,10 @@
namespace mbgl {
-void addSpriteImage(Images& images, const std::string& id,
+void addSpriteImage(Images& images,
std::unique_ptr<style::Image> image_,
std::function<void (style::Image&)> onAdded) {
-
+ std::string id = image_->getID();
auto it = images.find(id);
if (it == images.end()) {
// Add new
diff --git a/src/mbgl/sprite/sprite_image_collection.hpp b/src/mbgl/sprite/sprite_image_collection.hpp
index 00e252f74f..44c7bcd411 100644
--- a/src/mbgl/sprite/sprite_image_collection.hpp
+++ b/src/mbgl/sprite/sprite_image_collection.hpp
@@ -12,7 +12,6 @@ namespace mbgl {
using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
void addSpriteImage(Images&,
- const std::string&,
std::unique_ptr<style::Image>,
std::function<void (style::Image&)> onAdded = [] (style::Image&){});
diff --git a/src/mbgl/sprite/sprite_loader.cpp b/src/mbgl/sprite/sprite_loader.cpp
index 86325bba35..7c5fe40e05 100644
--- a/src/mbgl/sprite/sprite_loader.cpp
+++ b/src/mbgl/sprite/sprite_loader.cpp
@@ -89,10 +89,7 @@ void SpriteLoader::emitSpriteLoadedIfComplete() {
loader->worker.invoke(&SpriteLoaderWorker::parse, loader->image, loader->json);
}
-void SpriteLoader::onParsed(Images&& result) {
-
-
-
+void SpriteLoader::onParsed(std::vector<std::unique_ptr<style::Image>>&& result) {
observer->onSpriteLoaded(std::move(result));
}
diff --git a/src/mbgl/sprite/sprite_loader.hpp b/src/mbgl/sprite/sprite_loader.hpp
index dbebede03b..0daf46be9c 100644
--- a/src/mbgl/sprite/sprite_loader.hpp
+++ b/src/mbgl/sprite/sprite_loader.hpp
@@ -6,7 +6,7 @@
#include <string>
#include <map>
#include <set>
-#include <unordered_map>
+#include <vector>
#include <array>
#include <memory>
@@ -18,8 +18,6 @@ class SpriteLoaderObserver;
class SpriteLoader : public util::noncopyable {
public:
- using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
-
SpriteLoader(float pixelRatio);
~SpriteLoader();
@@ -32,7 +30,7 @@ private:
// Invoked by SpriteAtlasWorker
friend class SpriteLoaderWorker;
- void onParsed(Images&& result);
+ void onParsed(std::vector<std::unique_ptr<style::Image>>&&);
void onError(std::exception_ptr);
const float pixelRatio;
diff --git a/src/mbgl/sprite/sprite_loader_observer.hpp b/src/mbgl/sprite/sprite_loader_observer.hpp
index 632c48ea56..c730549c2c 100644
--- a/src/mbgl/sprite/sprite_loader_observer.hpp
+++ b/src/mbgl/sprite/sprite_loader_observer.hpp
@@ -2,8 +2,7 @@
#include <exception>
#include <memory>
-#include <unordered_map>
-#include <string>
+#include <vector>
namespace mbgl {
@@ -13,11 +12,9 @@ class Image;
class SpriteLoaderObserver {
public:
- using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
-
virtual ~SpriteLoaderObserver() = default;
- virtual void onSpriteLoaded(Images&&) {}
+ virtual void onSpriteLoaded(std::vector<std::unique_ptr<style::Image>>&&) {}
virtual void onSpriteError(std::exception_ptr) {}
};
diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp
index c3ed20d03f..1a36e3e990 100644
--- a/src/mbgl/sprite/sprite_parser.cpp
+++ b/src/mbgl/sprite/sprite_parser.cpp
@@ -13,13 +13,14 @@
namespace mbgl {
-std::unique_ptr<style::Image> createStyleImage(const PremultipliedImage& image,
- const uint32_t srcX,
- const uint32_t srcY,
- const uint32_t width,
- const uint32_t height,
- const double ratio,
- const bool sdf) {
+std::unique_ptr<style::Image> createStyleImage(const std::string& id,
+ const PremultipliedImage& image,
+ 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 ||
@@ -37,7 +38,7 @@ std::unique_ptr<style::Image> createStyleImage(const PremultipliedImage& image,
// Copy from the source image into our individual sprite image
PremultipliedImage::copy(image, dstImage, { srcX, srcY }, { 0, 0 }, { width, height });
- return std::make_unique<style::Image>(std::move(dstImage), ratio, sdf);
+ return std::make_unique<style::Image>(id, std::move(dstImage), ratio, sdf);
}
namespace {
@@ -84,7 +85,7 @@ bool getBoolean(const JSValue& value, const char* name, const bool def = false)
} // namespace
-Images parseSprite(const std::string& encodedImage, const std::string& json) {
+std::vector<std::unique_ptr<style::Image>> parseSprite(const std::string& encodedImage, const std::string& json) {
const PremultipliedImage raster = decodeImage(encodedImage);
JSDocument doc;
@@ -96,7 +97,7 @@ Images parseSprite(const std::string& encodedImage, const std::string& json) {
} else if (!doc.IsObject()) {
throw std::runtime_error("Sprite JSON root must be an object");
} else {
- Images images;
+ std::vector<std::unique_ptr<style::Image>> images;
for (const auto& property : doc.GetObject()) {
const std::string name = { property.name.GetString(), property.name.GetStringLength() };
const JSValue& value = property.value;
@@ -109,9 +110,9 @@ Images parseSprite(const std::string& encodedImage, const std::string& json) {
const double pixelRatio = getDouble(value, "pixelRatio", 1);
const bool sdf = getBoolean(value, "sdf", false);
- auto image = createStyleImage(raster, x, y, width, height, pixelRatio, sdf);
+ auto image = createStyleImage(name, raster, x, y, width, height, pixelRatio, sdf);
if (image) {
- images.emplace(name, std::move(image));
+ images.push_back(std::move(image));
}
}
}
diff --git a/src/mbgl/sprite/sprite_parser.hpp b/src/mbgl/sprite/sprite_parser.hpp
index 175ec8a883..f602818d3b 100644
--- a/src/mbgl/sprite/sprite_parser.hpp
+++ b/src/mbgl/sprite/sprite_parser.hpp
@@ -1,13 +1,10 @@
#pragma once
#include <mbgl/util/image.hpp>
-#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/util/variant.hpp>
-#include <mbgl/util/geo.hpp>
#include <string>
#include <memory>
-#include <unordered_map>
+#include <vector>
namespace mbgl {
@@ -16,17 +13,16 @@ class Image;
} // namespace style
// Extracts an individual image from a spritesheet from the given location.
-std::unique_ptr<style::Image> createStyleImage(const PremultipliedImage&,
- uint32_t srcX,
- uint32_t srcY,
- uint32_t srcWidth,
- uint32_t srcHeight,
- double ratio,
- bool sdf);
-
-using Images = std::unordered_map<std::string, std::unique_ptr<style::Image>>;
+std::unique_ptr<style::Image> createStyleImage(const std::string& id,
+ const PremultipliedImage&,
+ uint32_t srcX,
+ uint32_t srcY,
+ uint32_t srcWidth,
+ uint32_t srcHeight,
+ double ratio,
+ bool sdf);
// Parses an image and an associated JSON file and returns the sprite objects.
-Images parseSprite(const std::string& image, const std::string& json);
+std::vector<std::unique_ptr<style::Image>> parseSprite(const std::string& image, const std::string& json);
} // namespace mbgl
diff --git a/src/mbgl/style/image.cpp b/src/mbgl/style/image.cpp
index 606d9907a4..3b35fa76f1 100644
--- a/src/mbgl/style/image.cpp
+++ b/src/mbgl/style/image.cpp
@@ -5,10 +5,15 @@
namespace mbgl {
namespace style {
-Image::Image(PremultipliedImage &&image,
+Image::Image(std::string id,
+ PremultipliedImage &&image,
const float pixelRatio,
bool sdf)
- : impl(makeMutable<Impl>(std::move(image), pixelRatio, sdf)) {
+ : impl(makeMutable<Impl>(std::move(id), std::move(image), pixelRatio, sdf)) {
+}
+
+std::string Image::getID() const {
+ return impl->id;
}
const PremultipliedImage& Image::getImage() const {
diff --git a/src/mbgl/style/image_impl.cpp b/src/mbgl/style/image_impl.cpp
index 910bffa905..ce327262e8 100644
--- a/src/mbgl/style/image_impl.cpp
+++ b/src/mbgl/style/image_impl.cpp
@@ -4,10 +4,12 @@
namespace mbgl {
namespace style {
-Image::Impl::Impl(PremultipliedImage&& image_,
- const float pixelRatio_,
- bool sdf_)
- : image(std::move(image_)),
+Image::Impl::Impl(std::string id_,
+ PremultipliedImage&& image_,
+ const float pixelRatio_,
+ bool sdf_)
+ : id(std::move(id_)),
+ image(std::move(image_)),
pixelRatio(pixelRatio_),
sdf(sdf_) {
diff --git a/src/mbgl/style/image_impl.hpp b/src/mbgl/style/image_impl.hpp
index dce4a6e4c0..b088a23261 100644
--- a/src/mbgl/style/image_impl.hpp
+++ b/src/mbgl/style/image_impl.hpp
@@ -7,7 +7,9 @@ namespace style {
class Image::Impl {
public:
- Impl(PremultipliedImage&&, float pixelRatio, bool sdf = false);
+ Impl(std::string id, PremultipliedImage&&, float pixelRatio, bool sdf = false);
+
+ const std::string id;
PremultipliedImage image;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index f601c4126c..84ee841c06 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -505,9 +505,9 @@ bool Style::isLoaded() const {
return true;
}
-void Style::addImage(const std::string& id, std::unique_ptr<style::Image> image) {
- addSpriteImage(spriteImages, id, std::move(image), [&](style::Image& added) {
- spriteAtlas->addImage(id, added.impl);
+void Style::addImage(std::unique_ptr<style::Image> image) {
+ addSpriteImage(spriteImages, std::move(image), [&](style::Image& added) {
+ spriteAtlas->addImage(added.impl);
observer->onUpdate(Update::Repaint);
});
}
@@ -735,19 +735,11 @@ void Style::onTileError(RenderSource& source, const OverscaledTileID& tileID, st
observer->onResourceError(error);
}
-void Style::onSpriteLoaded(SpriteLoader::Images&& images) {
- // Add images to collection
- Images addedImages;
- for (auto& entry : images) {
- addSpriteImage(spriteImages, entry.first, std::move(entry.second), [&] (style::Image& added) {
- addedImages.emplace(entry.first, std::make_unique<Image>(added));
- });
+void Style::onSpriteLoaded(std::vector<std::unique_ptr<Image>>&& images) {
+ for (auto& image : images) {
+ addImage(std::move(image));
}
-
- // Update render sprite atlas
- spriteAtlas->onSpriteLoaded(std::move(addedImages));
-
- // Update observer
+ spriteAtlas->onSpriteLoaded();
observer->onUpdate(Update::Repaint); // For *-pattern properties.
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index b4ff4f9ac4..bc1d52eed8 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -101,7 +101,7 @@ public:
const RenderLight& getRenderLight() const;
const style::Image* getImage(const std::string&) const;
- void addImage(const std::string&, std::unique_ptr<style::Image>);
+ void addImage(std::unique_ptr<style::Image>);
void removeImage(const std::string&);
RenderData getRenderData(MapDebugOptions, float angle) const;
@@ -151,7 +151,7 @@ private:
// SpriteLoaderObserver implementation.
std::unordered_map<std::string, std::unique_ptr<style::Image>> spriteImages;
- void onSpriteLoaded(SpriteLoaderObserver::Images&&) override;
+ void onSpriteLoaded(std::vector<std::unique_ptr<Image>>&&) override;
void onSpriteError(std::exception_ptr) override;
// SourceObserver implementation.
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index 100187c587..9e85a74c5b 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -17,8 +17,8 @@ using namespace mbgl;
namespace {
std::unique_ptr<style::Image> namedMarker(const std::string& name) {
- PremultipliedImage image = decodeImage(util::read_file("test/fixtures/sprites/" + name));
- return std::make_unique<style::Image>(std::move(image), 1.0);
+ PremultipliedImage image = decodeImage(util::read_file("test/fixtures/sprites/" + name + ".png"));
+ return std::make_unique<style::Image>(name, std::move(image), 1.0);
}
class AnnotationTest {
@@ -43,7 +43,7 @@ TEST(Annotations, SymbolAnnotation) {
AnnotationTest test;
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double>(0, 0), "default_marker" });
test.checkRendering("point_annotation");
@@ -148,7 +148,7 @@ TEST(Annotations, AddMultiple) {
AnnotationTest test;
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { -10, 0 }, "default_marker" });
test::render(test.map, test.view);
@@ -175,8 +175,8 @@ TEST(Annotations, UpdateSymbolAnnotationGeometry) {
AnnotationTest test;
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
- test.map.addAnnotationImage("flipped_marker", namedMarker("flipped_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
+ test.map.addAnnotationImage(namedMarker("flipped_marker"));
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
test::render(test.map, test.view);
@@ -189,8 +189,8 @@ TEST(Annotations, UpdateSymbolAnnotationIcon) {
AnnotationTest test;
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
- test.map.addAnnotationImage("flipped_marker", namedMarker("flipped_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
+ test.map.addAnnotationImage(namedMarker("flipped_marker"));
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
test::render(test.map, test.view);
@@ -271,7 +271,7 @@ TEST(Annotations, RemovePoint) {
AnnotationTest test;
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
test::render(test.map, test.view);
@@ -310,7 +310,7 @@ TEST(Annotations, SwitchStyle) {
AnnotationTest test;
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
test::render(test.map, test.view);
@@ -323,7 +323,7 @@ TEST(Annotations, QueryRenderedFeatures) {
AnnotationTest test;
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 50 }, "default_marker" });
@@ -347,7 +347,7 @@ TEST(Annotations, QueryFractionalZoomLevels) {
auto box = ScreenBox { {}, { double(viewSize.width), double(viewSize.height) } };
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
std::vector<mbgl::AnnotationID> ids;
for (int longitude = 0; longitude < 10; ++longitude) {
@@ -379,7 +379,7 @@ TEST(Annotations, VisibleFeatures) {
auto box = ScreenBox { {}, { double(viewSize.width), double(viewSize.height) } };
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.setLatLngZoom({ 5, 5 }, 3);
std::vector<mbgl::AnnotationID> ids;
@@ -432,7 +432,7 @@ TEST(Annotations, DebugSparse) {
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.setDebug(MapDebugOptions::TileBorders);
test.map.setZoom(1);
- test.map.addAnnotationImage("default_marker", namedMarker("default_marker.png"));
+ test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double>(10, 10), "default_marker" });
test.checkRendering("debug_sparse");
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index c509753d2d..5b7f7c00ff 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -20,7 +20,7 @@ class QueryTest {
public:
QueryTest() {
map.setStyleJSON(util::read_file("test/fixtures/api/query_style.json"));
- map.addImage("test-icon", std::make_unique<style::Image>(
+ map.addImage(std::make_unique<style::Image>("test-icon",
decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")), 1.0));
test::render(map, view);
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 2b7c3c2e3d..be78c8714b 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -445,14 +445,14 @@ TEST(Map, AddImage) {
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
auto decoded1 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
auto decoded2 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
- auto image1 = std::make_unique<style::Image>(std::move(decoded1), 1.0);
- auto image2 = std::make_unique<style::Image>(std::move(decoded2), 1.0);
+ auto image1 = std::make_unique<style::Image>("test-icon", std::move(decoded1), 1.0);
+ auto image2 = std::make_unique<style::Image>("test-icon", std::move(decoded2), 1.0);
// No-op.
- map.addImage("test-icon", std::move(image1));
+ map.addImage(std::move(image1));
map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json"));
- map.addImage("test-icon", std::move(image2));
+ map.addImage(std::move(image2));
test::checkImage("test/fixtures/map/add_icon", test::render(map, test.view));
}
@@ -461,10 +461,10 @@ TEST(Map, RemoveImage) {
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
- auto image = std::make_unique<style::Image>(std::move(decoded), 1.0);
+ auto image = std::make_unique<style::Image>("test-icon", std::move(decoded), 1.0);
map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json"));
- map.addImage("test-icon", std::move(image));
+ map.addImage(std::move(image));
map.removeImage("test-icon");
test::checkImage("test/fixtures/map/remove_icon", test::render(map, test.view));
}
@@ -474,10 +474,10 @@ TEST(Map, GetImage) {
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
- auto image = std::make_unique<style::Image>(std::move(decoded), 1.0);
+ auto image = std::make_unique<style::Image>("test-icon", std::move(decoded), 1.0);
map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json"));
- map.addImage("test-icon", std::move(image));
+ map.addImage(std::move(image));
test::checkImage("test/fixtures/map/get_icon", map.getImage("test-icon")->getImage());
}
diff --git a/test/sprite/sprite_atlas.test.cpp b/test/sprite/sprite_atlas.test.cpp
index 70cdfd9fa6..37a50ddddb 100644
--- a/test/sprite/sprite_atlas.test.cpp
+++ b/test/sprite/sprite_atlas.test.cpp
@@ -22,8 +22,8 @@ TEST(SpriteAtlas, Basic) {
auto images = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"),
util::read_file("test/fixtures/annotations/emerald.json"));
- for (auto& pair : images) {
- atlas.addImage(pair.first, pair.second->impl);
+ for (auto& image : images) {
+ atlas.addImage(image->impl);
}
EXPECT_EQ(1.0f, atlas.getPixelRatio());
@@ -79,8 +79,8 @@ TEST(SpriteAtlas, Size) {
auto images = parseSprite(util::read_file("test/fixtures/annotations/emerald.png"),
util::read_file("test/fixtures/annotations/emerald.json"));
- for (auto& pair : images) {
- atlas.addImage(pair.first, pair.second->impl);
+ for (auto& image : images) {
+ atlas.addImage(image->impl);
}
EXPECT_DOUBLE_EQ(1.4f, atlas.getPixelRatio());
@@ -113,7 +113,7 @@ TEST(SpriteAtlas, Updates) {
EXPECT_EQ(32u, atlas.getSize().width);
EXPECT_EQ(32u, atlas.getSize().height);
- atlas.addImage("one", makeMutable<style::Image::Impl>(PremultipliedImage({ 16, 12 }), 1));
+ atlas.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 12 }), 1));
auto one = *atlas.getIcon("one");
float imagePixelRatio = one.relativePixelRatio * atlas.getPixelRatio();
EXPECT_EQ(0, one.pos.x);
@@ -137,7 +137,7 @@ TEST(SpriteAtlas, Updates) {
for (size_t i = 0; i < image2.bytes(); i++) {
image2.data.get()[i] = 255;
}
- atlas.addImage("one", makeMutable<style::Image::Impl>(std::move(image2), 1));
+ atlas.addImage(makeMutable<style::Image::Impl>("one", std::move(image2), 1));
test::checkImage("test/fixtures/sprite_atlas/updates_after", atlas.getAtlasImage());
}
@@ -146,9 +146,9 @@ TEST(SpriteAtlas, AddRemove) {
FixtureLog log;
SpriteAtlas atlas({ 32, 32 }, 1);
- atlas.addImage("one", makeMutable<style::Image::Impl>(PremultipliedImage({ 16, 16 }), 2));
- atlas.addImage("two", makeMutable<style::Image::Impl>(PremultipliedImage({ 16, 16 }), 2));
- atlas.addImage("three", makeMutable<style::Image::Impl>(PremultipliedImage({ 16, 16 }), 2));
+ atlas.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 16 }), 2));
+ atlas.addImage(makeMutable<style::Image::Impl>("two", PremultipliedImage({ 16, 16 }), 2));
+ atlas.addImage(makeMutable<style::Image::Impl>("three", PremultipliedImage({ 16, 16 }), 2));
atlas.removeImage("one");
atlas.removeImage("two");
@@ -176,12 +176,12 @@ TEST(SpriteAtlas, RemoveReleasesBinPackRect) {
SpriteAtlas atlas({ 36, 36 }, 1);
- atlas.addImage("big", makeMutable<style::Image::Impl>(PremultipliedImage({ 32, 32 }), 1));
+ atlas.addImage(makeMutable<style::Image::Impl>("big", PremultipliedImage({ 32, 32 }), 1));
EXPECT_TRUE(atlas.getIcon("big"));
atlas.removeImage("big");
- atlas.addImage("big", makeMutable<style::Image::Impl>(PremultipliedImage({ 32, 32 }), 1));
+ atlas.addImage(makeMutable<style::Image::Impl>("big", PremultipliedImage({ 32, 32 }), 1));
EXPECT_TRUE(atlas.getIcon("big"));
EXPECT_TRUE(log.empty());
}
diff --git a/test/sprite/sprite_image_collection.test.cpp b/test/sprite/sprite_image_collection.test.cpp
index 51ea20fdf3..788d7a59d5 100644
--- a/test/sprite/sprite_image_collection.test.cpp
+++ b/test/sprite/sprite_image_collection.test.cpp
@@ -14,16 +14,16 @@ TEST(SpriteImageCollection, OtherPixelRatio) {
Images images;
// Adding mismatched sprite image
- addSpriteImage(images, "one", std::make_unique<style::Image>(PremultipliedImage({ 8, 8 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("one", PremultipliedImage({ 8, 8 }), 2));
}
TEST(SpriteImageCollection, Replace) {
FixtureLog log;
Images images;
- addSpriteImage(images, "sprite", std::make_unique<style::Image>(PremultipliedImage({ 16, 16 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 16, 16 }), 2));
auto image = images.find("sprite")->second.get();
- addSpriteImage(images, "sprite", std::make_unique<style::Image>(PremultipliedImage({ 16, 16 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 16, 16 }), 2));
EXPECT_NE(image, images.find("sprite")->second.get());
}
@@ -31,8 +31,8 @@ TEST(SpriteImageCollection, ReplaceWithDifferentDimensions) {
FixtureLog log;
Images images;
- addSpriteImage(images, "sprite", std::make_unique<style::Image>(PremultipliedImage({ 16, 16 }), 2));
- addSpriteImage(images, "sprite", std::make_unique<style::Image>(PremultipliedImage({ 18, 18 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 16, 16 }), 2));
+ addSpriteImage(images, std::make_unique<style::Image>("sprite", PremultipliedImage({ 18, 18 }), 2));
EXPECT_EQ(1u, log.count({
EventSeverity::Warning,
diff --git a/test/sprite/sprite_loader.test.cpp b/test/sprite/sprite_loader.test.cpp
index 99f44e57e4..3691572265 100644
--- a/test/sprite/sprite_loader.test.cpp
+++ b/test/sprite/sprite_loader.test.cpp
@@ -18,7 +18,7 @@ using namespace mbgl::style;
class StubSpriteLoaderObserver : public SpriteLoaderObserver {
public:
- void onSpriteLoaded(Images&& images) override {
+ void onSpriteLoaded(std::vector<std::unique_ptr<style::Image>>&& images) override {
if (spriteLoaded) spriteLoaded(std::move(images));
}
@@ -26,7 +26,7 @@ public:
if (spriteError) spriteError(error);
}
- std::function<void (Images&&)> spriteLoaded;
+ std::function<void (std::vector<std::unique_ptr<style::Image>>&&)> spriteLoaded;
std::function<void (std::exception_ptr)> spriteError;
};
@@ -94,8 +94,8 @@ TEST(SpriteLoader, LoadingSuccess) {
test.end();
};
- test.observer.spriteLoaded = [&] (SpriteLoaderObserver::Images&& images) {
- EXPECT_EQ(images.size(), Images::size_type(367));
+ test.observer.spriteLoaded = [&] (std::vector<std::unique_ptr<style::Image>>&& images) {
+ EXPECT_EQ(images.size(), 367u);
test.end();
};
@@ -171,7 +171,7 @@ TEST(SpriteLoader, LoadingCancel) {
return optional<Response>();
};
- test.observer.spriteLoaded = [&] (const SpriteLoaderObserver::Images&) {
+ test.observer.spriteLoaded = [&] (const std::vector<std::unique_ptr<style::Image>>&) {
FAIL() << "Should never be called";
};
diff --git a/test/sprite/sprite_parser.test.cpp b/test/sprite/sprite_parser.test.cpp
index 19c6b914a8..aad80b3d81 100644
--- a/test/sprite/sprite_parser.test.cpp
+++ b/test/sprite/sprite_parser.test.cpp
@@ -27,19 +27,19 @@ TEST(Sprite, SpriteImageCreationInvalid) {
ASSERT_EQ(200u, image_1x.size.width);
ASSERT_EQ(299u, image_1x.size.height);
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 0, 16, 1, false)); // width == 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, 0, 1, false)); // height == 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, -1, 16, 1, false)); // width < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, -1, 1, false)); // height < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 1, 1, 0, false)); // ratio == 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 1, 1, -1, false)); // ratio < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 1, 1, 23, false)); // ratio too large
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 2048, 16, 1, false)); // too wide
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, 1025, 1, false)); // too tall
- ASSERT_EQ(nullptr, createStyleImage(image_1x, -1, 0, 16, 16, 1, false)); // srcX < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, -1, 16, 16, 1, false)); // srcY < 0
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, image_1x.size.width + 1, 16, 1, false)); // right edge out of bounds
- ASSERT_EQ(nullptr, createStyleImage(image_1x, 0, 0, 16, image_1x.size.height + 1, 1, false)); // bottom edge out of bounds
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 0, 16, 1, false)); // width == 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 16, 0, 1, false)); // height == 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, -1, 16, 1, false)); // width < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 16, -1, 1, false)); // height < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 1, 1, 0, false)); // ratio == 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 1, 1, -1, false)); // ratio < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 1, 1, 23, false)); // ratio too large
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 2048, 16, 1, false)); // too wide
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 16, 1025, 1, false)); // too tall
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, -1, 0, 16, 16, 1, false)); // srcX < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, -1, 16, 16, 1, false)); // srcY < 0
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, image_1x.size.width + 1, 16, 1, false)); // right edge out of bounds
+ ASSERT_EQ(nullptr, createStyleImage("test", image_1x, 0, 0, 16, image_1x.size.height + 1, 1, false)); // bottom edge out of bounds
EXPECT_EQ(1u, log.count({
EventSeverity::Error,
@@ -141,7 +141,7 @@ TEST(Sprite, SpriteImageCreation1x) {
ASSERT_EQ(299u, image_1x.size.height);
{ // "museum_icon":{"x":177,"y":187,"width":18,"height":18,"pixelRatio":1,"sdf":false}
- const auto sprite = createStyleImage(image_1x, 177, 187, 18, 18, 1, false);
+ const auto sprite = createStyleImage("test", image_1x, 177, 187, 18, 18, 1, false);
ASSERT_TRUE(sprite.get());
EXPECT_EQ(18, sprite->getWidth());
EXPECT_EQ(18, sprite->getHeight());
@@ -157,7 +157,7 @@ TEST(Sprite, SpriteImageCreation2x) {
const PremultipliedImage image_2x = decodeImage(util::read_file("test/fixtures/annotations/emerald@2x.png"));
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
- const auto sprite = createStyleImage(image_2x, 354, 374, 36, 36, 2, false);
+ const auto sprite = createStyleImage("test", image_2x, 354, 374, 36, 36, 2, false);
ASSERT_TRUE(sprite.get());
EXPECT_EQ(18, sprite->getWidth());
EXPECT_EQ(18, sprite->getHeight());
@@ -172,7 +172,7 @@ TEST(Sprite, SpriteImageCreation1_5x) {
const PremultipliedImage image_2x = decodeImage(util::read_file("test/fixtures/annotations/emerald@2x.png"));
// "museum_icon":{"x":354,"y":374,"width":36,"height":36,"pixelRatio":2,"sdf":false}
- const auto sprite = createStyleImage(image_2x, 354, 374, 36, 36, 1.5, false);
+ const auto sprite = createStyleImage("test", image_2x, 354, 374, 36, 36, 1.5, false);
ASSERT_TRUE(sprite.get());
EXPECT_EQ(24, sprite->getWidth());
EXPECT_EQ(24, sprite->getHeight());
@@ -183,7 +183,7 @@ TEST(Sprite, SpriteImageCreation1_5x) {
sprite->getImage());
// "hospital_icon":{"x":314,"y":518,"width":36,"height":36,"pixelRatio":2,"sdf":false}
- const auto sprite2 = createStyleImage(image_2x, 314, 518, 35, 35, 1.5, false);
+ const auto sprite2 = createStyleImage("test", image_2x, 314, 518, 35, 35, 1.5, false);
ASSERT_TRUE(sprite2.get());
EXPECT_EQ(float(35 / 1.5), sprite2->getWidth());
EXPECT_EQ(float(35 / 1.5), sprite2->getHeight());
@@ -202,7 +202,7 @@ TEST(Sprite, SpriteParsing) {
std::set<std::string> names;
std::transform(images.begin(), images.end(), std::inserter(names, names.begin()),
- [](const auto& pair) { return pair.first; });
+ [](const auto& image) { return image->getID(); });
EXPECT_EQ(std::set<std::string>({ "airfield_icon",
"airport_icon",
@@ -280,7 +280,7 @@ TEST(Sprite, SpriteParsing) {
names);
{
- auto& sprite = images.find("generic-metro")->second;
+ auto& sprite = *std::find_if(images.begin(), images.end(), [] (const auto& image) { return image->getID() == "generic-metro"; });
EXPECT_EQ(18, sprite->getWidth());
EXPECT_EQ(18, sprite->getHeight());
EXPECT_EQ(18u, sprite->getImage().size.width);
diff --git a/test/style/style_image.test.cpp b/test/style/style_image.test.cpp
index 34814bee88..c535397be3 100644
--- a/test/style/style_image.test.cpp
+++ b/test/style/style_image.test.cpp
@@ -8,7 +8,7 @@ using namespace mbgl;
TEST(StyleImage, ZeroWidth) {
try {
- style::Image(PremultipliedImage({ 0, 16 }), 2.0);
+ style::Image("test", PremultipliedImage({ 0, 16 }), 2.0);
FAIL() << "Expected exception";
} catch (util::SpriteImageException& ex) {
EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
@@ -17,7 +17,7 @@ TEST(StyleImage, ZeroWidth) {
TEST(StyleImage, ZeroHeight) {
try {
- style::Image(PremultipliedImage({ 16, 0 }), 2.0);
+ style::Image("test", PremultipliedImage({ 16, 0 }), 2.0);
FAIL() << "Expected exception";
} catch (util::SpriteImageException& ex) {
EXPECT_STREQ("Sprite image dimensions may not be zero", ex.what());
@@ -26,7 +26,7 @@ TEST(StyleImage, ZeroHeight) {
TEST(StyleImage, ZeroRatio) {
try {
- style::Image(PremultipliedImage({ 16, 16 }), 0.0);
+ style::Image("test", PremultipliedImage({ 16, 16 }), 0.0);
FAIL() << "Expected exception";
} catch (util::SpriteImageException& ex) {
EXPECT_STREQ("Sprite pixelRatio may not be <= 0", ex.what());
@@ -34,7 +34,7 @@ TEST(StyleImage, ZeroRatio) {
}
TEST(StyleImage, Retina) {
- style::Image image(PremultipliedImage({ 32, 24 }), 2.0);
+ style::Image image("test", PremultipliedImage({ 32, 24 }), 2.0);
EXPECT_EQ(16, image.getWidth());
EXPECT_EQ(32u, image.getImage().size.width);
EXPECT_EQ(12, image.getHeight());
@@ -43,7 +43,7 @@ TEST(StyleImage, Retina) {
}
TEST(StyleImage, FractionalRatio) {
- style::Image image(PremultipliedImage({ 20, 12 }), 1.5);
+ style::Image image("test", PremultipliedImage({ 20, 12 }), 1.5);
EXPECT_EQ(float(20.0 / 1.5), image.getWidth());
EXPECT_EQ(20u, image.getImage().size.width);
EXPECT_EQ(float(12.0 / 1.5), image.getHeight());
diff --git a/test/text/quads.test.cpp b/test/text/quads.test.cpp
index 6b2b0e7586..dcc51bf6a3 100644
--- a/test/text/quads.test.cpp
+++ b/test/text/quads.test.cpp
@@ -14,7 +14,7 @@ TEST(getIconQuads, normal) {
Anchor anchor(2.0, 3.0, 0.0, 0.5f, 0);
SpriteAtlasElement image = {
Rect<uint16_t>( 0, 0, 15, 11 ),
- style::Image::Impl(PremultipliedImage({1,1}), 1.0),
+ style::Image::Impl("test", PremultipliedImage({1,1}), 1.0),
{ 0, 0 },
1.0f
};
@@ -47,7 +47,7 @@ TEST(getIconQuads, style) {
Anchor anchor(0.0, 0.0, 0.0, 0.5f, 0);
SpriteAtlasElement image = {
Rect<uint16_t>( 0, 0, 20, 20 ),
- style::Image::Impl(PremultipliedImage({1,1}), 1.0),
+ style::Image::Impl("test", PremultipliedImage({1,1}), 1.0),
{ 0, 0 },
1.0f
};