-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
using LayerInfoList = std::vector<std::tuple<std::string, int , int>>;
+
+using ColorFilter = std::function<void(float &r , float &g, float &b)>;
+
class LOT_EXPORT Animation {
public:
const std::string &resourcePath="", bool cachePolicy=true);
/**
+ * @brief Constructs an animation object from JSON string data and update.
+ * the color properties using ColorFilter.
+
+ * @param[in] jsonData The JSON string data.
+ * @param[in] resourcePath the path will be used to search for external resource.
+ * @param[in] filter The color filter that will be applied for each color property
+ * found during parsing.
+
+ * @return Animation object that can render the contents of the
+ * Lottie resource represented by JSON string data.
+ *
+ * @internal
+ */
+ static std::unique_ptr<Animation>
+ loadFromData(std::string jsonData, std::string resourcePath, ColorFilter filter);
+
+ /**
* @brief Returns default framerate of the Lottie resource.
*
* @return framerate of the Lottie resource
}
LottieLoader loader;
- if (loader.loadFromData(std::move(jsonData), key,
- (resourcePath.empty() ? " " : resourcePath), cachePolicy)) {
+ if (loader.loadFromData(std::move(jsonData), key, resourcePath, cachePolicy)) {
+ auto animation = std::unique_ptr<Animation>(new Animation);
+ animation->d->init(loader.model());
+ return animation;
+ }
+ return nullptr;
+}
+
+std::unique_ptr<Animation> Animation::loadFromData( std::string jsonData, std::string resourcePath, ColorFilter filter)
+{
+ if (jsonData.empty()) {
+ vWarning << "jason data is empty";
+ return nullptr;
+ }
+
+ LottieLoader loader;
+ if (loader.loadFromData(std::move(jsonData), std::move(resourcePath), std::move(filter))) {
auto animation = std::unique_ptr<Animation>(new Animation);
animation->d->init(loader.model());
return animation;
#include <cstring>
#include <fstream>
+#include <sstream>
#ifdef LOTTIE_CACHE_SUPPORT
if (content.empty()) return false;
const char *str = content.c_str();
- LottieParser parser(const_cast<char *>(str),
- dirname(path).c_str());
+ LottieParser parser(const_cast<char *>(str), dirname(path));
mModel = parser.model();
if (!mModel) return false;
return true;
}
-bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key,
- const std::string &resourcePath, bool cachePolicy)
+bool LottieLoader::loadFromData(std::string jsonData, const std::string &key,
+ std::string resourcePath, bool cachePolicy)
{
if (cachePolicy) {
mModel = LottieModelCache::instance().find(key);
if (mModel) return true;
}
- LottieParser parser(const_cast<char *>(jsonData.c_str()),
- resourcePath.c_str());
+ LottieParser parser(const_cast<char *>(jsonData.c_str()), std::move(resourcePath));
mModel = parser.model();
if (!mModel) return false;
return true;
}
+bool LottieLoader::loadFromData(std::string jsonData, std::string resourcePath, ColorFilter filter)
+{
+ LottieParser parser(const_cast<char *>(jsonData.c_str()), std::move(resourcePath), std::move(filter));
+ mModel = parser.model();
+
+ return mModel ? true : false;
+}
+
std::shared_ptr<LOTModel> LottieLoader::model()
{
return mModel;
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef LOTTIELOADER_H
#define LOTTIELOADER_H
-#include<sstream>
#include<memory>
+#include <functional>
class LOTModel;
class LottieLoader
{
public:
+ using ColorFilter = std::function<void(float &, float &, float&)>;
static void configureModelCacheSize(size_t cacheSize);
bool load(const std::string &filePath, bool cachePolicy);
- bool loadFromData(std::string &&jsonData, const std::string &key,
- const std::string &resourcePath, bool cachePolicy);
+ bool loadFromData(std::string jsonData, const std::string &key,
+ std::string resourcePath, bool cachePolicy);
+ bool loadFromData(std::string jsonData, std::string resourcePath, ColorFilter filter);
std::shared_ptr<LOTModel> model();
-private:
+private:
std::shared_ptr<LOTModel> mModel;
};
class LottieParserImpl : public LookaheadParserHandler {
public:
- LottieParserImpl(char *str, const char *dir_path)
- : LookaheadParserHandler(str), mDirPath(dir_path) {}
+ LottieParserImpl(char *str, std::string dir_path, ColorFilter filter)
+ : LookaheadParserHandler(str),
+ mColorFilter(std::move(filter)),
+ mDirPath(std::move(dir_path)) {}
bool VerifyType();
bool ParseNext();
public:
void resolveLayerRefs();
void parsePathInfo();
private:
+ ColorFilter mColorFilter;
struct {
std::vector<VPointF> mInPoint; /* "i" */
std::vector<VPointF> mOutPoint; /* "o" */
val[i++] = value;
}
}
+
+ if (mColorFilter) mColorFilter( val[0] , val[1], val[2]) ;
+
color.r = val[0];
color.g = val[1];
color.b = val[2];
#endif
LottieParser::~LottieParser() = default;
-LottieParser::LottieParser(char *str, const char *dir_path)
- : d(std::make_unique<LottieParserImpl>(str, dir_path))
+LottieParser::LottieParser(char *str, std::string dir_path, ColorFilter filter)
+ : d(std::make_unique<LottieParserImpl>(str, std::move(dir_path), std::move(filter)))
{
if (d->VerifyType())
d->parseComposition();
-/*
+/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "lottiemodel.h"
#include <memory>
+#include <functional>
+using ColorFilter = std::function<void(float &, float &, float &)>;
class LottieParserImpl;
class LottieParser {
public:
~LottieParser();
- LottieParser(char* str, const char *dir_path);
+ LottieParser(char* str, std::string dir_path, ColorFilter filter = {});
std::shared_ptr<LOTModel> model();
private:
std::unique_ptr<LottieParserImpl> d;