Ejemplo n.º 1
0
 def read_data(self, bit_reader):
     if self.state_move_to:
         move_bits = bit_reader.read(5)
         self.move_delta_x = bit_reader.read_signed(move_bits)
         self.move_delta_y = bit_reader.read_signed(move_bits)
     if self.state_fill_style0:
         self.fill_style0 = bit_reader.read(self.num_fill_bits)
     if self.state_fill_style1:
         self.fill_style1 = bit_reader.read(self.num_fill_bits)
     if self.state_line_style:
         self.line_style = bit_reader.read(self.num_line_bits)
     data = bit_reader.remain_buffer
     offset = 0
     if self.state_new_styles:
         self.fill_styles = FillStyleArray(shape_generation=self.shape_generation)
         size = self.fill_styles.read_data(data[offset:])
         offset += size
         self.line_styles = LineStyleArray(shape_generation=self.shape_generation)
         size = self.line_styles.read_data(data[offset:])
         offset += size
         num_bits = struct.unpack_from("B", data, offset)[0]
         offset += 1
         self.new_fill_bits = num_bits >> 4
         self.new_line_bits = num_bits & 0xF
         bit_reader = BitReader.memory_reader(data[offset:])
     return bit_reader
Ejemplo n.º 2
0
def read_button_record(data, button_generation=1):
    ret = ButtonRecord()
    flag_byte = struct.unpack_from('B', data)[0]
    offset = 1
    ret.has_blend_mode = (flag_byte & 0x20) > 0
    ret.has_filter_list = (flag_byte & 0x10) > 0
    ret.state_hit_test = (flag_byte & 0x8) > 00
    ret.state_down = (flag_byte & 0x4) > 00
    ret.state_over = (flag_byte & 0x2) > 00
    ret.state_up = (flag_byte & 0x1) > 0
    ret.chatacter_id = struct.unpack_from('H', data, offset)[0]
    offset += 2
    ret.place_depth = struct.unpack_from('H', data, offset)[0]
    offset += 2
    bit_reader = BitReader.memory_reader(data[offset:])
    ret.place_matrix = bit_reader.read_matrix()
    if button_generation>=2:
        ret.color_transform = bit_reader.read_cx_form_alpha()
        offset += bit_reader.offset
        if ret.has_filter_list:
            raise NotImplementedError
        if ret.has_blend_mode:
            ret.blend_mode = struct.unpack_from('B', data, offset)[0]
            offset += 1
    return ret, offset
Ejemplo n.º 3
0
def read_button_record(data, button_generation=1):
    ret = ButtonRecord()
    flag_byte = struct.unpack_from('B', data)[0]
    offset = 1
    ret.has_blend_mode = (flag_byte & 0x20) > 0
    ret.has_filter_list = (flag_byte & 0x10) > 0
    ret.state_hit_test = (flag_byte & 0x8) > 00
    ret.state_down = (flag_byte & 0x4) > 00
    ret.state_over = (flag_byte & 0x2) > 00
    ret.state_up = (flag_byte & 0x1) > 0
    ret.chatacter_id = struct.unpack_from('H', data, offset)[0]
    offset += 2
    ret.place_depth = struct.unpack_from('H', data, offset)[0]
    offset += 2
    bit_reader = BitReader.memory_reader(data[offset:])
    ret.place_matrix = bit_reader.read_matrix()
    if button_generation >= 2:
        ret.color_transform = bit_reader.read_cx_form_alpha()
        offset += bit_reader.offset
        if ret.has_filter_list:
            raise NotImplementedError
        if ret.has_blend_mode:
            ret.blend_mode = struct.unpack_from('B', data, offset)[0]
            offset += 1
    return ret, offset
Ejemplo n.º 4
0
 def __init__(self, **kwargs):
     tag_data = kwargs.get('tag_data')
     if tag_data is None:
         super().__init__(code=26)
         self.depth = kwargs.get('depth')
         self.character_id = kwargs.get('character_id')
         self.matrix = eval(kwargs.get('matrix'))
         self.color_transform = kwargs.get('color_transform')
         self.ratio = kwargs.get('ratio')
         self.name = kwargs.get('name')
         self.clip_depth = kwargs.get('clip_depth')
         self.clip_actions = kwargs.get('clip_actions')
         self.has_clip_actions = int(self.clip_actions is not None)
         self.has_clip_depth = int(self.has_clip_depth is not None)
         self.has_name = int(self.has_name is not None)
         self.has_ratio = int(self.has_ratio is not None)
         self.has_color_transform = int(self.has_color_transform is not None)
         self.has_matrix = int(self.has_matrix is not None)
         self.has_character = int(self.has_character is not None)
         self.has_move = int(self.has_move is not None)
     else:
         super().__init__(code=26, tag_data=tag_data)
         reader = BitReader.memory_reader(tag_data)
         self.has_clip_actions = reader.read(1)
         self.has_clip_depth = reader.read(1)
         self.has_name = reader.read(1)
         self.has_ratio = reader.read(1)
         self.has_color_transform = reader.read(1)
         self.has_matrix = reader.read(1)
         self.has_character = reader.read(1)
         self.has_move = reader.read(1)
         offset = reader.offset
         self.depth = struct.unpack_from('H', tag_data, offset)[0]
         offset += 2
         reader.skip_bytes(2)
         if self.has_character:
             self.character_id = struct.unpack_from('H', tag_data, offset)[0]
             offset += 2
             reader.skip_bytes(2)
         if self.has_matrix:
             self.matrix = reader.read_matrix()
             offset = reader.offset
         if self.has_color_transform:
             reader.skip_remain_bits()
             self.color_transform = reader.read_cx_form_alpha()
             offset = reader.offset
         if self.has_ratio:
             self.ratio = struct.unpack_from('H', tag_data, offset)[0]
             offset += 2
             reader.skip_bytes(2)
         if self.has_name:
             self.name, string_end = BasicData.read_string(tag_data[offset:])
             offset += string_end
             reader.skip_bytes(string_end)
         if self.has_clip_depth:
             self.clip_depth = struct.unpack_from('H', tag_data, offset)
             offset += 2
             reader.skip_bytes(2)
         if self.has_clip_actions:
             raise NotImplementedError
Ejemplo n.º 5
0
 def read_data(self, bit_reader):
     if self.state_move_to:
         move_bits = bit_reader.read(5)
         self.move_delta_x = bit_reader.read_signed(move_bits)
         self.move_delta_y = bit_reader.read_signed(move_bits)
     if self.state_fill_style0:
         self.fill_style0 = bit_reader.read(self.num_fill_bits)
     if self.state_fill_style1:
         self.fill_style1 = bit_reader.read(self.num_fill_bits)
     if self.state_line_style:
         self.line_style = bit_reader.read(self.num_line_bits)
     data = bit_reader.remain_buffer
     offset = 0
     if self.state_new_styles:
         self.fill_styles = FillStyleArray(
             shape_generation=self.shape_generation)
         size = self.fill_styles.read_data(data[offset:])
         offset += size
         self.line_styles = LineStyleArray(
             shape_generation=self.shape_generation)
         size = self.line_styles.read_data(data[offset:])
         offset += size
         num_bits = struct.unpack_from("B", data, offset)[0]
         offset += 1
         self.new_fill_bits = num_bits >> 4
         self.new_line_bits = num_bits & 0xF
         bit_reader = BitReader.memory_reader(data[offset:])
     return bit_reader
Ejemplo n.º 6
0
    def read_data(self, data):
        self.fill_styles = FillStyleArray(shape_generation=self.shape_generation)
        offset = self.fill_styles.read_data(data)
        self.line_styles = LineStyleArray(shape_generation=self.shape_generation)
        size = self.line_styles.read_data(data[offset:])
        offset += size

        reader = BitReader.memory_reader(data, offset)
        self.num_fill_bits = reader.read(4)
        self.num_line_bits = reader.read(4)
        offset += reader.offset

        self.shape_records = list()
        reader = BitReader.memory_reader(data[offset:])
        while True:
            record, reader = self.read_record_data(reader)
            self.shape_records.append(record)
            if isinstance(record, EndShapeRecord):
                break
        offset += reader.offset
        return offset
Ejemplo n.º 7
0
    def read_data(self, data):
        self.fill_styles = FillStyleArray(
            shape_generation=self.shape_generation)
        offset = self.fill_styles.read_data(data)
        self.line_styles = LineStyleArray(
            shape_generation=self.shape_generation)
        size = self.line_styles.read_data(data[offset:])
        offset += size

        reader = BitReader.memory_reader(data, offset)
        self.num_fill_bits = reader.read(4)
        self.num_line_bits = reader.read(4)
        offset += reader.offset

        self.shape_records = list()
        reader = BitReader.memory_reader(data[offset:])
        while True:
            record, reader = self.read_record_data(reader)
            self.shape_records.append(record)
            if isinstance(record, EndShapeRecord):
                break
        offset += reader.offset
        return offset
Ejemplo n.º 8
0
 def read_data(self, data, offset=0):
     self.head_str = data[0:3]
     offset += 3
     self.version = struct.unpack_from('B', data, offset)[0]
     offset += 1
     self.size = struct.unpack_from('I', data, offset)[0]
     offset += 4
     reader = BitReader.memory_reader(data[offset:])
     self.display_rect = reader.read_rectangle()
     offset += reader.offset
     self.frame_rate = struct.unpack_from('H', data, offset)[0] / 256
     offset += 2
     self.frame_count = struct.unpack_from('H', data, offset)[0]
     offset += 2
     return offset
Ejemplo n.º 9
0
 def read_data(self, data, offset=0):
     self.head_str = data[0:3]
     offset += 3
     self.version = struct.unpack_from('B', data, offset)[0]
     offset += 1
     self.size = struct.unpack_from('I', data, offset)[0]
     offset += 4
     reader = BitReader.memory_reader(data[offset:])
     self.display_rect = reader.read_rectangle()
     offset += reader.offset
     self.frame_rate = struct.unpack_from('H', data, offset)[0] / 256
     offset += 2
     self.frame_count = struct.unpack_from('H', data, offset)[0]
     offset += 2
     return offset
Ejemplo n.º 10
0
 def read_data(self, data):
     self.fill_style_type = struct.unpack_from('B', data)[0]
     offset = 1
     if self.fill_style_type == 0x00:
         if self.shape_generation <= 2:
             self.color = BasicData.read_rgb(data[offset:])
             offset += 3
         else:
             self.color = BasicData.read_rgba(data[offset:])
             offset += 4
     if self.fill_style_type in [0x10, 0x12, 0x13]:
         reader = BitReader.memory_reader(data, offset)
         self.gradient_matrix = reader.read_matrix()
         offset += reader.offset
     if self.fill_style_type in [0x10, 0x12]:
         self.gradient, size = BasicData.read_gradient(data[offset:], self.shape_generation)
         offset += size
     return offset
Ejemplo n.º 11
0
 def __init__(self, **kwargs):
     tag_data = kwargs.get('tag_data')
     if tag_data is None:
         super().__init__(code=69)
         self.use_direct_blit = kwargs.get('use_direct_blit')
         self.use_gpu = kwargs.get('use_gpu')
         self.has_metadata = kwargs.get('has_metadata')
         self.action_script3 = kwargs.get('action_script3')
         self.use_network = kwargs.get('use_network')
     else:
         super().__init__(code=69, tag_data=tag_data)
         reader = BitReader.memory_reader(tag_data)
         reader.read(1)  # Reserved
         self.use_direct_blit = reader.read(1)
         self.use_gpu = reader.read(1)
         self.has_metadata = reader.read(1)
         self.action_script3 = reader.read(1)
         reader.read(2)  # Reserved
         self.use_network = reader.read(1)
Ejemplo n.º 12
0
 def read_data(self, data):
     self.fill_style_type = struct.unpack_from('B', data)[0]
     offset = 1
     if self.fill_style_type == 0x00:
         if self.shape_generation <= 2:
             self.color = BasicData.read_rgb(data[offset:])
             offset += 3
         else:
             self.color = BasicData.read_rgba(data[offset:])
             offset += 4
     if self.fill_style_type in [0x10, 0x12, 0x13]:
         reader = BitReader.memory_reader(data, offset)
         self.gradient_matrix = reader.read_matrix()
         offset += reader.offset
     if self.fill_style_type in [0x10, 0x12]:
         self.gradient, size = BasicData.read_gradient(
             data[offset:], self.shape_generation)
         offset += size
     return offset
Ejemplo n.º 13
0
 def __init__(self, **kwargs):
     tag_data = kwargs.get('tag_data')
     if tag_data is None:
         super().__init__(code=69)
         self.use_direct_blit = kwargs.get('use_direct_blit')
         self.use_gpu = kwargs.get('use_gpu')
         self.has_metadata = kwargs.get('has_metadata')
         self.action_script3 = kwargs.get('action_script3')
         self.use_network = kwargs.get('use_network')
     else:
         super().__init__(code=69, tag_data=tag_data)
         reader = BitReader.memory_reader(tag_data)
         reader.read(1)  # Reserved
         self.use_direct_blit = reader.read(1)
         self.use_gpu = reader.read(1)
         self.has_metadata = reader.read(1)
         self.action_script3 = reader.read(1)
         reader.read(2)  # Reserved
         self.use_network = reader.read(1)
Ejemplo n.º 14
0
 def __init__(self, shape_generation=1, **kwargs):
     tag_data = kwargs.get('tag_data')
     if shape_generation == 1:
         code = 2
     elif shape_generation == 2:
         code = 22
     elif shape_generation == 3:
         code = 32
     else:
         raise NotImplementedError
     if tag_data is None:
         super().__init__(code=code)
         self.shape_id = kwargs.get('shape_id')
         self.shape_bounds = eval(kwargs.get('shape_bounds'))
         self.shapes = eval(kwargs.get('shapes'))
     else:
         super().__init__(code=code, tag_data=tag_data)
         self.shape_id = struct.unpack_from("H", tag_data)[0]
         offset = 2
         reader = BitReader.memory_reader(tag_data, offset)
         self.shape_bounds = reader.read_rectangle()
         offset += reader.offset
         self.shapes = ShapeWithStyle(shape_generation=shape_generation)
         self.shapes.read_data(tag_data[offset:])
Ejemplo n.º 15
0
 def __init__(self, shape_generation=1, **kwargs):
     tag_data = kwargs.get('tag_data')
     if shape_generation == 1:
         code = 2
     elif shape_generation == 2:
         code = 22
     elif shape_generation == 3:
         code = 32
     else:
         raise NotImplementedError
     if tag_data is None:
         super().__init__(code=code)
         self.shape_id = kwargs.get('shape_id')
         self.shape_bounds = eval(kwargs.get('shape_bounds'))
         self.shapes = eval(kwargs.get('shapes'))
     else:
         super().__init__(code=code, tag_data=tag_data)
         self.shape_id = struct.unpack_from("H", tag_data)[0]
         offset = 2
         reader = BitReader.memory_reader(tag_data, offset)
         self.shape_bounds = reader.read_rectangle()
         offset += reader.offset
         self.shapes = ShapeWithStyle(shape_generation=shape_generation)
         self.shapes.read_data(tag_data[offset:])
Ejemplo n.º 16
0
 def __init__(self, **kwargs):
     tag_data = kwargs.get('tag_data')
     if tag_data is None:
         super().__init__(code=26)
         self.depth = kwargs.get('depth')
         self.character_id = kwargs.get('character_id')
         self.matrix = eval(kwargs.get('matrix'))
         self.color_transform = kwargs.get('color_transform')
         self.ratio = kwargs.get('ratio')
         self.name = kwargs.get('name')
         self.clip_depth = kwargs.get('clip_depth')
         self.clip_actions = kwargs.get('clip_actions')
         self.has_clip_actions = int(self.clip_actions is not None)
         self.has_clip_depth = int(self.has_clip_depth is not None)
         self.has_name = int(self.has_name is not None)
         self.has_ratio = int(self.has_ratio is not None)
         self.has_color_transform = int(
             self.has_color_transform is not None)
         self.has_matrix = int(self.has_matrix is not None)
         self.has_character = int(self.has_character is not None)
         self.has_move = int(self.has_move is not None)
     else:
         super().__init__(code=26, tag_data=tag_data)
         reader = BitReader.memory_reader(tag_data)
         self.has_clip_actions = reader.read(1)
         self.has_clip_depth = reader.read(1)
         self.has_name = reader.read(1)
         self.has_ratio = reader.read(1)
         self.has_color_transform = reader.read(1)
         self.has_matrix = reader.read(1)
         self.has_character = reader.read(1)
         self.has_move = reader.read(1)
         offset = reader.offset
         self.depth = struct.unpack_from('H', tag_data, offset)[0]
         offset += 2
         reader.skip_bytes(2)
         if self.has_character:
             self.character_id = struct.unpack_from('H', tag_data,
                                                    offset)[0]
             offset += 2
             reader.skip_bytes(2)
         if self.has_matrix:
             self.matrix = reader.read_matrix()
             offset = reader.offset
         if self.has_color_transform:
             reader.skip_remain_bits()
             self.color_transform = reader.read_cx_form_alpha()
             offset = reader.offset
         if self.has_ratio:
             self.ratio = struct.unpack_from('H', tag_data, offset)[0]
             offset += 2
             reader.skip_bytes(2)
         if self.has_name:
             self.name, string_end = BasicData.read_string(
                 tag_data[offset:])
             offset += string_end
             reader.skip_bytes(string_end)
         if self.has_clip_depth:
             self.clip_depth = struct.unpack_from('H', tag_data, offset)
             offset += 2
             reader.skip_bytes(2)
         if self.has_clip_actions:
             raise NotImplementedError