mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 14:17:34 +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
|
@ -33,7 +33,7 @@ static ErrorOr<Optional<String>> image_details(StringView description, StringVie
|
|||
{
|
||||
auto mapped_file = TRY(Core::MappedFile::map(path));
|
||||
auto mime_type = Core::guess_mime_type_based_on_filename(path);
|
||||
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 OptionalNone {};
|
||||
|
||||
|
|
|
@ -276,7 +276,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
auto file = TRY(Core::MappedFile::map(path));
|
||||
|
||||
auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(file->bytes());
|
||||
auto decoder = TRY(Gfx::ImageDecoder::try_create_for_raw_bytes(file->bytes()));
|
||||
if (decoder) {
|
||||
if (auto embedded_icc_bytes = TRY(decoder->icc_data()); embedded_icc_bytes.has_value()) {
|
||||
icc_bytes = *embedded_icc_bytes;
|
||||
|
|
|
@ -227,9 +227,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
Options options = TRY(parse_options(arguments));
|
||||
|
||||
auto file = TRY(Core::MappedFile::map(options.in_path));
|
||||
auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(file->bytes());
|
||||
auto decoder = TRY(Gfx::ImageDecoder::try_create_for_raw_bytes(file->bytes()));
|
||||
if (!decoder)
|
||||
return Error::from_string_view("Failed to decode input file"sv);
|
||||
return Error::from_string_view("Could not find decoder for input file"sv);
|
||||
|
||||
LoadedImage image = TRY(load_image(*decoder, options.frame_index));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue