IPB

Bienvenue invité ( Connexion | Inscription )

[ En ligne ] · Standard · Linéaire+

> Pfouuu, java me fait chier, là ...

momo
post 09/08/2002 21:50
Message #1


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



.. alors je vais essayer Python ... ça à l'air marrant à premiere vu ...

Ceci est un communiqué sans interet aucun d'un momo qui se desespere de programmer bcp mieux en Basic que dans n'importe quel autre langage


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
 
Reply to this topicStart new topicStart Poll
Réponse(s)
momo
post 16/08/2002 10:24
Message #2


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
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Posts in this topic
momo   Pfouuu, java me fait chier, là ...   09/08/2002 21:50
Darhf   alors un petit article pour toi qui date une peu v...   09/08/2002 22:06
momo   je le relis +/- regulierement ... :)   09/08/2002 22:15
Poischack   arf moi j'ai fait l'inverse python -> java......   09/08/2002 23:30
momo   from Tkinter import * def Clear_button(...   10/08/2002 17:44
Gfx   Rah Python rulez !!!!   10/08/2002 17:44
momo   ben ça :)   10/08/2002 17:45
momo   m'enfin quand on voit ce que supporte ce langage, ...   10/08/2002 17:52
Poischack   tu peux toujours utilisé py2exe, il te fait des e...   10/08/2002 17:57
momo   dwd en cours .. done on verra ça à tête repos...   10/08/2002 18:03
Poischack   c vrai que elif plus que plus cool que else if ....   10/08/2002 18:20
momo   sans compter qu'il est sacrement rapide : je vou...   11/08/2002 8:53
momo   from Tkinter import * def Clear_bton(...   11/08/2002 15:13
momo   tiens, j'y pense, y a pas moyen de mettre une colo...   11/08/2002 15:15
Poischack   nan et c'est bete, sinon ton prog marche, c'est ...   11/08/2002 15:33
momo   Posté le: Dim Août 11, 2002 3:13 pm : "bon, i...   11/08/2002 20:01
Poischack   oula va peut etre falloir que je change de lunette...   11/08/2002 20:03
momo   m'enfin en attendant, "impr. Ecran" et paint font ...   11/08/2002 20:11
Gfx   Y'a des trucs mortels en Python momo, lit mes arti...   11/08/2002 23:36
Poischack   heu .... moi je prefere mes prog qui tiennent su...   11/08/2002 23:38
Gfx   Oui mais c beau techniquement :))) J'ai aussi Ã...   12/08/2002 0:13
Gfx   Au fait, jette un oeil aux générateurs. Et plutÃ...   12/08/2002 0:20
Gfx   Au fait momo, tu peux compiler le Python sous form...   12/08/2002 1:13
momo   ben le tinker, je l'utilise uniquement parceque tk...   12/08/2002 9:52
momo   téléchargement de pyQT : Done téléchargement...   12/08/2002 12:53
Gfx   momo, tu as juste besoin de la DLL de QT, qui ne f...   12/08/2002 13:39
momo   bon, de toutes façon, j'ai presque terminé le te...   12/08/2002 13:44
momo   bon voilà, done ....   12/08/2002 14:02
momo   localisation spatio-temporelle: Terre, 14/08/2002 ...   14/08/2002 20:59
Poischack   Microsoft, relation publique: pschht pschhtt momo...   14/08/2002 21:15
Gfx   Installe l'extension PIL. Ca rulez pour traiter le...   14/08/2002 21:43
momo   ce serait trop facile du coup ...   14/08/2002 21:46
Poischack   :) pff pourquoi faire facil quan don peut faire co...   14/08/2002 21:51
momo   et pourquoi ne pas develloper sa propre librairie ...   15/08/2002 10:53
momo   from Tkinter import * def Dwords(files...   16/08/2002 10:24


Reply to this topicTopic OptionsStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :
 

Version bas débit Nous sommes le : : 04/07/2025 15:22