mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:07:34 +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:
parent
c6f4ecced9
commit
d01b4327fa
6 changed files with 77 additions and 58 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue