diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-01-25 16:09:11 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-01-26 15:26:55 +0100 |
commit | 46fe0df2a2a2b4c28d8579245c0caad258a8b512 (patch) | |
tree | 53eb17f6b31be7f738a86c02324ae38340c091af | |
parent | be43310b6ff5465e6717128b577f6e61c0335c44 (diff) | |
download | qtlocation-mapboxgl-46fe0df2a2a2b4c28d8579245c0caad258a8b512.tar.gz |
[core] add clone() call to Image objects
-rw-r--r-- | include/mbgl/util/image.hpp | 7 | ||||
-rw-r--r-- | platform/default/png_writer.cpp | 8 |
2 files changed, 9 insertions, 6 deletions
diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp index 1d84d4824a..2de7646837 100644 --- a/include/mbgl/util/image.hpp +++ b/include/mbgl/util/image.hpp @@ -48,6 +48,13 @@ public: return size && data.get() != nullptr; } + template <typename T = Image> + T clone() const { + T copy(size); + std::copy(data.get(), data.get() + bytes(), copy.data.get()); + return copy; + } + size_t stride() const { return channels * size.width; } size_t bytes() const { return stride() * size.height; } diff --git a/platform/default/png_writer.cpp b/platform/default/png_writer.cpp index a620d8b986..13d60c34fe 100644 --- a/platform/default/png_writer.cpp +++ b/platform/default/png_writer.cpp @@ -39,12 +39,8 @@ namespace mbgl { // Encode PNGs without libpng. std::string encodePNG(const PremultipliedImage& pre) { - const UnassociatedImage src = [&pre] { - // Make copy of the image so that we can unpremultiply it. - PremultipliedImage copy(pre.size); - std::copy(pre.data.get(), pre.data.get() + pre.bytes(), copy.data.get()); - return util::unpremultiply(std::move(copy)); - }(); + // Make copy of the image so that we can unpremultiply it. + const auto src = util::unpremultiply(pre.clone()); // PNG magic bytes const char preamble[8] = { char(0x89), 'P', 'N', 'G', '\r', '\n', 0x1a, '\n' }; |