def repl_lossless2(swf, offset, lossless)
      swf.force_encoding("ASCII-8BIT") if swf.respond_to? :force_encoding

      org_format = swf[offset+8, 1].unpack("C").first
      # replace lossless2 data
      if lossless.format == 3
        if org_format == 3
          org_image_length = swf[offset+2, 4].unpack("i").first - 8
          delta_length = lossless.zlib_bitmap_data.size - org_image_length
          swf[offset+14, org_image_length] = lossless.zlib_bitmap_data
          swf[offset+13, 1] = [lossless.color_table_size].pack("C")
          swf[offset+11, 2] = [lossless.height].pack("v")
          swf[offset+9, 2] = [lossless.width].pack("v")
          swf[offset+8, 1] = [lossless.format].pack("C")
          swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 8].pack("i")
        elsif org_format == 5
          org_image_length = swf[offset+2, 4].unpack("i").first - 7
          delta_length = lossless.zlib_bitmap_data.size - org_image_length + 1
          swf[offset+13, org_image_length] = [lossless.color_table_size].pack("C") + lossless.zlib_bitmap_data
          swf[offset+11, 2] = [lossless.height].pack("v")
          swf[offset+9, 2] = [lossless.width].pack("v")
          swf[offset+8, 1] = [lossless.format].pack("C")
          swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 8].pack("i")
        else
          raise ReplaceTargetError
        end
      elsif lossless.format == 5
        if org_format == 3
          org_image_length = swf[offset+2, 4].unpack("i").first - 8
          delta_length = lossless.zlib_bitmap_data.size - org_image_length - 1
          swf[offset+13, org_image_length+1] = lossless.zlib_bitmap_data
          swf[offset+11, 2] = [lossless.height].pack("v")
          swf[offset+9, 2] = [lossless.width].pack("v")
          swf[offset+8, 1] = [lossless.format].pack("C")
          swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 7].pack("i")
        elsif org_format == 5
          org_image_length = swf[offset+2, 4].unpack("i").first - 7
          delta_length = lossless.zlib_bitmap_data.size - org_image_length
          swf[offset+13, org_image_length] = lossless.zlib_bitmap_data
          swf[offset+11, 2] = [lossless.height].pack("v")
          swf[offset+9, 2] = [lossless.width].pack("v")
          swf[offset+8, 1] = [lossless.format].pack("C")
          swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 7].pack("i")
        else
          raise ReplaceTargetError
        end
      else
        raise ReplaceTargetError
      end
      swf[4, 4] = [swf[4, 4].unpack("V").first + delta_length].pack("V")
      swf
    end
def repl_lossless2(swf, offset, lossless)
      swf.force_encoding("ASCII-8BIT") if swf.respond_to? :force_encoding

      org_format = swf[offset+8, 1].unpack("C").first
      # replace lossless2 data
      if lossless.format == 3
        if org_format == 3
          org_image_length = swf[offset+2, 4].unpack("i").first - 8
          delta_length = lossless.zlib_bitmap_data.size - org_image_length
          swf[offset+14, org_image_length] = lossless.zlib_bitmap_data
          swf[offset+13, 1] = [lossless.color_table_size].pack("C")
          swf[offset+11, 2] = [lossless.height].pack("v")
          swf[offset+9, 2] = [lossless.width].pack("v")
          swf[offset+8, 1] = [lossless.format].pack("C")
          swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 8].pack("i")
        elsif org_format == 5
          org_image_length = swf[offset+2, 4].unpack("i").first - 7
          delta_length = lossless.zlib_bitmap_data.size - org_image_length + 1
          swf[offset+13, org_image_length] = [lossless.color_table_size].pack("C") + lossless.zlib_bitmap_data
          swf[offset+11, 2] = [lossless.height].pack("v")
          swf[offset+9, 2] = [lossless.width].pack("v")
          swf[offset+8, 1] = [lossless.format].pack("C")
          swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 8].pack("i")
        else
          raise ReplaceTargetError
        end
      elsif lossless.format == 5
        if org_format == 3
          org_image_length = swf[offset+2, 4].unpack("i").first - 8
          delta_length = lossless.zlib_bitmap_data.size - org_image_length - 1
          swf[offset+13, org_image_length+1] = lossless.zlib_bitmap_data
          swf[offset+11, 2] = [lossless.height].pack("v")
          swf[offset+9, 2] = [lossless.width].pack("v")
          swf[offset+8, 1] = [lossless.format].pack("C")
          swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 7].pack("i")
        elsif org_format == 5
          org_image_length = swf[offset+2, 4].unpack("i").first - 7
          delta_length = lossless.zlib_bitmap_data.size - org_image_length
          swf[offset+13, org_image_length] = lossless.zlib_bitmap_data
          swf[offset+11, 2] = [lossless.height].pack("v")
          swf[offset+9, 2] = [lossless.width].pack("v")
          swf[offset+8, 1] = [lossless.format].pack("C")
          swf[offset+2, 4] = [lossless.zlib_bitmap_data.size + 7].pack("i")
        else
          raise ReplaceTargetError
        end
      else
        raise ReplaceTargetError
      end
      swf[4, 4] = [swf[4, 4].unpack("V").first + delta_length].pack("V")
      swf
    end
DefineBitsLossless2のイメージバイナリを置換.