diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 3594b55be..17498ec42 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -511,6 +511,7 @@ set(MBGL_CORE_FILES include/mbgl/util/noncopyable.hpp include/mbgl/util/optional.hpp include/mbgl/util/platform.hpp + include/mbgl/util/premultiply.hpp include/mbgl/util/projection.hpp include/mbgl/util/range.hpp include/mbgl/util/run_loop.hpp @@ -565,7 +566,6 @@ set(MBGL_CORE_FILES src/mbgl/util/offscreen_texture.cpp src/mbgl/util/offscreen_texture.hpp src/mbgl/util/premultiply.cpp - src/mbgl/util/premultiply.hpp src/mbgl/util/rapidjson.hpp src/mbgl/util/rect.hpp src/mbgl/util/std.hpp diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp index c019bb949..a41b8462b 100644 --- a/include/mbgl/util/image.hpp +++ b/include/mbgl/util/image.hpp @@ -40,11 +40,14 @@ public: Image(Image&& o) : size(o.size), - data(std::move(o.data)) {} + data(std::move(o.data)) { + o.size.width = o.size.height = 0; + } Image& operator=(Image&& o) { size = o.size; data = std::move(o.data); + o.size.width = o.size.height = 0; return *this; } diff --git a/src/mbgl/util/premultiply.hpp b/include/mbgl/util/premultiply.hpp similarity index 100% rename from src/mbgl/util/premultiply.hpp rename to include/mbgl/util/premultiply.hpp diff --git a/mapbox-gl-js b/mapbox-gl-js index d3b39cbba..431bce18e 160000 --- a/mapbox-gl-js +++ b/mapbox-gl-js @@ -1 +1 @@ -Subproject commit d3b39cbba4f09d26ef51159aa56270e67006c51b +Subproject commit 431bce18e1b3a26851b8e5037b1017ba35c41117 diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index ab49ca640..1c8bf6d1d 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -682,8 +683,9 @@ void NodeMap::AddImage(const Nan::FunctionCallbackInfo& info) { std::unique_ptr data = std::make_unique(imageLength); std::copy(imageDataBuffer, imageDataBuffer + imageLength, data.get()); - mbgl::PremultipliedImage cPremultipliedImage({ imageWidth, imageHeight}, std::move(data)); - + + 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(std::move(cPremultipliedImage), pixelRatio)); } diff --git a/platform/node/test/suite_implementation.js b/platform/node/test/suite_implementation.js index a5e96f726..8ac372b7c 100644 --- a/platform/node/test/suite_implementation.js +++ b/platform/node/test/suite_implementation.js @@ -76,7 +76,7 @@ module.exports = function (style, options, callback) { map.addImage(operation[1], img.data, { height: img.height, width: img.width, - pixelRatio: 1 + pixelRatio: operation[3] || 1 }); applyOperations(operations.slice(1), callback); diff --git a/test/util/image.test.cpp b/test/util/image.test.cpp index 0cd4a7d8a..4cacf8925 100644 --- a/test/util/image.test.cpp +++ b/test/util/image.test.cpp @@ -115,6 +115,21 @@ TEST(Image, Copy) { EXPECT_THROW(PremultipliedImage::copy(src10, dst10, {0, 0}, {0, 1}, {0, max}), std::out_of_range); } +TEST(Image, Move) { + UnassociatedImage rgba({ 1, 1 }); + rgba.data[0] = 255; + rgba.data[1] = 254; + rgba.data[2] = 253; + rgba.data[3] = 128; + + auto moved = std::move(rgba); + + EXPECT_EQ(0u, rgba.size.width); + EXPECT_EQ(nullptr, rgba.data.get()); + EXPECT_EQ(254, moved.data[1]); + EXPECT_EQ(1u, moved.size.width); +} + TEST(Image, Premultiply) { UnassociatedImage rgba({ 1, 1 }); rgba.data[0] = 255;