diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-01-20 00:07:04 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-01-20 10:35:44 +0200 |
commit | 9cd9065031f7d2af62e437f2b32b44207484baca (patch) | |
tree | 7eaa326b4d183fc1d26ae64492588bbeb7a4b615 /platform/default/image.cpp | |
parent | d34f8eb674b9753c47616f37ae88ff7a02f61ba0 (diff) | |
download | qtlocation-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/image.cpp')
-rw-r--r-- | platform/default/image.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/platform/default/image.cpp b/platform/default/image.cpp index bf8071af5c..71fb5414b3 100644 --- a/platform/default/image.cpp +++ b/platform/default/image.cpp @@ -70,6 +70,10 @@ std::string encodePNG(const PremultipliedImage& pre) { return result; } +#if !defined(__ANDROID__) && !defined(__APPLE__) +PremultipliedImage decodeWebP(const uint8_t*, size_t); +#endif // !defined(__ANDROID__) && !defined(__APPLE__) + PremultipliedImage decodePNG(const uint8_t*, size_t); PremultipliedImage decodeJPEG(const uint8_t*, size_t); @@ -77,16 +81,26 @@ PremultipliedImage decodeImage(const std::string& string) { const uint8_t* data = reinterpret_cast<const uint8_t*>(string.data()); const size_t size = string.size(); +#if !defined(__ANDROID__) && !defined(__APPLE__) + if (size >= 12) { + uint32_t riff_magic = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; + uint32_t webp_magic = (data[8] << 24) | (data[9] << 16) | (data[10] << 8) | data[11]; + if (riff_magic == 0x52494646 && webp_magic == 0x57454250) { + return decodeWebP(data, size); + } + } +#endif // !defined(__ANDROID__) && !defined(__APPLE__) + if (size >= 4) { - unsigned int magic = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; + uint32_t magic = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; if (magic == 0x89504E47U) { return decodePNG(data, size); } } if (size >= 2) { - unsigned int magic = ((data[0] << 8) | data[1]) & 0xffff; - if (magic == 0xffd8) { + uint16_t magic = ((data[0] << 8) | data[1]) & 0xffff; + if (magic == 0xFFD8) { return decodeJPEG(data, size); } } |