#NEWLINE# def make_CTF( x1 , x2 , hue_range = ( ( 2.0 / 3.0 ) , 0.0 ) , sat_range = ( 1.0 , 1.0 ) , val_range = ( 1.0 , 1.0 ) , n = 10 , mode = 'sqrt' ) : #NEWLINE# #INDENT# "Creates a CTF as per given arguments.  Lets one set a hue,\n    saturation and value range.  The mode can be one of 'sqrt', or\n    'linear'.  The idea of this function is to create a CTF that is\n    similar to the LUT being used.  's_curve' is not implemented.\n    Patches welcome.\n    " #NEWLINE# maxs = max ( x1 , x2 ) #NEWLINE# mins = min ( x1 , x2 ) #NEWLINE# ds = ( maxs - mins ) #NEWLINE# dhue = ( hue_range [ 1 ] - hue_range [ 0 ] ) #NEWLINE# dsat = ( sat_range [ 1 ] - sat_range [ 0 ] ) #NEWLINE# dval = ( val_range [ 1 ] - val_range [ 0 ] ) #NEWLINE# ctf = ColorTransferFunction ( ) #NEWLINE# try : #NEWLINE# #INDENT# ctf . range = ( mins , maxs ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( mode == 'sqrt' ) : #NEWLINE# #INDENT# for i in range ( ( n + 1 ) ) : #NEWLINE# #INDENT# x = ( 0.5 * ( 1.0 + cos ( ( ( ( n - i ) * pi ) / n ) ) ) ) #NEWLINE# h = ( hue_range [ 0 ] + ( dhue * x ) ) #NEWLINE# s = ( sat_range [ 0 ] + ( dsat * x ) ) #NEWLINE# v = ( val_range [ 0 ] + ( dval * x ) ) #NEWLINE# ( r , g , b , a ) = [ sqrt ( c ) for c in hsva_to_rgba ( h , s , v , 1.0 ) ] #NEWLINE# ctf . add_rgb_point ( ( mins + ( x * ds ) ) , r , g , b ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'linear' ) : #NEWLINE# #INDENT# for i in range ( ( n + 1 ) ) : #NEWLINE# #INDENT# x = ( float ( i ) / n ) #NEWLINE# h = ( hue_range [ 0 ] + ( dhue * x ) ) #NEWLINE# s = ( sat_range [ 0 ] + ( dsat * x ) ) #NEWLINE# v = ( val_range [ 0 ] + ( dval * x ) ) #NEWLINE# ( r , g , b , a ) = hsva_to_rgba ( h , s , v , 1.0 ) #NEWLINE# ctf . add_rgb_point ( ( mins + ( x * ds ) ) , r , g , b ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ctf