From bd7de786acd5cd85afc8e8652db69b50c4c5695a Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 6 Sep 2015 16:28:56 +0200 Subject: [PATCH] modification affichage --- code/bmp.py | 10 +++++----- code/{headerClass.py => classes.py} | 28 +++++++++++++++++++++++++++- code/classes.pyc | Bin 0 -> 1968 bytes 3 files changed, 32 insertions(+), 6 deletions(-) rename code/{headerClass.py => classes.py} (63%) create mode 100644 code/classes.pyc diff --git a/code/bmp.py b/code/bmp.py index 1f351ac..0b28047 100644 --- a/code/bmp.py +++ b/code/bmp.py @@ -4,7 +4,7 @@ ########################### # classes -from headerClass import * +from classes import * import dep import sys @@ -16,9 +16,9 @@ with open(sys.argv[1]) as f: headerSize = 54 -header = BMPHeader( fileData[0:headerSize] ) -content = fileData[headerSize:] +header = BMPHeader( fileData[:headerSize] ) +content = BMPContent( fileData[header.offset:], header.width, header.bpp) -print header.offset +print header.bpp print -print content \ No newline at end of file +print content.map \ No newline at end of file diff --git a/code/headerClass.py b/code/classes.py similarity index 63% rename from code/headerClass.py rename to code/classes.py index 22d80d0..6010be3 100644 --- a/code/headerClass.py +++ b/code/classes.py @@ -1,7 +1,12 @@ # ~*~ encoding: utf-8 ~*~ # + +################################################# +# classe qui parse le header (binaire) en objet # +################################################# class BMPHeader: + # convertit les octets en entier def toInt(self, bytes): intReturn = 0; for i, byte in enumerate(bytes): @@ -24,4 +29,25 @@ class BMPHeader: self.vertRes = self.toInt(binHeader[42:46]) # résolution verticale (pixels) self.colorNb = self.toInt(binHeader[46:50]) # nombre de couleurs de l'image (ou 0) self.colorINb = self.toInt(binHeader[50:54]) # nombre d'images importantes (ou 0) - self.header = binHeader \ No newline at end of file + self.header = binHeader + + +#################################################### +# classe qui parse le content (binaire) en matrice # +#################################################### +class BMPContent: + + # CONSTRUCTEUR: parse le content (bin) avec les informations: + # longueur de l'image (en pixels) + # nombre de bits par pixel + def __init__(self, binContent, width, bpp): + # gestion du bpp + if( bpp != 24 ): + print "ne prends pas en charge les versions autre que bmp24"; + exit + + # matrice du contenu + self.map = [] + + for byte in binContent: + self.map.append( ord(byte) ); \ No newline at end of file diff --git a/code/classes.pyc b/code/classes.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7437e8cfa064da73d5345afc870b1dc5a0c9ef83 GIT binary patch literal 1968 zcmb_cU2hXd6us;9N9@?)BM3nowc83+7D!kMh`v-%1tb!wMAZg_8WpY9JL7o3p55$> z+oW=y=+EsNe}HqZ-Ocu)FKM0Z*_}D_ap%rCH~ci{J$v=nn~c`K5bq!HxcdNw{}!o$ z{v`TH^vf~Y4N`4VVbv9oYSPiLgWO#pAvJXrg0GA)bGXwPfw% zkm93Z19ZmFT0hV6cFzD9bV4-2>rUNC3}cY~ckGQwHmpd=$7u=|qez2pL^!I8hg$TM32;FMRaS# zCaHc!^lC(()Sx0ZYs7%mRz>t{#1^S*6)~t0*GOHjh%MF_XA`{y_1r+>*XrSWFl`3D zC$q(Hli@Z4>)Y%we8uoB!*>k#86Gn1GCTncuLEMfXpxpPCpLw&wCApgndu|*hxWWx zKAAY}rQg^|F8wT*-;MH988Ox7Wa>pj#VoZ>#5^tvnUm%7;`Mo+h#wQ79+;I*G z7WntSAzMO1O%j{Vb&`mEl4PE%#SBf!Z+sV{E(82eQN|n-=gjfe?XcUC9Z~b1=hkcM zGakUds_5}q^goLpY8}%VufaFTZ*lfd_(1i7r$2;L-eG6I+(*p|EYXRW9u7ad$NGHn zZbwQVJQ~n@6hIhR3Lq*$a5|*7ilxgpb!hGY-D7~&QBi8ETvVhk(l*MbX?dcfnRXFW z;7o2^lrDU!qtk_sP_K3$uae9m>NDd-TJy9JO{7JE#bP#v)XkMJ*clMUIwA1@%~-_F zdAq!as|rP~^8uD}eE>E3K`ZEl-Nqo0)5dJV_)CWW^WNFjY-PuXZMP0D&#|%udMV~X XHG=!DdP-6C4=Wu%6~Xbw+h2bM{+n~O literal 0 HcmV?d00001