Skip to content
This repository was archived by the owner on Nov 22, 2019. It is now read-only.

Commit 06243df

Browse files
author
Marie
committed
rgb_to_xyz_matrix: add primaries only option
1 parent c71ac6d commit 06243df

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

lutLab/rgb_to_xyz_matrix.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
.. moduleauthor:: `Marie FETIVEAU <github.com/mfe>`_
66
77
"""
8-
__version__ = "0.3"
9-
from utils.colors_helper import get_RGB_to_XYZ_matrix
8+
__version__ = "0.4"
9+
from utils.colors_helper import get_RGB_to_XYZ_matrix, get_primaries_matrix
1010
from utils.colorspaces import COLORSPACES
1111
from utils.private_colorspaces import PRIVATE_COLORSPACES
1212
from utils.matrix_helper import matrix_to_string, matrix_to_spimtx_string
@@ -25,6 +25,7 @@ class RGBToXYZMatrixException(Exception):
2525
pass
2626

2727

28+
def display_matrix(colorspace, matrix_format, primaries_only=False):
2829
"""Display RGB to XYZ matrix corresponding to colorspace and formatting
2930
as format
3031
@@ -38,10 +39,17 @@ class RGBToXYZMatrixException(Exception):
3839
colorspace_obj = COLORSPACES[colorspace]
3940
except KeyError:
4041
colorspace_obj = PRIVATE_COLORSPACES[colorspace]
41-
matrix = get_RGB_to_XYZ_matrix(colorspace_obj.get_red_primaries(),
42-
colorspace_obj.get_green_primaries(),
43-
colorspace_obj.get_blue_primaries(),
44-
colorspace_obj.get_white_point())
42+
if primaries_only:
43+
matrix = get_primaries_matrix(colorspace_obj.get_red_primaries(),
44+
colorspace_obj.get_green_primaries(),
45+
colorspace_obj.get_blue_primaries())
46+
matrix_type = "Primaries"
47+
else:
48+
matrix = get_RGB_to_XYZ_matrix(colorspace_obj.get_red_primaries(),
49+
colorspace_obj.get_green_primaries(),
50+
colorspace_obj.get_blue_primaries(),
51+
colorspace_obj.get_white_point())
52+
matrix_type = "Primaries + white point"
4553
if matrix_format == 'simple':
4654
matrix_dump = matrix_to_string(matrix)
4755
inv_matrix_dump = matrix_to_string(matrix.I)
@@ -51,9 +59,9 @@ class RGBToXYZMatrixException(Exception):
5159
else:
5260
matrix_dump = "{0}".format(matrix)
5361
inv_matrix_dump = "{0}".format(matrix.I)
54-
print "{0} to XYZ matrix ({1} output):\n".format(colorspace, matrix_format)
62+
print "{0} to XYZ matrix ({1}, {2} output):\n".format(colorspace, matrix_type, matrix_format)
5563
print matrix_dump
56-
print "XYZ to {0} matrix ({1} output):\n".format(colorspace, matrix_format)
64+
print "XYZ to {0} matrix ({1}, {2} output):\n".format(colorspace, matrix_type, matrix_format)
5765
print inv_matrix_dump
5866

5967

@@ -74,6 +82,10 @@ def __get_options():
7482
choices=sorted(COLORSPACES.keys() +
7583
PRIVATE_COLORSPACES.keys()),
7684
default='Rec709')
85+
# Get primarie matrix only
86+
parser.add_argument("-po", "--primaries-only",
87+
help="Primaries matrix only, doesn't include white point.",
88+
action="store_true")
7789
# Output format
7890
parser.add_argument("-f", "--format",
7991
help=("Output formatting."),
@@ -97,4 +109,4 @@ def __get_options():
97109

98110
if __name__ == '__main__':
99111
ARGS = __get_options()
100-
display_matrix(ARGS.colorspace, ARGS.format)
112+
display_matrix(ARGS.colorspace, ARGS.format, ARGS.primaries_only)

0 commit comments

Comments
 (0)