summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/FileIconProvider.cpp6
-rw-r--r--Userland/Libraries/LibGUI/ImageWidget.cpp6
-rw-r--r--Userland/Libraries/LibGfx/BMPLoader.cpp12
-rw-r--r--Userland/Libraries/LibGfx/BMPLoader.h2
-rw-r--r--Userland/Libraries/LibGfx/Bitmap.cpp3
-rw-r--r--Userland/Libraries/LibGfx/DDSLoader.cpp12
-rw-r--r--Userland/Libraries/LibGfx/DDSLoader.h2
-rw-r--r--Userland/Libraries/LibGfx/GIFLoader.cpp20
-rw-r--r--Userland/Libraries/LibGfx/GIFLoader.h2
-rw-r--r--Userland/Libraries/LibGfx/ICOLoader.cpp17
-rw-r--r--Userland/Libraries/LibGfx/ICOLoader.h2
-rw-r--r--Userland/Libraries/LibGfx/ImageDecoder.h4
-rw-r--r--Userland/Libraries/LibGfx/JPGLoader.cpp12
-rw-r--r--Userland/Libraries/LibGfx/JPGLoader.h2
-rw-r--r--Userland/Libraries/LibGfx/PBMLoader.cpp12
-rw-r--r--Userland/Libraries/LibGfx/PBMLoader.h2
-rw-r--r--Userland/Libraries/LibGfx/PGMLoader.cpp12
-rw-r--r--Userland/Libraries/LibGfx/PGMLoader.h2
-rw-r--r--Userland/Libraries/LibGfx/PNGLoader.cpp12
-rw-r--r--Userland/Libraries/LibGfx/PNGLoader.h2
-rw-r--r--Userland/Libraries/LibGfx/PPMLoader.cpp12
-rw-r--r--Userland/Libraries/LibGfx/PPMLoader.h2
-rw-r--r--Userland/Services/ImageDecoder/ClientConnection.cpp10
-rw-r--r--Userland/Services/SpiceAgent/SpiceAgent.cpp9
24 files changed, 89 insertions, 88 deletions
diff --git a/Userland/Libraries/LibGUI/FileIconProvider.cpp b/Userland/Libraries/LibGUI/FileIconProvider.cpp
index 716e90fc27..90eafe9404 100644
--- a/Userland/Libraries/LibGUI/FileIconProvider.cpp
+++ b/Userland/Libraries/LibGUI/FileIconProvider.cpp
@@ -188,7 +188,11 @@ Icon FileIconProvider::icon_for_executable(const String& path)
if (!section.has_value()) {
bitmap = s_executable_icon.bitmap_for_size(icon_section.image_size);
} else {
- bitmap = Gfx::PNGImageDecoderPlugin(reinterpret_cast<u8 const*>(section->raw_data()), section->size()).frame(0).image;
+ // FIXME: Use the ImageDecoder service.
+ auto frame_or_error = Gfx::PNGImageDecoderPlugin(reinterpret_cast<u8 const*>(section->raw_data()), section->size()).frame(0);
+ if (!frame_or_error.is_error()) {
+ bitmap = frame_or_error.value().image;
+ }
}
if (!bitmap) {
diff --git a/Userland/Libraries/LibGUI/ImageWidget.cpp b/Userland/Libraries/LibGUI/ImageWidget.cpp
index dcf4f16d25..03cc58e271 100644
--- a/Userland/Libraries/LibGUI/ImageWidget.cpp
+++ b/Userland/Libraries/LibGUI/ImageWidget.cpp
@@ -56,7 +56,7 @@ void ImageWidget::animate()
{
m_current_frame_index = (m_current_frame_index + 1) % m_image_decoder->frame_count();
- const auto& current_frame = m_image_decoder->frame(m_current_frame_index);
+ auto current_frame = m_image_decoder->frame(m_current_frame_index).release_value_but_fixme_should_propagate_errors();
set_bitmap(current_frame.image);
if (current_frame.duration != m_timer->interval()) {
@@ -81,14 +81,14 @@ void ImageWidget::load_from_file(StringView path)
m_image_decoder = Gfx::ImageDecoder::try_create(mapped_file.bytes());
VERIFY(m_image_decoder);
- auto frame = m_image_decoder->frame(0);
+ auto frame = m_image_decoder->frame(0).release_value_but_fixme_should_propagate_errors();
auto bitmap = frame.image;
VERIFY(bitmap);
set_bitmap(bitmap);
if (m_image_decoder->is_animated() && m_image_decoder->frame_count() > 1) {
- const auto& first_frame = m_image_decoder->frame(0);
+ auto first_frame = m_image_decoder->frame(0).release_value_but_fixme_should_propagate_errors();
m_timer->set_interval(first_frame.duration);
m_timer->on_timeout = [this] { animate(); };
m_timer->start();
diff --git a/Userland/Libraries/LibGfx/BMPLoader.cpp b/Userland/Libraries/LibGfx/BMPLoader.cpp
index 04e406ac76..d642117177 100644
--- a/Userland/Libraries/LibGfx/BMPLoader.cpp
+++ b/Userland/Libraries/LibGfx/BMPLoader.cpp
@@ -1354,19 +1354,19 @@ size_t BMPImageDecoderPlugin::frame_count()
return 1;
}
-ImageFrameDescriptor BMPImageDecoderPlugin::frame(size_t i)
+ErrorOr<ImageFrameDescriptor> BMPImageDecoderPlugin::frame(size_t index)
{
- if (i > 0)
- return {};
+ if (index > 0)
+ return Error::from_string_literal("BMPImageDecoderPlugin: Invalid frame index"sv);
if (m_context->state == BMPLoadingContext::State::Error)
- return {};
+ return Error::from_string_literal("BMPImageDecoderPlugin: Decoding failed"sv);
if (m_context->state < BMPLoadingContext::State::PixelDataDecoded && !decode_bmp_pixel_data(*m_context))
- return {};
+ return Error::from_string_literal("BMPImageDecoderPlugin: Decoding failed"sv);
VERIFY(m_context->bitmap);
- return { m_context->bitmap, 0 };
+ return ImageFrameDescriptor { m_context->bitmap, 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/BMPLoader.h b/Userland/Libraries/LibGfx/BMPLoader.h
index f848ac4dd5..a690f32619 100644
--- a/Userland/Libraries/LibGfx/BMPLoader.h
+++ b/Userland/Libraries/LibGfx/BMPLoader.h
@@ -24,7 +24,7 @@ public:
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
- virtual ImageFrameDescriptor frame(size_t i) override;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
private:
OwnPtr<BMPLoadingContext> m_context;
diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp
index 5d2c6e823b..06f2afe419 100644
--- a/Userland/Libraries/LibGfx/Bitmap.cpp
+++ b/Userland/Libraries/LibGfx/Bitmap.cpp
@@ -136,7 +136,8 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_load_from_fd_and_close(int fd, String
{
auto file = TRY(MappedFile::map_from_fd_and_close(fd, path));
if (auto decoder = ImageDecoder::try_create(file->bytes())) {
- if (auto bitmap = decoder->frame(0).image)
+ auto frame = TRY(decoder->frame(0));
+ if (auto& bitmap = frame.image)
return bitmap.release_nonnull();
}
diff --git a/Userland/Libraries/LibGfx/DDSLoader.cpp b/Userland/Libraries/LibGfx/DDSLoader.cpp
index 915990465b..482184ff42 100644
--- a/Userland/Libraries/LibGfx/DDSLoader.cpp
+++ b/Userland/Libraries/LibGfx/DDSLoader.cpp
@@ -997,22 +997,22 @@ size_t DDSImageDecoderPlugin::frame_count()
return 1;
}
-ImageFrameDescriptor DDSImageDecoderPlugin::frame(size_t i)
+ErrorOr<ImageFrameDescriptor> DDSImageDecoderPlugin::frame(size_t index)
{
- if (i > 0)
- return {};
+ if (index > 0)
+ return Error::from_string_literal("DDSImageDecoderPlugin: Invalid frame index"sv);
if (m_context->state == DDSLoadingContext::State::Error)
- return {};
+ return Error::from_string_literal("DDSImageDecoderPlugin: Decoding failed"sv);
if (m_context->state < DDSLoadingContext::State::BitmapDecoded) {
bool success = decode_dds(*m_context);
if (!success)
- return {};
+ return Error::from_string_literal("DDSImageDecoderPlugin: Decoding failed"sv);
}
VERIFY(m_context->bitmap);
- return { m_context->bitmap, 0 };
+ return ImageFrameDescriptor { m_context->bitmap, 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/DDSLoader.h b/Userland/Libraries/LibGfx/DDSLoader.h
index 1ba87da25e..a313d7d3e2 100644
--- a/Userland/Libraries/LibGfx/DDSLoader.h
+++ b/Userland/Libraries/LibGfx/DDSLoader.h
@@ -245,7 +245,7 @@ public:
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
- virtual ImageFrameDescriptor frame(size_t i) override;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
private:
OwnPtr<DDSLoadingContext> m_context;
diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp
index 49f7a0b1c8..00892eb61a 100644
--- a/Userland/Libraries/LibGfx/GIFLoader.cpp
+++ b/Userland/Libraries/LibGfx/GIFLoader.cpp
@@ -691,36 +691,30 @@ size_t GIFImageDecoderPlugin::frame_count()
return m_context->images.size();
}
-ImageFrameDescriptor GIFImageDecoderPlugin::frame(size_t i)
+ErrorOr<ImageFrameDescriptor> GIFImageDecoderPlugin::frame(size_t index)
{
if (m_context->error_state >= GIFLoadingContext::ErrorState::FailedToDecodeAnyFrame) {
- return {};
+ return Error::from_string_literal("GIFImageDecoderPlugin: Decoding failed"sv);
}
if (m_context->state < GIFLoadingContext::State::FrameDescriptorsLoaded) {
if (!load_gif_frame_descriptors(*m_context)) {
m_context->error_state = GIFLoadingContext::ErrorState::FailedToLoadFrameDescriptors;
- return {};
+ return Error::from_string_literal("GIFImageDecoderPlugin: Decoding failed"sv);
}
}
- if (m_context->error_state == GIFLoadingContext::ErrorState::NoError && !decode_frame(*m_context, i)) {
+ if (m_context->error_state == GIFLoadingContext::ErrorState::NoError && !decode_frame(*m_context, index)) {
if (m_context->state < GIFLoadingContext::State::FrameComplete || !decode_frame(*m_context, 0)) {
m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAnyFrame;
- return {};
+ return Error::from_string_literal("GIFImageDecoderPlugin: Decoding failed"sv);
}
m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAllFrames;
}
- auto image_or_error = m_context->frame_buffer->clone();
- if (image_or_error.is_error()) {
- m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAllFrames;
- return {};
- }
-
ImageFrameDescriptor frame {};
- frame.image = image_or_error.release_value_but_fixme_should_propagate_errors();
- frame.duration = m_context->images.at(i).duration * 10;
+ frame.image = TRY(m_context->frame_buffer->clone());
+ frame.duration = m_context->images.at(index).duration * 10;
if (frame.duration <= 10) {
frame.duration = 100;
diff --git a/Userland/Libraries/LibGfx/GIFLoader.h b/Userland/Libraries/LibGfx/GIFLoader.h
index d3960cd8d0..e42de30106 100644
--- a/Userland/Libraries/LibGfx/GIFLoader.h
+++ b/Userland/Libraries/LibGfx/GIFLoader.h
@@ -25,7 +25,7 @@ public:
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
- virtual ImageFrameDescriptor frame(size_t i) override;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
private:
OwnPtr<GIFLoadingContext> m_context;
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 };
}
}
diff --git a/Userland/Libraries/LibGfx/ICOLoader.h b/Userland/Libraries/LibGfx/ICOLoader.h
index 0340b6249e..b99afcd662 100644
--- a/Userland/Libraries/LibGfx/ICOLoader.h
+++ b/Userland/Libraries/LibGfx/ICOLoader.h
@@ -24,7 +24,7 @@ public:
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
- virtual ImageFrameDescriptor frame(size_t i) override;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
private:
OwnPtr<ICOLoadingContext> m_context;
diff --git a/Userland/Libraries/LibGfx/ImageDecoder.h b/Userland/Libraries/LibGfx/ImageDecoder.h
index 7641402b99..62a164921d 100644
--- a/Userland/Libraries/LibGfx/ImageDecoder.h
+++ b/Userland/Libraries/LibGfx/ImageDecoder.h
@@ -39,7 +39,7 @@ public:
virtual bool is_animated() = 0;
virtual size_t loop_count() = 0;
virtual size_t frame_count() = 0;
- virtual ImageFrameDescriptor frame(size_t i) = 0;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) = 0;
protected:
ImageDecoderPlugin() { }
@@ -59,7 +59,7 @@ public:
bool is_animated() const { return m_plugin->is_animated(); }
size_t loop_count() const { return m_plugin->loop_count(); }
size_t frame_count() const { return m_plugin->frame_count(); }
- ImageFrameDescriptor frame(size_t i) const { return m_plugin->frame(i); }
+ ErrorOr<ImageFrameDescriptor> frame(size_t index) const { return m_plugin->frame(index); }
private:
explicit ImageDecoder(NonnullOwnPtr<ImageDecoderPlugin>);
diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp
index c32dac6cec..650684bf88 100644
--- a/Userland/Libraries/LibGfx/JPGLoader.cpp
+++ b/Userland/Libraries/LibGfx/JPGLoader.cpp
@@ -1276,23 +1276,23 @@ size_t JPGImageDecoderPlugin::frame_count()
return 1;
}
-ImageFrameDescriptor JPGImageDecoderPlugin::frame(size_t i)
+ErrorOr<ImageFrameDescriptor> JPGImageDecoderPlugin::frame(size_t index)
{
- if (i > 0)
- return {};
+ if (index > 0)
+ return Error::from_string_literal("JPGImageDecoderPlugin: Invalid frame index"sv);
if (m_context->state == JPGLoadingContext::State::Error)
- return {};
+ return Error::from_string_literal("JPGImageDecoderPlugin: Decoding failed"sv);
if (m_context->state < JPGLoadingContext::State::BitmapDecoded) {
if (!decode_jpg(*m_context)) {
m_context->state = JPGLoadingContext::State::Error;
- return {};
+ return Error::from_string_literal("JPGImageDecoderPlugin: Decoding failed"sv);
}
m_context->state = JPGLoadingContext::State::BitmapDecoded;
}
- return { m_context->bitmap, 0 };
+ return ImageFrameDescriptor { m_context->bitmap, 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/JPGLoader.h b/Userland/Libraries/LibGfx/JPGLoader.h
index 13573ea0ee..0813319177 100644
--- a/Userland/Libraries/LibGfx/JPGLoader.h
+++ b/Userland/Libraries/LibGfx/JPGLoader.h
@@ -23,7 +23,7 @@ public:
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
- virtual ImageFrameDescriptor frame(size_t i) override;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
private:
OwnPtr<JPGLoadingContext> m_context;
diff --git a/Userland/Libraries/LibGfx/PBMLoader.cpp b/Userland/Libraries/LibGfx/PBMLoader.cpp
index 4b2f45c8b3..8f2ff976b9 100644
--- a/Userland/Libraries/LibGfx/PBMLoader.cpp
+++ b/Userland/Libraries/LibGfx/PBMLoader.cpp
@@ -162,22 +162,22 @@ size_t PBMImageDecoderPlugin::frame_count()
return 1;
}
-ImageFrameDescriptor PBMImageDecoderPlugin::frame(size_t i)
+ErrorOr<ImageFrameDescriptor> PBMImageDecoderPlugin::frame(size_t index)
{
- if (i > 0)
- return {};
+ if (index > 0)
+ return Error::from_string_literal("PBMImageDecoderPlugin: Invalid frame index"sv);
if (m_context->state == PBMLoadingContext::State::Error)
- return {};
+ return Error::from_string_literal("PBMImageDecoderPlugin: Decoding failed"sv);
if (m_context->state < PBMLoadingContext::State::Decoded) {
bool success = decode(*m_context);
if (!success)
- return {};
+ return Error::from_string_literal("PBMImageDecoderPlugin: Decoding failed"sv);
}
VERIFY(m_context->bitmap);
- return { m_context->bitmap, 0 };
+ return ImageFrameDescriptor { m_context->bitmap, 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/PBMLoader.h b/Userland/Libraries/LibGfx/PBMLoader.h
index ce7c26558b..29e9da9310 100644
--- a/Userland/Libraries/LibGfx/PBMLoader.h
+++ b/Userland/Libraries/LibGfx/PBMLoader.h
@@ -27,7 +27,7 @@ public:
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
- virtual ImageFrameDescriptor frame(size_t i) override;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
private:
OwnPtr<PBMLoadingContext> m_context;
diff --git a/Userland/Libraries/LibGfx/PGMLoader.cpp b/Userland/Libraries/LibGfx/PGMLoader.cpp
index 837563e27b..9280f7f528 100644
--- a/Userland/Libraries/LibGfx/PGMLoader.cpp
+++ b/Userland/Libraries/LibGfx/PGMLoader.cpp
@@ -165,22 +165,22 @@ size_t PGMImageDecoderPlugin::frame_count()
return 1;
}
-ImageFrameDescriptor PGMImageDecoderPlugin::frame(size_t i)
+ErrorOr<ImageFrameDescriptor> PGMImageDecoderPlugin::frame(size_t index)
{
- if (i > 0)
- return {};
+ if (index > 0)
+ return Error::from_string_literal("PGMImageDecoderPlugin: Invalid frame index"sv);
if (m_context->state == PGMLoadingContext::State::Error)
- return {};
+ return Error::from_string_literal("PGMImageDecoderPlugin: Decoding failed"sv);
if (m_context->state < PGMLoadingContext::State::Decoded) {
bool success = decode(*m_context);
if (!success)
- return {};
+ return Error::from_string_literal("PGMImageDecoderPlugin: Decoding failed"sv);
}
VERIFY(m_context->bitmap);
- return { m_context->bitmap, 0 };
+ return ImageFrameDescriptor { m_context->bitmap, 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/PGMLoader.h b/Userland/Libraries/LibGfx/PGMLoader.h
index f3190ef709..ad97aa8085 100644
--- a/Userland/Libraries/LibGfx/PGMLoader.h
+++ b/Userland/Libraries/LibGfx/PGMLoader.h
@@ -27,7 +27,7 @@ public:
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
- virtual ImageFrameDescriptor frame(size_t i) override;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
private:
OwnPtr<PGMLoadingContext> m_context;
diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp
index 13220dfe53..eb0557f3ba 100644
--- a/Userland/Libraries/LibGfx/PNGLoader.cpp
+++ b/Userland/Libraries/LibGfx/PNGLoader.cpp
@@ -964,23 +964,23 @@ size_t PNGImageDecoderPlugin::frame_count()
return 1;
}
-ImageFrameDescriptor PNGImageDecoderPlugin::frame(size_t i)
+ErrorOr<ImageFrameDescriptor> PNGImageDecoderPlugin::frame(size_t index)
{
- if (i > 0)
- return {};
+ if (index > 0)
+ return Error::from_string_literal("PNGImageDecoderPlugin: Invalid frame index"sv);
if (m_context->state == PNGLoadingContext::State::Error)
- return {};
+ return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed"sv);
if (m_context->state < PNGLoadingContext::State::BitmapDecoded) {
// NOTE: This forces the chunk decoding to happen.
bool success = decode_png_bitmap(*m_context);
if (!success)
- return {};
+ return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed"sv);
}
VERIFY(m_context->bitmap);
- return { m_context->bitmap, 0 };
+ return ImageFrameDescriptor { m_context->bitmap, 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/PNGLoader.h b/Userland/Libraries/LibGfx/PNGLoader.h
index 77c4b19c3d..9f7c0e7b6c 100644
--- a/Userland/Libraries/LibGfx/PNGLoader.h
+++ b/Userland/Libraries/LibGfx/PNGLoader.h
@@ -24,7 +24,7 @@ public:
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
- virtual ImageFrameDescriptor frame(size_t i) override;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
private:
OwnPtr<PNGLoadingContext> m_context;
diff --git a/Userland/Libraries/LibGfx/PPMLoader.cpp b/Userland/Libraries/LibGfx/PPMLoader.cpp
index 5316c27ab0..c05789f344 100644
--- a/Userland/Libraries/LibGfx/PPMLoader.cpp
+++ b/Userland/Libraries/LibGfx/PPMLoader.cpp
@@ -169,22 +169,22 @@ size_t PPMImageDecoderPlugin::frame_count()
return 1;
}
-ImageFrameDescriptor PPMImageDecoderPlugin::frame(size_t i)
+ErrorOr<ImageFrameDescriptor> PPMImageDecoderPlugin::frame(size_t index)
{
- if (i > 0)
- return {};
+ if (index > 0)
+ return Error::from_string_literal("PPMImageDecoderPlugin: Invalid frame index"sv);
if (m_context->state == PPMLoadingContext::State::Error)
- return {};
+ return Error::from_string_literal("PGMImageDecoderPlugin: Decoding failed"sv);
if (m_context->state < PPMLoadingContext::State::Decoded) {
bool success = decode(*m_context);
if (!success)
- return {};
+ return Error::from_string_literal("PGMImageDecoderPlugin: Decoding failed"sv);
}
VERIFY(m_context->bitmap);
- return { m_context->bitmap, 0 };
+ return ImageFrameDescriptor { m_context->bitmap, 0 };
}
}
diff --git a/Userland/Libraries/LibGfx/PPMLoader.h b/Userland/Libraries/LibGfx/PPMLoader.h
index 0a9b876fba..19dc9e7ed8 100644
--- a/Userland/Libraries/LibGfx/PPMLoader.h
+++ b/Userland/Libraries/LibGfx/PPMLoader.h
@@ -27,7 +27,7 @@ public:
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
- virtual ImageFrameDescriptor frame(size_t i) override;
+ virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
private:
OwnPtr<PPMLoadingContext> m_context;
diff --git a/Userland/Services/ImageDecoder/ClientConnection.cpp b/Userland/Services/ImageDecoder/ClientConnection.cpp
index 3469a4ac83..d180433380 100644
--- a/Userland/Services/ImageDecoder/ClientConnection.cpp
+++ b/Userland/Services/ImageDecoder/ClientConnection.cpp
@@ -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 };
diff --git a/Userland/Services/SpiceAgent/SpiceAgent.cpp b/Userland/Services/SpiceAgent/SpiceAgent.cpp
index ce158cb31b..5d7f362c6a 100644
--- a/Userland/Services/SpiceAgent/SpiceAgent.cpp
+++ b/Userland/Services/SpiceAgent/SpiceAgent.cpp
@@ -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;