mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-30 13:19:47 +00: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:
@@ -78,7 +78,9 @@ void ImageWidget::load_from_file(const StringView& path)
|
||||
return;
|
||||
|
||||
auto& mapped_file = *file_or_error.value();
|
||||
m_image_decoder = Gfx::ImageDecoder::create((const u8*)mapped_file.data(), mapped_file.size());
|
||||
m_image_decoder = Gfx::ImageDecoder::try_create(mapped_file.bytes());
|
||||
VERIFY(m_image_decoder);
|
||||
|
||||
auto bitmap = m_image_decoder->bitmap();
|
||||
VERIFY(bitmap);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user