diff options
author | Itamar <itamar8910@gmail.com> | 2022-02-25 12:18:30 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-25 22:35:12 +0100 |
commit | 3a71748e5d16a244c21aaf28ca3c4220c47f484e (patch) | |
tree | ea2751b9752bf299a2b3e3cdd613c7f8a36b7db1 /Userland/Services/ImageDecoder/ConnectionFromClient.cpp | |
parent | efac8625703e9b059af0f32422d0d274f99ae475 (diff) | |
download | serenity-3a71748e5d16a244c21aaf28ca3c4220c47f484e.zip |
Userland: Rename IPC ClientConnection => ConnectionFromClient
This was done with CLion's automatic rename feature and with:
find . -name ClientConnection.h
| rename 's/ClientConnection\.h/ConnectionFromClient.h/'
find . -name ClientConnection.cpp
| rename 's/ClientConnection\.cpp/ConnectionFromClient.cpp/'
Diffstat (limited to 'Userland/Services/ImageDecoder/ConnectionFromClient.cpp')
-rw-r--r-- | Userland/Services/ImageDecoder/ConnectionFromClient.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Userland/Services/ImageDecoder/ConnectionFromClient.cpp b/Userland/Services/ImageDecoder/ConnectionFromClient.cpp new file mode 100644 index 0000000000..6911b3c0a7 --- /dev/null +++ b/Userland/Services/ImageDecoder/ConnectionFromClient.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/Debug.h> +#include <ImageDecoder/ConnectionFromClient.h> +#include <ImageDecoder/ImageDecoderClientEndpoint.h> +#include <LibGfx/Bitmap.h> +#include <LibGfx/ImageDecoder.h> + +namespace ImageDecoder { + +ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket) + : IPC::ConnectionFromClient<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint>(*this, move(socket), 1) +{ +} + +ConnectionFromClient::~ConnectionFromClient() +{ +} + +void ConnectionFromClient::die() +{ + Core::EventLoop::current().quit(0); +} + +Messages::ImageDecoderServer::DecodeImageResponse ConnectionFromClient::decode_image(Core::AnonymousBuffer const& encoded_buffer) +{ + if (!encoded_buffer.is_valid()) { + dbgln_if(IMAGE_DECODER_DEBUG, "Encoded data is invalid"); + return nullptr; + } + + auto decoder = Gfx::ImageDecoder::try_create(ReadonlyBytes { encoded_buffer.data<u8>(), encoded_buffer.size() }); + + if (!decoder) { + dbgln_if(IMAGE_DECODER_DEBUG, "Could not find suitable image decoder plugin for data"); + return { false, 0, Vector<Gfx::ShareableBitmap> {}, Vector<u32> {} }; + } + + if (!decoder->frame_count()) { + dbgln_if(IMAGE_DECODER_DEBUG, "Could not decode image from encoded data"); + return { false, 0, Vector<Gfx::ShareableBitmap> {}, Vector<u32> {} }; + } + + Vector<Gfx::ShareableBitmap> bitmaps; + Vector<u32> durations; + for (size_t i = 0; i < decoder->frame_count(); ++i) { + auto frame_or_error = decoder->frame(i); + if (frame_or_error.is_error()) { + bitmaps.append(Gfx::ShareableBitmap {}); + durations.append(0); + } else { + auto frame = frame_or_error.release_value(); + bitmaps.append(frame.image->to_shareable_bitmap()); + durations.append(frame.duration); + } + } + + return { decoder->is_animated(), static_cast<u32>(decoder->loop_count()), bitmaps, durations }; +} + +} |