rlottie_capi.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. * The above copyright notice and this permission notice shall be included in all
  10. * copies or substantial portions of the Software.
  11. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. * SOFTWARE.
  18. */
  19. #ifndef _RLOTTIE_CAPI_H_
  20. #define _RLOTTIE_CAPI_H_
  21. #include <stddef.h>
  22. #include <stdint.h>
  23. #include "rlottiecommon.h"
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. typedef enum {
  28. LOTTIE_ANIMATION_PROPERTY_FILLCOLOR, /*!< Color property of Fill object , value type is float [0 ... 1] */
  29. LOTTIE_ANIMATION_PROPERTY_FILLOPACITY, /*!< Opacity property of Fill object , value type is float [ 0 .. 100] */
  30. LOTTIE_ANIMATION_PROPERTY_STROKECOLOR, /*!< Color property of Stroke object , value type is float [0 ... 1] */
  31. LOTTIE_ANIMATION_PROPERTY_STROKEOPACITY, /*!< Opacity property of Stroke object , value type is float [ 0 .. 100] */
  32. LOTTIE_ANIMATION_PROPERTY_STROKEWIDTH, /*!< stroke with property of Stroke object , value type is float */
  33. LOTTIE_ANIMATION_PROPERTY_TR_ANCHOR, /*!< Transform Anchor property of Layer and Group object , value type is int */
  34. LOTTIE_ANIMATION_PROPERTY_TR_POSITION, /*!< Transform Position property of Layer and Group object , value type is int */
  35. LOTTIE_ANIMATION_PROPERTY_TR_SCALE, /*!< Transform Scale property of Layer and Group object , value type is float range[0 ..100] */
  36. LOTTIE_ANIMATION_PROPERTY_TR_ROTATION, /*!< Transform Scale property of Layer and Group object , value type is float. range[0 .. 360] in degrees*/
  37. LOTTIE_ANIMATION_PROPERTY_TR_OPACITY /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */
  38. }Lottie_Animation_Property;
  39. typedef struct Lottie_Animation_S Lottie_Animation;
  40. /**
  41. * @brief Runs lottie initialization code when rlottie library is loaded
  42. * dynamically.
  43. *
  44. *
  45. * This api should be called before any other api when rlottie library
  46. * is loaded using dlopen() or equivalent.
  47. *
  48. * @see lottie_shutdown()
  49. *
  50. * @ingroup Lottie_Animation
  51. * @internal
  52. */
  53. RLOTTIE_API void lottie_init(void);
  54. /**
  55. * @brief Runs lottie teardown code when rlottie library is loaded
  56. * dynamically.
  57. *
  58. * This api should be called before unloading the rlottie library for
  59. * proper cleanup of the resource without doing so will result in undefined
  60. * behaviour.
  61. *
  62. * @see lottie_init()
  63. *
  64. * @ingroup Lottie_Animation
  65. * @internal
  66. */
  67. RLOTTIE_API void lottie_shutdown(void);
  68. /**
  69. * @brief Constructs an animation object from file path.
  70. *
  71. * @param[in] path Lottie resource file path
  72. *
  73. * @return Animation object that can build the contents of the
  74. * Lottie resource represented by file path.
  75. *
  76. * @see lottie_animation_destroy()
  77. *
  78. * @ingroup Lottie_Animation
  79. * @internal
  80. */
  81. RLOTTIE_API Lottie_Animation *lottie_animation_from_file(const char *path);
  82. /**
  83. * @brief Constructs an animation object from JSON string data.
  84. *
  85. * @param[in] data The JSON string data.
  86. * @param[in] key the string that will be used to cache the JSON string data.
  87. * @param[in] resource_path the path that will be used to load external resource needed by the JSON data.
  88. *
  89. * @return Animation object that can build the contents of the
  90. * Lottie resource represented by JSON string data.
  91. *
  92. * @ingroup Lottie_Animation
  93. * @internal
  94. */
  95. RLOTTIE_API Lottie_Animation *lottie_animation_from_data(const char *data, const char *key, const char *resource_path);
  96. /**
  97. * @brief Free given Animation object resource.
  98. *
  99. * @param[in] animation Animation object to free.
  100. *
  101. * @see lottie_animation_from_file()
  102. * @see lottie_animation_from_data()
  103. *
  104. * @ingroup Lottie_Animation
  105. * @internal
  106. */
  107. RLOTTIE_API void lottie_animation_destroy(Lottie_Animation *animation);
  108. /**
  109. * @brief Returns default viewport size of the Lottie resource.
  110. *
  111. * @param[in] animation Animation object.
  112. * @param[out] w default width of the viewport.
  113. * @param[out] h default height of the viewport.
  114. *
  115. * @ingroup Lottie_Animation
  116. * @internal
  117. */
  118. RLOTTIE_API void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
  119. /**
  120. * @brief Returns total animation duration of Lottie resource in second.
  121. * it uses totalFrame() and frameRate() to calculate the duration.
  122. * duration = totalFrame() / frameRate().
  123. *
  124. * @param[in] animation Animation object.
  125. *
  126. * @return total animation duration in second.
  127. * @c 0 if the Lottie resource has no animation.
  128. *
  129. * @see lottie_animation_get_totalframe()
  130. * @see lottie_animation_get_framerate()
  131. *
  132. * @ingroup Lottie_Animation
  133. * @internal
  134. */
  135. RLOTTIE_API double lottie_animation_get_duration(const Lottie_Animation *animation);
  136. /**
  137. * @brief Returns total number of frames present in the Lottie resource.
  138. *
  139. * @param[in] animation Animation object.
  140. *
  141. * @return frame count of the Lottie resource.*
  142. *
  143. * @note frame number starts with 0.
  144. *
  145. * @see lottie_animation_get_duration()
  146. * @see lottie_animation_get_framerate()
  147. *
  148. * @ingroup Lottie_Animation
  149. * @internal
  150. */
  151. RLOTTIE_API size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
  152. /**
  153. * @brief Returns default framerate of the Lottie resource.
  154. *
  155. * @param[in] animation Animation object.
  156. *
  157. * @return framerate of the Lottie resource
  158. *
  159. * @ingroup Lottie_Animation
  160. * @internal
  161. *
  162. */
  163. RLOTTIE_API double lottie_animation_get_framerate(const Lottie_Animation *animation);
  164. /**
  165. * @brief Get the render tree which contains the snapshot of the animation object
  166. * at frame = @c frame_num, the content of the animation in that frame number.
  167. *
  168. * @param[in] animation Animation object.
  169. * @param[in] frame_num Content corresponds to the @p frame_num needs to be drawn
  170. * @param[in] width requested snapshot viewport width.
  171. * @param[in] height requested snapshot viewport height.
  172. *
  173. * @return Animation snapshot tree.
  174. *
  175. * @note: User has to traverse the tree for rendering.
  176. *
  177. * @see LOTLayerNode
  178. * @see LOTNode
  179. *
  180. * @ingroup Lottie_Animation
  181. * @internal
  182. */
  183. RLOTTIE_API const LOTLayerNode *lottie_animation_render_tree(Lottie_Animation *animation, size_t frame_num, size_t width, size_t height);
  184. /**
  185. * @brief Maps position to frame number and returns it.
  186. *
  187. * @param[in] animation Animation object.
  188. * @param[in] pos position in the range [ 0.0 .. 1.0 ].
  189. *
  190. * @return mapped frame numbe in the range [ start_frame .. end_frame ].
  191. * @c 0 if the Lottie resource has no animation.
  192. *
  193. *
  194. * @ingroup Lottie_Animation
  195. * @internal
  196. */
  197. RLOTTIE_API size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
  198. /**
  199. * @brief Request to render the content of the frame @p frame_num to buffer @p buffer.
  200. *
  201. * @param[in] animation Animation object.
  202. * @param[in] frame_num the frame number needs to be rendered.
  203. * @param[in] buffer surface buffer use for rendering.
  204. * @param[in] width width of the surface
  205. * @param[in] height height of the surface
  206. * @param[in] bytes_per_line stride of the surface in bytes.
  207. *
  208. *
  209. * @ingroup Lottie_Animation
  210. * @internal
  211. */
  212. RLOTTIE_API void lottie_animation_render(Lottie_Animation *animation, size_t frame_num, uint32_t *buffer, size_t width, size_t height, size_t bytes_per_line);
  213. /**
  214. * @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
  215. *
  216. * @param[in] animation Animation object.
  217. * @param[in] frame_num the frame number needs to be rendered.
  218. * @param[in] buffer surface buffer use for rendering.
  219. * @param[in] width width of the surface
  220. * @param[in] height height of the surface
  221. * @param[in] bytes_per_line stride of the surface in bytes.
  222. *
  223. * @note user must call lottie_animation_render_flush() to make sure render is finished.
  224. *
  225. * @ingroup Lottie_Animation
  226. * @internal
  227. */
  228. RLOTTIE_API 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);
  229. /**
  230. * @brief Request to finish the current async renderer job for this animation object.
  231. * If render is finished then this call returns immidiately.
  232. * If not, it waits till render job finish and then return.
  233. *
  234. * @param[in] animation Animation object.
  235. *
  236. * @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
  237. * in pair to get the benefit of async rendering.
  238. *
  239. * @return the pixel buffer it finished rendering.
  240. *
  241. * @ingroup Lottie_Animation
  242. * @internal
  243. */
  244. RLOTTIE_API uint32_t *lottie_animation_render_flush(Lottie_Animation *animation);
  245. /**
  246. * @brief Request to change the properties of this animation object.
  247. * Keypath should conatin object names separated by (.) and can handle globe(**) or wildchar(*)
  248. *
  249. * @usage
  250. * To change fillcolor property of fill1 object in the layer1->group1->fill1 hirarchy to RED color
  251. *
  252. * lottie_animation_property_override(animation, LOTTIE_ANIMATION_PROPERTY_FILLCOLOR, "layer1.group1.fill1", 1.0, 0.0, 0.0);
  253. *
  254. * if all the color property inside group1 needs to be changed to GREEN color
  255. *
  256. * lottie_animation_property_override(animation, LOTTIE_ANIMATION_PROPERTY_FILLCOLOR, "**.group1.**", 1.0, 0.0, 0.0);
  257. *
  258. * @param[in] animation Animation object.
  259. * @param[in] type Property type. (@p Lottie_Animation_Property)
  260. * @param[in] keypath Specific content of target.
  261. * @param[in] ... Property values.
  262. *
  263. * @ingroup Lottie_Animation
  264. * @internal
  265. * */
  266. RLOTTIE_API void lottie_animation_property_override(Lottie_Animation *animation, const Lottie_Animation_Property type, const char *keypath, ...);
  267. /**
  268. * @brief Returns list of markers in the Lottie resource
  269. * @p LOTMarkerList has a @p LOTMarker list and size of list
  270. * @p LOTMarker has the marker's name, start frame, and end frame.
  271. *
  272. * @param[in] animation Animation object.
  273. *
  274. * @return The list of marker. If there is no marker, return null.
  275. *
  276. * @ingroup Lottie_Animation
  277. * @internal
  278. * */
  279. RLOTTIE_API const LOTMarkerList* lottie_animation_get_markerlist(Lottie_Animation *animation);
  280. /**
  281. * @brief Configures rlottie model cache policy.
  282. *
  283. * Provides Library level control to configure model cache
  284. * policy. Setting it to 0 will disable
  285. * the cache as well as flush all the previously cached content.
  286. *
  287. * @param[in] cacheSize Maximum Model Cache size.
  288. *
  289. * @note to disable Caching configure with 0 size.
  290. * @note to flush the current Cache content configure it with 0 and
  291. * then reconfigure with the new size.
  292. *
  293. * @internal
  294. */
  295. RLOTTIE_API void lottie_configure_model_cache_size(size_t cacheSize);
  296. #ifdef __cplusplus
  297. }
  298. #endif
  299. #endif //_RLOTTIE_CAPI_H_