From c4ae166f8f21e5890d865056a321463d4cafffb9 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 8 Sep 2015 18:19:01 +0200 Subject: [PATCH] =?UTF-8?q?parse/unparse=20fonctionnells=20mais=20tjs=20pb?= =?UTF-8?q?=20avec=20header=5Fcompl=C3=A9mentaire...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/bmp.readme | 133 +++++++++++++++++++++++++++++++++++++++ code/classes.pyc | Bin 7621 -> 0 bytes code/images/blue.bmp | Bin 0 -> 126 bytes code/images/green.bmp | Bin 0 -> 126 bytes code/images/modified.bmp | Bin 0 -> 82 bytes code/images/red.bmp | Bin 0 -> 126 bytes code/images/rgbw.bmp | Bin 0 -> 138 bytes code/images/test.bmp | Bin 0 -> 170 bytes code/overwrite.py | 50 +++++++++++++++ 9 files changed, 183 insertions(+) create mode 100644 code/bmp.readme delete mode 100644 code/classes.pyc create mode 100644 code/images/blue.bmp create mode 100644 code/images/green.bmp create mode 100644 code/images/modified.bmp create mode 100644 code/images/red.bmp create mode 100644 code/images/rgbw.bmp create mode 100644 code/images/test.bmp create mode 100644 code/overwrite.py diff --git a/code/bmp.readme b/code/bmp.readme new file mode 100644 index 0000000..65c5181 --- /dev/null +++ b/code/bmp.readme @@ -0,0 +1,133 @@ +Classes: + + BMPHeader + /***************/ + /* ATTRIBUTS */ + /***************/ + + * CONTENU BRUT PARTIEL (54 premiers bytes) + - header brut (binaire) + - header format liste de (0-255) + + * STRUCTURE DU HEADER + - signature (4D42) par défaut + - taille du fichier .bmp (bytes) + 4 bytes à 0 + - début du codage de l'image (bytes) + - taille du INFO_HEADER + - longueur de l'image (pixels) + - hauteur de l'image (pixels) + - nombre de plans (défaut: 1) + - nombre de bits par pixel (1,4,8,24) + - type de compression (0=none, 1=RLE-8, 2=RLE-4) + - taille de l'image avec padding (bytes) + - résolution horizontale (pixels) + - résolution verticale (pixels) + - nombre de couleurs de l'image (ou 0) + - nombre de couleurs importantes de l'image (ou 0) + + * VALEURS CALCULEES + - taille réelle d'une ligne +padding (bytes) + - taille du padding de fin de ligne (bytes) + + /***************/ + /* METHODES */ + /***************/ + parse(binHeader=""): + Définit les attributs à partir de ou de l'argument si défini + + unparse(): + Définit , et à partir de tout les attributs de structure + + + info(type=0): + Affiche les informations du header au format humain + peut valoir 0 (valeur par défaut) pour afficher en nombre, ou 1 pour afficher en hexa + + + toInt(bytes): + Retourne les octets sous forme d'entier + + fromInt(value, size): + Retourne une chaine de bytes correspondant au binaire de value + + + + + + BMPContent + /***************/ + /* ATTRIBUTS */ + /***************/ + + * CONTENU BRUT + - matrice de pixels brut (binaire) + - matrice de pixels format liste de (0-255) + + * CONTENU EXPLOITABLE + - matrice de pixels (instance of RGBPixel) + + + /***************/ + /* METHODES */ + /***************/ + parse(binContent="", header): + Définit les attributs à partir de ou de l'argument si défini ainsi que du header + + unparse(): + Définit à partir map + + + + + + BMPFile + /***************/ + /* ATTRIBUTS */ + /***************/ + * CONTENU BRUT HEADER COMPLETS (début jusqu'aux pixels) + - header format binaire (0 à offset) + - header format list de (0-255) + - header format liste de (0x00 - 0xFF) + + * CONTENU BRUT + - contenu complet brut (binaire) + - contenu complet format liste de (0-255) + - contenu complet format liste de (0x00 - 0xFF) + + * CONTENU STRUCTURE + -
objet de type + - objet de type + + + /***************/ + /* METHODES */ + /***************/ + parse(binFile=""): + Définit les attributs à partir de ou de l'argument si défini + + unparse(header="", content=""): + Définit à partir d'un
et d'un + + + + + + + + + RGBPixel + /***************/ + /* ATTRIBUTS */ + /***************/ + - byte rouge entre 0 et 255 + - byte vert entre 0 et 255 + - byte bleu entre 0 et 255 + + + /***************/ + /* METHODES */ + /***************/ + Constructeur(r, g, b): + Définit les attributs + diff --git a/code/classes.pyc b/code/classes.pyc deleted file mode 100644 index 92a45499b155be69f50a1ffbe694370adc8f0c37..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7621 zcmb_h&2JmW6`v*bM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?w literal 0 HcmV?d00001 diff --git a/code/images/green.bmp b/code/images/green.bmp new file mode 100644 index 0000000000000000000000000000000000000000..48536de1cd217104ed917bacd4b47fc0bbbb47bb GIT binary patch literal 126 ucmZ?rtz&?IDj<~u#Eft(0hV9^lET~&3>E+qPVPa)FgCF?6S~6x3=9Bh?F60x literal 0 HcmV?d00001 diff --git a/code/images/modified.bmp b/code/images/modified.bmp new file mode 100644 index 0000000000000000000000000000000000000000..3a0751c1906cedd48b528e7dab29cf03768360f3 GIT binary patch literal 82 zcmZ?rWmv@k1ZF_U0)&hV5E+qPVPa)FgCF?6NbY73;<{D1fBo@ literal 0 HcmV?d00001 diff --git a/code/images/rgbw.bmp b/code/images/rgbw.bmp new file mode 100644 index 0000000000000000000000000000000000000000..1d89d2c2d207e5ad05a22a83e7aed2d9ac54b351 GIT binary patch literal 138 zcmZ?r?P7p{Dj<~u#7t1k$RGih5CD?G+z<>F01{5_LB%jOu{6kBWbmJX;s1Xi0i=MC GfdK&9QVFvF literal 0 HcmV?d00001 diff --git a/code/images/test.bmp b/code/images/test.bmp new file mode 100644 index 0000000000000000000000000000000000000000..0b2fe5d7b8b18009de7cfae21b8541b5553db332 GIT binary patch literal 170 zcmZ?rUBv(aRX{2Sh*_YRkwF41VE`nBxgi)V03@8;gNk8nVreEch5umyB<>C4fM^B= Q5b?j90muRZAQQv_0FpN$q5uE@ literal 0 HcmV?d00001 diff --git a/code/overwrite.py b/code/overwrite.py new file mode 100644 index 0000000..a381114 --- /dev/null +++ b/code/overwrite.py @@ -0,0 +1,50 @@ +# ~*~ encoding: utf-8 ~*~ # +########################### +# TRAITEMENT D'IMAGES # +########################### + +# classes +from classes import * + +import sys + +# lecture du fichier +binFile = "" +with open( sys.argv[1] ) as file: + for byte in file.read(): + binFile += byte; + +img = BMPFile() +img.parse( binFile ); + + +### print header human-readable data ### +#print img.header.info() + +### print file human-readable data ### +#print img.readableData + +### print header human-readable data ### +#print img.header.readableData + +### print content human-readable data ### +#print img.content.readableData + + +#print img.header.binData + img.content.binData + +img.content.unparse( img.content.map ) +img.header.unparse() + + +print img.header.binData + img.content.binData + + + +#print img.hexData + + +#for line in img.content.map: +# for pixel in line: +# print "rgb(%s, %s, %s)" % (pixel.r, pixel.g, pixel.b) +# print \ No newline at end of file