116 {
118 if (!descriptor) {
119 std::string decode_error("Invalid descriptor (should never happen)");
121 return DecompressResult{.decode_error = decode_error};
122 }
123
125 target_size.
width()),
128
129 const SkISize source_size = descriptor->image_info().dimensions();
130 auto decode_size = source_size;
131 if (descriptor->is_compressed()) {
132 decode_size = descriptor->get_scaled_dimensions(
std::max(
133 static_cast<float>(target_size.
width()) / source_size.
width(),
134 static_cast<float>(target_size.
height()) / source_size.
height()));
135 }
136
137
138
139
140
141 const auto base_image_info = descriptor->image_info();
142 const bool is_wide_gamut =
143 supports_wide_gamut ? IsWideGamut(base_image_info.colorSpace()) :
false;
147 if (is_wide_gamut) {
151 image_info =
152 base_image_info.
makeWH(decode_size.width(), decode_size.height())
156 } else {
157 image_info =
158 base_image_info.
makeWH(decode_size.width(), decode_size.height())
162 }
163
164 const auto pixel_format =
166 if (!pixel_format.has_value()) {
168 "Codec pixel format is not supported (SkColorType=%d)",
171 return DecompressResult{.decode_error = decode_error};
172 }
173
174 auto bitmap = std::make_shared<SkBitmap>();
175 bitmap->setInfo(image_info);
176 auto bitmap_allocator = std::make_shared<ImpellerAllocator>(allocator);
177
178 if (descriptor->is_compressed()) {
179 if (!
bitmap->tryAllocPixels(bitmap_allocator.get())) {
180 std::string decode_error(
181 "Could not allocate intermediate for image decompression.");
183 return DecompressResult{.decode_error = decode_error};
184 }
185
186 if (!descriptor->get_pixels(
bitmap->pixmap())) {
187 std::string decode_error("Could not decompress image.");
189 return DecompressResult{.decode_error = decode_error};
190 }
191 } else {
192 auto temp_bitmap = std::make_shared<SkBitmap>();
193 temp_bitmap->setInfo(base_image_info);
195 base_image_info, descriptor->row_bytes(), descriptor->data());
196 temp_bitmap->setPixelRef(pixel_ref, 0, 0);
197
198 if (!
bitmap->tryAllocPixels(bitmap_allocator.get())) {
199 std::string decode_error(
200 "Could not allocate intermediate for pixel conversion.");
202 return DecompressResult{.decode_error = decode_error};
203 }
204 temp_bitmap->readPixels(
bitmap->pixmap());
206 }
207
208 if (
bitmap->dimensions() == target_size) {
209 std::shared_ptr<impeller::DeviceBuffer>
buffer =
210 bitmap_allocator->GetDeviceBuffer();
212 return DecompressResult{.decode_error = "Unable to get device buffer"};
213 }
215
216 return DecompressResult{.device_buffer = std::move(
buffer),
218 .image_info =
bitmap->info()};
219 }
220
221
222
223
224
226 const auto scaled_image_info = image_info.
makeDimensions(target_size);
227
228 auto scaled_bitmap = std::make_shared<SkBitmap>();
229 auto scaled_allocator = std::make_shared<ImpellerAllocator>(allocator);
230 scaled_bitmap->setInfo(scaled_image_info);
231 if (!scaled_bitmap->tryAllocPixels(scaled_allocator.get())) {
232 std::string decode_error(
233 "Could not allocate scaled bitmap for image decompression.");
235 return DecompressResult{.decode_error = decode_error};
236 }
237 if (!
bitmap->pixmap().scalePixels(
238 scaled_bitmap->pixmap(),
240 FML_LOG(
ERROR) <<
"Could not scale decoded bitmap data.";
241 }
242 scaled_bitmap->setImmutable();
243
244 std::shared_ptr<impeller::DeviceBuffer>
buffer =
245 scaled_allocator->GetDeviceBuffer();
247
249 return DecompressResult{.decode_error = "Unable to get device buffer"};
250 }
251 return DecompressResult{.device_buffer = std::move(
buffer),
252 .sk_bitmap = scaled_bitmap,
253 .image_info = scaled_bitmap->info()};
254}
@ kOpaque_SkAlphaType
pixel is opaque
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
static sk_sp< SkColorSpace > MakeSRGB()
#define FML_DLOG(severity)
#define FML_LOG(severity)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
SK_API sk_sp< SkPixelRef > MakeWithData(const SkImageInfo &, size_t rowBytes, sk_sp< SkData > data)
static SkAlphaType ChooseCompatibleAlphaType(SkAlphaType type)
static SkColorType ChooseCompatibleColorType(SkColorType type)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
std::optional< impeller::PixelFormat > ToPixelFormat(SkColorType type)
std::string SPrintF(const char *format,...)
constexpr int32_t width() const
void set(int32_t w, int32_t h)
constexpr int32_t height() const
SkImageInfo makeWH(int newWidth, int newHeight) const
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
SkImageInfo makeDimensions(SkISize newSize) const
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const
SkColorType colorType() const
SkImageInfo makeColorType(SkColorType newColorType) const
#define TRACE_EVENT0(category_group, name)