def display_matrix(in_colorspace, out_colorspace, matrix_format, primaries_only=False):
    """Display RGB to XYZ matrix corresponding to colorspace and formatting
    as format

    Args:
        colorspace (str): input colorspace.

        matrix_format (str): output format. simple, matrix, spimtx.

    """
    if in_colorspace == XYZ_colorspace:
        if out_colorspace == XYZ_colorspace:
            raise AttributeError("In and out colorspaces can't be both XYZ !")
        matrix = get_colorspace_matrix(out_colorspace, primaries_only, inv=True)
    elif out_colorspace == XYZ_colorspace:
        matrix = get_colorspace_matrix(in_colorspace, primaries_only, inv=False)
    else:
        matrix = get_RGB_to_RGB_matrix(in_colorspace, out_colorspace, primaries_only)

    if matrix_format == 'simple':
        matrix_dump = matrix_to_string(matrix)
    elif matrix_format == 'spimtx':
        matrix_dump = matrix_to_spimtx_string(matrix)
    else:
        matrix_dump = "{0}".format(matrix)

    print "{0} to {1} matrix ({2} {3} output):\n".format(in_colorspace,
                                                         out_colorspace,
                                                         primaries_only and "primaries" or
                                                         "primaries + white point",
                                                         matrix_format)
    print matrix_dump
    def test_colorspace_matrices(self):
        """Test matrix conversions

        """
        ACES_to_XYZ = [[0.95255239593818575, 0.0, 9.3678631660468553e-05],
                       [0.34396644976507507, 0.72816609661348575, -0.072132546378560786],
                       [0.0, 0.0, 1.0088251843515859]]

        XYZ_to_ACES = [[1.0498110174979742, 0.0, -9.7484540579252874e-05],
                       [-0.49590302307731976, 1.3733130458157063, 0.098240036057309993],
                       [0.0, 0.0, 0.99125201820049902]]
        self.assertEqual(ACES_to_XYZ, get_colorspace_matrix("ACES").tolist())
        self.assertEqual(XYZ_to_ACES, get_colorspace_matrix("ACES", inv=True).tolist())
示例#3
0
def display_matrix(in_colorspace,
                   out_colorspace,
                   matrix_format,
                   primaries_only=False):
    """Display RGB to XYZ matrix corresponding to colorspace and formatting
    as format

    Args:
        colorspace (str): input colorspace.

        matrix_format (str): output format. simple, matrix, spimtx.

    """
    if in_colorspace == XYZ_colorspace:
        if out_colorspace == XYZ_colorspace:
            raise AttributeError("In and out colorspaces can't be both XYZ !")
        matrix = get_colorspace_matrix(out_colorspace,
                                       primaries_only,
                                       inv=True)
    elif out_colorspace == XYZ_colorspace:
        matrix = get_colorspace_matrix(in_colorspace,
                                       primaries_only,
                                       inv=False)
    else:
        matrix = get_RGB_to_RGB_matrix(in_colorspace, out_colorspace,
                                       primaries_only)

    if matrix_format == 'simple':
        matrix_dump = matrix_to_string(matrix)
    elif matrix_format == 'spimtx':
        matrix_dump = matrix_to_spimtx_string(matrix)
    else:
        matrix_dump = "{0}".format(matrix)

    print("{0} to {1} matrix ({2} {3} output):\n".format(
        in_colorspace, out_colorspace, primaries_only and "primaries"
        or "primaries + white point", matrix_format))
    print(matrix_dump)