Skip to content

Commit a02261f

Browse files
committed
Define rec2020 color space to use 2.4 gamma
1 parent 080eaef commit a02261f

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

lib/src/value/color/space/rec2020.dart

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import '../conversions.dart';
1111
import '../space.dart';
1212
import 'utils.dart';
1313

14-
/// A constant used in the rec2020 gamma encoding/decoding functions.
15-
const _alpha = 1.09929682680944;
16-
17-
/// A constant used in the rec2020 gamma encoding/decoding functions.
18-
const _beta = 0.018053968510807;
19-
2014
/// The rec2020 color space.
2115
///
2216
/// https://www.w3.org/TR/css-color-4/#predefined-rec2020
@@ -30,20 +24,18 @@ final class Rec2020ColorSpace extends ColorSpace {
3024

3125
@protected
3226
double toLinear(double channel) {
33-
// Algorithm from https://www.w3.org/TR/css-color-4/#color-conversion-code
27+
// Non-linear transfer function from Rec. ITU-R BT.2020-2 table 4
28+
// Reference electro-optical transfer function from Rec. ITU-R BT.1886 Annex 1
29+
// with b (black lift) = 0 and a (user gain) = 1
30+
// defined over the extended range, not clamped
3431
var abs = channel.abs();
35-
return abs < _beta * 4.5
36-
? channel / 4.5
37-
: channel.sign * (math.pow((abs + _alpha - 1) / _alpha, 1 / 0.45));
32+
return channel.sign * math.pow(abs, 2.40);
3833
}
3934

4035
@protected
4136
double fromLinear(double channel) {
42-
// Algorithm from https://www.w3.org/TR/css-color-4/#color-conversion-code
4337
var abs = channel.abs();
44-
return abs > _beta
45-
? channel.sign * (_alpha * math.pow(abs, 0.45) - (_alpha - 1))
46-
: 4.5 * channel;
38+
return channel.sign * math.pow(abs, 1 / 2.40);
4739
}
4840

4941
@protected

0 commit comments

Comments
 (0)