#NEWLINE# def image_diff( path1 , path2 , outpath , diffcolor ) : #NEWLINE# #INDENT# im1 = Image . open ( path1 ) #NEWLINE# im2 = Image . open ( path2 ) #NEWLINE# rmsdiff = rmsdiff_2011 ( im1 , im2 ) #NEWLINE# pix1 = im1 . load ( ) #NEWLINE# pix2 = im2 . load ( ) #NEWLINE# if ( im1 . mode != im2 . mode ) : #NEWLINE# #INDENT# raise TestError ( ( 'Different pixel modes between %r and %r' % ( path1 , path2 ) ) ) #NEWLINE# #UNINDENT# if ( im1 . size != im2 . size ) : #NEWLINE# #INDENT# raise TestError ( ( 'Different dimensions between %r (%r) and %r (%r)' % ( path1 , diffcolor . size , path2 , im2 . size ) ) ) #NEWLINE# #UNINDENT# mode = im1 . mode #NEWLINE# if ( mode == '1' ) : #NEWLINE# #INDENT# value = 255 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'L' ) : #NEWLINE# #INDENT# value = 255 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'RGB' ) : #NEWLINE# #INDENT# value = diffcolor #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'RGBA' ) : #NEWLINE# #INDENT# value = ( diffcolor + ( 255 , ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'P' ) : #NEWLINE# #INDENT# raise NotImplementedError ( 'TODO: look up nearest palette color' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise NotImplementedError ( 'Unexpected PNG mode' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# ( width , height ) = im1 . size #NEWLINE# for y in xrange ( height ) : #NEWLINE# #INDENT# for x in xrange ( width ) : #NEWLINE# #INDENT# if ( pix1 [ ( x , y ) ] != pix2 [ ( x , y ) ] ) : #NEWLINE# #INDENT# pix2 [ ( x , y ) ] = value #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# im2 . save ( outpath ) #NEWLINE# return ( rmsdiff , width , height )