#NEWLINE# def __init__( self , width , height , data ) : #NEWLINE# #INDENT# ' Initialize an XBM image.\n\n        Parameters\n        ----------\n        width : int\n            The width of the bitmap.\n\n        height : int\n            The height of the bitmap.\n\n        data : list\n            A list of 1s and 0s which represent the bitmap data.\n            The length must be equal to width * height.\n\n        ' #NEWLINE# assert ( len ( data ) == ( width * height ) ) #NEWLINE# bytes = [ ] #NEWLINE# for row in xrange ( height ) : #NEWLINE# #INDENT# val = 0 #NEWLINE# offset = ( row * width ) #NEWLINE# for col in xrange ( width ) : #NEWLINE# #INDENT# d = ( col % 8 ) #NEWLINE# if ( ( col > 0 ) and ( d == 0 ) ) : #NEWLINE# #INDENT# bytes . append ( chr ( val ) ) #NEWLINE# val = 0 #NEWLINE# #UNINDENT# v = data [ ( offset + col ) ] #NEWLINE# val |= ( v << ( 7 - d ) ) #NEWLINE# #UNINDENT# bytes . append ( chr ( val ) ) #NEWLINE# #UNINDENT# self . width = width #NEWLINE# self . height = height #NEWLINE# self . data = '' . join ( bytes )