Fixed bug where images without specified colorspaces can crash wide gamut test. (flutter/engine#40097)

Fixed crash with images without specified colorspaces in wide gamut test
This commit is contained in:
gaaclarke 2023-03-09 15:07:22 -08:00 committed by GitHub
parent e9942f8f52
commit a83570e7bf
2 changed files with 31 additions and 3 deletions

View File

@ -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);
@ -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;

View File

@ -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);