lottie: rename public headers to rlottie namesapce. 94/198094/2
authorsub.mohanty@samsung.com <smohantty@gmail.com>
Fri, 18 Jan 2019 10:31:54 +0000 (19:31 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Mon, 21 Jan 2019 04:34:48 +0000 (13:34 +0900)
Change-Id: Ib8d3df2600eef84927c95eb6794de9f9074d6253

13 files changed:
CMakeLists.txt
example/lottieview.h
inc/lottieanimation.h
inc/lottieanimation_capi.h
inc/lottiecommon.h
inc/meson.build
inc/rlottie.h [new file with mode: 0644]
inc/rlottie_capi.h [new file with mode: 0644]
inc/rlottiecommon.h [new file with mode: 0644]
src/binding/c/lottieanimation_capi.cpp
src/lottie/lottieanimation.cpp
src/lottie/lottieitem.h
test/test_lottieanimation.cpp

index 34e994c..38a8a7a 100644 (file)
@@ -57,7 +57,14 @@ CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
 #install header
-install(FILES inc/lottieanimation.h inc/lottieanimation_capi.h inc/lottiecommon.h  DESTINATION include)
+install(FILES
+        inc/rlottie.h
+        inc/rlottie_capi.h
+        inc/rlottiecommon.h
+        inc/lottieanimation.h
+        inc/lottieanimation_capi.h
+        inc/lottiecommon.h
+        DESTINATION include)
 
 #install lib
 install( TARGETS lottie-player EXPORT lottie-player-targets
index 8dc8392..aab0336 100644 (file)
@@ -32,8 +32,8 @@
 #include <Evas.h>
 #include <Ecore.h>
 #include <Ecore_Evas.h>
-#include "lottieanimation.h"
-#include "lottieanimation_capi.h"
+#include "rlottie.h"
+#include "rlottie_capi.h"
 #include<future>
 #include <cmath>
 class LottieView
index 1d3efce..1508b2f 100644 (file)
@@ -1,276 +1 @@
-/* 
- * 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 _LOTTIE_ANIMATION_H_
-#define _LOTTIE_ANIMATION_H_
-
-#include <future>
-#include <vector>
-#include <memory>
-
-#ifdef _WIN32
-#ifdef LOT_BUILD
-#ifdef DLL_EXPORT
-#define LOT_EXPORT __declspec(dllexport)
-#else
-#define LOT_EXPORT
-#endif
-#else
-#define LOT_EXPORT __declspec(dllimport)
-#endif
-#else
-#ifdef __GNUC__
-#if __GNUC__ >= 4
-#define LOT_EXPORT __attribute__((visibility("default")))
-#else
-#define LOT_EXPORT
-#endif
-#else
-#define LOT_EXPORT
-#endif
-#endif
-
-class AnimationImpl;
-struct LOTNode;
-struct LOTLayerNode;
-
-namespace lottie {
-
-class LOT_EXPORT Surface {
-public:
-    /**
-     *  @brief Surface object constructor.
-     *
-     *  @param[in] buffer surface buffer.
-     *  @param[in] width  surface width.
-     *  @param[in] height  surface height.
-     *  @param[in] bytesPerLine  number of bytes in a surface scanline.
-     *
-     *  @note Default surface format is ARGB32_Premultiplied.
-     *
-     *  @internal
-     */
-    Surface(uint32_t *buffer, size_t width, size_t height, size_t bytesPerLine);
-
-    /**
-     *  @brief Returns width of the surface.
-     *
-     *  @return surface width
-     *
-     *  @internal
-     *
-     */
-    size_t width() const {return mWidth;}
-
-    /**
-     *  @brief Returns height of the surface.
-     *
-     *  @return surface height
-     *
-     *  @internal
-     */
-    size_t height() const {return mHeight;}
-
-    /**
-     *  @brief Returns number of bytes in the surface scanline.
-     *
-     *  @return number of bytes in scanline.
-     *
-     *  @internal
-     */
-    size_t  bytesPerLine() const {return mBytesPerLine;}
-
-    /**
-     *  @brief Returns buffer attached tp the surface.
-     *
-     *  @return buffer attaced to the Surface.
-     *
-     *  @internal
-     */
-    uint32_t *buffer() const {return mBuffer;}
-
-    /**
-     *  @brief Default constructor.
-     */
-    Surface() = default;
-private:
-    uint32_t    *mBuffer{nullptr};
-    size_t       mWidth{0};
-    size_t       mHeight{0};
-    size_t       mBytesPerLine{0};
-};
-
-class LOT_EXPORT Animation {
-public:
-
-    /**
-     *  @brief Constructs an animation object from file path.
-     *
-     *  @param[in] path Lottie resource file path
-     *
-     *  @return Animation object that can render the contents of the
-     *          Lottie resource represented by file path.
-     *
-     *  @internal
-     */
-    static std::unique_ptr<Animation>
-    loadFromFile(const std::string &path);
-
-    /**
-     *  @brief Constructs an animation object from JSON string data.
-     *
-     *  @param[in] jsonData The JSON string data.
-     *  @param[in] key the string that will be used to cache the JSON string data.
-     *
-     *  @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, const std::string &key);
-
-    /**
-     *  @brief Returns default framerate of the Lottie resource.
-     *
-     *  @return framerate of the Lottie resource
-     *
-     *  @internal
-     *
-     */
-    double frameRate() const;
-
-    /**
-     *  @brief Returns total number of frames present in the Lottie resource.
-     *
-     *  @return frame count of the Lottie resource.
-     *
-     *  @note frame number starts with 0.
-     *
-     *  @internal
-     */
-    size_t totalFrame() const;
-
-    /**
-     *  @brief Returns default viewport size of the Lottie resource.
-     *
-     *  @param[out] width  default width of the viewport.
-     *  @param[out] height default height of the viewport.
-     *
-     *  @internal
-     *
-     */
-    void   size(size_t &width, size_t &height) const;
-
-    /**
-     *  @brief Returns total animation duration of Lottie resource in second.
-     *         it uses totalFrame() and frameRate() to calculate the duration.
-     *         duration = totalFrame() / frameRate().
-     *
-     *  @return total animation duration in second.
-     *  @retval 0 if the Lottie resource has no animation.
-     *
-     *  @see totalFrame()
-     *  @see frameRate()
-     *
-     *  @internal
-     */
-    double duration() const;
-
-    /**
-     *  @brief Returns frame number for a given position.
-     *         this function helps to map the position value retuned
-     *         by the animator to a frame number in side the Lottie resource.
-     *         frame_number = lerp(start_frame, endframe, pos);
-     *
-     *  @param[in] pos normalized position value [0 ... 1]
-     *
-     *  @return frame numer maps to the position value [startFrame .... endFrame]
-     *
-     *  @internal
-     */
-    size_t frameAtPos(double pos);
-
-    /**
-     *  @brief Renders the content to surface Asynchronously.
-     *         it gives a future in return to get the result of the
-     *         rendering at a future point.
-     *         To get best performance user has to start rendering as soon as
-     *         it finds that content at {frameNo} has to be rendered and get the
-     *         result from the future at the last moment when the surface is needed
-     *         to draw into the screen.
-     *
-     *
-     *  @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
-     *  @param[in] surface Surface in which content will be drawn
-     *
-     *  @return future that will hold the result when rendering finished.
-     *
-     *  for Synchronus rendering @see renderSync
-     *
-     *  @see Surface
-     *  @internal
-     */
-    std::future<Surface> render(size_t frameNo, Surface surface);
-
-    /**
-     *  @brief Renders the content to surface synchronously.
-     *         for performance use the async rendering @see render
-     *
-     *  @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
-     *  @param[in] surface Surface in which content will be drawn
-     *
-     *  @internal
-     */
-    void              renderSync(size_t frameNo, Surface surface);
-
-    /**
-     *  @brief Returns root layer of the composition updated with
-     *         content of the Lottie resource at frame number @p frameNo.
-     *
-     *  @param[in] frameNo Content corresponds to the @p frameNo needs to be extracted.
-     *  @param[in] width   content viewbox width
-     *  @param[in] height  content viewbox height
-     *
-     *  @return Root layer node.
-     *
-     *  @internal
-     */
-    const LOTLayerNode * renderTree(size_t frameNo, size_t width, size_t height) const;
-
-    /**
-     *  @brief default destructor
-     *
-     *  @internal
-     */
-    ~Animation();
-
-private:
-    /**
-     *  @brief default constructor
-     *
-     *  @internal
-     */
-    Animation();
-
-    std::unique_ptr<AnimationImpl> d;
-};
-
-}  // namespace lotplayer
-
-#endif  // _LOTTIE_ANIMATION_H_
+#include "rlottie.h"
\ No newline at end of file
index ded215b..4b74147 100644 (file)
@@ -1,217 +1 @@
-/* 
- * 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 _LOTTIE_ANIMATION_CAPI_H_
-#define _LOTTIE_ANIMATION_CAPI_H_
-
-#include <stddef.h>
-#include <stdint.h>
-#include <lottiecommon.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct Lottie_Animation_S Lottie_Animation;
-
-/**
- *  @brief Constructs an animation object from file path.
- *
- *  @param[in] path Lottie resource file path
- *
- *  @return Animation object that can build the contents of the
- *          Lottie resource represented by file path.
- *
- *  @see lottie_animation_destroy()
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path);
-
-/**
- *  @brief Constructs an animation object from JSON string data.
- *
- *  @param[in] data The JSON string data.
- *  @param[in] key the string that will be used to cache the JSON string data.
- *
- *  @return Animation object that can build the contents of the
- *          Lottie resource represented by JSON string data.
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key);
-
-/**
- *  @brief Free given Animation object resource.
- *
- *  @param[in] animation Animation object to free.
- *
- *  @see lottie_animation_from_file()
- *  @see lottie_animation_from_data()
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT void lottie_animation_destroy(Lottie_Animation *animation);
-
-/**
- *  @brief Returns default viewport size of the Lottie resource.
- *
- *  @param[in] animation Animation object.
- *  @param[out] w default width of the viewport.
- *  @param[out] h default height of the viewport.
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
-
-/**
- *  @brief Returns total animation duration of Lottie resource in second.
- *         it uses totalFrame() and frameRate() to calculate the duration.
- *         duration = totalFrame() / frameRate().
- *
- *  @param[in] animation Animation object.
- *
- *  @return total animation duration in second.
- *          @c 0 if the Lottie resource has no animation.
- *
- *  @see lottie_animation_get_totalframe()
- *  @see lottie_animation_get_framerate()
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation *animation);
-
-/**
- *  @brief Returns total number of frames present in the Lottie resource.
- *
- *  @param[in] animation Animation object.
- *
- *  @return frame count of the Lottie resource.*
- *
- *  @note frame number starts with 0.
- *
- *  @see lottie_animation_get_duration()
- *  @see lottie_animation_get_framerate()
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
-
-/**
- *  @brief Returns default framerate of the Lottie resource.
- *
- *  @param[in] animation Animation object.
- *
- *  @return framerate of the Lottie resource
- *
- *  @ingroup Lottie_Animation
- *  @internal
- *
- */
-LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation *animation);
-
-/**
- *  @brief Get the render tree which contains the snapshot of the animation object
- *         at frame = @c frame_num, the content of the animation in that frame number.
- *
- *  @param[in] animation Animation object.
- *  @param[in] width requested snapshot viewport width.
- *  @param[in] height requested snapshot viewport height.
- *
- *  @return Animation snapshot tree.
- *
- * @note: User has to traverse the tree for rendering.
- *
- * @see LOTLayerNode
- * @see LOTNode
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation *animation,
-                                                             size_t frame_num,
-                                                             size_t width, size_t height);
-
-/**
- *  @brief Maps position to frame number and returns it.
- *
- *  @param[in] animation Animation object.
- *  @param[in] pos position in the range [ 0.0 .. 1.0 ].
- *
- *  @return mapped frame numbe in the range [ start_frame .. end_frame ].
- *          @c 0 if the Lottie resource has no animation.
- *
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
-
-/**
- *  @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
- *
- *  @param[in] animation Animation object.
- *  @param[in] frame_num the frame number needs to be rendered.
- *  @param[in] buffer surface buffer use for rendering.
- *  @param[in] width width of the surface
- *  @param[in] height height of the surface
- *  @param[in] bytes_per_line stride of the surface in bytes.
- *
- *  @note user must call lottie_animation_render_flush() to make sure render is finished.
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT void
-lottie_animation_render_async(Lottie_Animation *animation,
-                              size_t frame_num,
-                              uint32_t *buffer,
-                              size_t width,
-                              size_t height,
-                              size_t bytes_per_line);
-
-/**
- *  @brief Request to finish the current async renderer job for this animation object.
- *  If render is finished then this call returns immidiately.
- *  If not, it waits till render job finish and then return.
- *
- *  @param[in] animation Animation object.
- *
- *  @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
- *  in pair to get the benefit of async rendering.
- *
- *  @return the pixel buffer it finished rendering.
- *
- *  @ingroup Lottie_Animation
- *  @internal
- */
-LOT_EXPORT uint32_t *
-lottie_animation_render_flush(Lottie_Animation *animation);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //_LOTTIE_ANIMATION_CAPI_H_
-
+#include "rlottie_capi.h"
\ No newline at end of file
index d35fcdf..86267e5 100644 (file)
@@ -1,223 +1 @@
-/* 
- * 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 _LOTTIE_COMMON_H_
-#define _LOTTIE_COMMON_H_
-
-#ifdef _WIN32
-#ifdef LOT_BUILD
-#ifdef DLL_EXPORT
-#define LOT_EXPORT __declspec(dllexport)
-#else
-#define LOT_EXPORT
-#endif
-#else
-#define LOT_EXPORT __declspec(dllimport)
-#endif
-#else
-#ifdef __GNUC__
-#if __GNUC__ >= 4
-#define LOT_EXPORT __attribute__((visibility("default")))
-#else
-#define LOT_EXPORT
-#endif
-#else
-#define LOT_EXPORT
-#endif
-#endif
-
-
-/**
- * @defgroup Lottie_Animation Lottie_Animation
- *
- * Lottie Animation is a modern style vector based animation design. Its animation
- * resource(within json format) could be generated by Adobe After Effect using
- * bodymovin plugin. You can find a good examples in Lottie Community which
- * shares many free resources(see: www.lottiefiles.com).
- *
- * This Lottie_Animation is a common engine to manipulate, control Lottie
- * Animation from the Lottie resource - json file. It provides a scene-graph
- * node tree per frames by user demand as well as rasterized frame images.
- *
- */
-
-/**
- * @ingroup Lottie_Animation
- */
-
-
-/**
- * @brief Enumeration for Lottie Player error code.
- */
-typedef enum
-{
-   //TODO: Coding convention??
-    LOT_ANIMATION_ERROR_NONE = 0,
-    LOT_ANIMATION_ERROR_NOT_PERMITTED,
-    LOT_ANIMATION_ERROR_OUT_OF_MEMORY,
-    LOT_ANIMATION_ERROR_INVALID_PARAMETER,
-    LOT_ANIMATION_ERROR_RESULT_OUT_OF_RANGE,
-    LOT_ANIMATION_ERROR_ALREADY_IN_PROGRESS,
-    LOT_ANIMATION_ERROR_UNKNOWN
-} LOTErrorType;
-
-typedef enum
-{
-    BrushSolid = 0,
-    BrushGradient
-} LOTBrushType;
-
-typedef enum
-{
-    FillEvenOdd = 0,
-    FillWinding
-} LOTFillRule;
-
-typedef enum
-{
-    JoinMiter = 0,
-    JoinBevel,
-    JoinRound
-} LOTJoinStyle;
-
-typedef enum
-{
-    CapFlat = 0,
-    CapSquare,
-    CapRound
-} LOTCapStyle;
-
-typedef enum
-{
-    GradientLinear = 0,
-    GradientRadial
-} LOTGradientType;
-
-typedef struct LOTGradientStop
-{
-    float         pos;
-    unsigned char r, g, b, a;
-} LOTGradientStop;
-
-typedef enum
-{
-    MaskModeAdd = 0,
-    MaskModeSubstract,
-    MaskModeIntersect,
-    MaskModeDifference
-} LOTMaskMode;
-
-typedef struct LOTMask {
-    struct {
-        const float *ptPtr;
-        int          ptCount;
-        const char*  elmPtr;
-        int          elmCount;
-    } mPath;
-    LOTMaskMode mMode;
-}LOTMask;
-
-typedef enum
-{
-    MatteNone = 0,
-    MatteAlpha,
-    MatteAlphaInv,
-    MatteLuma,
-    MatteLumaInv
-} LOTMatteType;
-
-typedef struct LOTNode {
-
-#define ChangeFlagNone 0x0000
-#define ChangeFlagPath 0x0001
-#define ChangeFlagPaint 0x0010
-#define ChangeFlagAll (ChangeFlagPath & ChangeFlagPaint)
-
-    struct {
-        const float *ptPtr;
-        int          ptCount;
-        const char*  elmPtr;
-        int          elmCount;
-    } mPath;
-
-    struct {
-        unsigned char r, g, b, a;
-    } mColor;
-
-    struct {
-        unsigned char  enable;
-        int       width;
-        LOTCapStyle  cap;
-        LOTJoinStyle join;
-        int       meterLimit;
-        float*    dashArray;
-        int       dashArraySize;
-    } mStroke;
-
-    struct {
-        LOTGradientType type;
-        LOTGradientStop *stopPtr;
-        unsigned int stopCount;
-        struct {
-            float x, y;
-        } start, end, center, focal;
-        float cradius;
-        float fradius;
-    } mGradient;
-
-    int       mFlag;
-    LOTBrushType mBrushType;
-    LOTFillRule  mFillRule;
-} LOTNode;
-
-
-
-typedef struct LOTLayerNode {
-
-    struct {
-        LOTMask        *ptr;
-        unsigned int    size;
-    } mMaskList;
-
-    struct {
-        const float *ptPtr;
-        int          ptCount;
-        const char*  elmPtr;
-        int          elmCount;
-    } mClipPath;
-
-    struct {
-        struct LOTLayerNode   **ptr;
-        unsigned int          size;
-    } mLayerList;
-
-    struct {
-        LOTNode       **ptr;
-        unsigned int   size;
-    } mNodeList;
-
-    LOTMatteType mMatte;
-    int          mVisible;
-
-} LOTLayerNode;
-
-/**
- * @}
- */
-
-#endif  // _LOTTIE_COMMON_H_
+#include "rlottiecommon.h"
\ No newline at end of file
index c2d6e4e..fca654b 100644 (file)
@@ -1,3 +1,8 @@
-install_headers(['lottieanimation.h',
+install_headers([
+                 'rlottie.h',
+                 'rlottie_capi.h',
+                 'rlottiecommon.h',
+                 'lottieanimation.h',
                  'lottiecommon.h',
-                 'lottieanimation_capi.h'])
+                 'lottieanimation_capi.h'
+                ])
diff --git a/inc/rlottie.h b/inc/rlottie.h
new file mode 100644 (file)
index 0000000..47aa4e2
--- /dev/null
@@ -0,0 +1,276 @@
+/* 
+ * 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 _RLOTTIE_H_
+#define _RLOTTIE_H_
+
+#include <future>
+#include <vector>
+#include <memory>
+
+#ifdef _WIN32
+#ifdef LOT_BUILD
+#ifdef DLL_EXPORT
+#define LOT_EXPORT __declspec(dllexport)
+#else
+#define LOT_EXPORT
+#endif
+#else
+#define LOT_EXPORT __declspec(dllimport)
+#endif
+#else
+#ifdef __GNUC__
+#if __GNUC__ >= 4
+#define LOT_EXPORT __attribute__((visibility("default")))
+#else
+#define LOT_EXPORT
+#endif
+#else
+#define LOT_EXPORT
+#endif
+#endif
+
+class AnimationImpl;
+struct LOTNode;
+struct LOTLayerNode;
+
+namespace lottie {
+
+class LOT_EXPORT Surface {
+public:
+    /**
+     *  @brief Surface object constructor.
+     *
+     *  @param[in] buffer surface buffer.
+     *  @param[in] width  surface width.
+     *  @param[in] height  surface height.
+     *  @param[in] bytesPerLine  number of bytes in a surface scanline.
+     *
+     *  @note Default surface format is ARGB32_Premultiplied.
+     *
+     *  @internal
+     */
+    Surface(uint32_t *buffer, size_t width, size_t height, size_t bytesPerLine);
+
+    /**
+     *  @brief Returns width of the surface.
+     *
+     *  @return surface width
+     *
+     *  @internal
+     *
+     */
+    size_t width() const {return mWidth;}
+
+    /**
+     *  @brief Returns height of the surface.
+     *
+     *  @return surface height
+     *
+     *  @internal
+     */
+    size_t height() const {return mHeight;}
+
+    /**
+     *  @brief Returns number of bytes in the surface scanline.
+     *
+     *  @return number of bytes in scanline.
+     *
+     *  @internal
+     */
+    size_t  bytesPerLine() const {return mBytesPerLine;}
+
+    /**
+     *  @brief Returns buffer attached tp the surface.
+     *
+     *  @return buffer attaced to the Surface.
+     *
+     *  @internal
+     */
+    uint32_t *buffer() const {return mBuffer;}
+
+    /**
+     *  @brief Default constructor.
+     */
+    Surface() = default;
+private:
+    uint32_t    *mBuffer{nullptr};
+    size_t       mWidth{0};
+    size_t       mHeight{0};
+    size_t       mBytesPerLine{0};
+};
+
+class LOT_EXPORT Animation {
+public:
+
+    /**
+     *  @brief Constructs an animation object from file path.
+     *
+     *  @param[in] path Lottie resource file path
+     *
+     *  @return Animation object that can render the contents of the
+     *          Lottie resource represented by file path.
+     *
+     *  @internal
+     */
+    static std::unique_ptr<Animation>
+    loadFromFile(const std::string &path);
+
+    /**
+     *  @brief Constructs an animation object from JSON string data.
+     *
+     *  @param[in] jsonData The JSON string data.
+     *  @param[in] key the string that will be used to cache the JSON string data.
+     *
+     *  @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, const std::string &key);
+
+    /**
+     *  @brief Returns default framerate of the Lottie resource.
+     *
+     *  @return framerate of the Lottie resource
+     *
+     *  @internal
+     *
+     */
+    double frameRate() const;
+
+    /**
+     *  @brief Returns total number of frames present in the Lottie resource.
+     *
+     *  @return frame count of the Lottie resource.
+     *
+     *  @note frame number starts with 0.
+     *
+     *  @internal
+     */
+    size_t totalFrame() const;
+
+    /**
+     *  @brief Returns default viewport size of the Lottie resource.
+     *
+     *  @param[out] width  default width of the viewport.
+     *  @param[out] height default height of the viewport.
+     *
+     *  @internal
+     *
+     */
+    void   size(size_t &width, size_t &height) const;
+
+    /**
+     *  @brief Returns total animation duration of Lottie resource in second.
+     *         it uses totalFrame() and frameRate() to calculate the duration.
+     *         duration = totalFrame() / frameRate().
+     *
+     *  @return total animation duration in second.
+     *  @retval 0 if the Lottie resource has no animation.
+     *
+     *  @see totalFrame()
+     *  @see frameRate()
+     *
+     *  @internal
+     */
+    double duration() const;
+
+    /**
+     *  @brief Returns frame number for a given position.
+     *         this function helps to map the position value retuned
+     *         by the animator to a frame number in side the Lottie resource.
+     *         frame_number = lerp(start_frame, endframe, pos);
+     *
+     *  @param[in] pos normalized position value [0 ... 1]
+     *
+     *  @return frame numer maps to the position value [startFrame .... endFrame]
+     *
+     *  @internal
+     */
+    size_t frameAtPos(double pos);
+
+    /**
+     *  @brief Renders the content to surface Asynchronously.
+     *         it gives a future in return to get the result of the
+     *         rendering at a future point.
+     *         To get best performance user has to start rendering as soon as
+     *         it finds that content at {frameNo} has to be rendered and get the
+     *         result from the future at the last moment when the surface is needed
+     *         to draw into the screen.
+     *
+     *
+     *  @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
+     *  @param[in] surface Surface in which content will be drawn
+     *
+     *  @return future that will hold the result when rendering finished.
+     *
+     *  for Synchronus rendering @see renderSync
+     *
+     *  @see Surface
+     *  @internal
+     */
+    std::future<Surface> render(size_t frameNo, Surface surface);
+
+    /**
+     *  @brief Renders the content to surface synchronously.
+     *         for performance use the async rendering @see render
+     *
+     *  @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
+     *  @param[in] surface Surface in which content will be drawn
+     *
+     *  @internal
+     */
+    void              renderSync(size_t frameNo, Surface surface);
+
+    /**
+     *  @brief Returns root layer of the composition updated with
+     *         content of the Lottie resource at frame number @p frameNo.
+     *
+     *  @param[in] frameNo Content corresponds to the @p frameNo needs to be extracted.
+     *  @param[in] width   content viewbox width
+     *  @param[in] height  content viewbox height
+     *
+     *  @return Root layer node.
+     *
+     *  @internal
+     */
+    const LOTLayerNode * renderTree(size_t frameNo, size_t width, size_t height) const;
+
+    /**
+     *  @brief default destructor
+     *
+     *  @internal
+     */
+    ~Animation();
+
+private:
+    /**
+     *  @brief default constructor
+     *
+     *  @internal
+     */
+    Animation();
+
+    std::unique_ptr<AnimationImpl> d;
+};
+
+}  // namespace lotplayer
+
+#endif  // _RLOTTIE_H_
diff --git a/inc/rlottie_capi.h b/inc/rlottie_capi.h
new file mode 100644 (file)
index 0000000..8cc84c5
--- /dev/null
@@ -0,0 +1,217 @@
+/* 
+ * 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 _RLOTTIE_CAPI_H_
+#define _RLOTTIE_CAPI_H_
+
+#include <stddef.h>
+#include <stdint.h>
+#include <rlottiecommon.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Lottie_Animation_S Lottie_Animation;
+
+/**
+ *  @brief Constructs an animation object from file path.
+ *
+ *  @param[in] path Lottie resource file path
+ *
+ *  @return Animation object that can build the contents of the
+ *          Lottie resource represented by file path.
+ *
+ *  @see lottie_animation_destroy()
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path);
+
+/**
+ *  @brief Constructs an animation object from JSON string data.
+ *
+ *  @param[in] data The JSON string data.
+ *  @param[in] key the string that will be used to cache the JSON string data.
+ *
+ *  @return Animation object that can build the contents of the
+ *          Lottie resource represented by JSON string data.
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key);
+
+/**
+ *  @brief Free given Animation object resource.
+ *
+ *  @param[in] animation Animation object to free.
+ *
+ *  @see lottie_animation_from_file()
+ *  @see lottie_animation_from_data()
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT void lottie_animation_destroy(Lottie_Animation *animation);
+
+/**
+ *  @brief Returns default viewport size of the Lottie resource.
+ *
+ *  @param[in] animation Animation object.
+ *  @param[out] w default width of the viewport.
+ *  @param[out] h default height of the viewport.
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
+
+/**
+ *  @brief Returns total animation duration of Lottie resource in second.
+ *         it uses totalFrame() and frameRate() to calculate the duration.
+ *         duration = totalFrame() / frameRate().
+ *
+ *  @param[in] animation Animation object.
+ *
+ *  @return total animation duration in second.
+ *          @c 0 if the Lottie resource has no animation.
+ *
+ *  @see lottie_animation_get_totalframe()
+ *  @see lottie_animation_get_framerate()
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation *animation);
+
+/**
+ *  @brief Returns total number of frames present in the Lottie resource.
+ *
+ *  @param[in] animation Animation object.
+ *
+ *  @return frame count of the Lottie resource.*
+ *
+ *  @note frame number starts with 0.
+ *
+ *  @see lottie_animation_get_duration()
+ *  @see lottie_animation_get_framerate()
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
+
+/**
+ *  @brief Returns default framerate of the Lottie resource.
+ *
+ *  @param[in] animation Animation object.
+ *
+ *  @return framerate of the Lottie resource
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ *
+ */
+LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation *animation);
+
+/**
+ *  @brief Get the render tree which contains the snapshot of the animation object
+ *         at frame = @c frame_num, the content of the animation in that frame number.
+ *
+ *  @param[in] animation Animation object.
+ *  @param[in] width requested snapshot viewport width.
+ *  @param[in] height requested snapshot viewport height.
+ *
+ *  @return Animation snapshot tree.
+ *
+ * @note: User has to traverse the tree for rendering.
+ *
+ * @see LOTLayerNode
+ * @see LOTNode
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation *animation,
+                                                             size_t frame_num,
+                                                             size_t width, size_t height);
+
+/**
+ *  @brief Maps position to frame number and returns it.
+ *
+ *  @param[in] animation Animation object.
+ *  @param[in] pos position in the range [ 0.0 .. 1.0 ].
+ *
+ *  @return mapped frame numbe in the range [ start_frame .. end_frame ].
+ *          @c 0 if the Lottie resource has no animation.
+ *
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
+
+/**
+ *  @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
+ *
+ *  @param[in] animation Animation object.
+ *  @param[in] frame_num the frame number needs to be rendered.
+ *  @param[in] buffer surface buffer use for rendering.
+ *  @param[in] width width of the surface
+ *  @param[in] height height of the surface
+ *  @param[in] bytes_per_line stride of the surface in bytes.
+ *
+ *  @note user must call lottie_animation_render_flush() to make sure render is finished.
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT void
+lottie_animation_render_async(Lottie_Animation *animation,
+                              size_t frame_num,
+                              uint32_t *buffer,
+                              size_t width,
+                              size_t height,
+                              size_t bytes_per_line);
+
+/**
+ *  @brief Request to finish the current async renderer job for this animation object.
+ *  If render is finished then this call returns immidiately.
+ *  If not, it waits till render job finish and then return.
+ *
+ *  @param[in] animation Animation object.
+ *
+ *  @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
+ *  in pair to get the benefit of async rendering.
+ *
+ *  @return the pixel buffer it finished rendering.
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT uint32_t *
+lottie_animation_render_flush(Lottie_Animation *animation);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //_RLOTTIE_CAPI_H_
+
diff --git a/inc/rlottiecommon.h b/inc/rlottiecommon.h
new file mode 100644 (file)
index 0000000..edc6299
--- /dev/null
@@ -0,0 +1,223 @@
+/* 
+ * 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 _RLOTTIE_COMMON_H_
+#define _RLOTTIE_COMMON_H_
+
+#ifdef _WIN32
+#ifdef LOT_BUILD
+#ifdef DLL_EXPORT
+#define LOT_EXPORT __declspec(dllexport)
+#else
+#define LOT_EXPORT
+#endif
+#else
+#define LOT_EXPORT __declspec(dllimport)
+#endif
+#else
+#ifdef __GNUC__
+#if __GNUC__ >= 4
+#define LOT_EXPORT __attribute__((visibility("default")))
+#else
+#define LOT_EXPORT
+#endif
+#else
+#define LOT_EXPORT
+#endif
+#endif
+
+
+/**
+ * @defgroup Lottie_Animation Lottie_Animation
+ *
+ * Lottie Animation is a modern style vector based animation design. Its animation
+ * resource(within json format) could be generated by Adobe After Effect using
+ * bodymovin plugin. You can find a good examples in Lottie Community which
+ * shares many free resources(see: www.lottiefiles.com).
+ *
+ * This Lottie_Animation is a common engine to manipulate, control Lottie
+ * Animation from the Lottie resource - json file. It provides a scene-graph
+ * node tree per frames by user demand as well as rasterized frame images.
+ *
+ */
+
+/**
+ * @ingroup Lottie_Animation
+ */
+
+
+/**
+ * @brief Enumeration for Lottie Player error code.
+ */
+typedef enum
+{
+   //TODO: Coding convention??
+    LOT_ANIMATION_ERROR_NONE = 0,
+    LOT_ANIMATION_ERROR_NOT_PERMITTED,
+    LOT_ANIMATION_ERROR_OUT_OF_MEMORY,
+    LOT_ANIMATION_ERROR_INVALID_PARAMETER,
+    LOT_ANIMATION_ERROR_RESULT_OUT_OF_RANGE,
+    LOT_ANIMATION_ERROR_ALREADY_IN_PROGRESS,
+    LOT_ANIMATION_ERROR_UNKNOWN
+} LOTErrorType;
+
+typedef enum
+{
+    BrushSolid = 0,
+    BrushGradient
+} LOTBrushType;
+
+typedef enum
+{
+    FillEvenOdd = 0,
+    FillWinding
+} LOTFillRule;
+
+typedef enum
+{
+    JoinMiter = 0,
+    JoinBevel,
+    JoinRound
+} LOTJoinStyle;
+
+typedef enum
+{
+    CapFlat = 0,
+    CapSquare,
+    CapRound
+} LOTCapStyle;
+
+typedef enum
+{
+    GradientLinear = 0,
+    GradientRadial
+} LOTGradientType;
+
+typedef struct LOTGradientStop
+{
+    float         pos;
+    unsigned char r, g, b, a;
+} LOTGradientStop;
+
+typedef enum
+{
+    MaskModeAdd = 0,
+    MaskModeSubstract,
+    MaskModeIntersect,
+    MaskModeDifference
+} LOTMaskMode;
+
+typedef struct LOTMask {
+    struct {
+        const float *ptPtr;
+        int          ptCount;
+        const char*  elmPtr;
+        int          elmCount;
+    } mPath;
+    LOTMaskMode mMode;
+}LOTMask;
+
+typedef enum
+{
+    MatteNone = 0,
+    MatteAlpha,
+    MatteAlphaInv,
+    MatteLuma,
+    MatteLumaInv
+} LOTMatteType;
+
+typedef struct LOTNode {
+
+#define ChangeFlagNone 0x0000
+#define ChangeFlagPath 0x0001
+#define ChangeFlagPaint 0x0010
+#define ChangeFlagAll (ChangeFlagPath & ChangeFlagPaint)
+
+    struct {
+        const float *ptPtr;
+        int          ptCount;
+        const char*  elmPtr;
+        int          elmCount;
+    } mPath;
+
+    struct {
+        unsigned char r, g, b, a;
+    } mColor;
+
+    struct {
+        unsigned char  enable;
+        int       width;
+        LOTCapStyle  cap;
+        LOTJoinStyle join;
+        int       meterLimit;
+        float*    dashArray;
+        int       dashArraySize;
+    } mStroke;
+
+    struct {
+        LOTGradientType type;
+        LOTGradientStop *stopPtr;
+        unsigned int stopCount;
+        struct {
+            float x, y;
+        } start, end, center, focal;
+        float cradius;
+        float fradius;
+    } mGradient;
+
+    int       mFlag;
+    LOTBrushType mBrushType;
+    LOTFillRule  mFillRule;
+} LOTNode;
+
+
+
+typedef struct LOTLayerNode {
+
+    struct {
+        LOTMask        *ptr;
+        unsigned int    size;
+    } mMaskList;
+
+    struct {
+        const float *ptPtr;
+        int          ptCount;
+        const char*  elmPtr;
+        int          elmCount;
+    } mClipPath;
+
+    struct {
+        struct LOTLayerNode   **ptr;
+        unsigned int          size;
+    } mLayerList;
+
+    struct {
+        LOTNode       **ptr;
+        unsigned int   size;
+    } mNodeList;
+
+    LOTMatteType mMatte;
+    int          mVisible;
+
+} LOTLayerNode;
+
+/**
+ * @}
+ */
+
+#endif  // _RLOTTIE_COMMON_H_
index 084b994..6748f20 100644 (file)
@@ -16,7 +16,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "lottieanimation.h"
+#include "rlottie.h"
 #include "vdebug.h"
 
 using namespace lottie;
index c0cce77..1f041f8 100644 (file)
@@ -16,7 +16,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "lottieanimation.h"
+#include "rlottie.h"
 #include "lottieitem.h"
 #include "lottieloader.h"
 #include "lottiemodel.h"
index d225699..b38a379 100644 (file)
@@ -27,8 +27,8 @@
 #include"vpath.h"
 #include"vpoint.h"
 #include"vpathmesure.h"
-#include"lottiecommon.h"
-#include"lottieanimation.h"
+#include"rlottiecommon.h"
+#include"rlottie.h"
 #include"vpainter.h"
 #include"vdrawable.h"
 
index ee4d8a1..7b08b4f 100644 (file)
@@ -1,5 +1,5 @@
 #include <gtest/gtest.h>
-#include "lottieanimation.h"
+#include "rlottie.h"
 
 class AnimationTest : public ::testing::Test {
 public: