#NEWLINE# def showImage( led , imagePath = '' , imageObj = None , offset = ( 0 , 0 ) , bgcolor = colors . Off , brightness = 255 ) : #NEWLINE# #INDENT# 'Display an image on the matrix' #NEWLINE# if ( not isinstance ( led , LEDMatrix ) ) : #NEWLINE# #INDENT# raise RuntimeError ( 'Must use LEDMatrix with showImage!' ) #NEWLINE# #UNINDENT# bgcolor = colors . color_scale ( bgcolor , brightness ) #NEWLINE# img = imageObj #NEWLINE# if ( ( not img ) and ( not ( imagePath == '' ) ) ) : #NEWLINE# #INDENT# img = Image . open ( imagePath ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not img ) : #NEWLINE# #INDENT# raise ValueError ( 'Must provide either imagePath or imageObj' ) #NEWLINE# #UNINDENT# #UNINDENT# w = ( led . width - offset [ 0 ] ) #NEWLINE# if ( img . size [ 0 ] < w ) : #NEWLINE# #INDENT# w = img . size [ 0 ] #NEWLINE# #UNINDENT# h = ( led . height - offset [ 1 ] ) #NEWLINE# if ( img . size [ 1 ] < h ) : #NEWLINE# #INDENT# h = img . size [ 1 ] #NEWLINE# #UNINDENT# ox = offset [ 0 ] #NEWLINE# oy = offset [ 1 ] #NEWLINE# led . all_off ( ) #NEWLINE# for x in range ( ox , ( w + ox ) ) : #NEWLINE# #INDENT# for y in range ( oy , ( h + oy ) ) : #NEWLINE# #INDENT# ( r , g , b , a ) = ( 0 , 0 , 0 , 255 ) #NEWLINE# rgba = img . getpixel ( ( ( x - ox ) , ( y - oy ) ) ) #NEWLINE# if isinstance ( rgba , int ) : #NEWLINE# #INDENT# raise ValueError ( 'Image must be in RGB or RGBA format!' ) #NEWLINE# #UNINDENT# if ( len ( rgba ) == 3 ) : #NEWLINE# #INDENT# ( r , g , b ) = rgba #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( rgba ) == 4 ) : #NEWLINE# #INDENT# ( r , g , b , a ) = rgba #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'Image must be in RGB or RGBA format!' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( a == 0 ) : #NEWLINE# #INDENT# ( r , g , b ) = bgcolor #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( r , g , b ) = colors . color_scale ( ( r , g , b ) , a ) #NEWLINE# #UNINDENT# if ( brightness != 255 ) : #NEWLINE# #INDENT# ( r , g , b ) = colors . color_scale ( ( r , g , b ) , brightness ) #NEWLINE# #UNINDENT# led . set ( x , y , ( r , g , b ) )