Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,13 @@ if(MSVC)
target_compile_options(rlottie
PUBLIC
PRIVATE
/std:c++14
/EHs-c- # disable exceptions
/GR- # disable RTTI
/W3
)
else()
target_compile_options(rlottie
PUBLIC
PRIVATE
-std=c++14
-fno-exceptions
-fno-unwind-tables
-fno-asynchronous-unwind-tables
-fno-rtti
Expand All @@ -88,7 +84,7 @@ target_link_libraries(rlottie
"${CMAKE_THREAD_LIBS_INIT}"
)

if (NOT APPLE AND NOT WIN32)
if (NOT APPLE AND NOT WIN32 AND NOT EMSCRIPTEN)
target_link_libraries(rlottie
PRIVATE
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/rlottie.expmap"
Expand All @@ -101,7 +97,12 @@ if (LOTTIE_MODULE)
endif()

if (NOT LOTTIE_ASAN)
if(APPLE)
if(EMSCRIPTEN)
target_link_libraries(rlottie
PUBLIC
"-Wl"
)
elseif(APPLE)
target_link_libraries(rlottie
PUBLIC
"-Wl, -undefined error"
Expand Down Expand Up @@ -134,6 +135,11 @@ if (NOT LIB_INSTALL_DIR)
set (LIB_INSTALL_DIR "/usr/lib")
endif (NOT LIB_INSTALL_DIR)

if(NOT EMSCRIPTEN)
generate_dll_rc_filepath(rlottie ${DLL_PRODUCT_NUMBER} ${DLL_PRODUCT_VERSION} ${DLL_BUILD_NUMBER} 2021)
target_sources(rlottie PRIVATE ${rlottie_RCFILEPATH})
endif()

#declare source and include files
add_subdirectory(inc)
add_subdirectory(src)
Expand Down
4 changes: 4 additions & 0 deletions example/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class Demo
return rlottie::Color(1, 0, 0);
}
});
view8->player()->setValue<rlottie::Property::TrimEnd>("Shape Layer 2.Trim Paths 1",
[](const rlottie::FrameInfo& info) {
return rlottie::Point(0, 30);
});
}
view8->setPos(2100, 0);
view8->setSize(300, 300);
Expand Down
6 changes: 3 additions & 3 deletions example/evasapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ void EvasApp::run()
ecore_evas_shutdown();
}

static bool isJsonFile(const char *filename) {
static bool isLottiefile(const char *filename) {
const char *dot = strrchr(filename, '.');
if(!dot || dot == filename) return false;
return !strcmp(dot + 1, "json");
return !strcmp(dot + 1, "json") || !strcmp(dot + 1, "lottie");
}

std::vector<std::string>
Expand All @@ -136,7 +136,7 @@ EvasApp::jsonFiles(const std::string &dirName, bool /*recurse*/)
d = opendir(dirName.c_str());
if (d) {
while ((dir = readdir(d)) != NULL) {
if (isJsonFile(dir->d_name))
if (isLottiefile(dir->d_name))
result.push_back(dirName + dir->d_name);
}
closedir(d);
Expand Down
Binary file added example/resource/1st_animation.lottie
Binary file not shown.
11 changes: 8 additions & 3 deletions inc/rlottie.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ enum class Property {
TrPosition, /*!< Transform Position property of Layer and Group object , value type is rlottie::Point */
TrScale, /*!< Transform Scale property of Layer and Group object , value type is rlottie::Size. range[0 ..100] */
TrRotation, /*!< Transform Rotation property of Layer and Group object , value type is float. range[0 .. 360] in degrees*/
TrOpacity /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */
TrOpacity, /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */
TrimStart, /*!< Trim Start property of Shape object , value type is float [ 0 .. 100] */
TrimEnd /*!< Trim End property of Shape object , value type is rlottie::Point [ 0 .. 100] */
};

struct Color_Type{};
Expand Down Expand Up @@ -487,6 +489,9 @@ class RLOTTIE_API Animation {
*/
~Animation();

std::vector<Color> colorPalette() const;
void setReplacementColors(const std::vector<Color>& replacementColors);

private:
void setValue(Color_Type, Property, const std::string &, Color);
void setValue(Float_Type, Property, const std::string &, float);
Expand Down Expand Up @@ -518,8 +523,8 @@ template<> struct MapType<std::integral_constant<Property, Property::TrOpacity>>
template<> struct MapType<std::integral_constant<Property, Property::TrAnchor>>: Point_Type{};
template<> struct MapType<std::integral_constant<Property, Property::TrPosition>>: Point_Type{};
template<> struct MapType<std::integral_constant<Property, Property::TrScale>>: Size_Type{};


template<> struct MapType<std::integral_constant<Property, Property::TrimStart>>: Float_Type{};
template<> struct MapType<std::integral_constant<Property, Property::TrimEnd>>: Point_Type{};
} // namespace lotplayer

#endif // _RLOTTIE_H_
4 changes: 3 additions & 1 deletion inc/rlottie_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ typedef enum {
LOTTIE_ANIMATION_PROPERTY_TR_POSITION, /*!< Transform Position property of Layer and Group object , value type is int */
LOTTIE_ANIMATION_PROPERTY_TR_SCALE, /*!< Transform Scale property of Layer and Group object , value type is float range[0 ..100] */
LOTTIE_ANIMATION_PROPERTY_TR_ROTATION, /*!< Transform Scale property of Layer and Group object , value type is float. range[0 .. 360] in degrees*/
LOTTIE_ANIMATION_PROPERTY_TR_OPACITY /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */
LOTTIE_ANIMATION_PROPERTY_TR_OPACITY, /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */
LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_START, /*!< Trim Path Start property of Shape object , value type is float [0 .. 100] */
LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_END /*!< Trim Path End property of Shape object , value type is float [0 .. 100] */
}Lottie_Animation_Property;

typedef struct Lottie_Animation_S Lottie_Animation;
Expand Down
15 changes: 15 additions & 0 deletions src/binding/c/lottieanimation_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ lottie_animation_property_override(Lottie_Animation_S *animation,
case LOTTIE_ANIMATION_PROPERTY_STROKEOPACITY:
case LOTTIE_ANIMATION_PROPERTY_STROKEWIDTH:
case LOTTIE_ANIMATION_PROPERTY_TR_ROTATION:
case LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_START:
return 1;
case LOTTIE_ANIMATION_PROPERTY_TR_POSITION:
case LOTTIE_ANIMATION_PROPERTY_TR_SCALE:
case LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_END:
return 2;
default:
return 0;
Expand Down Expand Up @@ -278,6 +280,19 @@ lottie_animation_property_override(Lottie_Animation_S *animation,
animation->mAnimation->setValue<rlottie::Property::TrRotation>(keypath, (float)r);
break;
}
case LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_START: {
double start = v[0];
if (start < 0 || start > 100) break;
animation->mAnimation->setValue<rlottie::Property::TrimStart>(keypath, (float)start);
break;
}
case LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_END: {
double start = v[0];
double end = v[1];
if (start < 0 || start > 100 || end < 0 || end > 100) break;
animation->mAnimation->setValue<rlottie::Property::TrimEnd>(keypath, rlottie::Point((float)start, (float)end));
break;
}
case LOTTIE_ANIMATION_PROPERTY_TR_ANCHOR:
case LOTTIE_ANIMATION_PROPERTY_TR_OPACITY:
//@TODO handle propery update.
Expand Down
1 change: 1 addition & 0 deletions src/lottie/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(zip)

target_sources(rlottie
PRIVATE
Expand Down
46 changes: 45 additions & 1 deletion src/lottie/lottieanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ class AnimationImpl {
const MarkerList &markers() const { return mModel->markers(); }
void setValue(const std::string &keypath, LOTVariant &&value);
void removeFilter(const std::string &keypath, Property prop);

std::vector<Color> colorPalette() const;
void setReplacementColors(const std::vector<Color> &replacementColors);

private:
mutable LayerInfoList mLayerList;
model::Composition * mModel;
SharedRenderTask mTask;
std::atomic<bool> mRenderInProgress;
std::unique_ptr<renderer::Composition> mRenderer{nullptr};
std::vector<model::Color> mReplacementColors;
};

void AnimationImpl::setValue(const std::string &keypath, LOTVariant &&value)
Expand Down Expand Up @@ -108,9 +111,15 @@ bool AnimationImpl::update(size_t frameNo, const VSize &size,
Surface AnimationImpl::render(size_t frameNo, const Surface &surface,
bool keepAspectRatio)
{
static std::atomic_flag sReplacementColorsLock;
// model::Color::s_ReplacementColors is global. Make sure only one thread renders at a time.
while ( sReplacementColorsLock.test_and_set() ) {}

model::Color::s_ReplacementColors = mReplacementColors;
bool renderInProgress = mRenderInProgress.load();
if (renderInProgress) {
vCritical << "Already Rendering Scheduled for this Animation";
sReplacementColorsLock.clear();
return surface;
}

Expand All @@ -121,6 +130,7 @@ Surface AnimationImpl::render(size_t frameNo, const Surface &surface,
keepAspectRatio);
mRenderer->render(surface);
mRenderInProgress.store(false);
sReplacementColorsLock.clear();

return surface;
}
Expand All @@ -132,6 +142,30 @@ void AnimationImpl::init(std::shared_ptr<model::Composition> composition)
mRenderInProgress = false;
}

std::vector<Color> AnimationImpl::colorPalette() const
{
std::vector<Color> result;
for (const auto &color : mModel->mColorPalette)
{
result.emplace_back(Color(color.r, color.g, color.b));
}
return result;
}

void AnimationImpl::setReplacementColors( const std::vector<Color> &replacementColors )
{
std::vector<model::Color> updatedReplacementColors;
for (const auto &color : replacementColors)
{
updatedReplacementColors.emplace_back( model::Color(color.r(), color.g(), color.b()) );
}
if (updatedReplacementColors != mReplacementColors)
{
mReplacementColors = updatedReplacementColors;
mRenderer->setDirty();
}
}

#ifdef LOTTIE_THREAD_SUPPORT

#include <thread>
Expand Down Expand Up @@ -447,6 +481,16 @@ Surface::Surface(uint32_t *buffer, size_t width, size_t height,
mDrawArea.h = mHeight;
}

std::vector<Color> Animation::colorPalette() const
{
return d->colorPalette();
}

void Animation::setReplacementColors( const std::vector<Color> &replacementColors )
{
d->setReplacementColors(replacementColors);
}

void Surface::setDrawRegion(size_t x, size_t y, size_t width, size_t height)
{
if ((x + width > mWidth) || (y + height > mHeight)) return;
Expand Down
19 changes: 19 additions & 0 deletions src/lottie/lottiefiltermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,25 @@ class Filter<model::Group> : public FilterBase<model::Group>
}
};

template <>
class Filter<model::Trim>: public FilterBase<model::Trim>
{
public:
Filter(model::Trim* model) : FilterBase<model::Trim>(model) {}

model::Trim::Segment segment(int frameNo) const
{
if (this->hasFilter(rlottie::Property::TrimStart)) {
this->model_->updateTrimStartValue(this->filter()->value(rlottie::Property::TrimStart, frameNo));
}
if (this->hasFilter(rlottie::Property::TrimEnd)) {
this->model_->updateTrimEndValue(this->filter()->point(rlottie::Property::TrimEnd, frameNo));
}
model::Trim::Segment segment = this->model()->segment(frameNo);
return segment;
}
};


} // namespace model

Expand Down
Loading