mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 13:27:36 +00:00
LibGfx+Fallout: Make ImageDecoder return ErrorOr
...from try_create_for_raw_bytes(). If a plugin returns `true` from sniff but then fails when calling its `create()` method, we now no longer swallow that error. Allows `image` (and other places in the system) to print a more actionable error if early image headers are invalid. (We now no longer try to find another plugin that can also handle the image.) Fixes a regression from #20063 / #19893 -- before then, we didn't do fallible work this early.
This commit is contained in:
parent
be5e7a360f
commit
2e2cae26c6
12 changed files with 22 additions and 22 deletions
|
@ -403,7 +403,7 @@ ErrorOr<void> PropertiesWindow::create_font_tab(GUI::TabWidget& tab_widget, Nonn
|
|||
|
||||
ErrorOr<void> PropertiesWindow::create_image_tab(GUI::TabWidget& tab_widget, NonnullOwnPtr<Core::MappedFile> mapped_file, StringView mime_type)
|
||||
{
|
||||
auto image_decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(mapped_file->bytes(), mime_type);
|
||||
auto image_decoder = TRY(Gfx::ImageDecoder::try_create_for_raw_bytes(mapped_file->bytes(), mime_type));
|
||||
if (!image_decoder)
|
||||
return {};
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ ErrorOr<void> ViewWidget::try_open_file(String const& path, Core::File& file)
|
|||
Vector<Animation::Frame> frames;
|
||||
// Note: Doing this check only requires reading the header of images
|
||||
// (so if the image is not vector graphics it can be still be decoded OOP).
|
||||
if (auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(file_data); decoder && decoder->natural_frame_format() == Gfx::NaturalFrameFormat::Vector) {
|
||||
if (auto decoder = TRY(Gfx::ImageDecoder::try_create_for_raw_bytes(file_data)); decoder && decoder->natural_frame_format() == Gfx::NaturalFrameFormat::Vector) {
|
||||
// Use in-process decoding for vector graphics.
|
||||
is_animated = decoder->is_animated();
|
||||
loop_count = decoder->loop_count();
|
||||
|
|
|
@ -341,11 +341,12 @@ void MapWidget::process_tile_queue()
|
|||
m_first_image_loaded = true;
|
||||
|
||||
// Decode loaded PNG image data
|
||||
auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(payload, "image/png");
|
||||
if (!decoder || (decoder->frame_count() == 0)) {
|
||||
auto decoder_or_err = Gfx::ImageDecoder::try_create_for_raw_bytes(payload, "image/png");
|
||||
if (decoder_or_err.is_error() || !decoder_or_err.value() || (decoder_or_err.value()->frame_count() == 0)) {
|
||||
dbgln("Maps: Can't decode image: {}", url);
|
||||
return;
|
||||
}
|
||||
auto decoder = decoder_or_err.release_value();
|
||||
m_tiles.set(tile_key, decoder->frame(0).release_value_but_fixme_should_propagate_errors().image);
|
||||
|
||||
// FIXME: only update the part of the screen that this tile covers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue