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

"""
Common Transfer Functions Utilities
===================================

Defines various transfer functions common utilities.
"""

from __future__ import annotations

import numpy as np

from colour.hints import ArrayLike, NDArrayReal
from colour.utilities import as_float, as_float_array, as_int, as_int_array

__author__ = "Colour Developers"
__copyright__ = "Copyright 2013 Colour Developers"
__license__ = "BSD-3-Clause - 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: int = 10, is_legal: bool = False, is_int: bool = False ) -> NDArrayReal: """ Return the code value :math:`CV` range for given bit-depth, range legality and representation. Parameters ---------- bit_depth Bit-depth of the code value :math:`CV` range. is_legal Whether the code value :math:`CV` range is legal. is_int Whether the code value :math:`CV` range represents int code values. Returns ------- :class:`numpy.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 = as_float_array(ranges) / (2**bit_depth - 1) return ranges