@@ -133,8 +133,14 @@ def compress(dist, lim, thr, invert, method, power):
133133
134134
135135def main (rgb , method = 2 , invert = False , hexagonal = False , threshold = 0.8 , cyan = 0.09 , magenta = 0.24 , yellow = 0.12 , power = 1.2 , shd_rolloff = 0 ):
136+ rgb = np .asarray (rgb )
137+ threshold = np .asarray (threshold )
138+ if not threshold .shape :
139+ threshold = np .tile (threshold , 3 )
140+
136141 # thr is the percentage of the core gamut to protect.
137- thr = np .clip (threshold , - np .inf , 0.9999 )
142+ thr = np .clip (threshold , - np .inf , 0.9999 ).reshape (
143+ [1 ] * (rgb .ndim - 1 ) + [3 ])
138144
139145 # lim is the max distance from the gamut boundary that will be compressed
140146 # 0 is a no-op, 1 will compress colors from a distance of 2 from achromatic to the gamut boundary
@@ -148,9 +154,9 @@ def main(rgb, method=2, invert=False, hexagonal=False, threshold=0.8, cyan=0.09,
148154 # Not sure of a way to pre-calculate a constant using the values from the ui parameters in GLSL...
149155 # This approach might have performance implications
150156 lim = np .array ([
151- bisect (max ( 0.0001 , cyan )+ 1 , threshold , method ),
152- bisect (max ( 0.0001 , magenta )+ 1 , threshold , method ),
153- bisect (max ( 0.0001 , yellow )+ 1 , threshold , method )])
157+ bisect (np . clip ( cyan , 0.0001 , np . inf )+ 1 , np . float ( np . squeeze ( thr [..., 0 ])) , method ),
158+ bisect (np . clip ( magenta , 0.0001 , np . inf )+ 1 , np . float ( np . squeeze ( thr [..., 1 ])) , method ),
159+ bisect (np . clip ( yellow , 0.0001 , np . inf )+ 1 , np . float ( np . squeeze ( thr [..., 2 ])) , method )])
154160
155161 # achromatic axis
156162 ach = np .max (rgb , axis = - 1 )[..., np .newaxis ]
@@ -189,7 +195,7 @@ def generate_test_images(samples=16):
189195 return
190196
191197 np .random .seed (4 )
192- RGB = (np .random .random ([samples , samples , 3 ]) - 0.5 ) * 2
198+ RGB = (np .random .random ([samples , samples , 3 ]) - 0.5 ) * 4
193199 name_template = 'Gamut_Compress_{0}.exr'
194200 colour .write_image (RGB , name_template .format ('Reference' ))
195201 for method in range (0 , 6 ):
@@ -199,8 +205,20 @@ def generate_test_images(samples=16):
199205
200206 colour .write_image (
201207 gamut_compression_operator (RGB , method = method , hexagonal = True ),
202- name_template .format ('GM_Hexagonal_Method_{0}' .format (method )))
208+ name_template .format ('GM_Method_{0}_Hexagonal' .format (method )))
209+
210+ colour .write_image (
211+ gamut_compression_operator (
212+ RGB , threshold = [0.2 , 0.4 , 0.6 ], method = method ),
213+ name_template .format (
214+ 'GM_Method_{0}_DecoupledThreshold' .format (method )))
215+
216+ colour .write_image (
217+ gamut_compression_operator (
218+ RGB , threshold = [0.2 , 0.4 , 0.6 ], method = method , hexagonal = True ),
219+ name_template .format (
220+ 'GM_Method_{0}_Hexagonal_DecoupledThreshold' .format (method )))
203221
204222
205223if __name__ == '__main__' :
206- generate_test_images ()
224+ generate_test_images ()
0 commit comments