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

Commit 2e5b1bf

Browse files
authored
Updated the wide-gamut constant and added a unit test for it. (#39776)
* Updated the wide-gamut constant and added a unit test for it. * dan feedback
1 parent 03b5998 commit 2e5b1bf

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/ui/painting/image_decoder_impeller.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ float CalculateArea(SkPoint abc[3]) {
4949
b.fX * a.fY);
5050
}
5151

52-
static constexpr float kSrgbD50GamutArea = 0.084f;
52+
// Note: This was calculated from SkColorSpace::MakeSRGB().
53+
static constexpr float kSrgbGamutArea = 0.0982f;
5354

5455
// Source:
5556
// https://source.chromium.org/chromium/_/skia/skia.git/+/393fb1ec80f41d8ad7d104921b6920e69749fda1:src/codec/SkAndroidCodec.cpp;l=67;drc=46572b4d445f41943059d0e377afc6d6748cd5ca;bpv=1;bpt=0
@@ -58,7 +59,8 @@ bool IsWideGamut(const SkColorSpace& color_space) {
5859
color_space.toXYZD50(&xyzd50);
5960
SkPoint rgb[3];
6061
LoadGamut(rgb, xyzd50);
61-
return CalculateArea(rgb) > kSrgbD50GamutArea;
62+
float area = CalculateArea(rgb);
63+
return area > kSrgbGamutArea;
6264
}
6365
} // namespace
6466

lib/ui/painting/image_decoder_unittests.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,28 @@ TEST_F(ImageDecoderFixtureTest, ImpellerWideGamutDisplayP3) {
333333
#endif // IMPELLER_SUPPORTS_RENDERING
334334
}
335335

336+
TEST_F(ImageDecoderFixtureTest, ImpellerNonWideGamut) {
337+
auto data = OpenFixtureAsSkData("Horizontal.jpg");
338+
auto image = SkImage::MakeFromEncoded(data);
339+
ASSERT_TRUE(image != nullptr);
340+
ASSERT_EQ(SkISize::Make(600, 200), image->dimensions());
341+
342+
ImageGeneratorRegistry registry;
343+
std::shared_ptr<ImageGenerator> generator =
344+
registry.CreateCompatibleGenerator(data);
345+
ASSERT_TRUE(generator);
346+
347+
auto descriptor = fml::MakeRefCounted<ImageDescriptor>(std::move(data),
348+
std::move(generator));
349+
350+
#if IMPELLER_SUPPORTS_RENDERING
351+
std::shared_ptr<SkBitmap> bitmap = ImageDecoderImpeller::DecompressTexture(
352+
descriptor.get(), SkISize::Make(600, 200), {600, 200},
353+
/*supports_wide_gamut=*/true);
354+
ASSERT_EQ(bitmap->colorType(), kRGBA_8888_SkColorType);
355+
#endif // IMPELLER_SUPPORTS_RENDERING
356+
}
357+
336358
TEST_F(ImageDecoderFixtureTest, ExifDataIsRespectedOnDecode) {
337359
auto loop = fml::ConcurrentMessageLoop::Create();
338360
TaskRunners runners(GetCurrentTestName(), // label

0 commit comments

Comments
 (0)