
lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
   
Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12

|
CODE |
from Tkinter import *
def Dwords(files):
temp1=ord(files.read(1))*256**0
temp2=ord(files.read(1))*256**1
temp3=ord(files.read(1))*256**2
temp4=ord(files.read(1))*256**3
return temp1+temp2+temp3+temp4
def Words(files):
temp3=ord(files.read(1))*256**0
temp4=ord(files.read(1))*256**1
return temp3+temp4
def Read_Header_Bmp(bmpfile):
text=bmpfile.read(2)
print
print bmpfile
print "========BMP-Header Information========"
if text=="BM":
print "first Dword 'BM' : ok"
else:
print text
bfSize=Dwords(bmpfile)
print "File size in Dwords:", bfSize
reserv1=Words(bmpfile)
print "Must be zero:",
if reserv1==0:
print "ok"
else:
print "error"
reserv2=Words(bmpfile)
print "Must be zero:",
if reserv2==0:
print "ok"
else:
print "error"
offbits=Dwords(bmpfile)
print "Image data offset:",offbits
info=Words(bmpfile)
print "Info header=",info,"bytes"
#Why Dwords are differents here ???
# it seems to be a .read error ... ???
temp1=ord(bmpfile.read(1))*256**2
temp2=ord(bmpfile.read(1))*256**3
temp3=ord(bmpfile.read(1))*256**0
temp4=ord(bmpfile.read(1))*256**1
width=temp1+temp2+temp3+temp4
print "Width=",width
temp1=ord(bmpfile.read(1))*256**2
temp2=ord(bmpfile.read(1))*256**3
temp3=ord(bmpfile.read(1))*256**0
temp4=ord(bmpfile.read(1))*256**1
height=temp1+temp2+temp3+temp4
print "Height=",height
temp1=ord(bmpfile.read(1))*256**2
temp2=ord(bmpfile.read(1))*256**3
temp3=ord(bmpfile.read(1))*256**0
temp4=ord(bmpfile.read(1))*256**1
planes=temp1+temp2+temp3+temp4
print "Must be '1':",
if planes==1:
print "ok"
else:
print "error"
bitcount=Words(bmpfile)
print "Bits per pixel:",bitcount
compression=Dwords(bmpfile)
print "Compression type:",compression
sizeimage=Dwords(bmpfile)
print "Image size in Bytes:",sizeimage
xpxelpermeter=Dwords(bmpfile)
print "Pixels per meter (X):",xpxelpermeter
ypxelpermeter=Dwords(bmpfile)
print "Pixels per meter (Y):",ypxelpermeter
colorused=Dwords(bmpfile)
if colorused==0:
print "All colors used"
else:
print colorused,"colors used"
colorimportant=Dwords(bmpfile)
print colorimportant,"important color(s)"
print "============End of header ============"
return [width,height,bitcount,offbits,sizeimage]
def Bmp_read_24(offbits,width,height,bmpfile,size):
data=[]
print bmpfile.tell()
bmpfile.seek(0)
bmpfile.seek(offbits)
if bmpfile.tell()<>offbits:
print "file error"
for count in range(0,size,3):
blue=ord(bmpfile.read(1))
green=ord(bmpfile.read(1))
red=ord(bmpfile.read(1))
data.append([red,green,blue])
return data
# file=open("C:/Documents and Settings/momo1/Bureau/Python/Test.dat","rb")
file=open("Test.dat","rb")
bmpinfo=Read_Header_Bmp(file)
if bmpinfo[2]==24:
print "launch 24 bits decoding routine"
bmpdata=Bmp_read_24(bmpinfo[3],bmpinfo[0],bmpinfo[1],file,bmpinfo[4])
file.close()
print"file closed"
root=Tk()
bitmap=Canvas(width=bmpinfo[0],height=bmpinfo[1])
bitmap.pack()
root.title("just a dumb test")
counter=0
# need to find a less memory and cpu hungry method
# a "raw" bitmap would be perfect
for count1 in range(bmpinfo[1],0,-1):
for count in range(bmpinfo[0]+1):
color="#%02x%02x%02x" % (bmpdata[counter][0],bmpdata[counter][1],bmpdata[counter][2])
counter+=1
bitmap.create_line(count,count1,count,count1+1,fill=color)
root.mainloop()
|
bon à part le fait que la mauvaise idée d'utiliser un canvas pour l'affichage en fait un gouffre cpu et ram, ça marche ... pour les bmp 24 bits ... du moins
( même s'il va falloir que je comprennes d'où vient mon pb avec le decodage Width et Height ... :/ )
--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude. Kevin Kelly - Out of control
|