Skip to content

Commit b80ebce

Browse files
committed
[css-color-hdr] forward and reverse for HLG
1 parent 4460f57 commit b80ebce

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

css-color-hdr/Overview.bs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,44 @@ Predefined colorspaces for HDR: {#predefined-HDR}
217217
</pre>
218218
</div>
219219

220-
Linear-light RGB signals are converted to HLG as follows:
220+
Linear-light RGB signals are converted to HLG encoded as follows [[Rec.2390]]:
221+
222+
<!-- From BT.2390 p.26
223+
-->
221224

222225
<pre class="lang-javascript">
223-
var E; // the red, green or blue component, normalized to reference white
224-
var r = 0.5; // reference white level
226+
var E; // the red, green or blue component, [0, 1]]
225227
const a = 0.17883277;
226-
const b = 0.28466892;
227-
const c = 0.55991073;
228-
if (E <= 1) {
229-
Edash = r * Math.sqrt(E);
228+
const b = 0.28466892; // 1 - (4 * a)
229+
const c = 0.55991073; // 0.5 - a * Math.log(4 *a)
230+
if (E <= 1/12) {
231+
Edash = Math.sqrt( 3 * E);
230232
}
231233
else {
232-
Edash = a * Math.log(E - b) + c;
234+
Edash = a * Math.log(12 * E - b) + c;
233235
}
234236
</pre>
235-
Edash is the "gamma-corrected" signal.
237+
Edash is the "gamma-corrected" (OETF-adjusted) signal.
238+
239+
The reverse conversion (HLG encoded to linear light) is as follows:
240+
241+
<!-- From BT.2390 p.33
242+
-->
243+
244+
<pre class="lang-javascript">
245+
var Edash; // the red, green or blue encoded component, [0, 1]]
246+
const a = 0.17883277;
247+
const b = 0.28466892; // 1 - (4 * a)
248+
const c = 0.55991073; // 0.5 - a * Math.log(4 *a)
249+
if (Edash <= 0.5) {
250+
E = (Edash ** 2) / 3;
251+
}
252+
else {
253+
E = Math.exp(((Edash - c) / a) + b) / 12;
254+
}
255+
</pre>
256+
257+
<!-- add black level lift as defined on same page?-->
236258

237259
<dfn export>Jzazbz</dfn> {#Jzazbz}
238260
-----------------

0 commit comments

Comments
 (0)