diff --git a/docs/BMPFile.readme b/docs/BMPFile.readme new file mode 100644 index 0000000..5b82a33 --- /dev/null +++ b/docs/BMPFile.readme @@ -0,0 +1,224 @@ +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(headerHandler=None): + Définit à partir map et définit aussi l'objet s'il est passé en paramètres + + + + + + BMPFile + /***************/ + /* ATTRIBUTS */ + /***************/ + * CONTENU PALETTE (fin du header jusqu'aux pixels) + - palette format binaire (header à offset) + - palette format list de (0-255) + + * CONTENU BRUT + - contenu complet brut (binaire) + - contenu complet format liste de (0-255) + + * 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(): + Définit à partir des attributs et + + + + + + + + + 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 + + + + + + + + + + + + +############# +## To Do ## +############# +[x] gestion de la palette (attribut au ) définit par défaut au +[x] faire que le unparse du content créée le header +[ ] prise en charge des formats 1, 4, et 8 bpp + + + +####################################################################### +####### RECHERCHE DE PRISE EN CHARGE DES DIFFERENTS FORMATS BPP ####### +####################################################################### +PixelColor(r, g, b, bpp=24) + , , respectivement les composantes bleue, rouge, verte + correspond aux bpp + +CAS BPP=1 (noir et blanc) + (r+g+b)/3 >= 256 / 2 + + 1 - blanc + 2 - noir + +CAS BPP=4 (niveaux de gris) + 16 * ((r+g+b)/3) / 256 + +CAS BPP=8 + (r+g+b) / 3 + +class PixelColor(r, g, b, bpp=24): + if bpp not in [1,4,8,24]: + self.bpp = 24 + else: + self.bpp = bpp + + + self.r = r + self.g = g + self.b = b + + + # gestion des différents bpp + if bpp == 1: + self.intColor = int( (r+g+b)/3 > 256/2 ) + self.binColor = chr( self.intColor ) + elif bpp == 4: + self.intColor = int( 16 * ((r+g+b)/3) / 256 ) ) + self.binColor = chr( self.intColor ) + elif bpp == 8: + self.intColor = int( (r+g+b) / 3 ) + self.binColor = chr( self.intColor ) + else: + self.intColor = [r, g, b] + self.binColor = chr(b) + chr(g) + chr(r) + + + +####################################################################### +####### RECHERCHE DE PARSAGE DES PIXELS DE DIFFERENTS BPPS ####### +####################################################################### +ALGO: + + +firstBit = int(i) + i%1.0; # retourne le rang du premier bit (pas byte) +lastBit = firstBit + bpp/8.0 + +startByte = int( firstBit ) # ex: pour i =29, on a: 3 octets +startBit = int( 8 * (firstBit-startByte) ) # et 5 bits + +stopByte = int( lastBit ) +stopBit = int( 8 * (lastBit-stopByte) ) + +bytes = binData[startByte:stopByte+1] + +intArray = [ ord(x) for x in bytes ] +binArray = [ "0" + bin(x)[2:] for x in intArray ] +binArray = [ "0"*(8-len(binArray[x])) + binArray[x] for x in range(0, len(binArray)) ] +binary = "" +for byte in binArray: + binary += byte; + +print binArray +print "%s to %s => %s" % ( startBit, 8*(stopByte-startByte)+stopBit, binary[startBit:8*(stopByte-startByte) + stopBit] ) \ No newline at end of file diff --git a/docs/Noise.readme b/docs/Noise.readme new file mode 100644 index 0000000..6372d66 --- /dev/null +++ b/docs/Noise.readme @@ -0,0 +1,192 @@ +Classes: + + +/******************/ +/** COLORIZATION **/ +/******************/ +Principe: colorer en modifiant les pixels (n&b) dans un ton (teinte) précisée + +restitue la contraste mais recentre la couleur autour de la teinte +/************ ALGO **************/ +i = 50 // incertitude +t = RGBPixel(1,2,3) // teinte souhaitée +p = RGBPixel(1,2,3) // couleur actuelle + +/************ CODE **************/ +def colorize(pixel, tint): + + + + +/*****************/ +/** SHAPIZATION **/ +/*****************/ +Principe: récupérer une forme par récurrence + +Ajouter les 8 bits périphériques du pixel courant s'il existe et s'il a des couleurs pas trop éloignées des précédentes +/************ ALGO **************/ + +/************ CODE **************/ +def getShape(self, coords, pixelMap, pixelList ): # return PixelList + # coords = [lastx, lasty, x, y] + width = len( pixelMap[0] ) + height = len( pixelMap ) + + lastx = coords[0] + lasty = coords[1] + x = coords[2] + y = coords[3] + + newCoords = [x, y] + + + # si le pixel existe (pas de dépassement de la pixelMap) + if x=0 and y=0: + + already = False; + for i in range(0, len(pixelList)): + if pixelList[i] == pixelMap[y][x]: + already = True; + break + + # si le pixel n'est pas déjà dans le tableau + if not already: + + pixelMap[y][x].setRGB(255,0,0); # debug, tout rouge + + pixelList.append( pixelMap[y][x] ) # ajout au tableau + + self.getShape(newCoords+[x-1, y+1], pixelMap, pixelList) # 1 + self.getShape(newCoords+[x, y+1], pixelMap, pixelList) # 2 + self.getShape(newCoords+[x+1, y+1], pixelMap, pixelList) # 3 + + self.getShape(newCoords+[x-1, y], pixelMap, pixelList) # 4 + # current pixel + self.getShape(newCoords+[x+1, y], pixelMap, pixelList) # 6 + + self.getShape(newCoords+[x-1, y-1], pixelMap, pixelList) # 7 + self.getShape(newCoords+[x, y-1], pixelMap, pixelList) # 8 + self.getShape(newCoords+[x+1, y-1], pixelMap, pixelList) # 9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +def getShapeRecursive(self, coords, pixelMap, pixelList ): # return PixelList + # coords = [lastx, lasty, x, y] + width = len( pixelMap[0] ) + height = len( pixelMap ) + + lastx = coords[0] + lasty = coords[1] + x = coords[2] + y = coords[3] + + newCoords = [x, y] + + + # si le pixel existe (pas de dépassement de la pixelMap) + if x=0 and y=0: + + already = False; + for i in range(0, len(pixelList)): + if pixelList[i] == pixelMap[y][x]: + already = True; + break + + # si le pixel n'est pas déjà dans le tableau + if not already: + + pixelMap[y][x].setRGB(255,0,0); + + # si trop de différence + lastP = pixelMap[lasty][lastx] + pix = pixelMap[y][x] + + + + if abs(lastP.r-pix.r) <= 50 and abs(lastP.g-pix.g) <= 50 and abs(lastP.b-pix.b) <= 50: + + pixelList.append( pixelMap[y][x] ) # ajout au tableau + + self.getShapeRecursive( [x, y, x-1, y+1], pixelMap, pixelList) # 1 + self.getShapeRecursive( [x, y, x, y+1], pixelMap, pixelList) # 2 + self.getShapeRecursive( [x, y, x+1, y+1], pixelMap, pixelList) # 3 + + self.getShapeRecursive( [x, y, x-1, y ], pixelMap, pixelList) # 4 + # current pixel + self.getShapeRecursive( [x, y, x+1, y ], pixelMap, pixelList) # 6 + + self.getShapeRecursive( [x, y, x-1, y-1], pixelMap, pixelList) # 7 + self.getShapeRecursive( [x, y, x, y-1], pixelMap, pixelList) # 8 + self.getShapeRecursive( [x, y, x+1, y-1], pixelMap, pixelList) # 9 + + + def getShape(self, coords, pixelMap, pixelList): + # coords = [lastx, lasty, x, y] + width = len( pixelMap[0] ) + height = len( pixelMap ) + + lastx = coords[0] + lasty = coords[1] + x = coords[2] + y = coords[3] + + if x=0 and y=0: + + already = False; + for pix in pixelList: + if pix == pixelMap[y][x]: + already = True; + break + + # si le pixel n'est pas déjà dans le tableau + if not already: + + # si trop de différence + lastP = pixelMap[lasty][lastx] + pix = pixelMap[y][x] + + if abs(lastP.r-pix.r) <= 50 and abs(lastP.g-pix.g) <= 50 and abs(lastP.b-pix.b) <= 50: + + return pixelMap[y][x]; + + # self.getShape( [x, y, x-1, y+1], pixelMap, pixelList) # 1 + # self.getShape( [x, y, x, y+1], pixelMap, pixelList) # 2 + # self.getShape( [x, y, x+1, y+1], pixelMap, pixelList) # 3 + + # self.getShape( [x, y, x-1, y ], pixelMap, pixelList) # 4 + # # current pixel + # self.getShape( [x, y, x+1, y ], pixelMap, pixelList) # 6 + + # self.getShape( [x, y, x-1, y-1], pixelMap, pixelList) # 7 + # self.getShape( [x, y, x, y-1], pixelMap, pixelList) # 8 + # self.getShape( [x, y, x+1, y-1], pixelMap, pixelList) # 9 + + return None # return none si le pixel n'est plus de la forme \ No newline at end of file