|
| 1 | +// Copyright 2025 Google Inc. Use of this source code is governed by an |
| 2 | +// MIT-style license that can be found in the LICENSE file or at |
| 3 | +// https://opensource.org/licenses/MIT. |
| 4 | + |
| 5 | +// ignore_for_file: avoid_renaming_method_parameters |
| 6 | + |
| 7 | +import 'dart:typed_data'; |
| 8 | + |
| 9 | +import 'package:meta/meta.dart'; |
| 10 | + |
| 11 | +import '../../../util/nullable.dart'; |
| 12 | +import '../../color.dart'; |
| 13 | +import '../conversions.dart'; |
| 14 | +import 'utils.dart'; |
| 15 | + |
| 16 | +/// The display-p3-linear color space. |
| 17 | +/// |
| 18 | +/// https://drafts.csswg.org/css-color/#predefined-display-p3-linear |
| 19 | +/// |
| 20 | +/// @nodoc |
| 21 | +@internal |
| 22 | +final class DisplayP3LinearColorSpace extends ColorSpace { |
| 23 | + bool get isBoundedInternal => true; |
| 24 | + |
| 25 | + const DisplayP3LinearColorSpace() : super('display-p3-linear', rgbChannels); |
| 26 | + |
| 27 | + SassColor convert( |
| 28 | + ColorSpace dest, |
| 29 | + double? red, |
| 30 | + double? green, |
| 31 | + double? blue, |
| 32 | + double? alpha, |
| 33 | + ) => |
| 34 | + dest == ColorSpace.displayP3 |
| 35 | + ? SassColor.forSpaceInternal( |
| 36 | + dest, |
| 37 | + red.andThen(srgbAndDisplayP3FromLinear), |
| 38 | + green.andThen(srgbAndDisplayP3FromLinear), |
| 39 | + blue.andThen(srgbAndDisplayP3FromLinear), |
| 40 | + alpha, |
| 41 | + ) |
| 42 | + : super.convert(dest, red, green, blue, alpha); |
| 43 | + |
| 44 | + @protected |
| 45 | + double toLinear(double channel) => channel; |
| 46 | + |
| 47 | + @protected |
| 48 | + double fromLinear(double channel) => channel; |
| 49 | + |
| 50 | + @protected |
| 51 | + Float64List transformationMatrix(ColorSpace dest) => switch (dest) { |
| 52 | + ColorSpace.srgbLinear || |
| 53 | + ColorSpace.srgb || |
| 54 | + ColorSpace.rgb => |
| 55 | + linearDisplayP3ToLinearSrgb, |
| 56 | + ColorSpace.a98Rgb => linearDisplayP3ToLinearA98Rgb, |
| 57 | + ColorSpace.prophotoRgb => linearDisplayP3ToLinearProphotoRgb, |
| 58 | + ColorSpace.rec2020 => linearDisplayP3ToLinearRec2020, |
| 59 | + ColorSpace.xyzD65 => linearDisplayP3ToXyzD65, |
| 60 | + ColorSpace.xyzD50 => linearDisplayP3ToXyzD50, |
| 61 | + ColorSpace.lms => linearDisplayP3ToLms, |
| 62 | + _ => super.transformationMatrix(dest), |
| 63 | + }; |
| 64 | +} |
0 commit comments