Flutter Engine
 
Loading...
Searching...
No Matches
dl_color.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <algorithm>
8
9namespace flutter {
10
11namespace {
12const std::array<DlScalar, 12> kP3ToSrgb = {
13 1.306671048092539, -0.298061942172353,
14 0.213228303487995, -0.213580156254466, //
15 -0.117390025596251, 1.127722006101976,
16 0.109727644608938, -0.109450321455370, //
17 0.214813187718391, 0.054268702864647,
18 1.406898424029350, -0.364892765879631};
19
20DlColor transform(const DlColor& color,
21 const std::array<DlScalar, 12>& matrix,
22 DlColorSpace color_space) {
23 return DlColor(color.getAlphaF(),
24 matrix[0] * color.getRedF() + //
25 matrix[1] * color.getGreenF() + //
26 matrix[2] * color.getBlueF() + //
27 matrix[3], //
28 matrix[4] * color.getRedF() + //
29 matrix[5] * color.getGreenF() + //
30 matrix[6] * color.getBlueF() + //
31 matrix[7], //
32 matrix[8] * color.getRedF() + //
33 matrix[9] * color.getGreenF() + //
34 matrix[10] * color.getBlueF() + //
35 matrix[11], //
36 color_space);
37}
38} // namespace
39
41 switch (color_space_) {
43 switch (color_space) {
45 return *this;
47 return DlColor(alpha_, red_, green_, blue_,
50 FML_CHECK(false) << "not implemented";
51 return *this;
52 }
54 switch (color_space) {
56 return DlColor(alpha_, std::clamp(red_, 0.0f, 1.0f),
57 std::clamp(green_, 0.0f, 1.0f),
58 std::clamp(blue_, 0.0f, 1.0f), DlColorSpace::kSRGB);
60 return *this;
62 FML_CHECK(false) << "not implemented";
63 return *this;
64 }
66 switch (color_space) {
68 return transform(*this, kP3ToSrgb, DlColorSpace::kExtendedSRGB)
69 .withColorSpace(DlColorSpace::kSRGB);
71 return transform(*this, kP3ToSrgb, DlColorSpace::kExtendedSRGB);
73 return *this;
74 }
75 }
76}
77
78} // namespace flutter
#define FML_CHECK(condition)
Definition logging.h:104
DlColorSpace
Definition dl_color.h:13
flutter::DlColor DlColor
constexpr DlColor()
Definition dl_color.h:23
DlColor withColorSpace(DlColorSpace color_space) const
Definition dl_color.cc:40