mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
LibGfx: Make mime-based image loaders not throw away their error either
Small follow-up to #23489.
This commit is contained in:
parent
8ec6dad449
commit
75a8d37c99
1 changed files with 4 additions and 6 deletions
|
@ -61,7 +61,7 @@ static ErrorOr<OwnPtr<ImageDecoderPlugin>> probe_and_sniff_for_appropriate_plugi
|
||||||
return OwnPtr<ImageDecoderPlugin> {};
|
return OwnPtr<ImageDecoderPlugin> {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static OwnPtr<ImageDecoderPlugin> probe_and_sniff_for_appropriate_plugin_with_known_mime_type(StringView mime_type, ReadonlyBytes bytes)
|
static ErrorOr<OwnPtr<ImageDecoderPlugin>> probe_and_sniff_for_appropriate_plugin_with_known_mime_type(StringView mime_type, ReadonlyBytes bytes)
|
||||||
{
|
{
|
||||||
struct ImagePluginWithMIMETypeInitializer {
|
struct ImagePluginWithMIMETypeInitializer {
|
||||||
bool (*validate_before_create)(ReadonlyBytes) = nullptr;
|
bool (*validate_before_create)(ReadonlyBytes) = nullptr;
|
||||||
|
@ -79,11 +79,9 @@ static OwnPtr<ImageDecoderPlugin> probe_and_sniff_for_appropriate_plugin_with_kn
|
||||||
auto validation_result = plugin.validate_before_create(bytes);
|
auto validation_result = plugin.validate_before_create(bytes);
|
||||||
if (!validation_result)
|
if (!validation_result)
|
||||||
continue;
|
continue;
|
||||||
auto plugin_decoder = plugin.create(bytes);
|
return TRY(plugin.create(bytes));
|
||||||
if (!plugin_decoder.is_error())
|
|
||||||
return plugin_decoder.release_value();
|
|
||||||
}
|
}
|
||||||
return {};
|
return OwnPtr<ImageDecoderPlugin> {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<RefPtr<ImageDecoder>> ImageDecoder::try_create_for_raw_bytes(ReadonlyBytes bytes, Optional<ByteString> mime_type)
|
ErrorOr<RefPtr<ImageDecoder>> ImageDecoder::try_create_for_raw_bytes(ReadonlyBytes bytes, Optional<ByteString> mime_type)
|
||||||
|
@ -92,7 +90,7 @@ ErrorOr<RefPtr<ImageDecoder>> ImageDecoder::try_create_for_raw_bytes(ReadonlyByt
|
||||||
return adopt_ref_if_nonnull(new (nothrow) ImageDecoder(plugin.release_nonnull()));
|
return adopt_ref_if_nonnull(new (nothrow) ImageDecoder(plugin.release_nonnull()));
|
||||||
|
|
||||||
if (mime_type.has_value()) {
|
if (mime_type.has_value()) {
|
||||||
if (OwnPtr<ImageDecoderPlugin> plugin = probe_and_sniff_for_appropriate_plugin_with_known_mime_type(mime_type.value(), bytes); plugin)
|
if (OwnPtr<ImageDecoderPlugin> plugin = TRY(probe_and_sniff_for_appropriate_plugin_with_known_mime_type(mime_type.value(), bytes)); plugin)
|
||||||
return adopt_ref_if_nonnull(new (nothrow) ImageDecoder(plugin.release_nonnull()));
|
return adopt_ref_if_nonnull(new (nothrow) ImageDecoder(plugin.release_nonnull()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue