#NEWLINE# def brightness( self , factor ) : #NEWLINE# #INDENT# '\n        Adjust the brightness by the given factor.\n\n        Brightness is determined by percieved luminance.\n        ' #NEWLINE# channels = [ 'r' , 'g' , 'b' ] #NEWLINE# total_lumes = clamp ( ( ( self . get_luminance ( ) + ( 255.0 * factor ) ) - 255.0 ) , 0.0 , 255.0 ) #NEWLINE# if ( total_lumes == 255.0 ) : #NEWLINE# #INDENT# ( self . r , self . g , self . b ) = ( 255 , 255 , 255 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( total_lumes == 0.0 ) : #NEWLINE# #INDENT# ( self . r , self . g , self . b ) = ( 0 , 0 , 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pts = ( ( ( total_lumes - ( 0.299 * self . r ) ) - ( 0.587 * self . g ) ) - ( 0.114 * self . b ) ) #NEWLINE# slots = set ( channels ) #NEWLINE# components = [ ( float ( self . r ) + pts ) , ( float ( self . g ) + pts ) , ( float ( self . b ) + pts ) ] #NEWLINE# count = 0 #NEWLINE# for c in channels : #NEWLINE# #INDENT# ( overage , components [ count ] ) = self . _get_overage ( components [ count ] ) #NEWLINE# if overage : #NEWLINE# #INDENT# slots . remove ( c ) #NEWLINE# components = list ( self . _distribute_overage ( components , overage , slots ) ) #NEWLINE# #UNINDENT# count += 1 #NEWLINE# #UNINDENT# self . r = ( clamp ( round_int ( components [ 0 ] ) , 0 , 255 ) & 255 ) #NEWLINE# self . g = ( clamp ( round_int ( components [ 1 ] ) , 0 , 255 ) & 255 ) #NEWLINE# self . b = ( clamp ( round_int ( components [ 2 ] ) , 0 , 255 ) & 255 )