[all] Rationalize style::Image
A style has a collection of images, just as it has collections of sources and layers. * Name things appropriately * Use std::unique_ptr
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <mbgl/sprite/sprite_parser.hpp>
|
||||
#include <mbgl/sprite/sprite_image.hpp>
|
||||
#include <mbgl/style/image.hpp>
|
||||
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
SpriteImagePtr createSpriteImage(const PremultipliedImage& image,
|
||||
std::unique_ptr<style::Image> createStyleImage(const PremultipliedImage& image,
|
||||
const uint32_t srcX,
|
||||
const uint32_t srcY,
|
||||
const uint32_t width,
|
||||
@@ -37,7 +37,7 @@ SpriteImagePtr createSpriteImage(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<const SpriteImage>(std::move(dstImage), ratio, sdf);
|
||||
return std::make_unique<style::Image>(std::move(dstImage), ratio, sdf);
|
||||
}
|
||||
|
||||
namespace {
|
||||
@@ -84,8 +84,8 @@ bool getBoolean(const JSValue& value, const char* name, const bool def = false)
|
||||
|
||||
} // namespace
|
||||
|
||||
Sprites parseSprite(const std::string& image, const std::string& json) {
|
||||
const PremultipliedImage raster = decodeImage(image);
|
||||
Images parseSprite(const std::string& encodedImage, const std::string& json) {
|
||||
const PremultipliedImage raster = decodeImage(encodedImage);
|
||||
|
||||
JSDocument doc;
|
||||
doc.Parse<0>(json.c_str());
|
||||
@@ -96,7 +96,7 @@ Sprites parseSprite(const std::string& image, const std::string& json) {
|
||||
} else if (!doc.IsObject()) {
|
||||
throw std::runtime_error("Sprite JSON root must be an object");
|
||||
} else {
|
||||
Sprites sprites;
|
||||
Images images;
|
||||
for (const auto& property : doc.GetObject()) {
|
||||
const std::string name = { property.name.GetString(), property.name.GetStringLength() };
|
||||
const JSValue& value = property.value;
|
||||
@@ -109,13 +109,13 @@ Sprites parseSprite(const std::string& image, const std::string& json) {
|
||||
const double pixelRatio = getDouble(value, "pixelRatio", 1);
|
||||
const bool sdf = getBoolean(value, "sdf", false);
|
||||
|
||||
auto sprite = createSpriteImage(raster, x, y, width, height, pixelRatio, sdf);
|
||||
if (sprite) {
|
||||
sprites.emplace(name, sprite);
|
||||
auto image = createStyleImage(raster, x, y, width, height, pixelRatio, sdf);
|
||||
if (image) {
|
||||
images.emplace(name, std::move(image));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sprites;
|
||||
return images;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user