summaryrefslogtreecommitdiff
path: root/platform/default/webp_reader.cpp
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-01-20 00:07:04 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-01-20 10:35:44 +0200
commit9cd9065031f7d2af62e437f2b32b44207484baca (patch)
tree7eaa326b4d183fc1d26ae64492588bbeb7a4b615 /platform/default/webp_reader.cpp
parentd34f8eb674b9753c47616f37ae88ff7a02f61ba0 (diff)
downloadqtlocation-mapboxgl-9cd9065031f7d2af62e437f2b32b44207484baca.tar.gz
Revert "Revert WebP support due to broken builds"
This reverts commit 6709bdcacd5a45a10b554f3f225206c9494e5e43. There was an issue with the script that removes '-lwebp' from WebP linker flags, since we're statically linking. This is now fixed.
Diffstat (limited to 'platform/default/webp_reader.cpp')
-rw-r--r--platform/default/webp_reader.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/platform/default/webp_reader.cpp b/platform/default/webp_reader.cpp
new file mode 100644
index 0000000000..37d23da110
--- /dev/null
+++ b/platform/default/webp_reader.cpp
@@ -0,0 +1,27 @@
+#include <mbgl/util/image.hpp>
+#include <mbgl/util/premultiply.hpp>
+#include <mbgl/platform/log.hpp>
+
+extern "C"
+{
+#include <webp/decode.h>
+}
+
+namespace mbgl {
+
+PremultipliedImage decodeWebP(const uint8_t* data, size_t size) {
+ int width = 0, height = 0;
+ if (WebPGetInfo(data, size, &width, &height) == 0) {
+ throw std::runtime_error("failed to retrieve WebP basic header information");
+ }
+
+ std::unique_ptr<uint8_t[]> webp(WebPDecodeRGBA(data, size, &width, &height));
+ if (!webp) {
+ throw std::runtime_error("failed to decode WebP data");
+ }
+
+ UnassociatedImage image { size_t(width), size_t(height), std::move(webp) };
+ return util::premultiply(std::move(image));
+}
+
+} // namespace mbgl