freetype: cherry pick optimization patches from freetype.
[platform/core/uifw/lottie-player.git] / README.md
1
2 # rlottie
3
4 [![Build Status](https://travis-ci.org/Samsung/rlottie.svg?branch=master)](https://travis-ci.org/Samsung/rlottie)
5 [![Build status](https://ci.appveyor.com/api/projects/status/n3xonxk1ooo6s7nr?svg=true&passingText=windows%20-%20passing)](https://ci.appveyor.com/project/smohantty/rlottie-mliua)
6
7
8 rlottie is a platform independent standalone c++ library for rendering vector based animations and art in realtime.
9
10 Lottie loads and renders animations and vectors exported in the bodymovin JSON format. Bodymovin JSON can be created and exported from After Effects with [bodymovin](https://github.com/bodymovin/bodymovin), Sketch with [Lottie Sketch Export](https://github.com/buba447/Lottie-Sketch-Export), and from [Haiku](https://www.haiku.ai).
11
12 For the first time, designers can create and ship beautiful animations without an engineer painstakingly recreating it by hand. Since the animation is backed by JSON they are extremely small in size but can be large in complexity! 
13
14 Here are small samples of the power of Lottie.
15
16 ![Example1](.Gifs/1.gif)
17 ![Example2](.Gifs/2.gif)
18 ![Example2](https://github.com/airbnb/lottie-ios/blob/master/_Gifs/Examples1.gif)
19
20 ## Contents
21 - [Building Lottie](#building-lottie)
22         - [Meson Build](#meson-build)
23         - [Cmake Build](#cmake-build)
24         - [Test](#test)
25 - [Demo](#demo)
26 - [Previewing Lottie JSON Files](#previewing-lottie-json-files)
27 - [Quick Start](#quick-start)
28 - [Dynamic Property](#dynamic-property)
29 - [Supported After Effects Features](#supported-after-effects-features)
30 - [Issues or Feature Requests?](#issues-or-feature-requests)
31
32 ## Building Lottie
33 rottie supports [meson](https://mesonbuild.com/) and [cmake](https://cmake.org/) build system. rottie is written in `C++14`. and has a public header dependancy of `C++11`
34
35 ### Meson Build
36 install [meson](http://mesonbuild.com/Getting-meson.html) and [ninja](https://ninja-build.org/) if not already installed.
37
38 Run meson to configure rlottie
39 ```
40 meson build
41 ```
42 Run ninja to build rlottie
43 ```
44 ninja -C build
45 ```
46
47 ### Cmake Build
48
49 Install [cmake](https://cmake.org/download/) if not already installed
50
51 Create a build directory for out of source build
52 ```
53 mkdir build
54 ```
55 Run cmake command inside build directory to configure rlottie.
56 ```
57 cd build
58 cmake ..
59
60 # install in a different path. eg ~/test/usr/lib
61
62 cmake -DCMAKE_INSTALL_PREFIX=~/test ..
63
64 ```
65 Run make to build rlottie
66
67 ```
68 make -j 2
69 ```
70 To install rlottie library
71
72 ```
73 make install
74 ```
75
76 ### Test
77
78 Configure to build test
79 ```
80 meson configure -Dtest=true
81 ```
82 Build test suit
83
84 ```
85 ninja
86 ```
87 Run test suit
88 ```
89 ninja test
90 ```
91 [Back to contents](#contents)
92
93 #
94 ## Demo
95 If you want to see rlottie librray in action without building it please visit [rlottie online viewer](http://rlottie.com)
96
97 While building rlottie library it generates a simple lottie to GIF converter which can be used to convert lottie json file to GIF file.
98
99 Run Demo 
100 ```
101 lottie2gif [lottie file name]
102 ```
103
104 #
105 ## Previewing Lottie JSON Files
106 Please visit [rlottie online viewer](http://rlottie.com)
107
108 [rlottie online viewer](http://rlottie.com) uses rlottie wasm library to render the resource locally in your browser. To test your JSON resource drag and drop it to the browser window.
109
110 #
111 ## Quick Start
112
113 Lottie loads and renders animations and vectors exported in the bodymovin JSON format. Bodymovin JSON can be created and exported from After Effects with [bodymovin](https://github.com/bodymovin/bodymovin), Sketch with [Lottie Sketch Export](https://github.com/buba447/Lottie-Sketch-Export), and from [Haiku](https://www.haiku.ai). 
114  
115 You can quickly load a Lottie animation with:
116 ```cpp
117 std::unique_ptr<rlottie::Animation> animation = 
118                                         rlottie::loadFromFile(std::string("absolute_path/test.json"));
119 ```
120 You can load a lottie animation from raw data with:
121 ```cpp
122 std::unique_ptr<rlottie::Animation> animation = rlottie::loadFromData(std::string(rawData),
123                                                                       std::string(cacheKey));
124 ```
125
126 Properties like `frameRate` , `totalFrame` , `duration` can be queried with:
127 ```cpp
128 # get the frame rate of the resource. 
129 double frameRate = animation->frameRate();
130
131 #get total frame that exists in the resource
132 size_t totalFrame = animation->totalFrame();
133
134 #get total animation duration in sec for the resource 
135 double duration = animation->duration();
136 ```
137 Render a particular frame in a surface buffer `immediately` with:
138 ```cpp
139 rlottie::Surface surface(buffer, width , height , stride);
140 animation->renderSync(frameNo, surface); 
141 ```
142 Render a particular frame in a surface buffer `asyncronousely` with:
143 ```cpp
144 rlottie::Surface surface(buffer, width , height , stride);
145 # give a render request
146 std::future<rlottie::Surface> handle = animation->render(frameNo, surface);
147 ...
148 #when the render data is needed
149 rlottie::Surface surface = handle.get();
150 ```
151
152 [Back to contents](#contents)
153
154
155 ## Dynamic Property
156
157 You can update properties dynamically at runtime. This can be used for a variety of purposes such as:
158 - Theming (day and night or arbitrary themes).
159 - Responding to events such as an error or a success.
160 - Animating a single part of an animation in response to an event.
161 - Responding to view sizes or other values not known at design time.
162
163 ### Understanding After Effects
164
165 To understand how to change animation properties in Lottie, you should first understand how animation properties are stored in Lottie. Animation properties are stored in a data tree that mimics the information heirarchy of After Effects. In After Effects a Composition is a collection of Layers that each have their own timelines. Layer objects have string names, and their contents can be an image, shape layers, fills, strokes, or just about anything that is drawable. Each object in After Effects has a name. Lottie can find these objects and properties by their name using a KeyPath.
166
167 ### Usage
168
169 To update a property at runtime, you need 3 things:
170 1. KeyPath
171 2. rLottie::Property
172 3. setValue()
173
174 ### KeyPath
175
176 A KeyPath is used to target a specific content or a set of contents that will be updated. A KeyPath is specified by a list of strings that correspond to the hierarchy of After Effects contents in the original animation.
177 KeyPaths can include the specific name of the contents or wildcards:
178 - Wildcard *
179         - Wildcards match any single content name in its position in the keypath.
180 - Globstar **
181         - Globstars match zero or more layers.
182
183 ### Properties
184
185 `rLottie::Property` is an enumeration of properties that can be set. They correspond to the animatable value in After Effects and the available properties are listed below.
186 ```cpp
187 enum class Property {
188     FillColor,     /*!< Color property of Fill object , value type is rlottie::Color */
189     FillOpacity,   /*!< Opacity property of Fill object , value type is float [ 0 .. 100] */
190     StrokeColor,   /*!< Color property of Stroke object , value type is rlottie::Color */
191     StrokeOpacity, /*!< Opacity property of Stroke object , value type is float [ 0 .. 100] */
192     StrokeWidth,   /*!< stroke with property of Stroke object , value type is float */
193     ...
194 };
195 ```
196
197 ### setValue()
198
199 `setValue()` requires a keypath of string and value. The value can be `Color`, `Size` and `Point` structure or a function that returns them. `Color`, `Size`, and `Point` vary depending on the type of `rLottie::Property`. This value or function(callback) is called and applied to every frame. This value can be set differently for each frame by using the `FrameInfo` argument passed to the function.
200
201
202 ### Usage
203 ```cpp
204 animation->setValue<rlottie::Property::FillColor>("**",rlottie::Color(0, 1, 0));
205 ```
206
207 ```cpp
208 animation->setValue<rlottie::Property::FillColor>("Layer1.Box 1.Fill1",
209     [](const rlottie::FrameInfo& info) {
210          if (info.curFrame() < 15 )
211              return rlottie::Color(0, 1, 0);
212          else {
213              return rlottie::Color(1, 0, 0);
214          }
215      });
216 ```
217
218 [Back to contents](#contents)
219
220 #
221 #
222 ## Supported After Effects Features
223
224 | **Shapes** | **Supported** |
225 |:--|:-:|
226 | Shape | 👍 |
227 | Ellipse | 👍 |
228 | Rectangle | 👍 |
229 | Rounded Rectangle | 👍 |
230 | Polystar | 👍 |
231 | Group | 👍 |
232 | Trim Path (individually) | 👍 |
233 | Trim Path (simultaneously) | 👍 |
234 | **Renderable** | **Supported** |
235 | Fill  | 👍 |
236 | Stroke | 👍 |
237 | Radial Gradient | 👍 |
238 | Linear Gradient | 👍 | 
239 | Gradient Stroke | 👍 | 
240 | **Transforms** | **Supported** |
241 | Position | 👍 |
242 | Position (separated X/Y) | 👍 |
243 | Scale | 👍 |
244 | Skew | ⛔️ |
245 | Rotation | 👍 | 
246 | Anchor Point | 👍 |
247 | Opacity | 👍 |
248 | Parenting | 👍 |
249 | Auto Orient | 👍 |
250 | **Interpolation** | **Supported** |
251 | Linear Interpolation | 👍 |
252 | Bezier Interpolation | 👍 |
253 | Hold Interpolation | 👍 |
254 | Spatial Bezier Interpolation | 👍 |
255 | Rove Across Time | 👍 |
256 | **Masks** | **Supported** |
257 | Mask Path | 👍 |
258 | Mask Opacity | 👍 |
259 | Add | 👍 |
260 | Subtract | 👍 |
261 | Intersect | 👍 |
262 | Lighten | ⛔️ |
263 | Darken | ⛔️ |
264 | Difference | ⛔️ |
265 | Expansion | ⛔️ |
266 | Feather | ⛔️ |
267 | **Mattes** | **Supported** |
268 | Alpha Matte | 👍 |
269 | Alpha Inverted Matte | 👍 |
270 | Luma Matte | 👍 |
271 | Luma Inverted Matte | 👍 |
272 | **Merge Paths** | **Supported** |
273 | Merge | ⛔️ |
274 | Add | ⛔️ |
275 | Subtract | ⛔️ |
276 | Intersect | ⛔️ |
277 | Exclude Intersection | ⛔️ |
278 | **Layer Effects** | **Supported** |
279 | Fill | ⛔️ |
280 | Stroke | ⛔️ |
281 | Tint | ⛔️ |
282 | Tritone | ⛔️ |
283 | Levels Individual Controls | ⛔️ |
284 | **Text** | **Supported** |
285 | Glyphs |  ⛔️ | 
286 | Fonts | ⛔️ |
287 | Transform | ⛔️ |
288 | Fill | ⛔️ | 
289 | Stroke | ⛔️ | 
290 | Tracking | ⛔️ | 
291 | Anchor point grouping | ⛔️ | 
292 | Text Path | ⛔️ |
293 | Per-character 3D | ⛔️ |
294 | Range selector (Units) | ⛔️ |
295 | Range selector (Based on) | ⛔️ |
296 | Range selector (Amount) | ⛔️ |
297 | Range selector (Shape) | ⛔️ |
298 | Range selector (Ease High) | ⛔️ |
299 | Range selector (Ease Low)  | ⛔️ |
300 | Range selector (Randomize order) | ⛔️ |
301 | expression selector | ⛔️ |
302 | **Other** | **Supported** |
303 | Expressions | ⛔️ |
304 | Images | 👍 |
305 | Precomps | 👍 |
306 | Time Stretch |  👍 |
307 | Time remap |  👍 |
308 | Markers | 👍  |
309
310 #
311 [Back to contents](#contents)
312
313 ## Issues or Feature Requests?
314 File github issues for anything that is broken. Be sure to check the [list of supported features](#supported-after-effects-features) before submitting.  If an animation is not working, please attach the After Effects file to your issue. Debugging without the original can be very difficult. For immidiate assistant or support please reach us in [Gitter](https://gitter.im/rLottie-dev/community#)