Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用多个数据块解压缩GIF_Python_Gif_Compression - Fatal编程技术网

Python 使用多个数据块解压缩GIF

Python 使用多个数据块解压缩GIF,python,gif,compression,Python,Gif,Compression,我编写了python脚本,该脚本采用如下GIF数据: ['8c', '2d', '99', '87', '2a', '1c', 'dc'] 把它变成这样: [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] 首先,我获取所有块中的所有数据,并将其转换为比特流>>我不确定这一步。我不知道是要将所有块作为一个流一次性解压缩,还是要将它们单独解压缩 for byte in data: bit=bin(int(m,16))[2:]

我编写了python脚本,该脚本采用如下GIF数据:

['8c', '2d', '99', '87', '2a', '1c', 'dc']
把它变成这样:

[1, 1, 1, 1, 1, 2, 2, 2, 2, 2]
首先,我获取所有块中的所有数据,并将其转换为比特流>>我不确定这一步。我不知道是要将所有块作为一个流一次性解压缩,还是要将它们单独解压缩

         for byte in data:
             bit=bin(int(m,16))[2:]
             while len(bit)<8:
                 bit='0'+bit
             c.append(bit[::-1] )
         stream=  ''.join(c)  
         decompress(stream)
对于数据中的字节:
位=bin(int(m,16))[2:]

而len(bit)GIF使用LZW编码。要复制原始数据,您需要(至少)进行LZW解码。您是如何将这7个十六进制字节转换为
[1,1,1,1,2,2,2,2]
?更重要的是,为什么?这10个数字代表什么?同时,Wikipedia上的文章对文件格式有一个很好的概述,包括使用多个图像块的不同方式(单独的瓷砖、动画、>256色等)。如果您需要更详细的信息或更友好的新手解释,本文还提供了从实际规格到教程页面的所有链接。这些数字['8c'、'2d'、'99'、'87'、'2a'、'1c'、'dc']只是压缩数据的一小部分。[1,1,1,1,1,2,2,2,2]是解压后的数据
def decompress(s,InitialCodeSize):
    index=[]
    table=Initialize(InitialCodeSize)
    codesize = InitialCodeSize + 1
    ClearCode=int(math.pow(2, InitialCodeSize))
    L=int(math.pow(2, codesize))
    code = int(s[:codesize][::-1],2)
    s=s[codesize:]
    c = table[code]

    old = c
    for i in c:
       index.append(i)
    while s !='':
      code = int(s[:codesize][::-1],2)

      s=s[codesize:]

      if code == ClearCode:

           table=Initialize(InitialCodeSize)
           codesize = InitialCodeSize + 1

      if code in  list(xrange(len(table ))):
          c=table[code]
          table.append(old + [c[0]])

      else:

        table.append(old + [old[0]])

        c=  old + [old[0]]

      for i in c:
         index.append(i)
      old=c
      if len(table) == L and codesize< 12:
          codesize=codesize+1

          L=int(math.pow(2, codesize))

    return index