Example #1
0
def decode(effects):
    """
    Reads and decodes info about layer effects.
    """
    fp = io.BytesIO(effects)

    version, effects_count = read_fmt("HH", fp)

    effects_list = []
    for idx in range(effects_count):
        sig = fp.read(4)
        if sig != b'8BIM':
            raise Error("Error parsing layer effect: invalid signature (%r)" %
                        sig)

        effect_type = fp.read(4)
        if not EffectOSType.is_known(effect_type):
            warnings.warn("Unknown effect type (%s)" % effect_type)

        effect_info_length = read_fmt("I", fp)[0]
        effect_info = fp.read(effect_info_length)

        decoder = _effect_info_decoders.get(effect_type, lambda data: data)
        effects_list.append(LayerEffect(effect_type, decoder(effect_info)))

    return Effects(version, effects_count, effects_list)
Example #2
0
def decode(effects):
    """
    Reads and decodes info about layer effects.
    """
    fp = io.BytesIO(effects)

    version, effects_count = read_fmt("HH", fp)

    effects_list = []
    for idx in range(effects_count):
        sig = fp.read(4)
        if sig != b'8BIM':
            raise Error("Error parsing layer effect: invalid signature (%r)" % sig)

        effect_type = fp.read(4)
        if not EffectOSType.is_known(effect_type):
            warnings.warn("Unknown effect type (%s)" % effect_type)

        effect_info_length = read_fmt("I", fp)[0]
        effect_info = fp.read(effect_info_length)

        decoder = _effect_info_decoders.get(effect_type, lambda data: data)
        effects_list.append(LayerEffect(effect_type, decoder(effect_info)))

    return Effects(version, effects_count, effects_list)
Example #3
0
 def _repr_pretty_(self, p, cycle):
     if cycle:
         p.text(repr(self))
     else:
         with p.group(0, 'LayerEffect(', ')'):
             p.text("%s %s, " % (self.effect_type, EffectOSType.name_of(self.effect_type)))
             p.pretty(self.effect_info)
 def read(cls, fp, **kwargs):
     version, count = read_fmt('2H', fp)
     items = []
     for _ in range(count):
         signature = read_fmt('4s', fp)[0]
         assert signature == b'8BIM', 'Invalid signature %r' % (signature)
         ostype = EffectOSType(read_fmt('4s', fp)[0])
         kls = cls.EFFECT_TYPES.get(ostype)
         items.append((ostype, kls.frombytes(read_length_block(fp))))
     return cls(version=version, items=items)
Example #5
0
 def _repr_pretty_(self, p, cycle):
     # IS NOT TESTED!!
     if cycle:
         p.text('LayerEffect(...)')
     else:
         with p.group(1, 'LayerEffect(', ')'):
             p.breakable()
             p.text("%s %s," % (self.effect_type, EffectOSType.name_of(self.effect_type)))
             p.breakable()
             p.pretty(self.effect_info)
Example #6
0
 def _repr_pretty_(self, p, cycle):
     # IS NOT TESTED!!
     if cycle:
         p.text('LayerEffect(...)')
     else:
         with p.group(1, 'LayerEffect(', ')'):
             p.breakable()
             p.text("%s %s," % (self.effect_type, EffectOSType.name_of(self.effect_type)))
             p.breakable()
             p.pretty(self.effect_info)
Example #7
0
 def __repr__(self):
     return "LayerEffect(%s %s, %s)" % (self.effect_type, EffectOSType.name_of(self.effect_type),
                                        self.effect_info)
Example #8
0
 def __repr__(self):
     return "LayerEffect(%s %s, %s)" % (
         self.effect_type, EffectOSType.name_of(
             self.effect_type), self.effect_info)