mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 06:25:14 +01:00
Update to 8.3.0
This commit is contained in:
parent
dcf1c6d4c3
commit
3477d72367
9 changed files with 131 additions and 21 deletions
|
@ -51,7 +51,7 @@ typedef struct LottieInfo {
|
|||
volatile uint32_t framesAvailableInCache = 0;
|
||||
};
|
||||
|
||||
JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_create(JNIEnv *env, jclass clazz, jstring src, jstring json, jint w, jint h, jintArray data, jboolean precache, jintArray colorReplacement, jboolean limitFps) {
|
||||
JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_create(JNIEnv *env, jclass clazz, jstring src, jstring json, jint w, jint h, jintArray data, jboolean precache, jintArray colorReplacement, jboolean limitFps, jint fitzModifier) {
|
||||
auto info = new LottieInfo();
|
||||
|
||||
std::map<int32_t, int32_t> *colors = nullptr;
|
||||
|
@ -71,16 +71,35 @@ JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_create(JNIEnv *e
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
FitzModifier modifier = FitzModifier::None;
|
||||
switch (fitzModifier) {
|
||||
case 12:
|
||||
modifier = FitzModifier::Type12;
|
||||
break;
|
||||
case 3:
|
||||
modifier = FitzModifier::Type3;
|
||||
break;
|
||||
case 4:
|
||||
modifier = FitzModifier::Type4;
|
||||
break;
|
||||
case 5:
|
||||
modifier = FitzModifier::Type5;
|
||||
break;
|
||||
case 6:
|
||||
modifier = FitzModifier::Type6;
|
||||
break;
|
||||
}
|
||||
char const *srcString = env->GetStringUTFChars(src, nullptr);
|
||||
info->path = srcString;
|
||||
if (json != nullptr) {
|
||||
char const *jsonString = env->GetStringUTFChars(json, nullptr);
|
||||
if (jsonString) {
|
||||
info->animation = rlottie::Animation::loadFromData(jsonString, info->path, colors);
|
||||
info->animation = rlottie::Animation::loadFromData(jsonString, info->path, colors, modifier);
|
||||
env->ReleaseStringUTFChars(json, jsonString);
|
||||
}
|
||||
} else {
|
||||
info->animation = rlottie::Animation::loadFromFile(info->path, colors);
|
||||
info->animation = rlottie::Animation::loadFromFile(info->path, colors, modifier);
|
||||
}
|
||||
if (srcString) {
|
||||
env->ReleaseStringUTFChars(src, srcString);
|
||||
|
|
|
@ -52,6 +52,15 @@ struct LOTLayerNode;
|
|||
|
||||
namespace rlottie {
|
||||
|
||||
enum class FitzModifier {
|
||||
None,
|
||||
Type12,
|
||||
Type3,
|
||||
Type4,
|
||||
Type5,
|
||||
Type6
|
||||
};
|
||||
|
||||
struct Color {
|
||||
Color() = default;
|
||||
Color(float r, float g , float b):_r(r), _g(g), _b(b){}
|
||||
|
@ -258,7 +267,7 @@ public:
|
|||
* @internal
|
||||
*/
|
||||
static std::unique_ptr<Animation>
|
||||
loadFromFile(const std::string &path, std::map<int32_t, int32_t> *colorReplacement);
|
||||
loadFromFile(const std::string &path, std::map<int32_t, int32_t> *colorReplacement, FitzModifier fitzModifier);
|
||||
|
||||
/**
|
||||
* @brief Constructs an animation object from JSON string data.
|
||||
|
@ -273,7 +282,7 @@ public:
|
|||
* @internal
|
||||
*/
|
||||
static std::unique_ptr<Animation>
|
||||
loadFromData(std::string jsonData, const std::string &key, std::map<int32_t, int32_t> *colorReplacement, const std::string &resourcePath="");
|
||||
loadFromData(std::string jsonData, const std::string &key, std::map<int32_t, int32_t> *colorReplacement, FitzModifier fitzModifier = FitzModifier::None, const std::string &resourcePath="");
|
||||
|
||||
/**
|
||||
* @brief Returns default framerate of the Lottie resource.
|
||||
|
|
|
@ -125,6 +125,7 @@ void AnimationImpl::init(const std::shared_ptr<LOTModel> &model)
|
|||
std::unique_ptr<Animation> Animation::loadFromData(
|
||||
std::string jsonData, const std::string &key,
|
||||
std::map<int32_t, int32_t> *colorReplacement,
|
||||
FitzModifier fitzModifier,
|
||||
const std::string &resourcePath)
|
||||
{
|
||||
if (jsonData.empty()) {
|
||||
|
@ -135,7 +136,7 @@ std::unique_ptr<Animation> Animation::loadFromData(
|
|||
LottieLoader loader;
|
||||
if (loader.loadFromData(std::move(jsonData), key,
|
||||
colorReplacement,
|
||||
(resourcePath.empty() ? " " : resourcePath))) {
|
||||
(resourcePath.empty() ? " " : resourcePath), fitzModifier)) {
|
||||
auto animation = std::unique_ptr<Animation>(new Animation);
|
||||
animation->colorMap = colorReplacement;
|
||||
animation->d->init(loader.model());
|
||||
|
@ -145,7 +146,7 @@ std::unique_ptr<Animation> Animation::loadFromData(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Animation> Animation::loadFromFile(const std::string &path, std::map<int32_t, int32_t> *colorReplacement)
|
||||
std::unique_ptr<Animation> Animation::loadFromFile(const std::string &path, std::map<int32_t, int32_t> *colorReplacement, FitzModifier fitzModifier)
|
||||
{
|
||||
if (path.empty()) {
|
||||
vWarning << "File path is empty";
|
||||
|
@ -153,7 +154,7 @@ std::unique_ptr<Animation> Animation::loadFromFile(const std::string &path, std:
|
|||
}
|
||||
|
||||
LottieLoader loader;
|
||||
if (loader.load(path, colorReplacement)) {
|
||||
if (loader.load(path, colorReplacement, fitzModifier)) {
|
||||
auto animation = std::unique_ptr<Animation>(new Animation);
|
||||
animation->colorMap = colorReplacement;
|
||||
animation->d->init(loader.model());
|
||||
|
|
|
@ -75,7 +75,7 @@ static std::string dirname(const std::string &path)
|
|||
return std::string(path, 0, len);
|
||||
}
|
||||
|
||||
bool LottieLoader::load(const std::string &path, std::map<int32_t, int32_t> *colorReplacement)
|
||||
bool LottieLoader::load(const std::string &path, std::map<int32_t, int32_t> *colorReplacement, rlottie::FitzModifier fitzModifier)
|
||||
{
|
||||
mModel = LottieFileCache::instance().find(path);
|
||||
if (mModel) return true;
|
||||
|
@ -95,7 +95,7 @@ bool LottieLoader::load(const std::string &path, std::map<int32_t, int32_t> *col
|
|||
if (content.empty()) return false;
|
||||
|
||||
const char *str = content.c_str();
|
||||
LottieParser parser(const_cast<char *>(str), dirname(path).c_str(), colorReplacement);
|
||||
LottieParser parser(const_cast<char *>(str), dirname(path).c_str(), colorReplacement, fitzModifier);
|
||||
if (parser.hasParsingError()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -111,12 +111,12 @@ bool LottieLoader::load(const std::string &path, std::map<int32_t, int32_t> *col
|
|||
|
||||
bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key,
|
||||
std::map<int32_t, int32_t> *colorReplacement,
|
||||
const std::string &resourcePath)
|
||||
const std::string &resourcePath, rlottie::FitzModifier fitzModifier)
|
||||
{
|
||||
mModel = LottieFileCache::instance().find(key);
|
||||
if (mModel) return true;
|
||||
|
||||
LottieParser parser(const_cast<char *>(jsonData.c_str()), resourcePath.c_str(), colorReplacement);
|
||||
LottieParser parser(const_cast<char *>(jsonData.c_str()), resourcePath.c_str(), colorReplacement, fitzModifier);
|
||||
mModel = parser.model();
|
||||
|
||||
if (!mModel) return false;
|
||||
|
|
|
@ -22,13 +22,14 @@
|
|||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <rlottie.h>
|
||||
|
||||
class LOTModel;
|
||||
class LottieLoader
|
||||
{
|
||||
public:
|
||||
bool load(const std::string &filePath, std::map<int32_t, int32_t> *colorReplacement);
|
||||
bool loadFromData(std::string &&jsonData, const std::string &key, std::map<int32_t, int32_t> *colorReplacement, const std::string &resourcePath);
|
||||
bool load(const std::string &filePath, std::map<int32_t, int32_t> *colorReplacement, rlottie::FitzModifier fitzModifier);
|
||||
bool loadFromData(std::string &&jsonData, const std::string &key, std::map<int32_t, int32_t> *colorReplacement, const std::string &resourcePath, rlottie::FitzModifier fitzModifier);
|
||||
std::shared_ptr<LOTModel> model();
|
||||
private:
|
||||
std::shared_ptr<LOTModel> mModel;
|
||||
|
|
|
@ -182,8 +182,8 @@ protected:
|
|||
|
||||
class LottieParserImpl : protected LookaheadParserHandler {
|
||||
public:
|
||||
LottieParserImpl(char *str, const char *dir_path, std::map<int32_t, int32_t> *colorReplacement)
|
||||
: LookaheadParserHandler(str), mDirPath(dir_path), colorMap(colorReplacement)
|
||||
LottieParserImpl(char *str, const char *dir_path, std::map<int32_t, int32_t> *colorReplacement, rlottie::FitzModifier fitzModifier)
|
||||
: LookaheadParserHandler(str), mDirPath(dir_path), colorMap(colorReplacement), mFitzModifier(fitzModifier)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -270,6 +270,9 @@ public:
|
|||
void parseShapeProperty(LOTAnimatable<LottieShapeData> &obj);
|
||||
void parseDashProperty(LOTDashProperty &dash);
|
||||
|
||||
void parseFitzColorReplacements();
|
||||
void parseFitzColorReplacement();
|
||||
|
||||
std::shared_ptr<VInterpolator> interpolator(VPointF, VPointF, std::string);
|
||||
|
||||
LottieColor toColor(const char *str);
|
||||
|
@ -279,6 +282,7 @@ public:
|
|||
bool hasParsingError();
|
||||
|
||||
protected:
|
||||
const rlottie::FitzModifier mFitzModifier;
|
||||
std::unordered_map<std::string, std::shared_ptr<VInterpolator>>
|
||||
mInterpolatorCache;
|
||||
std::shared_ptr<LOTCompositionData> mComposition;
|
||||
|
@ -611,6 +615,8 @@ void LottieParserImpl::parseComposition() {
|
|||
parseAssets(comp);
|
||||
} else if (0 == strcmp(key, "layers")) {
|
||||
parseLayers(comp);
|
||||
} else if (0 == strcmp(key, "fitz")) {
|
||||
parseFitzColorReplacements();
|
||||
} else {
|
||||
#ifdef DEBUG_PARSER
|
||||
vWarning << "Composition Attribute Skipped : " << key;
|
||||
|
@ -659,6 +665,79 @@ void LottieParserImpl::parseAssets(LOTCompositionData *composition) {
|
|||
// update the precomp layers with the actual layer object
|
||||
}
|
||||
|
||||
void LottieParserImpl::parseFitzColorReplacements()
|
||||
{
|
||||
RAPIDJSON_ASSERT(PeekType() == kArrayType);
|
||||
EnterArray();
|
||||
while (NextArrayValue()) {
|
||||
parseFitzColorReplacement();
|
||||
}
|
||||
}
|
||||
|
||||
void LottieParserImpl::parseFitzColorReplacement()
|
||||
{
|
||||
uint32_t original = 0;
|
||||
uint32_t type12 = 0;
|
||||
uint32_t type3 = 0;
|
||||
uint32_t type4 = 0;
|
||||
uint32_t type5 = 0;
|
||||
uint32_t type6 = 0;
|
||||
|
||||
EnterObject();
|
||||
while (const char *key = NextObjectKey()) {
|
||||
if (0 == strcmp(key, "o")) {
|
||||
RAPIDJSON_ASSERT(PeekType() == kNumberType);
|
||||
original = GetInt();
|
||||
} else if (0 == strcmp(key, "f12")) {
|
||||
RAPIDJSON_ASSERT(PeekType() == kNumberType);
|
||||
type12 = GetInt();
|
||||
} else if (0 == strcmp(key, "f3")) {
|
||||
RAPIDJSON_ASSERT(PeekType() == kNumberType);
|
||||
type3 = GetInt();
|
||||
} else if (0 == strcmp(key, "f4")) {
|
||||
RAPIDJSON_ASSERT(PeekType() == kNumberType);
|
||||
type4 = GetInt();
|
||||
} else if (0 == strcmp(key, "f5")) {
|
||||
RAPIDJSON_ASSERT(PeekType() == kNumberType);
|
||||
type5 = GetInt();
|
||||
} else if (0 == strcmp(key, "f6")) {
|
||||
RAPIDJSON_ASSERT(PeekType() == kNumberType);
|
||||
type6 = GetInt();
|
||||
} else {
|
||||
Skip(key);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t replacedType = 0;
|
||||
|
||||
switch (mFitzModifier) {
|
||||
case rlottie::FitzModifier::None:
|
||||
break;
|
||||
case rlottie::FitzModifier::Type12:
|
||||
replacedType = type12;
|
||||
break;
|
||||
case rlottie::FitzModifier::Type3:
|
||||
replacedType = type3;
|
||||
break;
|
||||
case rlottie::FitzModifier::Type4:
|
||||
replacedType = type4;
|
||||
break;
|
||||
case rlottie::FitzModifier::Type5:
|
||||
replacedType = type5;
|
||||
break;
|
||||
case rlottie::FitzModifier::Type6:
|
||||
replacedType = type6;
|
||||
break;
|
||||
}
|
||||
|
||||
if (replacedType != 0) {
|
||||
if (colorMap == NULL) {
|
||||
colorMap = new std::map<int32_t, int32_t>();
|
||||
}
|
||||
colorMap->insert(std::pair<int32_t, int32_t>(original, replacedType));
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr const unsigned char B64index[256] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -2654,8 +2733,8 @@ LottieParser::~LottieParser()
|
|||
delete d;
|
||||
}
|
||||
|
||||
LottieParser::LottieParser(char *str, const char *dir_path, std::map<int32_t, int32_t> *colorReplacement)
|
||||
: d(new LottieParserImpl(str, dir_path, colorReplacement))
|
||||
LottieParser::LottieParser(char *str, const char *dir_path, std::map<int32_t, int32_t> *colorReplacement, rlottie::FitzModifier fitzModifier)
|
||||
: d(new LottieParserImpl(str, dir_path, colorReplacement, fitzModifier))
|
||||
{
|
||||
d->parseComposition();
|
||||
if (d->hasParsingError()) {
|
||||
|
|
|
@ -21,12 +21,13 @@
|
|||
|
||||
#include "lottiemodel.h"
|
||||
#include <map>
|
||||
#include <rlottie.h>
|
||||
|
||||
class LottieParserImpl;
|
||||
class LottieParser {
|
||||
public:
|
||||
~LottieParser();
|
||||
LottieParser(char* str, const char *dir_path, std::map<int32_t, int32_t> *colorReplacement);
|
||||
LottieParser(char* str, const char *dir_path, std::map<int32_t, int32_t> *colorReplacement, rlottie::FitzModifier fitzModifier = rlottie::FitzModifier::None);
|
||||
std::shared_ptr<LOTModel> model();
|
||||
bool hasParsingError();
|
||||
private:
|
||||
|
|
|
@ -989,7 +989,7 @@ auth_Authorization *auth_Authorization::TLdeserialize(NativeByteBuffer *stream,
|
|||
case 0x44747e9a:
|
||||
result = new TL_auth_authorizationSignUpRequired();
|
||||
break;
|
||||
case 0xcd050916:
|
||||
case 0x33fb7bb8:
|
||||
result = new TL_auth_authorization();
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -680,7 +680,7 @@ public:
|
|||
class TL_auth_authorization : public auth_Authorization {
|
||||
|
||||
public:
|
||||
static const uint32_t constructor = 0xcd050916;
|
||||
static const uint32_t constructor = 0x33fb7bb8;
|
||||
|
||||
int32_t flags;
|
||||
int32_t tmp_sessions;
|
||||
|
|
Loading…
Reference in a new issue