class ImageDescriptor(bin.Structure): separator = bin.FixedString(b',') left = bin.Integer(size=2) top = bin.Integer(size=2) width = bin.Integer(size=2) height = bin.Integer(size=2) info = bin.SubStructure(ImageInfoBits) with info.has_color_map == True: color_map = bin.List(bin.SubStructure(Color), size=2**info.bits_per_pixel)
class TGA(bin.Structure, endianness=bin.LittleEndian): id_size = bin.Integer(size=1) color_map_type = bin.Integer(size=1, choices=COLOR_MAP_TYPES) image_type = bin.Integer(size=1, choices=IMAGE_TYPES) color_map_info = bin.SubStructure(ColorMap) x_origin = bin.Integer(size=2) y_origin = bin.Integer(size=2) width = bin.Integer(size=2) height = bin.Integer(size=2) bit_depth = bin.Integer(size=1) image_origin, alpha_depth = bin.SubStructure(AlphaOrigin) image_id = bin.Bytes(size=id_size) color_map_data = bin.List(bin.Integer(size=color_map_info.entry_size) / 8, size=color_map_info.length) image_data = bin.List(bin.Integer(size=1), size=width * height * bit_depth)
class ScreenDescriptor(bin.Structure, endianness=bin.LittleEndian): width = bin.Integer(size=2) height = bin.Integer(size=2) info = bin.SubStructure(ScreenInfoBits) background_color = bin.Integer(size=1) pixel_ratio = bin.Integer(size=1) with info.has_color_map == True: color_map = bin.List(bin.SubStructure(Color), size=2**info.bits_per_pixel) @property def aspect_ratio(self): if self.pixel_ratio == 0: return None return (self.pixel_ratio + 15) / 64
class JFIF(bin.Structure): start = bin.SubStructure(Start) header = bin.SubStructure(Header) chunks = bin.ChunkList(Chunk, (StartFrame, Comment), terminator=End) @property def width(self): return self.chunks.of_type(StartFrame)[0].width @property def height(self): return self.chunks.of_type(StartFrame)[0].height @property def comment(self): return self.chunks.of_type(Comment)[0].value
class PNG(bin.Structure): signature = bin.FixedString(b'\x89PNG\x0d\x0a\x1a\x0a') header = bin.SubStructure(Header) chunks = bin.ChunkList(Chunk, (Header, Chromaticity, Gamma, ICCProfile, SignificantBits, sRGB, Palette, Background, Histogram, Transparency, PhysicalDimentions, SuggestedPalette, Data, Timestamp, Text, CompressedText, InternationalText), terminator=End) @property def data_chunks(self): for chunk in chunks: if isinstance(chunk, Data): yield chunk
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 Sample(bin.Structure): name = bin.FixedLengthString(size=22) size = SampleLength(size=2) finetune = bin.SubStructure(FineTune) volume = bin.PositiveInteger(size=1) loop_start = SampleLength(size=2, default_value=0) loop_length = SampleLength(size=2, default_value=0) @property def loop_end(self): return self.loop_start + self.loop_length @property def data(self): index = self.get_parent().samples.index(self) return self.get_parent().sample_data[index] def __unicode__(self): return self.name
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 Palette(bin.Structure): colors = bin.List(bin.SubStructure(PaletteColor), size=bin.Remainder) def __iter__(self): return iter(self.colors)