class InternationalText(bin.Structure, encoding='utf8'): keyword = bin.String() is_compressed = bin.Integer(size=1) compression = bin.Integer(size=1, choices=COMPRESSION_CHOICES) language = bin.String() translated_keyword = bin.String() content = bin.Bytes(size=bin.Remainder) # TODO: decompress
class _669(bin.File): marker = bin.FixedString('if') message = bin.List(bin.String(size=36, encoding='ascii', padding=' '), size=3) sample_count = bin.PositiveInteger(size=1, max_value=64) pattern_count = bin.PositiveInteger(size=1, max_value=128) restart_position = bin.PositiveInteger(size=1) pattern_order = bin.List(bin.PositiveInteger(size=1, max_value=128), size=128) pattern_tempos = bin.List(bin.PositiveInteger(size=1), size=128) pattern_breaks = bin.List(bin.PositiveInteger(size=1), size=128) samples = bin.List(Sample, size=sample_count) patterns = bin.List(Pattern, size=pattern_count) sample_data = bin.ByteString(size=bin.REMAINDER) @sample_data.getter def sample_data(self, data): offset = 0 output = [] for info in self.samples: output.append(data[offset:offset + info.size]) offset += info.size return output @sample_data.setter def sample_data(self, data_list): return ''.join(data_list) def __iter__(self): for index in self.pattern_order: yield self.patterns[index] def __unicode__(self): return self.message[0] class Options: endianness = bin.LittleEndian
class GIF(bin.Structure, endianness=bin.LittleEndian, encoding='ascii'): tag = bin.FixedString('GIF') version = bin.String(size=3, choices=VERSIONS) # with tag == 'GIF': # version = bin.String(size=3, choices=VERSIONS) screen = bin.SubStructure(ScreenDescriptor) @property def width(self): return self.screen.width @property def height(self): return self.screen.height
class Chunk(bin.Chunk, encoding='ascii'): """ A special chunk for PNG, which puts the size before the type and includes a CRC field for verifying data integrity. """ size = bin.Integer(size=4) id = bin.String(size=4) payload = bin.Payload(size=size) crc = bin.CRC32(first=id) @property def is_critical(self): # Critical chunks will always have an uppercase letter for the # first character in the type. Ancillary will always be lower. return self.type[0].upper() == self.type[0] @property def is_public(self): # Public chunks will always have an uppercase letter for the # second character in the type. Private will always be lower. return self.type[1].upper() == self.type[1]
class Chunk(bin.Chunk): id = bin.String(size=4, encoding='ascii') size = bin.Integer(size=4) payload = bin.Payload(size=size)
class Form(bin.Chunk, encoding='ascii'): tag = bin.FixedString('FORM') size = bin.Integer(size=4) id = bin.String(size=4) payload = bin.Payload(size=size)
class Comment(bin.Structure): value = bin.String(encoding='utf8', size=bin.Remainder) def __str__(self): return self.value
class TestStructure(bin.Structure): integer = bin.Integer('number', size=1) string = bin.String(encoding='ascii')
class TestStructure(bin.Structure): forty_two = bin.Integer(size=2, endianness=bin.LittleEndian) sixty_six = bin.Integer(size=1) valid = bin.String(encoding='ascii') test = bin.String(encoding='ascii')
class TestStructure(bin.Structure): length = bin.Integer('number', size=1) content = bin.String(encoding='ascii', size=length)
class ICCProfile(bin.Structure): name = bin.String(encoding='latin-1') compression = bin.Integer(size=1, choices=COMPRESSION_CHOICES) profile = bin.Bytes(size=bin.Remainder) # TODO: decompress
class CompressedText(bin.Structure, encoding='latin-1'): keyword = bin.String() compression = bin.Integer(size=1, choices=COMPRESSION_CHOICES) content = bin.Bytes(size=bin.Remainder) # TODO: decompress
class Text(bin.Structure, encoding='latin-1'): keyword = bin.String() content = bin.String(size=bin.Remainder)
class SuggestedPalette(bin.Structure): name = bin.String(encoding='latin-1') sample_depth = bin.Integer(size=1) colors = bin.List(bin.SubStructure(SuggestedPaletteEntry), size=bin.Remainder)
class GIF(bin.Structure, endianness=bin.LittleEndian, encoding='ascii'): tag = bin.FixedString('GIF') version = bin.String(size=3, choices=GIF_VERSIONS) width = bin.Integer(size=2) height = bin.Integer(size=2)