Traitement de fichier bpp1,4,8,24 fonctionnel, rapidité et efficience de l'algo à revoir

This commit is contained in:
xdrm-brackets 2015-09-09 22:37:44 +02:00
parent ffcfbf1f69
commit 3494ecec32
6 changed files with 14 additions and 20 deletions

View File

@ -269,16 +269,16 @@ class RGBPixel:
# gestion des différents bpp # gestion des différents bpp
if bpp == 1: if bpp == 1:
self.intData = [ int( (r+g+b)/3 > 256/2 ) ] self.intData = [ int( (r+g+b)/3 >= 128 ) ]
self.binData = chr( self.intData[0] ) self.binData = chr( self.intData[0] )
elif bpp == 4: elif bpp == 4:
self.intData = [ int( 16 * ((r+g+b)/3) / 256 ) ] self.intData = [ int( 16 * ((r+g+b)/3) / 256 ) ]
self.binData = chr( self.intData[0] ) self.binData = chr( self.intData[0] )
elif bpp == 8: elif bpp == 8:
self.intData = [ int( (r+g+b) / 3 ) ] self.intData = [ int( (r+g+b) / 3 ) ]
self.binData = chr( self.intData[0] ) self.binData = chr( self.intData[0] )
else: else:
self.intData = [ r, g, b ] self.intData = [ r, g, b ]
self.binData = chr(b) + chr(g) + chr(r) self.binData = chr(b) + chr(g) + chr(r)
@ -287,7 +287,8 @@ class RGBPixel:
def setBin(self, binData, index, bpp=24): def setBin(self, binData, index, 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

View File

@ -201,10 +201,6 @@ class PixelColor(r, g, b, bpp=24):
####################################################################### #######################################################################
ALGO: ALGO:
binData="01234567890123456789012345678\0ABCD"
i = 29.125 + .125
bpp = 1
firstBit = int(i) + i%1.0; # retourne le rang du premier bit (pas byte) firstBit = int(i) + i%1.0; # retourne le rang du premier bit (pas byte)
lastBit = firstBit + bpp/8.0 lastBit = firstBit + bpp/8.0

View File

@ -29,24 +29,21 @@ def testFileIntegrity():
# Parsing # Parsing
img.parse( binFile ); img.parse( binFile );
# MODIFICATIONS des pixels
for line in img.content.map: for line in img.content.map:
for pixel in line: for pixel in line:
print "rgb(%s, %s, %s)" % (pixel.r, pixel.g, pixel.b) pixel.setRGB(
print ( 255 - pixel.r ) % 256,
( 255 - pixel.g ) % 256,
# # MODIFICATIONS des pixels ( 255 - pixel.b ) % 256
# for line in img.content.map: )
# for pixel in line:
# pixel.r = 255
# pixel.g = 75
# pixel.b = 255
# # Unparsing # Unparsing
# img.unparse() img.unparse()
# print img.binData print img.binData

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 KiB

BIN
code/images/lena2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 KiB