[Qt] WebP support

This commit is contained in:
Bruno de Oliveira Abinader
2016-01-19 18:34:32 +02:00
committed by Thiago Marcos P. Santos
parent 8ff17ffc9a
commit 01b06c2301
3 changed files with 21 additions and 9 deletions

View File

@@ -42,6 +42,7 @@
'../default/sqlite3.cpp',
'../default/string_stdlib.cpp',
'../default/thread.cpp',
'../default/webp_reader.cpp',
'include/qmapbox.hpp',
'include/qmapboxgl.hpp',
'qmapbox.qrc',
@@ -70,6 +71,7 @@
'<@(rapidjson_cflags)',
'<@(sqlite_cflags)',
'<@(variant_cflags)',
'<@(webp_cflags)',
'-Wno-error', # TODO: eliminate
'-fPIC',
],
@@ -78,11 +80,13 @@
'<@(opengl_ldflags)',
'<@(qt_ldflags)',
'<@(sqlite_ldflags)',
'<@(webp_ldflags)',
'<@(zlib_ldflags)',
],
'libraries': [
'<@(nunicode_static_libs)',
'<@(sqlite_static_libs)',
'<@(webp_static_libs)',
'<@(zlib_static_libs)',
],
},

View File

@@ -9,6 +9,7 @@ RAPIDJSON_VERSION=1.0.2
SQLITE_VERSION=3.9.1
VARIANT_VERSION=1.1.0
ZLIB_VERSION=system
WEBP_VERSION=0.5.0
if [ "$MASON_PLATFORM" == "osx" ]; then
function print_opengl_flags {

View File

@@ -19,10 +19,23 @@ std::string encodePNG(const PremultipliedImage& pre) {
return std::string(array.constData(), array.size());
}
PremultipliedImage decodeWebP(const uint8_t*, size_t);
PremultipliedImage decodeImage(const std::string& string) {
const uint8_t* data = reinterpret_cast<const uint8_t*>(string.data());
const size_t size = string.size();
// FIXME: Use Qt WebP decoder plugin.
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);
}
}
PremultipliedImage decodeImage(const std::string& data) {
QImage image =
QImage::fromData(reinterpret_cast<const uint8_t*>(data.data()), data.size())
QImage::fromData(data, size)
.rgbSwapped()
.convertToFormat(QImage::Format_ARGB32_Premultiplied);
@@ -30,16 +43,10 @@ PremultipliedImage decodeImage(const std::string& data) {
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;
return { size_t(image.width()), size_t(image.height()), std::move(img) };
}
}