58 return std::numeric_limits<float>::infinity();
60 return -std::numeric_limits<float>::infinity();
62 bool negative = half >> 15;
63 uint16_t exponent = (half >> 10) & 0x1f;
64 uint16_t fraction = half & 0x3ff;
65 float fExponent = exponent - 15.0f;
66 float fFraction =
static_cast<float>(fraction) / 1024.f;
67 float pow_value = powf(2.0f, fExponent);
68 return (negative ? -1.f : 1.f) * pow_value * (1.0f + fFraction);
79TEST(ImageDecoderNoGLTest, ImpellerWideGamutDisplayP3) {
80#if defined(OS_FUCHSIA)
81 GTEST_SKIP() <<
"Fuchsia can't load the test fixtures.";
84 auto image = SkImages::DeferredFromEncodedData(
data);
85 std::shared_ptr<impeller::Capabilities> capabilities =
89 ASSERT_TRUE(
image !=
nullptr);
90 ASSERT_EQ(SkISize::Make(100, 100),
image->dimensions());
93 std::shared_ptr<ImageGenerator> generator =
95 ASSERT_TRUE(generator);
97 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(std::move(
data),
98 std::move(generator));
101 IsPngWithPLTE(descriptor->data()->bytes(), descriptor->data()->size()));
103#if IMPELLER_SUPPORTS_RENDERING
104 std::shared_ptr<impeller::Allocator> allocator =
105 std::make_shared<impeller::TestImpellerAllocator>();
106 std::optional<DecompressResult> wide_result =
108 descriptor.get(), SkISize::Make(100, 100), {100, 100},
109 true, capabilities, allocator);
110 ASSERT_TRUE(wide_result.has_value());
111 ASSERT_EQ(wide_result->image_info.colorType(), kRGBA_F16_SkColorType);
112 ASSERT_TRUE(wide_result->image_info.colorSpace()->isSRGB());
114 const SkPixmap& wide_pixmap = wide_result->sk_bitmap->pixmap();
115 const uint16_t* half_ptr =
static_cast<const uint16_t*
>(wide_pixmap.addr());
116 bool found_deep_red =
false;
117 for (
int i = 0;
i < wide_pixmap.width() * wide_pixmap.height(); ++
i) {
122 if (fabsf(red - 1.0931f) < 0.01f && fabsf(green - -0.2268f) < 0.01f &&
123 fabsf(blue - -0.1501f) < 0.01f) {
124 found_deep_red =
true;
129 ASSERT_TRUE(found_deep_red);
130 std::optional<DecompressResult> narrow_result =
132 descriptor.get(), SkISize::Make(100, 100), {100, 100},
133 false, capabilities, allocator);
135 ASSERT_TRUE(narrow_result.has_value());
136 ASSERT_EQ(narrow_result->image_info.colorType(), kRGBA_8888_SkColorType);
140TEST(ImageDecoderNoGLTest, ImpellerWideGamutIndexedPng) {
141#if defined(OS_FUCHSIA)
142 GTEST_SKIP() <<
"Fuchsia can't load the test fixtures.";
145 auto image = SkImages::DeferredFromEncodedData(
data);
146 std::shared_ptr<impeller::Capabilities> capabilities =
150 ASSERT_TRUE(
image !=
nullptr);
151 ASSERT_EQ(SkISize::Make(100, 100),
image->dimensions());
154 std::shared_ptr<ImageGenerator> generator =
156 ASSERT_TRUE(generator);
158 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(std::move(
data),
159 std::move(generator));
162 IsPngWithPLTE(descriptor->data()->bytes(), descriptor->data()->size()));
164#if IMPELLER_SUPPORTS_RENDERING
165 std::shared_ptr<impeller::Allocator> allocator =
166 std::make_shared<impeller::TestImpellerAllocator>();
167 std::optional<DecompressResult> wide_result =
169 descriptor.get(), SkISize::Make(100, 100), {100, 100},
170 true, capabilities, allocator);
171 ASSERT_EQ(wide_result->image_info.colorType(), kBGR_101010x_XR_SkColorType);
172 ASSERT_TRUE(wide_result->image_info.colorSpace()->isSRGB());
174 const SkPixmap& wide_pixmap = wide_result->sk_bitmap->pixmap();
175 const uint32_t* pixel_ptr =
static_cast<const uint32_t*
>(wide_pixmap.addr());
176 bool found_deep_red =
false;
177 for (
int i = 0;
i < wide_pixmap.width() * wide_pixmap.height(); ++
i) {
178 uint32_t pixel = *pixel_ptr++;
182 if (fabsf(red - 1.0931f) < 0.01f && fabsf(green - -0.2268f) < 0.01f &&
183 fabsf(blue - -0.1501f) < 0.01f) {
184 found_deep_red =
true;
189 ASSERT_TRUE(found_deep_red);
190 std::optional<DecompressResult> narrow_result =
192 descriptor.get(), SkISize::Make(100, 100), {100, 100},
193 false, capabilities, allocator);
195 ASSERT_TRUE(narrow_result.has_value());
196 ASSERT_EQ(narrow_result->image_info.colorType(), kRGBA_8888_SkColorType);
200TEST(ImageDecoderNoGLTest, ImpellerUnmultipliedAlphaPng) {
201#if defined(OS_FUCHSIA)
202 GTEST_SKIP() <<
"Fuchsia can't load the test fixtures.";
205 auto image = SkImages::DeferredFromEncodedData(
data);
206 std::shared_ptr<impeller::Capabilities> capabilities =
210 ASSERT_TRUE(
image !=
nullptr);
211 ASSERT_EQ(SkISize::Make(11, 11),
image->dimensions());
214 std::shared_ptr<ImageGenerator> generator =
216 ASSERT_TRUE(generator);
218 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(std::move(
data),
219 std::move(generator));
221#if IMPELLER_SUPPORTS_RENDERING
222 std::shared_ptr<impeller::Allocator> allocator =
223 std::make_shared<impeller::TestImpellerAllocator>();
224 std::optional<DecompressResult> result =
226 descriptor.get(), SkISize::Make(11, 11), {11, 11},
227 true, capabilities, allocator);
228 ASSERT_EQ(result->image_info.colorType(), kRGBA_8888_SkColorType);
230 const SkPixmap& pixmap = result->sk_bitmap->pixmap();
231 const uint32_t* pixel_ptr =
static_cast<const uint32_t*
>(pixmap.addr());
233 ASSERT_EQ(*pixel_ptr, (uint32_t)0x1000001);
235 ASSERT_EQ(*(pixel_ptr + 11 * 4 + 4), (uint32_t)0xFF00FF00);
static DecompressResult DecompressTexture(ImageDescriptor *descriptor, SkISize target_size, impeller::ISize max_texture_size, bool supports_wide_gamut, const std::shared_ptr< const impeller::Capabilities > &capabilities, const std::shared_ptr< impeller::Allocator > &allocator)