10#include "include/core/SkColorType.h"
16#if defined(OS_FUCHSIA)
17#pragma GCC diagnostic ignored "-Wunreachable-code"
22bool IsPngWithPLTE(
const uint8_t* bytes,
size_t size) {
23 constexpr std::string_view kPngMagic =
"\x89PNG\x0d\x0a\x1a\x0a";
24 constexpr std::string_view kPngPlte =
"PLTE";
25 constexpr uint32_t kLengthBytes = 4;
26 constexpr uint32_t kTypeBytes = 4;
27 constexpr uint32_t kCrcBytes = 4;
29 if (
size < kPngMagic.size()) {
33 if (memcmp(bytes, kPngMagic.data(), kPngMagic.size()) != 0) {
37 const uint8_t*
end = bytes +
size;
38 const uint8_t* loc = bytes + kPngMagic.size();
39 while (loc + kLengthBytes + kTypeBytes <=
end) {
40 uint32_t chunk_length =
43 if (memcmp(loc + kLengthBytes, kPngPlte.data(), kPngPlte.size()) == 0) {
47 loc += kLengthBytes + kTypeBytes + chunk_length + kCrcBytes;
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);
72 const float max = 1.25098f;
73 const float min = -0.752941f;
74 const float intercept = min;
75 const float slope = (max - min) / 1024.0f;
76 return (
x * slope) + intercept;
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 absl::StatusOr<ImageDecoderImpeller::DecompressResult> wide_result =
108 descriptor.get(), {.target_width = 100, .target_height = 100},
111 ASSERT_TRUE(wide_result.ok());
112 ASSERT_EQ(wide_result->image_info.format,
115 const uint16_t* half_ptr =
reinterpret_cast<const uint16_t*
>(
116 wide_result->device_buffer->OnGetContents());
117 bool found_deep_red =
false;
118 for (
int i = 0;
i < wide_result->image_info.size.width *
119 wide_result->image_info.size.height;
125 if (fabsf(red - 1.0931f) < 0.01f && fabsf(green - -0.2268f) < 0.01f &&
126 fabsf(blue - -0.1501f) < 0.01f) {
127 found_deep_red =
true;
132 ASSERT_TRUE(found_deep_red);
133 absl::StatusOr<ImageDecoderImpeller::DecompressResult> narrow_result =
135 descriptor.get(), {.target_width = 100, .target_height = 100},
139 ASSERT_TRUE(narrow_result.ok());
140 ASSERT_EQ(narrow_result->image_info.format,
145TEST(ImageDecoderNoGLTest, ImpellerWideGamutIndexedPng) {
146#if defined(OS_FUCHSIA)
147 GTEST_SKIP() <<
"Fuchsia can't load the test fixtures.";
150 auto image = SkImages::DeferredFromEncodedData(
data);
151 std::shared_ptr<impeller::Capabilities> capabilities =
155 ASSERT_TRUE(
image !=
nullptr);
156 ASSERT_EQ(SkISize::Make(100, 100),
image->dimensions());
159 std::shared_ptr<ImageGenerator> generator =
161 ASSERT_TRUE(generator);
163 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(std::move(
data),
164 std::move(generator));
167 IsPngWithPLTE(descriptor->data()->bytes(), descriptor->data()->size()));
169#if IMPELLER_SUPPORTS_RENDERING
170 std::shared_ptr<impeller::Allocator>
allocator =
171 std::make_shared<impeller::TestImpellerAllocator>();
172 absl::StatusOr<ImageDecoderImpeller::DecompressResult> wide_result =
174 descriptor.get(), {.target_width = 100, .target_height = 100},
177 ASSERT_TRUE(wide_result.ok());
178 ASSERT_EQ(wide_result->image_info.format,
181 const uint32_t* pixel_ptr =
reinterpret_cast<const uint32_t*
>(
182 wide_result->device_buffer->OnGetContents());
183 bool found_deep_red =
false;
184 for (
int i = 0;
i < wide_result->image_info.size.width *
185 wide_result->image_info.size.height;
187 uint32_t pixel = *pixel_ptr++;
191 if (fabsf(red - 1.0931f) < 0.01f && fabsf(green - -0.2268f) < 0.01f &&
192 fabsf(blue - -0.1501f) < 0.01f) {
193 found_deep_red =
true;
198 ASSERT_TRUE(found_deep_red);
199 absl::StatusOr<ImageDecoderImpeller::DecompressResult> narrow_result =
201 descriptor.get(), {.target_width = 100, .target_height = 100},
205 ASSERT_TRUE(narrow_result.ok());
206 ASSERT_EQ(narrow_result->image_info.format,
211TEST(ImageDecoderNoGLTest, ImpellerRGBA32FDecode) {
212#if defined(OS_FUCHSIA)
213 GTEST_SKIP() <<
"Fuchsia can't load the test fixtures.";
216#if IMPELLER_SUPPORTS_RENDERING
218 float pixel_data[] = {1.0f, 0.5f, 0.25f, 1.0f};
219 sk_sp<SkData> sk_data = SkData::MakeWithCopy(pixel_data,
sizeof(pixel_data));
220 auto immutable_buffer =
221 fml::MakeRefCounted<ImmutableBuffer>(std::move(sk_data));
228 .alpha_type = kUnpremul_SkAlphaType,
230 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(
231 immutable_buffer->data(), image_info,
sizeof(pixel_data));
234 std::shared_ptr<impeller::Capabilities> capabilities =
238 std::shared_ptr<impeller::Allocator>
allocator =
239 std::make_shared<impeller::TestImpellerAllocator>();
242 absl::StatusOr<ImageDecoderImpeller::DecompressResult> result =
249 ImageDecoder::TargetPixelFormat::kR32G32B32A32Float},
255 ASSERT_TRUE(result.ok());
256 ASSERT_EQ(result->image_info.format,
260 const float* decompressed_pixel_ptr =
261 reinterpret_cast<const float*
>(result->device_buffer->OnGetContents());
262 ASSERT_NE(decompressed_pixel_ptr,
nullptr);
263 EXPECT_EQ(decompressed_pixel_ptr[0], 1.0f);
264 EXPECT_EQ(decompressed_pixel_ptr[1], 0.5f);
265 EXPECT_EQ(decompressed_pixel_ptr[2], 0.25f);
266 EXPECT_EQ(decompressed_pixel_ptr[3], 1.0f);
271TEST(ImageDecoderNoGLTest, ImpellerR32FDecode) {
272#if defined(OS_FUCHSIA)
273 GTEST_SKIP() <<
"Fuchsia can't load the test fixtures.";
276#if !IMPELLER_SUPPORTS_RENDERING
277 GTEST_SKIP() <<
"test only supported on impeller";
280 float pixel_data[] = {1.0f};
281 sk_sp<SkData> sk_data = SkData::MakeWithCopy(pixel_data,
sizeof(pixel_data));
282 auto immutable_buffer =
283 fml::MakeRefCounted<ImmutableBuffer>(std::move(sk_data));
290 .alpha_type = kUnpremul_SkAlphaType,
292 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(
293 immutable_buffer->data(), image_info,
sizeof(pixel_data));
296 std::shared_ptr<impeller::Capabilities> capabilities =
300 std::shared_ptr<impeller::Allocator>
allocator =
301 std::make_shared<impeller::TestImpellerAllocator>();
304 absl::StatusOr<ImageDecoderImpeller::DecompressResult> result =
310 .target_format = ImageDecoder::TargetPixelFormat::kR32Float},
316 ASSERT_TRUE(result.ok());
320 const float* decompressed_pixel_ptr =
321 reinterpret_cast<const float*
>(result->device_buffer->OnGetContents());
322 ASSERT_NE(decompressed_pixel_ptr,
nullptr);
323 EXPECT_EQ(decompressed_pixel_ptr[0], 1.0f);
328TEST(ImageDecoderNoGLTest, ImpellerUnmultipliedAlphaPng) {
329#if defined(OS_FUCHSIA)
330 GTEST_SKIP() <<
"Fuchsia can't load the test fixtures.";
333 auto image = SkImages::DeferredFromEncodedData(
data);
334 std::shared_ptr<impeller::Capabilities> capabilities =
338 ASSERT_TRUE(
image !=
nullptr);
339 ASSERT_EQ(SkISize::Make(11, 11),
image->dimensions());
342 std::shared_ptr<ImageGenerator> generator =
344 ASSERT_TRUE(generator);
346 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(std::move(
data),
347 std::move(generator));
349#if IMPELLER_SUPPORTS_RENDERING
350 std::shared_ptr<impeller::Allocator>
allocator =
351 std::make_shared<impeller::TestImpellerAllocator>();
352 absl::StatusOr<ImageDecoderImpeller::DecompressResult> result =
354 descriptor.get(), {.target_width = 11, .target_height = 11}, {11, 11},
356 ASSERT_TRUE(result.ok());
357 ASSERT_EQ(result->image_info.format,
360 const uint32_t* pixel_ptr =
361 reinterpret_cast<const uint32_t*
>(result->device_buffer->OnGetContents());
363 ASSERT_EQ(*pixel_ptr, (uint32_t)0x1000001);
365 ASSERT_EQ(*(pixel_ptr + 11 * 4 + 4), (uint32_t)0xFF00FF00);
static absl::StatusOr< DecompressResult > DecompressTexture(ImageDescriptor *descriptor, const ImageDecoder::Options &options, impeller::ISize max_texture_size, bool supports_wide_gamut, const std::shared_ptr< const impeller::Capabilities > &capabilities, const std::shared_ptr< impeller::Allocator > &allocator)
Keeps a priority-ordered registry of image generator builders to be used when decoding images....
std::shared_ptr< ImageGenerator > CreateCompatibleGenerator(const sk_sp< SkData > &buffer)
Walks the list of image generator builders in descending priority order until a compatible ImageGener...
CapabilitiesBuilder & SetSupportsTextureToTextureBlits(bool value)
std::unique_ptr< Capabilities > Build()
FlutterVulkanImage * image
std::shared_ptr< ImpellerAllocator > allocator
float DecodeBGR10(uint32_t x)
sk_sp< SkData > OpenFixtureAsSkData(const std::string &fixture_name)
Opens a fixture of the given file name and returns a Skia SkData holding its contents.
TEST(NativeAssetsManagerTest, NoAvailableAssets)
float HalfToFloat(uint16_t half)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
constexpr T BigEndianToArch(T n)
Convert a known big endian value to match the endianness of the current architecture....