forsakenedzero 0 Newbie Poster

hey, i am trying to create a progam that reads gif images and displays them from raw binary , but some how only small images worked till now

from imagehex2 import*
def lzw(hexList,asclist,numberbinary,numberbyte):
   lzw,x,numberbyte=[],0,numberbyte+1
   number=numberbyte
   print number
   print 'numberc binary =',numberbinary
   numberbitperbinary=numberbinary+1
   for t in range(len(hexList)):
      if asclist[t]==',':
         if hexList[t+5] == hexList[6]and hexList[t+7] == hexList[8]:
            for i in range(len(hexList)-(t+14),0,-1):
##               print i ,hexList[t+11+i], hex2bin(hexList[t+11+i])
               lzw.append(hex2bin(hexList[t+11+i]))
   xy =''
   for i in range(len(lzw)):
      for x in range(8):
         xy = xy+ lzw[i][x]
   heximagecode = []
   print lzw,'\n',xy
   y=len(xy)-numberbitperbinary
   while y >= -1:
      if 2**numberbitperbinary == numberbyte:
         print numberbitperbinary
         numberbitperbinary=numberbitperbinary+1
         print numberbitperbinary
      z =  xy[y:y+numberbitperbinary]
      x = bintohex(z)
      heximagecode.append(x)
      numberbyte =numberbyte+1
      y = y - numberbitperbinary
      print 'z=',z,'x=',x,'y=',y,'len(xy)=',len(xy),'numberbyte',numberbyte,dec2hex(number)

   return heximagecode







def makeglobalcolortable(hexList,t,numberofcolor):
   colorlist=[]
   for x in range(0,3*numberofcolor):
      colorlist.append(hexList[t+3+x])
   dctcolortable={}
   n = 0
   for i in range(0,len(colorlist),3):
      dctcolortable[dec2hex(n)]=colorlist[i:3+i]
      n = n+1
   return dctcolortable
from imagehex2 import*
from types import*




def drawGrid(w,lzwcodeimage,height,colortablelist):
   col = 0; row = 0
   for color in lzwcodeimage:
      w.create_rectangle(col, row, col+1, row+1, fill=rgb2Hex(colortablelist[dec2hex(hex2dec(color))]), outline=rgb2Hex(colortablelist[dec2hex(hex2dec(color))]))
      col+=1
      if col == height:
         row += 1; col = 0





def decompress(lzwcode,numbercolortable):
   colortablelist = dict((dec2hex(i), dec2hex(i)) for i in xrange(numbercolortable))
   colortablelist[dec2hex(numbercolortable)]='the code start'
   colortablelist[dec2hex(numbercolortable+1)]='the end of the code'
   result,numbercolortable=[],numbercolortable+2
   entr,entrr,entry,w=[],[],[],[]
   print 'len',len(lzwcode)
   lzwcode.pop(0)
   w.append(lzwcode.pop(0))
   result.append(w[0])
   for k1 in lzwcode:
      k2 = eval(k1)
      k = dec2hex(k2)
      if k in colortablelist:
         ##print len(colortablelist[k]),type(colortablelist[k]),colortablelist[k]
         if type(colortablelist[k]) is ListType:
           ## print len(colortablelist[k]),type(colortablelist[k]),colortablelist[k]
            for i in range(len(colortablelist[k])):
                  entry.append(colortablelist[k][i])
         else:entry.append(colortablelist[k])
         ##print 'entry',entry,'k',k,'w',w
      elif k == dec2hex(numbercolortable):
         for i in range(len(w)):
            entr.append(w[i])
         entr.append(w[0])
         for i in range(len(entr)):
            entry.append(entr[i])
        ##print 'entry',entry
      else:
         for i in range(len(colortablelist)):
            print colortablelist[dec2hex(i)] ,i
         print numbercolortable,k,hex2dec(k)
         raise ValueError('Bad compressed k: %s' % k)
      for i in range(len(entry)):
         result.append(entry[i])
      for i in range(len(w)):
         entrr.append(w[i])
      entrr.append(entry[0])
      ##print 'w',w ,'entry[0]', entry[0],'entrr',entrr
      colortablelist[dec2hex(numbercolortable)]=entrr
      ##print dec2hex(numbercolortable),'colortablelist[dec2hex(numbercolortable)',colortablelist[dec2hex(numbercolortable)]
      numbercolortable += 1
      w = entry
      entrr,entry,entr=[],[],[]
   return result

any help pointing at the error would be appreciated, thnx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.