1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:37:35 +00:00

LibGfx: Make ImageDecoderPlugin::frame() return ErrorOr<>

This is a first step towards better error propagation from image codecs.
This commit is contained in:
Andreas Kling 2021-11-20 14:29:33 +01:00
parent ae7656072a
commit 5a79c69b02
26 changed files with 101 additions and 100 deletions

View file

@ -52,12 +52,12 @@ Messages::ImageDecoderServer::DecodeImageResponse ClientConnection::decode_image
Vector<Gfx::ShareableBitmap> bitmaps;
Vector<u32> durations;
for (size_t i = 0; i < decoder->frame_count(); ++i) {
auto frame = decoder->frame(i);
if (frame.image)
bitmaps.append(frame.image->to_shareable_bitmap());
else
auto frame_or_error = decoder->frame(i);
if (frame_or_error.is_error() || !frame_or_error.value().image)
bitmaps.append(Gfx::ShareableBitmap {});
durations.append(frame.duration);
else
bitmaps.append(frame_or_error.value().image->to_shareable_bitmap());
durations.append(frame_or_error.value().duration);
}
return { decoder->is_animated(), static_cast<u32>(decoder->loop_count()), bitmaps, durations };

View file

@ -140,17 +140,18 @@ void SpiceAgent::on_message_received()
m_clipboard_connection.async_set_clipboard_data(anon_buffer, "text/plain", {});
return;
} else {
RefPtr<Gfx::Bitmap> bitmap;
ErrorOr<Gfx::ImageFrameDescriptor> frame_or_error = Gfx::ImageFrameDescriptor {};
if (type == ClipboardType::PNG) {
bitmap = Gfx::PNGImageDecoderPlugin(data_buffer.data(), data_buffer.size()).frame(0).image;
frame_or_error = Gfx::PNGImageDecoderPlugin(data_buffer.data(), data_buffer.size()).frame(0);
} else if (type == ClipboardType::BMP) {
bitmap = Gfx::BMPImageDecoderPlugin(data_buffer.data(), data_buffer.size()).frame(0).image;
frame_or_error = Gfx::BMPImageDecoderPlugin(data_buffer.data(), data_buffer.size()).frame(0);
} else if (type == ClipboardType::JPG) {
bitmap = Gfx::JPGImageDecoderPlugin(data_buffer.data(), data_buffer.size()).frame(0).image;
frame_or_error = Gfx::JPGImageDecoderPlugin(data_buffer.data(), data_buffer.size()).frame(0);
} else {
dbgln("Unknown clipboard type: {}", (u32)type);
return;
}
auto const& bitmap = frame_or_error.value().image;
m_clipboard_connection.set_bitmap(*bitmap);
}
break;