5#include "flutter/lib/ui/painting/image_decoder_no_gl_unittests.h"
7#include "flutter/fml/endianness.h"
13#if defined(OS_FUCHSIA)
14#pragma GCC diagnostic ignored "-Wunreachable-code"
19bool IsPngWithPLTE(
const uint8_t* bytes,
size_t size) {
20 constexpr std::string_view kPngMagic =
"\x89PNG\x0d\x0a\x1a\x0a";
21 constexpr std::string_view kPngPlte =
"PLTE";
22 constexpr uint32_t kLengthBytes = 4;
23 constexpr uint32_t kTypeBytes = 4;
24 constexpr uint32_t kCrcBytes = 4;
26 if (
size < kPngMagic.size()) {
30 if (memcmp(bytes, kPngMagic.data(), kPngMagic.size()) != 0) {
34 const uint8_t*
end = bytes +
size;
35 const uint8_t* loc = bytes + kPngMagic.size();
36 while (loc + kLengthBytes + kTypeBytes <= end) {
37 uint32_t chunk_length =
40 if (memcmp(loc + kLengthBytes, kPngPlte.data(), kPngPlte.size()) == 0) {
44 loc += kLengthBytes + kTypeBytes + chunk_length + kCrcBytes;
55 return std::numeric_limits<float>::infinity();
57 return -std::numeric_limits<float>::infinity();
59 bool negative = half >> 15;
60 uint16_t exponent = (half >> 10) & 0x1f;
61 uint16_t fraction = half & 0x3ff;
62 float fExponent = exponent - 15.0f;
63 float fFraction =
static_cast<float>(fraction) / 1024.f;
64 float pow_value = powf(2.0f, fExponent);
65 return (negative ? -1.f : 1.f) * pow_value * (1.0f + fFraction);
69 const float max = 1.25098f;
70 const float min = -0.752941f;
71 const float intercept =
min;
72 const float slope = (
max -
min) / 1024.0f;
73 return (
x * slope) + intercept;
76TEST(ImageDecoderNoGLTest, ImpellerWideGamutDisplayP3) {
77#if defined(OS_FUCHSIA)
78 GTEST_SKIP() <<
"Fuchsia can't load the test fixtures.";
82 ASSERT_TRUE(
image !=
nullptr);
86 std::shared_ptr<ImageGenerator> generator =
88 ASSERT_TRUE(generator);
90 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(std::move(
data),
91 std::move(generator));
94 IsPngWithPLTE(descriptor->data()->bytes(), descriptor->data()->size()));
96#if IMPELLER_SUPPORTS_RENDERING
97 std::shared_ptr<impeller::Allocator> allocator =
98 std::make_shared<impeller::TestImpellerAllocator>();
99 std::optional<DecompressResult> wide_result =
103 ASSERT_TRUE(wide_result.has_value());
105 ASSERT_TRUE(wide_result->image_info.colorSpace()->isSRGB());
107 const SkPixmap& wide_pixmap = wide_result->sk_bitmap->pixmap();
108 const uint16_t* half_ptr =
static_cast<const uint16_t*
>(wide_pixmap.
addr());
109 bool found_deep_red =
false;
110 for (
int i = 0;
i < wide_pixmap.
width() * wide_pixmap.
height(); ++
i) {
115 if (fabsf(red - 1.0931f) < 0.01f && fabsf(green - -0.2268f) < 0.01f &&
116 fabsf(blue - -0.1501f) < 0.01f) {
117 found_deep_red =
true;
122 ASSERT_TRUE(found_deep_red);
123 std::optional<DecompressResult> narrow_result =
128 ASSERT_TRUE(narrow_result.has_value());
133TEST(ImageDecoderNoGLTest, ImpellerWideGamutIndexedPng) {
134#if defined(OS_FUCHSIA)
135 GTEST_SKIP() <<
"Fuchsia can't load the test fixtures.";
139 ASSERT_TRUE(
image !=
nullptr);
143 std::shared_ptr<ImageGenerator> generator =
145 ASSERT_TRUE(generator);
147 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(std::move(
data),
148 std::move(generator));
151 IsPngWithPLTE(descriptor->data()->bytes(), descriptor->data()->size()));
153#if IMPELLER_SUPPORTS_RENDERING
154 std::shared_ptr<impeller::Allocator> allocator =
155 std::make_shared<impeller::TestImpellerAllocator>();
156 std::optional<DecompressResult> wide_result =
161 ASSERT_TRUE(wide_result->image_info.colorSpace()->isSRGB());
163 const SkPixmap& wide_pixmap = wide_result->sk_bitmap->pixmap();
164 const uint32_t* pixel_ptr =
static_cast<const uint32_t*
>(wide_pixmap.
addr());
165 bool found_deep_red =
false;
166 for (
int i = 0;
i < wide_pixmap.
width() * wide_pixmap.
height(); ++
i) {
167 uint32_t pixel = *pixel_ptr++;
171 if (fabsf(red - 1.0931f) < 0.01f && fabsf(green - -0.2268f) < 0.01f &&
172 fabsf(blue - -0.1501f) < 0.01f) {
173 found_deep_red =
true;
178 ASSERT_TRUE(found_deep_red);
179 std::optional<DecompressResult> narrow_result =
184 ASSERT_TRUE(narrow_result.has_value());
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
SkISize dimensions() const
const void * addr() const
static DecompressResult DecompressTexture(ImageDescriptor *descriptor, SkISize target_size, impeller::ISize max_texture_size, bool supports_wide_gamut, 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...
static float max(float r, float g, float b)
static float min(float r, float g, float b)
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
sk_sp< const SkImage > image
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(DisplayListComplexity, EmptyDisplayList)
float HalfToFloat(uint16_t half)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
it will be possible to load the file into Perfetto s trace viewer 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
constexpr T BigEndianToArch(T n)
Convert a known big endian value to match the endianness of the current architecture....
static constexpr SkISize Make(int32_t w, int32_t h)