File indexing completed on 2025-01-19 03:59:52

0001 from .base import LottieObject, LottieProp, PseudoBool
0002 from .properties import Value, MultiDimensional, ColorValue
0003 from ..nvector import NVector
0004 from ..utils.color import Color
0005 
0006 
0007 #5: EffectsManager,
0008 #11: MaskEffect,
0009 class EffectValue(LottieObject):
0010     """!
0011     Value for an effect
0012     """
0013     ## %Effect value type.
0014     type = None
0015     _classses = {}
0016 
0017     _props = [
0018         LottieProp("effect_index", "ix", int, False),
0019         #LottieProp("match_name", "mn", str, False),
0020         LottieProp("name", "nm", str, False),
0021         LottieProp("type", "ty", int, False),
0022     ]
0023 
0024     def __init__(self):
0025         ## Effect Index. Used for expressions.
0026         self.effect_index = None
0027         ## After Effect's Name. Used for expressions.
0028         self.name = None
0029 
0030         """
0031         ## After Effect's Match Name. Used for expressions.
0032         self.match_name = ""
0033         """
0034 
0035     @classmethod
0036     def _load_get_class(cls, lottiedict):
0037         if not EffectValue._classses:
0038             EffectValue._classses = {
0039                 sc.type: sc
0040                 for sc in EffectValue.__subclasses__()
0041             }
0042         return EffectValue._classses[lottiedict["ty"]]
0043 
0044     def __str__(self):
0045         return self.name or super().__str__()
0046 
0047 
0048 ## @ingroup Lottie
0049 class Effect(LottieObject):
0050     """!
0051     Layer effect
0052     """
0053     ## %Effect type.
0054     type = None
0055     _classses = {}
0056 
0057     _props = [
0058         LottieProp("effect_index", "ix", int, False),
0059         #LottieProp("match_name", "mn", str, False),
0060         LottieProp("name", "nm", str, False),
0061         LottieProp("type", "ty", int, False),
0062         LottieProp("effects", "ef", EffectValue, True),
0063     ]
0064     _effects = []
0065 
0066     def __init__(self, *args, **kwargs):
0067         ## Effect Index. Used for expressions.
0068         self.effect_index = None
0069         ## After Effect's Name. Used for expressions.
0070         self.name = None
0071         ## Effect parameters
0072         self.effects = self._load_values(*args, **kwargs)
0073 
0074         """
0075         ## After Effect's Match Name. Used for expressions.
0076         self.match_name = ""
0077         """
0078 
0079     @classmethod
0080     def _load_get_class(cls, lottiedict):
0081         if not Effect._classses:
0082             Effect._classses = {
0083                 sc.type: sc
0084                 for sc in Effect.__subclasses__()
0085             }
0086         type = lottiedict["ty"]
0087 
0088         if type in Effect._classses:
0089             return Effect._classses[type]
0090         else:
0091             return Effect
0092 
0093     def _load_values(self, *args, **kwargs):
0094         values = []
0095         for i, (name, type) in enumerate(self._effects):
0096             val = []
0097             if len(args) > i:
0098                 val = [args[i]]
0099             if name in kwargs:
0100                 val = [kwargs[name]]
0101             values.append(type(*val))
0102         return values
0103 
0104     def __getattr__(self, key):
0105         for i, (name, type) in enumerate(self._effects):
0106             if name == key:
0107                 return self.effects[i].value
0108         return super().__getattr__(key)
0109 
0110     def __str__(self):
0111         return self.name or super().__str__()
0112 
0113 
0114 ## @ingroup Lottie
0115 ## @ingroup LottieCheck
0116 class EffectNoValue(EffectValue):
0117     _props = []
0118 
0119 
0120 ## @ingroup Lottie
0121 class EffectValueSlider(EffectValue):
0122     _props = [
0123         LottieProp("value", "v", Value, False),
0124     ]
0125     ## %Effect type.
0126     type = 0
0127 
0128     def __init__(self, value=0):
0129         EffectValue.__init__(self)
0130         ## Effect value.
0131         self.value = Value(value)
0132 
0133 
0134 ## @ingroup Lottie
0135 class EffectValueAngle(EffectValue):
0136     _props = [
0137         LottieProp("value", "v", Value, False),
0138     ]
0139     ## %Effect type.
0140     type = 1
0141 
0142     def __init__(self, angle=0):
0143         EffectValue.__init__(self)
0144         ## Effect value.
0145         self.value = Value(angle)
0146 
0147 
0148 ## @ingroup Lottie
0149 class EffectValueColor(EffectValue):
0150     _props = [
0151         LottieProp("value", "v", ColorValue, False),
0152     ]
0153     ## %Effect type.
0154     type = 2
0155 
0156     def __init__(self, value=Color(0, 0, 0)):
0157         EffectValue.__init__(self)
0158         ## Effect value.
0159         self.value = ColorValue(value)
0160 
0161 
0162 ## @ingroup Lottie
0163 class EffectValuePoint(EffectValue):
0164     _props = [
0165         LottieProp("value", "v", MultiDimensional, False),
0166     ]
0167     ## %Effect type.
0168     type = 3
0169 
0170     def __init__(self, value=NVector(0, 0)):
0171         EffectValue.__init__(self)
0172         ## Effect value.
0173         self.value = MultiDimensional(value)
0174 
0175 
0176 ## @ingroup Lottie
0177 class EffectValueCheckbox(EffectValue):
0178     _props = [
0179         LottieProp("value", "v", Value, False),
0180     ]
0181     ## %Effect type.
0182     type = 4
0183 
0184     def __init__(self, value=0):
0185         EffectValue.__init__(self)
0186         ## Effect value.
0187         self.value = Value(value)
0188 
0189 
0190 ## @ingroup Lottie
0191 ## @ingroup LottieCheck
0192 ## Lottie-web ignores these
0193 class IgnoredValue(EffectValue):
0194     _props = [
0195         LottieProp("value", "v", float, False),
0196     ]
0197     ## %Effect type.
0198     type = 6
0199 
0200     def __init__(self, value=0):
0201         EffectValue.__init__(self)
0202         ## Effect value.
0203         self.value = value
0204 
0205 
0206 ## @ingroup Lottie
0207 ## @ingroup LottieCheck
0208 class EffectValueDropDown(EffectValue):
0209     _props = [
0210         LottieProp("value", "v", Value, False),
0211     ]
0212     ## %Effect type.
0213     type = 7
0214 
0215     def __init__(self, value=0):
0216         EffectValue.__init__(self)
0217         ## Effect value.
0218         self.value = Value(value)
0219 
0220 
0221 ## @ingroup Lottie
0222 ## @ingroup LottieCheck
0223 class EffectValueLayer(EffectValue):
0224     _props = [
0225         LottieProp("value", "v", Value, False),
0226     ]
0227     ## %Effect type.
0228     type = 10
0229 
0230     def __init__(self):
0231         EffectValue.__init__(self)
0232         ## Effect value.
0233         self.value = Value()
0234 
0235 
0236 ## @ingroup Lottie
0237 class FillEffect(Effect):
0238     """!
0239     Replaces the whole layer with the given color
0240     @note Opacity is in [0, 1]
0241     """
0242     _effects = [
0243         ("00", EffectValuePoint),
0244         ("01", EffectValueDropDown),
0245         ("color", EffectValueColor),
0246         ("03", EffectValueDropDown),
0247         ("04", EffectValueSlider),
0248         ("05", EffectValueSlider),
0249         ("opacity", EffectValueSlider),
0250     ]
0251     ## %Effect type.
0252     type = 21
0253 
0254 
0255 ## @ingroup Lottie
0256 class StrokeEffect(Effect):
0257     _effects = [
0258         ("00", EffectValueColor),
0259         ("01", EffectValueCheckbox),
0260         ("02", EffectValueCheckbox),
0261         ("color", EffectValueColor),
0262         ("04", EffectValueSlider),
0263         ("05", EffectValueSlider),
0264         ("06", EffectValueSlider),
0265         ("07", EffectValueSlider),
0266         ("08", EffectValueSlider),
0267         ("09", EffectValueDropDown),
0268         ("type", EffectValueDropDown),
0269     ]
0270     ## %Effect type.
0271     type = 22
0272 
0273 
0274 ## @ingroup Lottie
0275 class TritoneEffect(Effect):
0276     """!
0277     Maps layers colors based on bright/mid/dark colors
0278     """
0279     _effects = [
0280         ("bright", EffectValueColor),
0281         ("mid", EffectValueColor),
0282         ("dark", EffectValueColor),
0283     ]
0284     ## %Effect type.
0285     type = 23
0286 
0287 
0288 """
0289 ## @ingroup Lottie
0290 ## @ingroup LottieCheck
0291 class GroupEffect(Effect):
0292     _props = [
0293         LottieProp("enabled", "en", PseudoBool, False),
0294     ]
0295 
0296     def __init__(self):
0297         Effect.__init__(self)
0298         ## Enabled AE property value
0299         self.enabled = True
0300 """
0301 
0302 
0303 ## @ingroup Lottie
0304 ## @ingroup LottieCheck
0305 class ProLevelsEffect(Effect):
0306     _effects = [
0307         ("00", EffectValueDropDown),
0308         ("01", EffectNoValue),
0309         ("02", EffectNoValue),
0310         ("comp_inblack", EffectValueSlider),
0311         ("comp_inwhite", EffectValueSlider),
0312         ("comp_gamma", EffectValueSlider),
0313         ("comp_outblack", EffectValueSlider),
0314         ("comp_outwhite", EffectNoValue),
0315         ("08", EffectNoValue),
0316         ("09", EffectValueSlider),
0317         ("r_inblack", EffectValueSlider),
0318         ("r_inwhite", EffectValueSlider),
0319         ("r_gamma", EffectValueSlider),
0320         ("r_outblack", EffectValueSlider),
0321         ("r_outwhite", EffectNoValue),
0322         ("15", EffectValueSlider),
0323         ("16", EffectValueSlider),
0324         ("g_inblack", EffectValueSlider),
0325         ("g_inwhite", EffectValueSlider),
0326         ("g_gamma", EffectValueSlider),
0327         ("g_outblack", EffectValueSlider),
0328         ("g_outwhite", EffectNoValue),
0329         ("22", EffectValueSlider),
0330         ("b3", EffectValueSlider),
0331         ("b_inblack", EffectValueSlider),
0332         ("b_inwhite", EffectValueSlider),
0333         ("b_gamma", EffectValueSlider),
0334         ("b_outblack", EffectValueSlider),
0335         ("b_outwhite", EffectNoValue),
0336         ("29", EffectValueSlider),
0337         ("a_inblack", EffectValueSlider),
0338         ("a_inwhite", EffectValueSlider),
0339         ("a_gamma", EffectValueSlider),
0340         ("a_outblack", EffectValueSlider),
0341         ("a_outwhite", EffectNoValue),
0342     ]
0343     ## %Effect type.
0344     type = 24
0345 
0346 
0347 ## @ingroup Lottie
0348 class TintEffect(Effect):
0349     """!
0350     Colorizes the layer
0351     @note Opacity is in [0, 100]
0352     """
0353     _effects = [
0354         ("color_black", EffectValueColor),
0355         ("color_white", EffectValueColor),
0356         ("opacity", EffectValueSlider),
0357     ]
0358     ## %Effect type.
0359     type = 20
0360 
0361 
0362 ## @ingroup Lottie
0363 class DropShadowEffect(Effect):
0364     """!
0365     Adds a shadow to the layer
0366     @note Opacity is in [0, 255]
0367     """
0368     _effects = [
0369         ("color", EffectValueColor),
0370         ("opacity", EffectValueSlider),
0371         ("angle", EffectValueAngle),
0372         ("distance", EffectValueSlider),
0373         ("blur", EffectValueSlider),
0374     ]
0375     ## %Effect type.
0376     type = 25
0377 
0378 
0379 ## @ingroup Lottie
0380 ## @ingroup LottieCheck
0381 class Matte3Effect(Effect):
0382     _effects = [
0383         ("index", EffectValueSlider),
0384     ]
0385     ## %Effect type.
0386     type = 28
0387 
0388 
0389 ## @ingroup Lottie
0390 class GaussianBlurEffect(Effect):
0391     """!
0392     Gaussian blur
0393     """
0394     _effects = [
0395         ("sigma", EffectValueSlider),
0396         ("dimensions", EffectValueSlider),
0397         ("wrap", EffectValueCheckbox),
0398     ]
0399     ## %Effect type.
0400     type = 29
0401 
0402 
0403 #class ChangeColorEffect(Effect):
0404     #"""!
0405     #Gaussian blur
0406     #"""
0407     #_effects = [
0408         #("view", EffectValueDropDown),
0409         #("hue", EffectValueSlider),
0410         #("lightness", EffectValueSlider),
0411         #("saturation", EffectValueSlider),
0412         #("color_to_change", EffectValueColor),
0413         #("tolerance", EffectValueSlider),
0414         #("softness", EffectValueSlider),
0415         #("match", EffectValueDropDown),
0416         #("invert_mask", EffectValueDropDown),
0417     #]
0418     ### %Effect type.
0419     #type = 29
0420 
0421 
0422 ## @ingroup Lottie
0423 class ChangeToColorEffect(Effect):
0424     """!
0425     Change to color
0426     """
0427     _effects = [
0428         ("from_color", EffectValueColor),
0429         ("to_color", EffectValueColor),
0430         ("change", EffectValueDropDown),
0431         ("change_by", EffectValueDropDown),
0432         ("tolerance", IgnoredValue),
0433         ("hue", EffectValueSlider),
0434         ("lightness", EffectValueSlider),
0435         ("saturation", EffectValueSlider),
0436         ("saturation_", IgnoredValue),
0437         ("softness", EffectValueSlider),
0438         ("view_correction", EffectValueDropDown),
0439     ]
0440     ## %Effect type.
0441     type = 5