QtLottie: Add precomp assets parsing.

This commit is contained in:
John Preston 2019-05-02 11:23:32 +04:00
parent f9a32dc70f
commit 2caa3e3def
6 changed files with 160 additions and 7 deletions

View File

@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtBodymovin/private/bmbase_p.h>
#include <QtBodymovin/private/bmlayer_p.h>
#include <QtBodymovin/private/bmasset_p.h>
#include "rasterrenderer/lottierasterrenderer.h"
@ -138,8 +139,14 @@ void Animation::parse(const QByteArray &content) {
}
}
if (root.value(qstr("assets")).toArray().count()) {
_unsupported = true;
const auto assets = root.value(qstr("assets")).toArray();
for (const auto &entry : assets) {
if (const auto asset = BMAsset::construct(entry.toObject())) {
_assetIndexById.emplace(asset->id(), _assets.size());
_assets.emplace_back(asset);
} else {
_unsupported = true;
}
}
if (root.value(qstr("chars")).toArray().count()) {

View File

@ -11,12 +11,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/flat_map.h"
#include <crl/crl_time.h>
#include <QString>
#include <QHash>
#include <QPainter>
class QImage;
class QString;
class QByteArray;
class BMBase;
class BMLayer;
class BMAsset;
namespace Lottie {
@ -77,6 +78,8 @@ private:
PlaybackOptions _options;
std::unique_ptr<BMBase> _treeBlueprint;
std::vector<std::unique_ptr<BMAsset>> _assets;
base::flat_map<QString, int> _assetIndexById;
};

@ -1 +1 @@
Subproject commit 270cd6f31b9c67bdf2ff7cd961df8e5bb86e137c
Subproject commit 44fa230637dafe2fe01ffc6e93c3e3f5841dcc5a

View File

@ -0,0 +1,72 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the lottie-qt module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef BMASSET_P_H
#define BMASSET_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtBodymovin/private/bmbase_p.h>
QT_BEGIN_NAMESPACE
class LottieRenderer;
class BODYMOVIN_EXPORT BMAsset : public BMBase
{
public:
BMAsset() = default;
explicit BMAsset (const BMAsset &other) = default;
~BMAsset() = default;
BMBase *clone() const override;
static BMAsset *construct(QJsonObject definition);
void parse(const QJsonObject &definition) override;
QString id() const;
private:
QString m_id;
};
QT_END_NAMESPACE
#endif // BMASSET_P_H

View File

@ -0,0 +1,67 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the lottie-qt module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef BMPRECOMPASSET_P_H
#define BMPRECOMPASSET_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtBodymovin/private/bmasset_p.h>
QT_BEGIN_NAMESPACE
class LottieRenderer;
class BODYMOVIN_EXPORT BMPreCompAsset : public BMAsset
{
public:
BMPreCompAsset() = default;
explicit BMPreCompAsset (const BMPreCompAsset &other) = default;
BMPreCompAsset(const QJsonObject &definition);
~BMPreCompAsset() = default;
BMBase *clone() const override;
private:
void parseLayers(const QJsonArray &definition);
};
QT_END_NAMESPACE
#endif // BMPRECOMPASSET_P_H

View File

@ -123,8 +123,12 @@
'<(lottie_loc)/imports/rasterrenderer/lottierasterrenderer.h',
# added to qtlottie/src/bodymovin/bodymovin.pro
'<(lottie_loc)/bodymovin/bmasset.cpp',
'<(lottie_loc)/bodymovin/bmprecompasset.cpp',
'<(lottie_loc)/bodymovin/bmnulllayer.cpp',
'<(lottie_loc)/bodymovin/bmasset_p.h',
'<(lottie_loc)/bodymovin/bmprecompasset_p.h',
'<(lottie_loc)/bodymovin/bmnulllayer_p.h',
],
'conditions': [[ 'build_macold', {