python-lottie  0.6.10+devbd5499b
A framework to work with lottie files and telegram animated stickers (tgs)
effects.py
Go to the documentation of this file.
1 from .base import LottieObject, LottieProp, PseudoBool
2 from .properties import Value, MultiDimensional, ColorValue
3 from ..nvector import NVector
4 from ..utils.color import Color
5 
6 
7 #5: EffectsManager,
8 #11: MaskEffect,
10  """!
11  Value for an effect
12  """
13  ## %Effect value type.
14  type = None
15  _classses = {}
16 
17  _props = [
18  LottieProp("effect_index", "ix", int, False),
19  #LottieProp("match_name", "mn", str, False),
20  LottieProp("name", "nm", str, False),
21  LottieProp("type", "ty", int, False),
22  ]
23 
24  def __init__(self):
25  ## Effect Index. Used for expressions.
26  self.effect_index = None
27  ## After Effect's Name. Used for expressions.
28  self.name = None
29 
30  """
31  ## After Effect's Match Name. Used for expressions.
32  self.match_name = ""
33  """
34 
35  @classmethod
36  def _load_get_class(cls, lottiedict):
37  if not EffectValue._classses:
38  EffectValue._classses = {
39  sc.type: sc
40  for sc in EffectValue.__subclasses__()
41  }
42  return EffectValue._classses[lottiedict["ty"]]
43 
44  def __str__(self):
45  return self.name or super().__str__()
46 
47 
48 ## @ingroup Lottie
50  """!
51  Layer effect
52  """
53  ## %Effect type.
54  type = None
55  _classses = {}
56 
57  _props = [
58  LottieProp("effect_index", "ix", int, False),
59  #LottieProp("match_name", "mn", str, False),
60  LottieProp("name", "nm", str, False),
61  LottieProp("type", "ty", int, False),
62  LottieProp("effects", "ef", EffectValue, True),
63  ]
64  _effects = []
65 
66  def __init__(self, *args, **kwargs):
67  ## Effect Index. Used for expressions.
68  self.effect_index = None
69  ## After Effect's Name. Used for expressions.
70  self.name = None
71  ## Effect parameters
72  self.effects = self._load_values(*args, **kwargs)
73 
74  """
75  ## After Effect's Match Name. Used for expressions.
76  self.match_name = ""
77  """
78 
79  @classmethod
80  def _load_get_class(cls, lottiedict):
81  if not Effect._classses:
82  Effect._classses = {
83  sc.type: sc
84  for sc in Effect.__subclasses__()
85  }
86  type = lottiedict["ty"]
87 
88  if type in Effect._classses:
89  return Effect._classses[type]
90  else:
91  return Effect
92 
93  def _load_values(self, *args, **kwargs):
94  values = []
95  for i, (name, type) in enumerate(self._effects):
96  val = []
97  if len(args) > i:
98  val = [args[i]]
99  if name in kwargs:
100  val = [kwargs[name]]
101  values.append(type(*val))
102  return values
103 
104  def __getattr__(self, key):
105  for i, (name, type) in enumerate(self._effects):
106  if name == key:
107  return self.effects[i].value
108  return super().__getattr__(key)
109 
110  def __str__(self):
111  return self.name or super().__str__()
112 
113 
114 ## @ingroup Lottie
115 ## @ingroup LottieCheck
117  _props = []
118 
119 
120 ## @ingroup Lottie
122  _props = [
123  LottieProp("value", "v", Value, False),
124  ]
125  ## %Effect type.
126  type = 0
127 
128  def __init__(self, value=0):
129  EffectValue.__init__(self)
130  ## Effect value.
131  self.value = Value(value)
132 
133 
134 ## @ingroup Lottie
136  _props = [
137  LottieProp("value", "v", Value, False),
138  ]
139  ## %Effect type.
140  type = 1
141 
142  def __init__(self, angle=0):
143  EffectValue.__init__(self)
144  ## Effect value.
145  self.value = Value(angle)
146 
147 
148 ## @ingroup Lottie
150  _props = [
151  LottieProp("value", "v", ColorValue, False),
152  ]
153  ## %Effect type.
154  type = 2
155 
156  def __init__(self, value=Color(0, 0, 0)):
157  EffectValue.__init__(self)
158  ## Effect value.
159  self.value = ColorValue(value)
160 
161 
162 ## @ingroup Lottie
164  _props = [
165  LottieProp("value", "v", MultiDimensional, False),
166  ]
167  ## %Effect type.
168  type = 3
169 
170  def __init__(self, value=NVector(0, 0)):
171  EffectValue.__init__(self)
172  ## Effect value.
173  self.value = MultiDimensional(value)
174 
175 
176 ## @ingroup Lottie
178  _props = [
179  LottieProp("value", "v", Value, False),
180  ]
181  ## %Effect type.
182  type = 4
183 
184  def __init__(self, value=0):
185  EffectValue.__init__(self)
186  ## Effect value.
187  self.value = Value(value)
188 
189 
190 ## @ingroup Lottie
191 ## @ingroup LottieCheck
192 ## Lottie-web ignores these
194  _props = [
195  LottieProp("value", "v", float, False),
196  ]
197  ## %Effect type.
198  type = 6
199 
200  def __init__(self, value=0):
201  EffectValue.__init__(self)
202  ## Effect value.
203  self.value = value
204 
205 
206 ## @ingroup Lottie
207 ## @ingroup LottieCheck
209  _props = [
210  LottieProp("value", "v", Value, False),
211  ]
212  ## %Effect type.
213  type = 7
214 
215  def __init__(self, value=0):
216  EffectValue.__init__(self)
217  ## Effect value.
218  self.value = Value(value)
219 
220 
221 ## @ingroup Lottie
222 ## @ingroup LottieCheck
224  _props = [
225  LottieProp("value", "v", Value, False),
226  ]
227  ## %Effect type.
228  type = 10
229 
230  def __init__(self):
231  EffectValue.__init__(self)
232  ## Effect value.
233  self.value = Value()
234 
235 
236 ## @ingroup Lottie
238  """!
239  Replaces the whole layer with the given color
240  @note Opacity is in [0, 1]
241  """
242  _effects = [
243  ("00", EffectValuePoint),
244  ("01", EffectValueDropDown),
245  ("color", EffectValueColor),
246  ("03", EffectValueDropDown),
247  ("04", EffectValueSlider),
248  ("05", EffectValueSlider),
249  ("opacity", EffectValueSlider),
250  ]
251  ## %Effect type.
252  type = 21
253 
254 
255 ## @ingroup Lottie
257  _effects = [
258  ("00", EffectValueColor),
259  ("01", EffectValueCheckbox),
260  ("02", EffectValueCheckbox),
261  ("color", EffectValueColor),
262  ("04", EffectValueSlider),
263  ("05", EffectValueSlider),
264  ("06", EffectValueSlider),
265  ("07", EffectValueSlider),
266  ("08", EffectValueSlider),
267  ("09", EffectValueDropDown),
268  ("type", EffectValueDropDown),
269  ]
270  ## %Effect type.
271  type = 22
272 
273 
274 ## @ingroup Lottie
276  """!
277  Maps layers colors based on bright/mid/dark colors
278  """
279  _effects = [
280  ("bright", EffectValueColor),
281  ("mid", EffectValueColor),
282  ("dark", EffectValueColor),
283  ]
284  ## %Effect type.
285  type = 23
286 
287 
288 """
289 ## @ingroup Lottie
290 ## @ingroup LottieCheck
291 class GroupEffect(Effect):
292  _props = [
293  LottieProp("enabled", "en", PseudoBool, False),
294  ]
295 
296  def __init__(self):
297  Effect.__init__(self)
298  ## Enabled AE property value
299  self.enabled = True
300 """
301 
302 
303 ## @ingroup Lottie
304 ## @ingroup LottieCheck
306  _effects = [
307  ("00", EffectValueDropDown),
308  ("01", EffectNoValue),
309  ("02", EffectNoValue),
310  ("comp_inblack", EffectValueSlider),
311  ("comp_inwhite", EffectValueSlider),
312  ("comp_gamma", EffectValueSlider),
313  ("comp_outblack", EffectValueSlider),
314  ("comp_outwhite", EffectNoValue),
315  ("08", EffectNoValue),
316  ("09", EffectValueSlider),
317  ("r_inblack", EffectValueSlider),
318  ("r_inwhite", EffectValueSlider),
319  ("r_gamma", EffectValueSlider),
320  ("r_outblack", EffectValueSlider),
321  ("r_outwhite", EffectNoValue),
322  ("15", EffectValueSlider),
323  ("16", EffectValueSlider),
324  ("g_inblack", EffectValueSlider),
325  ("g_inwhite", EffectValueSlider),
326  ("g_gamma", EffectValueSlider),
327  ("g_outblack", EffectValueSlider),
328  ("g_outwhite", EffectNoValue),
329  ("22", EffectValueSlider),
330  ("b3", EffectValueSlider),
331  ("b_inblack", EffectValueSlider),
332  ("b_inwhite", EffectValueSlider),
333  ("b_gamma", EffectValueSlider),
334  ("b_outblack", EffectValueSlider),
335  ("b_outwhite", EffectNoValue),
336  ("29", EffectValueSlider),
337  ("a_inblack", EffectValueSlider),
338  ("a_inwhite", EffectValueSlider),
339  ("a_gamma", EffectValueSlider),
340  ("a_outblack", EffectValueSlider),
341  ("a_outwhite", EffectNoValue),
342  ]
343  ## %Effect type.
344  type = 24
345 
346 
347 ## @ingroup Lottie
349  """!
350  Colorizes the layer
351  @note Opacity is in [0, 100]
352  """
353  _effects = [
354  ("color_black", EffectValueColor),
355  ("color_white", EffectValueColor),
356  ("opacity", EffectValueSlider),
357  ]
358  ## %Effect type.
359  type = 20
360 
361 
362 ## @ingroup Lottie
364  """!
365  Adds a shadow to the layer
366  @note Opacity is in [0, 255]
367  """
368  _effects = [
369  ("color", EffectValueColor),
370  ("opacity", EffectValueSlider),
371  ("angle", EffectValueAngle),
372  ("distance", EffectValueSlider),
373  ("blur", EffectValueSlider),
374  ]
375  ## %Effect type.
376  type = 25
377 
378 
379 ## @ingroup Lottie
380 ## @ingroup LottieCheck
382  _effects = [
383  ("index", EffectValueSlider),
384  ]
385  ## %Effect type.
386  type = 28
387 
388 
389 ## @ingroup Lottie
391  """!
392  Gaussian blur
393  """
394  _effects = [
395  ("sigma", EffectValueSlider),
396  ("dimensions", EffectValueSlider),
397  ("wrap", EffectValueCheckbox),
398  ]
399  ## %Effect type.
400  type = 29
401 
402 
403 #class ChangeColorEffect(Effect):
404  #"""!
405  #Gaussian blur
406  #"""
407  #_effects = [
408  #("view", EffectValueDropDown),
409  #("hue", EffectValueSlider),
410  #("lightness", EffectValueSlider),
411  #("saturation", EffectValueSlider),
412  #("color_to_change", EffectValueColor),
413  #("tolerance", EffectValueSlider),
414  #("softness", EffectValueSlider),
415  #("match", EffectValueDropDown),
416  #("invert_mask", EffectValueDropDown),
417  #]
418  ### %Effect type.
419  #type = 29
420 
421 
422 ## @ingroup Lottie
424  """!
425  Change to color
426  """
427  _effects = [
428  ("from_color", EffectValueColor),
429  ("to_color", EffectValueColor),
430  ("change", EffectValueDropDown),
431  ("change_by", EffectValueDropDown),
432  ("tolerance", IgnoredValue),
433  ("hue", EffectValueSlider),
434  ("lightness", EffectValueSlider),
435  ("saturation", EffectValueSlider),
436  ("saturation_", IgnoredValue),
437  ("softness", EffectValueSlider),
438  ("view_correction", EffectValueDropDown),
439  ]
440  ## %Effect type.
441  type = 5
lottie.objects.effects.EffectValueCheckbox
Definition: effects.py:177
lottie.objects.effects.Effect._effects
list _effects
Definition: effects.py:64
lottie.objects.effects.EffectValueColor.value
value
Effect value.
Definition: effects.py:159
lottie.objects.effects.ChangeToColorEffect
Change to color.
Definition: effects.py:423
lottie.objects.properties.Value
An animatable property that holds a float.
Definition: properties.py:608
lottie.objects.effects.IgnoredValue.__init__
def __init__(self, value=0)
Definition: effects.py:200
lottie.objects.effects.TritoneEffect
Maps layers colors based on bright/mid/dark colors.
Definition: effects.py:275
lottie.objects.effects.Matte3Effect
Definition: effects.py:381
lottie.objects.effects.IgnoredValue
Definition: effects.py:193
lottie.objects.effects.FillEffect
Replaces the whole layer with the given color.
Definition: effects.py:237
lottie.objects.effects.EffectValuePoint.__init__
def __init__(self, value=NVector(0, 0))
Definition: effects.py:170
lottie.objects.effects.IgnoredValue.value
value
Effect value.
Definition: effects.py:203
lottie.objects.effects.EffectValueColor.__init__
def __init__(self, value=Color(0, 0, 0))
Definition: effects.py:156
lottie.objects.effects.Effect.effects
effects
Effect parameters.
Definition: effects.py:72
lottie.objects.effects.EffectValueSlider.value
value
Effect value.
Definition: effects.py:131
lottie.objects.effects.EffectValueLayer.value
value
Effect value.
Definition: effects.py:233
lottie.objects.effects.EffectValue.__str__
def __str__(self)
Definition: effects.py:44
lottie.objects.base.LottieObject
Base class for mapping Python classes into Lottie JSON objects.
Definition: base.py:224
lottie.objects.effects.StrokeEffect
Definition: effects.py:256
lottie.objects.effects.Effect.__str__
def __str__(self)
Definition: effects.py:110
lottie.objects.effects.Effect.__init__
def __init__(self, *args, **kwargs)
Definition: effects.py:66
lottie.objects.effects.EffectValueAngle
Definition: effects.py:135
lottie.objects.base.LottieProp
Lottie <-> Python property mapper.
Definition: base.py:88
lottie.objects.effects.EffectValueSlider
Definition: effects.py:121
lottie.objects.effects.Effect.__getattr__
def __getattr__(self, key)
Definition: effects.py:104
lottie.objects.effects.EffectValue.effect_index
effect_index
Effect Index.
Definition: effects.py:26
lottie.objects.effects.Effect.name
name
After Effect's Name.
Definition: effects.py:70
lottie.objects.effects.Effect
Layer effect.
Definition: effects.py:49
lottie.objects.effects.EffectValue.name
name
After Effect's Name.
Definition: effects.py:28
lottie.objects.effects.EffectValueLayer.__init__
def __init__(self)
Definition: effects.py:230
lottie.objects.effects.EffectValueLayer
Definition: effects.py:223
lottie.objects.effects.EffectValueAngle.__init__
def __init__(self, angle=0)
Definition: effects.py:142
lottie.objects.effects.EffectValueCheckbox.__init__
def __init__(self, value=0)
Definition: effects.py:184
lottie.objects.effects.EffectValueCheckbox.value
value
Effect value.
Definition: effects.py:187
lottie.objects.effects.EffectValueColor
Definition: effects.py:149
lottie.objects.effects.EffectValueDropDown.__init__
def __init__(self, value=0)
Definition: effects.py:215
lottie.objects.effects.DropShadowEffect
Adds a shadow to the layer.
Definition: effects.py:363
lottie.objects.effects.Effect._load_values
def _load_values(self, *args, **kwargs)
Definition: effects.py:93
lottie.objects.effects.GaussianBlurEffect
Gaussian blur.
Definition: effects.py:390
lottie.objects.effects.Effect.effect_index
effect_index
Effect Index.
Definition: effects.py:68
lottie.objects.effects.EffectValue
Value for an effect.
Definition: effects.py:9
lottie.objects.effects.ProLevelsEffect
Definition: effects.py:305
lottie.objects.effects.EffectNoValue
Definition: effects.py:116
lottie.objects.effects.TintEffect
Colorizes the layer.
Definition: effects.py:348
lottie.objects.effects.EffectValueDropDown
Definition: effects.py:208
lottie.objects.effects.EffectValuePoint.value
value
Effect value.
Definition: effects.py:173
lottie.objects.effects.Effect.type
type
Effect type.
Definition: effects.py:54
lottie.objects.properties.MultiDimensional
An animatable property that holds a NVector.
Definition: properties.py:385
lottie.objects.effects.EffectValueAngle.value
value
Effect value.
Definition: effects.py:145
lottie.objects.effects.EffectValueSlider.__init__
def __init__(self, value=0)
Definition: effects.py:128
lottie.objects.effects.EffectValuePoint
Definition: effects.py:163
lottie.objects.effects.EffectValue.__init__
def __init__(self)
Definition: effects.py:24
lottie.objects.effects.EffectValueDropDown.value
value
Effect value.
Definition: effects.py:218
lottie.objects.properties.ColorValue
An animatable property that holds a Color.
Definition: properties.py:452