Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 85a426f

Browse files
committed
added p3->srgb_xr transform
1 parent 2ed29bf commit 85a426f

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

display_list/dl_color.cc

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@
66

77
namespace flutter {
88

9+
namespace {
10+
const std::array<DlScalar, 12> kP3ToSrgb = {
11+
1.306671048092539, -0.298061942172353,
12+
0.213228303487995, -0.213580156254466, //
13+
-0.117390025596251, 1.127722006101976,
14+
0.109727644608938, -0.109450321455370, //
15+
0.214813187718391, 0.054268702864647,
16+
1.406898424029350, -0.364892765879631};
17+
18+
DlColor transform(const DlColor& color,
19+
const std::array<DlScalar, 12>& matrix,
20+
DlColorSpace color_space) {
21+
return DlColor(color.getAlphaF(),
22+
matrix[0] * color.getRedF() + //
23+
matrix[1] * color.getGreenF() + //
24+
matrix[2] * color.getBlueF() + //
25+
matrix[3], //
26+
matrix[4] * color.getRedF() + //
27+
matrix[5] * color.getGreenF() + //
28+
matrix[6] * color.getBlueF() + //
29+
matrix[7], //
30+
matrix[8] * color.getRedF() + //
31+
matrix[9] * color.getGreenF() + //
32+
matrix[10] * color.getBlueF() + //
33+
matrix[11], //
34+
color_space);
35+
}
36+
} // namespace
37+
938
DlColor DlColor::withColorSpace(DlColorSpace color_space) const {
1039
switch (color_space_) {
1140
case DlColorSpace::kSRGB:
@@ -36,8 +65,7 @@ DlColor DlColor::withColorSpace(DlColorSpace color_space) const {
3665
FML_CHECK(false) << "not implemented";
3766
return *this;
3867
case DlColorSpace::kExtendedSRGB:
39-
FML_CHECK(false) << "not implemented";
40-
return *this;
68+
return transform(*this, kP3ToSrgb, DlColorSpace::kExtendedSRGB);
4169
case DlColorSpace::kDisplayP3:
4270
return *this;
4371
}

display_list/dl_color_unittests.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#include "flutter/display_list/dl_color.h"
6+
#include "flutter/testing/display_list_testing.h"
67
#include "flutter/testing/testing.h"
78

89
#include "third_party/skia/include/core/SkColor.h"
@@ -269,6 +270,25 @@ TEST(DisplayListColor, ColorSpaceP3ToP3) {
269270
p3.withColorSpace(DlColorSpace::kDisplayP3));
270271
}
271272

273+
TEST(DisplayListColor, ColorSpaceP3ToExtendedSRGB) {
274+
DlColor red(0.9, 1.0, 0.0, 0.0, DlColorSpace::kDisplayP3);
275+
EXPECT_TRUE(
276+
DlColor(0.9, 1.0931, -0.2268, -0.1501, DlColorSpace::kExtendedSRGB)
277+
.isClose(red.withColorSpace(DlColorSpace::kExtendedSRGB)))
278+
<< red.withColorSpace(DlColorSpace::kExtendedSRGB);
279+
280+
DlColor green(0.9, 0.0, 1.0, 0.0, DlColorSpace::kDisplayP3);
281+
EXPECT_TRUE(
282+
DlColor(0.9, -0.5116, 1.0183, -0.3106, DlColorSpace::kExtendedSRGB)
283+
.isClose(green.withColorSpace(DlColorSpace::kExtendedSRGB)))
284+
<< green.withColorSpace(DlColorSpace::kExtendedSRGB);
285+
286+
DlColor blue(0.9, 0.0, 0.0, 1.0, DlColorSpace::kDisplayP3);
287+
EXPECT_TRUE(DlColor(0.9, -0.0004, 0.0003, 1.0420, DlColorSpace::kExtendedSRGB)
288+
.isClose(blue.withColorSpace(DlColorSpace::kExtendedSRGB)))
289+
<< blue.withColorSpace(DlColorSpace::kExtendedSRGB);
290+
}
291+
272292
TEST(DisplayListColor, isClose) {
273293
EXPECT_TRUE(DlColor(0xffaabbcc).isClose(DlColor(0xffaabbcc)));
274294
}

testing/display_list_testing.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,24 @@ std::ostream& operator<<(std::ostream& os, const DlFilterMode& mode) {
284284
}
285285

286286
std::ostream& operator<<(std::ostream& os, const DlColor& color) {
287-
return os << "DlColor(" << std::hex << color.argb() << std::dec << ")";
287+
const char* color_space;
288+
switch(color.getColorSpace()) {
289+
case flutter::DlColorSpace::kSRGB:
290+
color_space = "srgb";
291+
break;
292+
case flutter::DlColorSpace::kExtendedSRGB:
293+
color_space = "srgb_xr";
294+
break;
295+
case flutter::DlColorSpace::kDisplayP3:
296+
color_space = "p3";
297+
break;
298+
}
299+
return os << "DlColor(" << //
300+
color.getAlphaF() << ", " << //
301+
color.getRedF() << ", " << //
302+
color.getGreenF() << ", " << //
303+
color.getBlueF() << ", " << //
304+
color_space << ")";
288305
}
289306

290307
std::ostream& operator<<(std::ostream& os, DlImageSampling sampling) {

0 commit comments

Comments
 (0)