Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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
Exemple #4
0
class MOD(bin.File):
    channels = 4

    title = bin.FixedLengthString(size=20)
    samples = bin.List(Sample, size=15)
    order_count = bin.PositiveInteger(size=1)
    restart_position = bin.PositiveInteger(size=1)
    pattern_order = bin.List(bin.PositiveInteger(size=1), size=128)
    marker = bin.FixedString('M.K.')
    patterns = bin.List(Pattern, size=lambda self: max(self.pattern_order) + 1)
    sample_data = bin.ByteString(size=bin.REMAINDER)

    @property
    def pattern_count(self):
        return max(self.order) + 1

    @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.title

    class Options:
        endianness = bin.BigEndian
Exemple #5
0
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
Exemple #6
0
class BMP(bin.Structure, endianness=bin.LittleEndian):
    signature = bin.FixedString('BM')
    filesize = bin.Integer('Total file size', size=4)
    reserved = bin.Reserved(size=4)
    data_offset = bin.Integer('Offset of the actual image data', size=4)
    header_size = bin.Integer(size=4, default_value=40)
    width = bin.Integer(size=4)
    height = bin.Integer(size=4)
    plane_count = bin.Integer(size=2, default_value=1)
    bit_depth = bin.Integer(size=2)
    compression_type = bin.Integer(size=4,
                                   choices=COMPRESSION_TYPES,
                                   default_value=0)
    data_size = bin.Integer('Size of the actual image data', size=4)
    ppm_x = bin.Integer('Pixels per meter (X axis)', size=4)
    ppm_y = bin.Integer('Pixels per meter (Y axis)', size=4)
    color_count = bin.Integer('Number of colors', size=4)
    important_color_count = bin.Integer('Number of important colors', size=4)
    palette = bin.List(PaletteColor, size=color_count)
    pixel_data = bin.Bytes(size=bin.Remainder)
Exemple #7
0
class Pattern(bin.Structure):
    rows = bin.List(Row, size=64)
    
    def __iter__(self):
        return iter(self.rows)
Exemple #8
0
class Row(bin.Structure):
    notes = bin.List(Note, size=8)
    
    def __iter__(self):
        return iter(self.notes)
Exemple #9
0
class Row(bin.Structure):
    notes = bin.List(Note, size=lambda self: self.get_parent().channels)

    def __iter__(self):
        return iter(self.rows)
Exemple #10
0
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)
Exemple #11
0
class Histogram(bin.Structure):
    frequencies = bin.List(bin.Integer(size=2), size=bin.Remainder)
Exemple #12
0
class Palette(bin.Structure):
    colors = bin.List(bin.SubStructure(PaletteColor), size=bin.Remainder)

    def __iter__(self):
        return iter(self.colors)