2020-06-22 19:35:22 +00:00
|
|
|
/*
|
2021-01-31 08:24:46 +00:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-06-22 19:35:22 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-22 19:35:22 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-16 22:58:57 +00:00
|
|
|
#include <LibCore/AnonymousBuffer.h>
|
2020-06-22 19:35:22 +00:00
|
|
|
#include <LibImageDecoderClient/Client.h>
|
|
|
|
|
|
|
|
namespace ImageDecoderClient {
|
|
|
|
|
|
|
|
Client::Client()
|
|
|
|
: IPC::ServerConnection<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint>(*this, "/tmp/portal/image")
|
|
|
|
{
|
|
|
|
handshake();
|
|
|
|
}
|
|
|
|
|
2021-02-20 10:35:00 +00:00
|
|
|
void Client::die()
|
|
|
|
{
|
|
|
|
if (on_death)
|
|
|
|
on_death();
|
|
|
|
}
|
|
|
|
|
2020-06-22 19:35:22 +00:00
|
|
|
void Client::handshake()
|
|
|
|
{
|
2021-05-03 11:33:59 +00:00
|
|
|
greet();
|
2020-06-22 19:35:22 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 17:54:34 +00:00
|
|
|
void Client::dummy()
|
2020-06-22 19:35:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-01-29 21:30:48 +00:00
|
|
|
Optional<DecodedImage> Client::decode_image(const ByteBuffer& encoded_data)
|
2020-06-22 19:35:22 +00:00
|
|
|
{
|
|
|
|
if (encoded_data.is_empty())
|
2021-01-29 21:30:48 +00:00
|
|
|
return {};
|
2020-06-22 19:35:22 +00:00
|
|
|
|
2021-01-16 22:58:57 +00:00
|
|
|
auto encoded_buffer = Core::AnonymousBuffer::create_with_size(encoded_data.size());
|
|
|
|
if (!encoded_buffer.is_valid()) {
|
|
|
|
dbgln("Could not allocate encoded buffer");
|
2021-01-29 21:30:48 +00:00
|
|
|
return {};
|
2020-06-22 19:35:22 +00:00
|
|
|
}
|
|
|
|
|
2021-01-16 22:58:57 +00:00
|
|
|
memcpy(encoded_buffer.data<void>(), encoded_data.data(), encoded_data.size());
|
2021-02-20 10:33:34 +00:00
|
|
|
auto response = send_sync_but_allow_failure<Messages::ImageDecoderServer::DecodeImage>(move(encoded_buffer));
|
|
|
|
|
|
|
|
if (!response) {
|
|
|
|
dbgln("ImageDecoder died heroically");
|
|
|
|
return {};
|
|
|
|
}
|
2021-01-29 21:30:48 +00:00
|
|
|
|
|
|
|
DecodedImage image;
|
|
|
|
image.is_animated = response->is_animated();
|
|
|
|
image.loop_count = response->loop_count();
|
|
|
|
image.frames.resize(response->bitmaps().size());
|
|
|
|
for (size_t i = 0; i < image.frames.size(); ++i) {
|
|
|
|
auto& frame = image.frames[i];
|
|
|
|
frame.bitmap = response->bitmaps()[i].bitmap();
|
|
|
|
frame.duration = response->durations()[i];
|
|
|
|
}
|
2021-03-17 15:30:02 +00:00
|
|
|
return image;
|
2020-06-22 19:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|