Correction de RGBPixel.setBin
This commit is contained in:
parent
592d19184d
commit
aa7d1eee34
|
@ -194,12 +194,12 @@ class BMPContent:
|
||||||
|
|
||||||
for pixel in range(0, header.width):
|
for pixel in range(0, header.width):
|
||||||
newPixel = RGBPixel()
|
newPixel = RGBPixel()
|
||||||
newPixel.setBin(binContent, i, header.bpp)
|
newPixel.setBin(binContent, header.width, header.padding, i, header.bpp)
|
||||||
self.map[line].append( newPixel );
|
self.map[line].append( newPixel );
|
||||||
|
|
||||||
i += header.bpp / 8.0 # on passe à la suite
|
i += header.bpp / 8.0 # on passe à la suite
|
||||||
|
|
||||||
i += 8 * header.padding # on saute le padding de saut de ligne
|
i += header.padding # on saute le padding de saut de ligne
|
||||||
|
|
||||||
self.map = self.map[::-1] # on inverse les lignes
|
self.map = self.map[::-1] # on inverse les lignes
|
||||||
|
|
||||||
|
@ -258,7 +258,8 @@ class BMPContent:
|
||||||
class RGBPixel:
|
class RGBPixel:
|
||||||
def __init__(self, r=0, g=0, b=0, bpp=24):
|
def __init__(self, r=0, g=0, b=0, bpp=24):
|
||||||
if bpp not in [1,4,8,24]:
|
if bpp not in [1,4,8,24]:
|
||||||
self.bpp = 24
|
if not hasattr(self, 'bpp'): # si l'attribut n'est pas déjà défini, alors on met la valeur par défaut
|
||||||
|
self.bpp = 24
|
||||||
else:
|
else:
|
||||||
self.bpp = bpp
|
self.bpp = bpp
|
||||||
|
|
||||||
|
@ -285,7 +286,7 @@ class RGBPixel:
|
||||||
def setRGB(self, r, g, b, bpp=24):
|
def setRGB(self, r, g, b, bpp=24):
|
||||||
self.__init__(r, g, b, bpp);
|
self.__init__(r, g, b, bpp);
|
||||||
|
|
||||||
def setBin(self, binData, index, bpp=24):
|
def setBin(self, binData, width, padding, index, bpp=24):
|
||||||
if bpp not in [1,4,8,24]:
|
if bpp not in [1,4,8,24]:
|
||||||
if not hasattr(self, 'bpp'): # si l'attribut n'est pas déjà défini, alors on met la valeur par défaut
|
if not hasattr(self, 'bpp'): # si l'attribut n'est pas déjà défini, alors on met la valeur par défaut
|
||||||
self.bpp = 24
|
self.bpp = 24
|
||||||
|
@ -305,6 +306,7 @@ class RGBPixel:
|
||||||
|
|
||||||
bytes = binData[startByte:stopByte+1]
|
bytes = binData[startByte:stopByte+1]
|
||||||
|
|
||||||
|
|
||||||
intArray = [ ord(x) for x in bytes ]
|
intArray = [ ord(x) for x in bytes ]
|
||||||
binArray = [ bin(x)[2:] for x in intArray ]
|
binArray = [ bin(x)[2:] for x in intArray ]
|
||||||
binArray = [ "0"*(8-len(binArray[x])) + binArray[x] for x in range(0, len(binArray)) ]
|
binArray = [ "0"*(8-len(binArray[x])) + binArray[x] for x in range(0, len(binArray)) ]
|
||||||
|
|
|
@ -2,4 +2,34 @@
|
||||||
|
|
||||||
class Noise:
|
class Noise:
|
||||||
|
|
||||||
def
|
def getShape( x, y, map, pixelList ): # return PixelList
|
||||||
|
width = len( map[0] )
|
||||||
|
height = len( map )
|
||||||
|
|
||||||
|
|
||||||
|
# si le pixel existe (pas de dépassement de la map)
|
||||||
|
if x < width and y < height:
|
||||||
|
|
||||||
|
already = False;
|
||||||
|
for i in range(0, len(pixelList)):
|
||||||
|
if pixelList[i] == map[y][x]:
|
||||||
|
already = True;
|
||||||
|
break
|
||||||
|
|
||||||
|
# si le pixel n'est pas déjà dans le tableau
|
||||||
|
if not already:
|
||||||
|
|
||||||
|
pixelList.append( map[y][x] ) # ajout au tableau
|
||||||
|
|
||||||
|
getShape(x-1, y+1, map, pixelList) # 1
|
||||||
|
getShape(x, y+1, map, pixelList) # 2
|
||||||
|
getShape(x+1, y+1, map, pixelList) # 3
|
||||||
|
|
||||||
|
getShape(x-1, y, map, pixelList) # 4
|
||||||
|
# current pixel
|
||||||
|
getShape(x+1, y, map, pixelList) # 6
|
||||||
|
|
||||||
|
getShape(x-1, y-1, map, pixelList) # 7
|
||||||
|
getShape(x, y-1, map, pixelList) # 8
|
||||||
|
getShape(x+1, y-1, map, pixelList) # 9
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
Classes:
|
Classes:
|
||||||
|
|
||||||
|
|
||||||
/******************/
|
/******************/
|
||||||
/** COLORIZATION **/
|
/** COLORIZATION **/
|
||||||
/******************/
|
/******************/
|
||||||
|
@ -13,3 +14,47 @@ p = RGBPixel(1,2,3) // couleur actuelle
|
||||||
|
|
||||||
/************ CODE **************/
|
/************ CODE **************/
|
||||||
def colorize(pixel, tint):
|
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( x, y, map, pixelList): # return PixelList
|
||||||
|
width = len( map[0] )
|
||||||
|
height = len( map )
|
||||||
|
|
||||||
|
|
||||||
|
# si le pixel existe (pas de dépassement de la map)
|
||||||
|
if x < width and y < height:
|
||||||
|
|
||||||
|
already = False;
|
||||||
|
for i in range(0, len(pixelList)):
|
||||||
|
if pixelList[i] == map[y][x]:
|
||||||
|
already = True;
|
||||||
|
break
|
||||||
|
|
||||||
|
# si le pixel n'est pas déjà dans le tableau
|
||||||
|
if not already:
|
||||||
|
|
||||||
|
pixelList.append( map[y][x] ) # ajout au tableau
|
||||||
|
|
||||||
|
getShape(x-1, y+1, map, pixelList) # 1
|
||||||
|
getShape(x, y+1, map, pixelList) # 2
|
||||||
|
getShape(x+1, y+1, map, pixelList) # 3
|
||||||
|
|
||||||
|
getShape(x-1, y, map, pixelList) # 4
|
||||||
|
# current pixel
|
||||||
|
getShape(x+1, y, map, pixelList) # 6
|
||||||
|
|
||||||
|
getShape(x-1, y-1, map, pixelList) # 7
|
||||||
|
getShape(x, y-1, map, pixelList) # 8
|
||||||
|
getShape(x+1, y-1, map, pixelList) # 9
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
# classes
|
# classes
|
||||||
from BMPFile import *
|
from BMPFile import *
|
||||||
|
from Noise import *
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 732 KiB |
Binary file not shown.
After Width: | Height: | Size: 732 KiB |
Loading…
Reference in New Issue