summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-08-04 15:36:18 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-04-20 20:55:51 +0300
commit2af3863b5716b290c852e2dae93ca023cb6bf0f4 (patch)
tree116171840391847e19121027ec6826db71040ef2 /platform
parent7a44b95627f4875756b2701b65eb7e6a33ab7c7f (diff)
downloadqtlocation-mapboxgl-2af3863b5716b290c852e2dae93ca023cb6bf0f4.tar.gz
[Qt] Use QImage for decompressing images
Needs to explicitly define the target platform, otherwise it will use linux/osx.
Diffstat (limited to 'platform')
-rw-r--r--platform/qt/src/image.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/platform/qt/src/image.cpp b/platform/qt/src/image.cpp
new file mode 100644
index 0000000000..60ea84e50f
--- /dev/null
+++ b/platform/qt/src/image.cpp
@@ -0,0 +1,45 @@
+#include <mbgl/util/image.hpp>
+
+#include <QBuffer>
+#include <QByteArray>
+#include <QImage>
+
+namespace mbgl {
+
+std::string encodePNG(const PremultipliedImage& pre) {
+ QImage image(pre.data.get(), pre.width, pre.height,
+ QImage::Format_ARGB32_Premultiplied);
+
+ QByteArray array;
+ QBuffer buffer(&array);
+
+ buffer.open(QIODevice::WriteOnly);
+ image.rgbSwapped().save(&buffer, "PNG");
+
+ return std::string(array.constData(), array.size());
+}
+
+
+PremultipliedImage decodeImage(const std::string& data) {
+ QImage image =
+ QImage::fromData(reinterpret_cast<const uint8_t*>(data.data()), data.size())
+ .rgbSwapped()
+ .convertToFormat(QImage::Format_ARGB32_Premultiplied);
+
+ if (image.isNull()) {
+ throw std::runtime_error("Unsupported image type");
+ }
+
+ PremultipliedImage pre;
+ pre.width = image.width();
+ pre.height = image.height();
+
+ auto img = std::make_unique<uint8_t[]>(image.byteCount());
+ memcpy(img.get(), image.constBits(), image.byteCount());
+
+ pre.data = std::move(img);
+
+ return pre;
+}
+
+}