Source code for colour.models.rgb.transfer_functions.common

# -*- coding: utf-8 -*-
"""
Common Transfer Functions Utilities
===================================

Defines various transfer functions common utilities.
"""

import numpy as np

from colour.constants import DEFAULT_FLOAT_DTYPE, DEFAULT_INT_DTYPE
from colour.utilities import as_float_array

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2021 - Colour Developers'
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = 'colour-developers@colour-science.org'
__status__ = 'Production'

__all__ = ['CV_range', 'legal_to_full', 'full_to_legal']


[docs]def CV_range(bit_depth=10, is_legal=False, is_int=False): """ Returns the code value :math:`CV` range for given bit depth, range legality and representation. Parameters ---------- bit_depth : int, optional Bit depth of the code value :math:`CV` range. is_legal : bool, optional Whether the code value :math:`CV` range is legal. is_int : bool, optional Whether the code value :math:`CV` range represents integer code values. Returns ------- ndarray Code value :math:`CV` range. Examples -------- >>> CV_range(8, True, True) array([ 16, 235]) >>> CV_range(8, True, False) # doctest: +ELLIPSIS array([ 0.0627451..., 0.9215686...]) >>> CV_range(10, False, False) array([ 0., 1.]) """ if is_legal: ranges = np.array([16, 235]) ranges *= 2 ** (bit_depth - 8) else: ranges = np.array([0, 2 ** bit_depth - 1]) if not is_int: ranges = ranges.astype(DEFAULT_FLOAT_DTYPE) / (2 ** bit_depth - 1) return ranges