From 0a5c105944860021abb1c3c9f4120afcbc122fa3 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 6 Sep 2015 16:01:17 +0200 Subject: [PATCH] =?UTF-8?q?cr=C3=A9ation=20de=20la=20classe=20BMPHeader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/bmp.py | 12 ++++++++---- code/headerClass.py | 27 +++++++++++++++++++++++++++ code/headerClass.pyc | Bin 0 -> 1451 bytes 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 code/headerClass.py create mode 100644 code/headerClass.pyc diff --git a/code/bmp.py b/code/bmp.py index f187ec2..511da93 100644 --- a/code/bmp.py +++ b/code/bmp.py @@ -3,22 +3,26 @@ # TRAITEMENT D'IMAGES # ########################### +# classes +from headerClass import * + import dep import sys tmp = "" -header = "" content = "" with open(sys.argv[1]) as f: for byte in f.read(): + content += byte tmp += str( hex( ord(byte) ) )[2:] + "," -headerSize = ( 2 + 4 + 2 + 2 + 4 + 4 + 4 + 4 + 2 + 2 + 4 + 4 + 4 + 4 + 4 + 4 ) -header = tmp[:headerSize] +headerSize = 54 + +header = BMPHeader(content[0:headerSize]) content = tmp[headerSize:] -print header +print header.offset print print content \ No newline at end of file diff --git a/code/headerClass.py b/code/headerClass.py new file mode 100644 index 0000000..22d80d0 --- /dev/null +++ b/code/headerClass.py @@ -0,0 +1,27 @@ +# ~*~ encoding: utf-8 ~*~ # + +class BMPHeader: + + def toInt(self, bytes): + intReturn = 0; + for i, byte in enumerate(bytes): + intReturn += ord(byte) * (256 ** i) + return intReturn + + # CONSTRUCTEUR: parse le header au format bin en objet + def __init__(self, binHeader): + self.signature = self.toInt(binHeader[ 0: 2]) # signature (4D42) + self.fileSize = self.toInt(binHeader[ 2: 6]) # taille du fichier bmp (bytes) + self.offset = self.toInt(binHeader[10:14]) # début de l'image (bytes) + self.infoSize = self.toInt(binHeader[14:18]) # taille du INFO_HEADER + self.width = self.toInt(binHeader[18:22]) # longueur de l'image (pixel) + self.height = self.toInt(binHeader[22:26]) # hauteur de l'image (pixel) + self.plans = self.toInt(binHeader[26:28]) # nombre de plans (default: 1) + self.bpp = self.toInt(binHeader[28:30]) # nombre de bits par pixel (1,4,8, 24) + self.compType = self.toInt(binHeader[30:34]) # type de compression (0=none, 1=RLE-8, 2=RLE-4) + self.size = self.toInt(binHeader[34:38]) # taille de l'image avec padding (bytes) + self.horiRes = self.toInt(binHeader[38:42]) # résolution horizontale (pixels) + 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 diff --git a/code/headerClass.pyc b/code/headerClass.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8493fb7898b8d0115fb6712c483a447fb578a629 GIT binary patch literal 1451 zcmb`HOK%e~5XWbC^M18Z1S+bKKnO(~x>67Hf&jG$ngbQuv_eFn)h2ejhU|m211(BV z<>PWed;w-=BeNGyCCUC{`{(hD$K&;W_dCB{{XCt)`s3mM3w-n)6oEevgabbSt^nRo zu*o;v^>Y+- zcj?0U9vFa?16K~b{P++)xNzygWerv?7zb800vOE7gRNWpXz*nV-XR+gX$Qv&1r%U3 z?1_Vw=`xW;WTc@fSs{kx+t6mTT+9virWZzPo~=?7NV6{K`?z}?3R%|x6YN=lnXwi%5OoW@3aEol z7W6A%1H`5U1FAF1CXNDD&<#xdx`OB&RD+~LG9bB0a+`!|Ty>X$ zK=*~Co~pFG?|cDRu5}A&?_sD?Wx}wBZB2OuyaxaNmM@>uFpUx!hK7zN43kVO7ue+- r2irLIH^^&88c