7
7
loaded by "Three.js".
8
8
"""
9
9
10
- from __future__ import division
11
-
12
10
import json
13
11
import numpy as np
14
12
import os
15
13
import re
16
- from werkzeug . contrib . cache import SimpleCache
14
+ from cachelib import SimpleCache
17
15
18
- from colour import (ILLUMINANTS , CCTF_DECODINGS , Lab_to_XYZ , LCHab_to_Lab ,
19
- POINTER_GAMUT_DATA , POINTER_GAMUT_ILLUMINANT ,
16
+ from colour import (CCS_ILLUMINANTS , CCTF_DECODINGS , Lab_to_XYZ , LCHab_to_Lab ,
20
17
RGB_COLOURSPACES , RGB_to_RGB , RGB_to_XYZ , XYZ_to_RGB ,
21
18
XYZ_to_JzAzBz , XYZ_to_OSA_UCS , convert ,
22
19
is_within_pointer_gamut , read_image )
23
- from colour .models import linear_function
20
+ from colour .models import (CCS_ILLUMINANT_POINTER_GAMUT ,
21
+ DATA_POINTER_GAMUT_VOLUME , linear_function )
24
22
from colour .plotting import filter_cmfs , filter_RGB_colourspaces
25
23
from colour .utilities import (CaseInsensitiveMapping , as_float_array ,
26
24
first_item , normalise_maximum , tsplit , tstack )
27
25
from colour .volume import XYZ_outer_surface
28
26
29
27
__author__ = 'Colour Developers'
30
- __copyright__ = 'Copyright (C) 2018-2019 - Colour Developers'
28
+ __copyright__ = 'Copyright (C) 2018-2020 - Colour Developers'
31
29
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause'
32
30
__maintainer__ = 'Colour Developers'
33
- __email__ = 'colour-[email protected] '
31
+ __email__ = 'colour-[email protected] '
34
32
__status__ = 'Production'
35
33
36
34
__all__ = [
88
86
COLOURSPACE_MODELS = ('CAM02LCD' , 'CAM02SCD' , 'CAM02UCS' , 'CAM16LCD' ,
89
87
'CAM16SCD' , 'CAM16UCS' , 'CIE XYZ' , 'CIE xyY' , 'CIE Lab' ,
90
88
'CIE Luv' , 'CIE UCS' , 'CIE UVW' , 'DIN 99' , 'Hunter Lab' ,
91
- 'Hunter Rdab' , 'ICTCP' , 'IPT ' , 'JzAzBz ' , 'OSA UCS ' ,
92
- 'hdr-CIELAB' , 'hdr-IPT' )
89
+ 'Hunter Rdab' , 'ICTCP' , 'IGPGTG ' , 'IPT ' , 'JzAzBz ' ,
90
+ 'OSA UCS' , ' hdr-CIELAB' , 'hdr-IPT' )
93
91
"""
94
92
Reference colourspace models defining available colour transformations from
95
93
CIE XYZ tristimulus values.
96
94
97
95
COLOURSPACE_MODELS : tuple
98
96
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD', 'CAM16UCS',
99
97
'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS', 'CIE UVW', 'DIN 99',
100
- 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT', 'JzAzBz', 'OSA UCS',
98
+ 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG', ' IPT', 'JzAzBz', 'OSA UCS',
101
99
'hdr-CIELAB', 'hdr-IPT'}**
102
100
"""
103
101
118
116
'Hunter Lab' : ('a' , 'L' , 'b' ),
119
117
'Hunter Rdab' : ('a' , 'Rd' , 'b' ),
120
118
'ICTCP' : ('CT' , 'I' , 'CP' ),
119
+ 'IGPGTG' : ('PG' , 'IG' , 'TG' ),
121
120
'IPT' : ('P' , 'I' , 'T' ),
122
121
'JzAzBz' : ('Az' , 'Jz' , 'Bz' ),
123
122
'OSA UCS' : ('j' , 'J' , 'g' ),
131
130
COLOURSPACE_MODELS : dict
132
131
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD', 'CAM16UCS',
133
132
'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS', 'CIE UVW', 'DIN 99',
134
- 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT', 'JzAzBz', 'OSA UCS',
133
+ 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG', ' IPT', 'JzAzBz', 'OSA UCS',
135
134
'hdr-CIELAB', 'hdr-IPT'}**
136
135
"""
137
136
174
173
COLOURSPACE_MODEL : unicode
175
174
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD', 'CAM16UCS',
176
175
'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS', 'CIE UVW', 'DIN 99',
177
- 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT', 'JzAzBz', 'OSA UCS',
176
+ 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG', ' IPT', 'JzAzBz', 'OSA UCS',
178
177
'hdr-CIELAB', 'hdr-IPT'}**
179
178
"""
180
179
181
- POINTER_GAMUT_DATA = Lab_to_XYZ (
182
- LCHab_to_Lab (POINTER_GAMUT_DATA ), POINTER_GAMUT_ILLUMINANT )
180
+ DATA_POINTER_GAMUT = Lab_to_XYZ (
181
+ LCHab_to_Lab (DATA_POINTER_GAMUT_VOLUME ), CCS_ILLUMINANT_POINTER_GAMUT )
183
182
"""
184
183
Pointer's Gamut data converted to *CIE XYZ* tristimulus values.
185
184
186
- POINTER_GAMUT_DATA : ndarray
185
+ DATA_POINTER_GAMUT : ndarray
187
186
"""
188
187
189
188
IMAGE_CACHE = SimpleCache (default_timeout = 60 * 24 * 7 )
@@ -246,8 +245,8 @@ def XYZ_to_colourspace_model(XYZ, illuminant, model, **kwargs):
246
245
model : unicode
247
246
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD',
248
247
'CAM16UCS', 'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS',
249
- 'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT ',
250
- 'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
248
+ 'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG ',
249
+ 'IPT', ' JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
251
250
Colourspace model to convert the *CIE XYZ* tristimulus values to.
252
251
253
252
Other Parameters
@@ -289,8 +288,8 @@ def colourspace_model_axis_reorder(a, model=None):
289
288
model : unicode, optional
290
289
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD',
291
290
'CAM16UCS', 'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS',
292
- 'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT ',
293
- 'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
291
+ 'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG ',
292
+ 'IPT', ' JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
294
293
Colourspace model.
295
294
296
295
Returns
@@ -306,8 +305,8 @@ def colourspace_model_axis_reorder(a, model=None):
306
305
a = tstack ([j , k , i ])
307
306
elif model in ('CAM02LCD' , 'CAM02SCD' , 'CAM02UCS' , 'CAM16LCD' , 'CAM16SCD' ,
308
307
'CAM16UCS' , 'CIE Lab' , 'CIE LCHab' , 'CIE Luv' , 'CIE LCHuv' ,
309
- 'DIN 99' , 'Hunter Lab' , 'Hunter Rdab' , 'ICTCP' , 'IPT ' ,
310
- 'JzAzBz' , 'OSA UCS' , 'hdr-CIELAB' , 'hdr-IPT' ):
308
+ 'DIN 99' , 'Hunter Lab' , 'Hunter Rdab' , 'ICTCP' , 'IGPGTG ' ,
309
+ 'IPT' , ' JzAzBz' , 'OSA UCS' , 'hdr-CIELAB' , 'hdr-IPT' ):
311
310
a = tstack ([k , i , j ])
312
311
313
312
return a
@@ -324,8 +323,8 @@ def colourspace_model_faces_reorder(a, model=None):
324
323
model : unicode, optional
325
324
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD',
326
325
'CAM16UCS', 'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS',
327
- 'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT ',
328
- 'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
326
+ 'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG ',
327
+ 'IPT', ' JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
329
328
Colourspace model.
330
329
331
330
Returns
@@ -384,13 +383,13 @@ def buffer_geometry(**kwargs):
384
383
"""
385
384
Returns given geometry formatted as *JSON* compatible with *Three.js*
386
385
`BufferGeometryLoader <https://threejs.org/docs/#api/loaders/\
387
- BufferGeometryLoader>`_ .
386
+ BufferGeometryLoader>`__ .
388
387
389
388
Other Parameters
390
389
----------------
391
390
\\ **kwargs : dict, optional
392
391
Valid attributes from `BufferGeometryLoader <https://threejs.org/docs/\
393
- #api/loaders/BufferGeometryLoader>`_ .
392
+ #api/loaders/BufferGeometryLoader>`__ .
394
393
395
394
Returns
396
395
-------
@@ -644,7 +643,8 @@ def create_box(width=1,
644
643
colors = np .hstack ([
645
644
np .reshape (
646
645
np .interp (colors , (np .min (colors ), np .max (colors )), (0 , 1 )),
647
- positions .shape ),
646
+ positions .shape ,
647
+ ),
648
648
np .ones ((positions .shape [0 ], 1 ))
649
649
])
650
650
@@ -733,8 +733,12 @@ def image_data(path,
733
733
734
734
if out_of_pointer_gamut :
735
735
O_PG = is_within_pointer_gamut (
736
- RGB_to_XYZ (RGB , colourspace .whitepoint , colourspace .whitepoint ,
737
- colourspace .RGB_to_XYZ_matrix )).astype (np .int_ )
736
+ RGB_to_XYZ (
737
+ RGB ,
738
+ colourspace .whitepoint ,
739
+ colourspace .whitepoint ,
740
+ colourspace .matrix_RGB_to_XYZ ,
741
+ )).astype (np .int_ )
738
742
O_PG = 1 - O_PG
739
743
RGB [O_PG != 1 ] = 0
740
744
RGB [O_PG == 1 ] = 1
@@ -788,11 +792,18 @@ def RGB_colourspace_volume_visual(colourspace=PRIMARY_COLOURSPACE,
788
792
np .reshape (cube [1 ], (- 1 , 1 )), colourspace_model )
789
793
RGB = cube [0 ]['colour' ]
790
794
791
- XYZ = RGB_to_XYZ (vertices , colourspace .whitepoint , colourspace .whitepoint ,
792
- colourspace .RGB_to_XYZ_matrix )
795
+ XYZ = RGB_to_XYZ (
796
+ vertices ,
797
+ colourspace .whitepoint ,
798
+ colourspace .whitepoint ,
799
+ colourspace .matrix_RGB_to_XYZ ,
800
+ )
793
801
vertices = colourspace_model_axis_reorder (
794
- XYZ_to_colourspace_model (XYZ , colourspace .whitepoint ,
795
- colourspace_model ), colourspace_model )
802
+ XYZ_to_colourspace_model (
803
+ XYZ ,
804
+ colourspace .whitepoint ,
805
+ colourspace_model ,
806
+ ), colourspace_model )
796
807
797
808
return buffer_geometry (position = vertices , color = RGB , index = faces )
798
809
@@ -884,17 +895,28 @@ def RGB_image_scatter_visual(path,
884
895
885
896
if out_of_pointer_gamut :
886
897
O_PG = is_within_pointer_gamut (
887
- RGB_to_XYZ (RGB , colourspace .whitepoint , colourspace .whitepoint ,
888
- colourspace .RGB_to_XYZ_matrix )).astype (np .int_ )
898
+ RGB_to_XYZ (
899
+ RGB ,
900
+ colourspace .whitepoint ,
901
+ colourspace .whitepoint ,
902
+ colourspace .matrix_RGB_to_XYZ ,
903
+ )).astype (np .int_ )
889
904
O_PG = 1 - O_PG
890
905
RGB = RGB [O_PG == 1 ]
891
906
892
- XYZ = RGB_to_XYZ (RGB , colourspace .whitepoint , colourspace .whitepoint ,
893
- colourspace .RGB_to_XYZ_matrix )
907
+ XYZ = RGB_to_XYZ (
908
+ RGB ,
909
+ colourspace .whitepoint ,
910
+ colourspace .whitepoint ,
911
+ colourspace .matrix_RGB_to_XYZ ,
912
+ )
894
913
895
914
vertices = colourspace_model_axis_reorder (
896
- XYZ_to_colourspace_model (XYZ , colourspace .whitepoint ,
897
- colourspace_model ), colourspace_model )
915
+ XYZ_to_colourspace_model (
916
+ XYZ ,
917
+ colourspace .whitepoint ,
918
+ colourspace_model ,
919
+ ), colourspace_model )
898
920
899
921
if (out_of_primary_colourspace_gamut or
900
922
out_of_secondary_colourspace_gamut or out_of_pointer_gamut ):
@@ -934,12 +956,19 @@ def spectral_locus_visual(colourspace=PRIMARY_COLOURSPACE,
934
956
XYZ = np .vstack ([XYZ , XYZ [0 , ...]])
935
957
936
958
vertices = colourspace_model_axis_reorder (
937
- XYZ_to_colourspace_model (XYZ , colourspace .whitepoint ,
938
- colourspace_model ), colourspace_model )
959
+ XYZ_to_colourspace_model (
960
+ XYZ ,
961
+ colourspace .whitepoint ,
962
+ colourspace_model ,
963
+ ), colourspace_model )
939
964
940
965
RGB = normalise_maximum (
941
- XYZ_to_RGB (XYZ , colourspace .whitepoint , colourspace .whitepoint ,
942
- colourspace .XYZ_to_RGB_matrix ),
966
+ XYZ_to_RGB (
967
+ XYZ ,
968
+ colourspace .whitepoint ,
969
+ colourspace .whitepoint ,
970
+ colourspace .matrix_XYZ_to_RGB ,
971
+ ),
943
972
axis = - 1 )
944
973
945
974
return buffer_geometry (position = vertices , color = RGB )
@@ -960,15 +989,16 @@ def pointer_gamut_visual(colourspace_model='CIE xyY'):
960
989
*Pointer's Gamut* visual geometry formatted as *JSON*.
961
990
"""
962
991
963
- pointer_gamut_data = np .reshape (POINTER_GAMUT_DATA , (16 , - 1 , 3 ))
992
+ data_pointer_gamut = np .reshape (DATA_POINTER_GAMUT , (16 , - 1 , 3 ))
964
993
vertices = []
965
994
for i in range (16 ):
966
995
section = colourspace_model_axis_reorder (
967
996
XYZ_to_colourspace_model (
968
997
np .vstack (
969
- [pointer_gamut_data [i ], pointer_gamut_data [i ][0 , ...]]),
970
- POINTER_GAMUT_ILLUMINANT , colourspace_model ),
971
- colourspace_model )
998
+ [data_pointer_gamut [i ], data_pointer_gamut [i ][0 , ...]]),
999
+ CCS_ILLUMINANT_POINTER_GAMUT ,
1000
+ colourspace_model ,
1001
+ ), colourspace_model )
972
1002
973
1003
vertices .append (list (zip (section , section [1 :])))
974
1004
@@ -995,8 +1025,10 @@ def visible_spectrum_visual(colourspace_model='CIE xyY'):
995
1025
XYZ = XYZ_outer_surface ()
996
1026
vertices = colourspace_model_axis_reorder (
997
1027
XYZ_to_colourspace_model (
998
- XYZ , ILLUMINANTS ['CIE 1931 2 Degree Standard Observer' ]['E' ],
999
- colourspace_model ), colourspace_model )
1028
+ XYZ ,
1029
+ CCS_ILLUMINANTS ['CIE 1931 2 Degree Standard Observer' ]['E' ],
1030
+ colourspace_model ,
1031
+ ), colourspace_model )
1000
1032
1001
1033
vertices = as_float_array (list (zip (vertices , vertices [1 :])))
1002
1034
0 commit comments