Example #1
0
    def replace_lossless(self, block, image_data):
        """
        DefineBitsLossless, DefineBitsLossless2 を置き換える関数
        画像を置き換える際に行うこと
        1. lossless データの置き換え
        2. ヘッダーの length の置き換え
        3. tag block での length の置き換え
        4. width, height, format データの置き換え
        """
        tag_raw = block['value'][:2]
        old_length = block['block_len']   # block['value'][2:6] と同じはず
        image_id = le2byte(block['value'][6:8])
        # format = ord(block['value'][8])

        # 1.
        g = Image2lossless(image_data, block['tag'])
        fv_read = g.convert()
        new_length = len(fv_read) + 7

        # 2.
        self.file_length += (new_length - old_length)

        # 3.
        block['block_len'] = new_length

        # 4.
        block['value'] = \
            tag_raw + \
            _h32(new_length) + \
            _h16(image_id) + \
            g.get_lossless_format() + \
            _h16(g.width()) + \
            _h16(g.height()) + \
            fv_read
Example #2
0
 def write(self, f):
     "swf 出力"
     # ヘッダー長を書き換え
     fl = _h32(self.file_length)
     self.swf_head = self.swf_head[:4] + fl + self.swf_head[8:]
     f.write(self.swf_head)
     for block in self.swf_blocks:
         f.write(block['value'])
     f.write('\00\00')
Example #3
0
    def replace_jpeg(self, block, image_data):
        """
        DefineBitsJPEG2 を置き換える関数
        1. SWF ヘッダーの length の置き換え
        2. tag block の書き換え
        """
        assert image_data[:2] == '\xff\xd8'   # JPEG SOI marker
        
        tag_raw = block['value'][:2]
        image_id = block['value'][6:8]

        # 1.
        old_length = block['block_len']
        new_length = len(image_data) + 2
        self.file_length += (new_length - old_length)

        # 2.
        block['block_len'] = new_length
        block['value'] = \
            tag_raw + \
            _h32(new_length) + \
            image_id + \
            image_data