Coverage for models/rgb/transfer_functions/srgb.py: 33%
21 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""
2SRGB
3====
5Define the *sRGB* electro-optical transfer function (EOTF) and its
6inverse.
8- :func:`colour.models.eotf_inverse_sRGB`
9- :func:`colour.models.eotf_sRGB`
11References
12----------
13- :cite:`InternationalElectrotechnicalCommission1999a` : International
14 Electrotechnical Commission. (1999). IEC 61966-2-1:1999 - Multimedia
15 systems and equipment - Colour measurement and management - Part 2-1:
16 Colour management - Default RGB colour space - sRGB (p. 51).
17 https://webstore.iec.ch/publication/6169
18- :cite:`InternationalTelecommunicationUnion2015i` : International
19 Telecommunication Union. (2015). Recommendation ITU-R BT.709-6 - Parameter
20 values for the HDTV standards for production and international programme
21 exchange BT Series Broadcasting service (pp. 1-32).
22 https://www.itu.int/dms_pubrec/itu-r/rec/bt/\
23R-REC-BT.709-6-201506-I!!PDF-E.pdf
24"""
26from __future__ import annotations
28import numpy as np
30from colour.algebra import spow
31from colour.hints import ( # noqa: TC001
32 Domain1,
33 Range1,
34)
35from colour.utilities import as_float, domain_range_scale, from_range_1, to_domain_1
37__author__ = "Colour Developers"
38__copyright__ = "Copyright 2013 Colour Developers"
39__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
40__maintainer__ = "Colour Developers"
41__email__ = "colour-developers@colour-science.org"
42__status__ = "Production"
44__all__ = [
45 "eotf_inverse_sRGB",
46 "eotf_sRGB",
47]
50def eotf_inverse_sRGB(L: Domain1) -> Range1:
51 """
52 Apply the *IEC 61966-2-1:1999* *sRGB* inverse electro-optical transfer
53 function (EOTF).
55 Parameters
56 ----------
57 L
58 *Luminance* :math:`L` of the image.
60 Returns
61 -------
62 :class:`numpy.ndarray`
63 Electrical signal :math:`V`.
65 Notes
66 -----
67 +------------+-----------------------+---------------+
68 | **Domain** | **Scale - Reference** | **Scale - 1** |
69 +============+=======================+===============+
70 | ``L`` | 1 | 1 |
71 +------------+-----------------------+---------------+
73 +------------+-----------------------+---------------+
74 | **Range** | **Scale - Reference** | **Scale - 1** |
75 +============+=======================+===============+
76 | ``V`` | 1 | 1 |
77 +------------+-----------------------+---------------+
79 References
80 ----------
81 :cite:`InternationalElectrotechnicalCommission1999a`,
82 :cite:`InternationalTelecommunicationUnion2015i`
84 Examples
85 --------
86 >>> eotf_inverse_sRGB(0.18) # doctest: +ELLIPSIS
87 0.4613561...
88 """
90 L = to_domain_1(L)
92 V = np.where(L <= 0.0031308, L * 12.92, 1.055 * spow(L, 1 / 2.4) - 0.055)
94 return as_float(from_range_1(V))
97def eotf_sRGB(V: Domain1) -> Range1:
98 """
99 Apply the *IEC 61966-2-1:1999* *sRGB* electro-optical transfer function
100 (EOTF).
102 Parameters
103 ----------
104 V
105 Electrical signal :math:`V`.
107 Returns
108 -------
109 :class:`numpy.ndarray`
110 *Luminance* :math:`L` of the image.
112 Notes
113 -----
114 +------------+-----------------------+---------------+
115 | **Domain** | **Scale - Reference** | **Scale - 1** |
116 +============+=======================+===============+
117 | ``V`` | 1 | 1 |
118 +------------+-----------------------+---------------+
120 +------------+-----------------------+---------------+
121 | **Range** | **Scale - Reference** | **Scale - 1** |
122 +============+=======================+===============+
123 | ``L`` | 1 | 1 |
124 +------------+-----------------------+---------------+
126 References
127 ----------
128 :cite:`InternationalElectrotechnicalCommission1999a`,
129 :cite:`InternationalTelecommunicationUnion2015i`
131 Examples
132 --------
133 >>> eotf_sRGB(0.461356129500442) # doctest: +ELLIPSIS
134 0.1...
135 """
137 V = to_domain_1(V)
139 with domain_range_scale("ignore"):
140 L = np.where(
141 eotf_inverse_sRGB(0.0031308) >= V,
142 V / 12.92,
143 spow((V + 0.055) / 1.055, 2.4),
144 )
146 return as_float(from_range_1(L))