1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibGfx: Improve ImageDecoder construction

Previously, ImageDecoder::create() would return a NonnullRefPtr and
could not "fail", although the returned decoder may be "invalid" which
you then had to check anyway.

The new interface looks like this:

    static RefPtr<Gfx::ImageDecoder> try_create(ReadonlyBytes);

This simplifies ImageDecoder since it no longer has to worry about its
validity. Client code gets slightly clearer as well.
This commit is contained in:
Andreas Kling 2021-07-27 01:12:53 +02:00
parent c6f4ecced9
commit d01b4327fa
Notes: sideshowbarker 2024-07-18 08:16:55 +09:00
6 changed files with 77 additions and 58 deletions

View file

@ -28,9 +28,8 @@ static Optional<String> image_details(const String& description, const String& p
return {};
auto& mapped_file = *file_or_error.value();
auto image_decoder = Gfx::ImageDecoder::create((const u8*)mapped_file.data(), mapped_file.size());
if (!image_decoder->is_valid())
auto image_decoder = Gfx::ImageDecoder::try_create(mapped_file.bytes());
if (!image_decoder)
return {};
return String::formatted("{}, {} x {}", description, image_decoder->width(), image_decoder->height());