Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/ui/painting/image_decoder_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ static constexpr float kSrgbGamutArea = 0.0982f;

// Source:
// https://source.chromium.org/chromium/_/skia/skia.git/+/393fb1ec80f41d8ad7d104921b6920e69749fda1:src/codec/SkAndroidCodec.cpp;l=67;drc=46572b4d445f41943059d0e377afc6d6748cd5ca;bpv=1;bpt=0
bool IsWideGamut(const SkColorSpace& color_space) {
bool IsWideGamut(const SkColorSpace* color_space) {
if (!color_space) {
return false;
}
skcms_Matrix3x3 xyzd50;
color_space.toXYZD50(&xyzd50);
color_space->toXYZD50(&xyzd50);
SkPoint rgb[3];
LoadGamut(rgb, xyzd50);
float area = CalculateArea(rgb);
Expand Down Expand Up @@ -134,7 +137,7 @@ std::shared_ptr<SkBitmap> ImageDecoderImpeller::DecompressTexture(

const auto base_image_info = descriptor->image_info();
const bool is_wide_gamut =
supports_wide_gamut ? IsWideGamut(*base_image_info.colorSpace()) : false;
supports_wide_gamut ? IsWideGamut(base_image_info.colorSpace()) : false;
SkAlphaType alpha_type =
ChooseCompatibleAlphaType(base_image_info.alphaType());
SkImageInfo image_info;
Expand Down
25 changes: 25 additions & 0 deletions lib/ui/painting/image_decoder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,31 @@ float HalfToFloat(uint16_t half) {
}
} // namespace

TEST_F(ImageDecoderFixtureTest, ImpellerNullColorspace) {
auto info = SkImageInfo::Make(10, 10, SkColorType::kRGBA_8888_SkColorType,
SkAlphaType::kPremul_SkAlphaType);
SkBitmap bitmap;
bitmap.allocPixels(info, 10 * 4);
auto data = SkData::MakeWithoutCopy(bitmap.getPixels(), 10 * 10 * 4);
auto image = SkImage::MakeFromBitmap(bitmap);
ASSERT_TRUE(image != nullptr);
ASSERT_EQ(SkISize::Make(10, 10), image->dimensions());
ASSERT_EQ(nullptr, image->colorSpace());

auto descriptor = fml::MakeRefCounted<ImageDescriptor>(
std::move(data), image->imageInfo(), 10 * 4);

#if IMPELLER_SUPPORTS_RENDERING
std::shared_ptr<SkBitmap> decompressed =
ImageDecoderImpeller::DecompressTexture(
descriptor.get(), SkISize::Make(100, 100), {100, 100},
/*supports_wide_gamut=*/true);
ASSERT_TRUE(decompressed);
ASSERT_EQ(decompressed->colorType(), kRGBA_8888_SkColorType);
ASSERT_EQ(decompressed->colorSpace(), nullptr);
#endif // IMPELLER_SUPPORTS_RENDERING
}

TEST_F(ImageDecoderFixtureTest, ImpellerWideGamutDisplayP3) {
auto data = OpenFixtureAsSkData("DisplayP3Logo.png");
auto image = SkImage::MakeFromEncoded(data);
Expand Down