mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 03:37:53 +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:
@@ -68,7 +68,9 @@ static bool build_text_document(DOM::Document& document, const ByteBuffer& data)
|
||||
|
||||
static bool build_image_document(DOM::Document& document, const ByteBuffer& data)
|
||||
{
|
||||
auto image_decoder = Gfx::ImageDecoder::create(data.data(), data.size());
|
||||
auto image_decoder = Gfx::ImageDecoder::try_create(data.bytes());
|
||||
if (!image_decoder)
|
||||
return false;
|
||||
auto bitmap = image_decoder->bitmap();
|
||||
if (!bitmap)
|
||||
return false;
|
||||
@@ -164,7 +166,11 @@ bool FrameLoader::load(const LoadRequest& request, Type type)
|
||||
favicon_url,
|
||||
[this, favicon_url](auto data, auto&, auto) {
|
||||
dbgln("Favicon downloaded, {} bytes from {}", data.size(), favicon_url);
|
||||
auto decoder = Gfx::ImageDecoder::create(data.data(), data.size());
|
||||
auto decoder = Gfx::ImageDecoder::try_create(data);
|
||||
if (!decoder) {
|
||||
dbgln("No image decoder plugin for favicon {}", favicon_url);
|
||||
return;
|
||||
}
|
||||
auto bitmap = decoder->bitmap();
|
||||
if (!bitmap) {
|
||||
dbgln("Could not decode favicon {}", favicon_url);
|
||||
|
||||
Reference in New Issue
Block a user