summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/ICOLoader.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-20 14:29:33 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-21 20:22:48 +0100
commit5a79c69b0216f070b07d8238e4c2c7e3420faeec (patch)
treea88ee6dff60c34b27f383d36a4dfd3ba4b11c482 /Userland/Libraries/LibGfx/ICOLoader.cpp
parentae7656072a403f69607109d941aa0c4b6274f60c (diff)
downloadserenity-5a79c69b0216f070b07d8238e4c2c7e3420faeec.zip
LibGfx: Make ImageDecoderPlugin::frame() return ErrorOr<>
This is a first step towards better error propagation from image codecs.
Diffstat (limited to 'Userland/Libraries/LibGfx/ICOLoader.cpp')
-rw-r--r--Userland/Libraries/LibGfx/ICOLoader.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp
index 4056d7c0f0..1ff99ad6c4 100644
--- a/Userland/Libraries/LibGfx/ICOLoader.cpp
+++ b/Userland/Libraries/LibGfx/ICOLoader.cpp
@@ -263,11 +263,12 @@ static bool load_ico_bitmap(ICOLoadingContext& context, Optional<size_t> index)
PNGImageDecoderPlugin png_decoder(context.data + desc.offset, desc.size);
if (png_decoder.sniff()) {
- desc.bitmap = png_decoder.frame(0).image;
- if (!desc.bitmap) {
+ auto decoded_png_frame = png_decoder.frame(0);
+ if (!decoded_png_frame.is_error() || !decoded_png_frame.value().image) {
dbgln_if(ICO_DEBUG, "load_ico_bitmap: failed to load PNG encoded image index: {}", real_index);
return false;
}
+ desc.bitmap = decoded_png_frame.value().image;
return true;
} else {
if (!load_ico_bmp(context, desc)) {
@@ -338,26 +339,26 @@ size_t ICOImageDecoderPlugin::frame_count()
return 1;
}
-ImageFrameDescriptor ICOImageDecoderPlugin::frame(size_t i)
+ErrorOr<ImageFrameDescriptor> ICOImageDecoderPlugin::frame(size_t index)
{
- if (i > 0)
- return {};
+ if (index > 0)
+ return Error::from_string_literal("ICOImageDecoderPlugin: Invalid frame index"sv);
if (m_context->state == ICOLoadingContext::State::Error)
- return {};
+ return Error::from_string_literal("ICOImageDecoderPlugin: Decoding failed"sv);
if (m_context->state < ICOLoadingContext::State::BitmapDecoded) {
// NOTE: This forces the chunk decoding to happen.
bool success = load_ico_bitmap(*m_context, {});
if (!success) {
m_context->state = ICOLoadingContext::State::Error;
- return {};
+ return Error::from_string_literal("ICOImageDecoderPlugin: Decoding failed"sv);
}
m_context->state = ICOLoadingContext::State::BitmapDecoded;
}
VERIFY(m_context->images[m_context->largest_index].bitmap);
- return { m_context->images[m_context->largest_index].bitmap, 0 };
+ return ImageFrameDescriptor { m_context->images[m_context->largest_index].bitmap, 0 };
}
}