src/open_vp_cal/core/utils.py [135:172]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def get_legal_and_extended_values(peak_lum: int,
                                  image_bit_depth: int = 10,
                                  use_pq_peak_luminance: bool = True) -> tuple[int, int, int, int]:
    """ Get the legal and extended values for a given peak luminance and the bit depth

    Args:
        peak_lum: The peak luminance of the LED wall or display
        image_bit_depth: The bit depth of the image
        use_pq_peak_luminance: Whether to use the PQ peak luminance or not

    Returns: A tuple containing the minimum legal code value,
        the maximum legal code value, the minimum extended code

    """
    min_code_value = 0
    max_code_value = (2 ** image_bit_depth) - 1

    minimum_legal_code_value = int((2 ** image_bit_depth) / 16.0)
    maximum_legal_code_value = int((2 ** (image_bit_depth - 8)) * (16 + 219))

    # If we are in a PQ HDR workflow, our maximum nits are limited by our LED panels
    if use_pq_peak_luminance:
        pq_v = nits_to_pq(peak_lum)

        full_peak_white_at_given_bit_depth = pq_v * max_code_value
        legal_white_at_given_bit_depth = (full_peak_white_at_given_bit_depth / max_code_value *
                                          (maximum_legal_code_value - minimum_legal_code_value) +
                                          minimum_legal_code_value)
        legal_white_for_peak_luminance = legal_white_at_given_bit_depth
        maximum_legal_code_value = legal_white_for_peak_luminance

    minimum_legal = normalize(minimum_legal_code_value, min_code_value, max_code_value)
    maximum_legal = normalize(maximum_legal_code_value, min_code_value, max_code_value)

    minimum_extended = normalize(min_code_value, min_code_value, max_code_value)
    maximum_extended = normalize(max_code_value, min_code_value, max_code_value)

    return minimum_legal, maximum_legal, minimum_extended, maximum_extended
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



