|
|
|
|
@ -1,8 +1,18 @@
|
|
|
|
|
#include "lottieicon.h" |
|
|
|
|
#include "debug_ui.h" |
|
|
|
|
#include <rlottie_capi.h> |
|
|
|
|
#include <zlib.h> |
|
|
|
|
#include <cstring> |
|
|
|
|
|
|
|
|
|
#ifdef RLOTTIE_HAS_WARNING_CALLBACK |
|
|
|
|
static thread_local QStringList *lottieLoadWarnings = nullptr; |
|
|
|
|
|
|
|
|
|
static void logLottieWarning(const char *message) { |
|
|
|
|
if (lottieLoadWarnings) lottieLoadWarnings->append(QString::fromUtf8(message)); |
|
|
|
|
else GUI_WARN("LottieIcon: rlottie: %s", message); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
static QByteArray unpackGzip(const QByteArray &data) { |
|
|
|
|
if (data.isEmpty()) return {}; |
|
|
|
|
z_stream strm = {}; |
|
|
|
|
@ -33,14 +43,25 @@ static QByteArray unpackGzip(const QByteArray &data) {
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LottieIcon::LottieIcon(const QByteArray &tgsData, const QString &key) { |
|
|
|
|
LottieIcon::LottieIcon(const QByteArray &tgsData, const QString &key) : m_key(key) { |
|
|
|
|
#ifdef RLOTTIE_HAS_WARNING_CALLBACK |
|
|
|
|
lottie_set_warning_callback(logLottieWarning); |
|
|
|
|
#endif |
|
|
|
|
m_tgsSize = (int)tgsData.size(); |
|
|
|
|
QByteArray json = unpackGzip(tgsData); |
|
|
|
|
if (json.isEmpty()) return; |
|
|
|
|
|
|
|
|
|
m_jsonData = json; |
|
|
|
|
QByteArray keyUtf8 = key.toUtf8(); |
|
|
|
|
#ifdef RLOTTIE_HAS_WARNING_CALLBACK |
|
|
|
|
// При старте настройки общего журнала применяются после загрузки иконок.
|
|
|
|
|
QStringList *previousWarnings = lottieLoadWarnings; |
|
|
|
|
lottieLoadWarnings = &m_loadWarnings; |
|
|
|
|
#endif |
|
|
|
|
m_anim = lottie_animation_from_data(m_jsonData.constData(), keyUtf8.constData(), ""); |
|
|
|
|
#ifdef RLOTTIE_HAS_WARNING_CALLBACK |
|
|
|
|
lottieLoadWarnings = previousWarnings; |
|
|
|
|
#endif |
|
|
|
|
if (!m_anim) return; |
|
|
|
|
|
|
|
|
|
lottie_animation_get_size(m_anim, &m_w, &m_h); |
|
|
|
|
@ -54,6 +75,10 @@ LottieIcon::~LottieIcon() {
|
|
|
|
|
if (m_anim) lottie_animation_destroy(m_anim); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LottieIcon::logWarnings() const { |
|
|
|
|
for (const QString &message : m_loadWarnings) GUI_WARN("LottieIcon: path=%s rlottie: %s", qPrintable(m_key), qPrintable(message)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QImage LottieIcon::renderFrame(int frameNum, QSize targetSize) const { |
|
|
|
|
if (!m_valid || targetSize.width() <= 0 || targetSize.height() <= 0) |
|
|
|
|
return QImage(); |
|
|
|
|
|