unparse content opérationnel

This commit is contained in:
xdrm-brackets 2015-09-07 10:24:28 +02:00
parent 16b42b7380
commit 3904137b97
3 changed files with 29 additions and 10 deletions

View File

@ -15,9 +15,6 @@ img.parse( sys.argv[1] );
### print header human-readable data ### ### print header human-readable data ###
print img.header.info() print img.header.info()
print
print img.content.readableData
print
### print file human-readable data ### ### print file human-readable data ###
#print img.readableData #print img.readableData
@ -28,7 +25,18 @@ print
#print img.content.readableData #print img.content.readableData
for line in img.content.map:
for pixel in line:
print "rgb(%s, %s, %s)" % (pixel.r, pixel.g, pixel.b) #for line in img.content.map:
print # for pixel in line:
# print "rgb(%s, %s, %s)" % (pixel.r, pixel.g, pixel.b)
# print
for byte in img.content.bin:
print ord(byte),
print
img.content.unparse( img.content.map )
for byte in img.content.bin:
print ord(byte),

View File

@ -140,8 +140,19 @@ class BMPContent:
# unparse une map de pixels en binaire # unparse une map de pixels en binaire
def unparse(self, map): def unparse(self, map):
print "To Do!" self.map = map
print "unparsing content and creating header"
height = len( map ) # nb de lignes = taille de la map
width = len( map[0] ) # nb de colonnes = taille des lignes de la map
padding = ( 4 - width*3 % 4 ) % 4 # padding de bourrage de lignes
self.bin = ""
for line in self.map[::-1]:
for pixel in line:
self.bin += unichr(pixel.b) + unichr(pixel.g) + unichr(pixel.r)
for zero in range(0, padding):
self.bin += unichr(0)
################################# #################################
# classe contenant un pixel RGB # # classe contenant un pixel RGB #

Binary file not shown.