diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-01-18 17:08:55 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-01-19 16:06:36 +0200 |
commit | a361ce47a19d37b96b48cd605c62c5ab79bba462 (patch) | |
tree | 269a1ee9996d9a69a398438ae42fbe16c78025b1 /platform/default/webp_reader.cpp | |
parent | d004bb275ae3ea60bb6c2febd6fa22f1f51c3993 (diff) | |
download | qtlocation-mapboxgl-a361ce47a19d37b96b48cd605c62c5ab79bba462.tar.gz |
[linux] Added WebP tile support
- Android support is currently disabled due to a libwebp build issue.
- iOS and OS X support will appear after the next Mapbox iOS SDK release.
Related: #https://github.com/mapbox/mapbox-gl-native/issues/2354
Diffstat (limited to 'platform/default/webp_reader.cpp')
-rw-r--r-- | platform/default/webp_reader.cpp | 27 |
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 |