2020-06-22 16:35:22 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2020-06-22 16:35:22 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-22 16:35:22 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2026-06-04 19:47:10 -03:00
|
|
|
#include <AK/Atomic.h>
|
|
|
|
|
#include <AK/AtomicRefCounted.h>
|
2020-06-22 16:35:22 -03:00
|
|
|
#include <AK/HashMap.h>
|
|
|
|
|
#include <ImageDecoder/Forward.h>
|
2020-09-12 06:44:00 -03:00
|
|
|
#include <ImageDecoder/ImageDecoderClientEndpoint.h>
|
2020-06-22 16:35:22 -03:00
|
|
|
#include <ImageDecoder/ImageDecoderServerEndpoint.h>
|
2026-02-13 11:03:35 -03:00
|
|
|
#include <LibCore/AnonymousBuffer.h>
|
2024-09-18 18:37:44 -03:00
|
|
|
#include <LibGfx/BitmapSequence.h>
|
LibGfx+LibWeb: Do some color management on images with an ICC profile
This patch introduces the `Gfx::ColorSpace` class, this is basically a
serializable wrapper for skia's SkColorSpace. Creation of the instances
of this class (and thus ICC profiles parsing) is performed in the
ImageDecoder process. Then the object is serialized and sent through
IPC, to finally be handed to skia for rendering.
However, to make sure that we're not making all LibGfx's users dependent
on Skia as well, we need to ensure the `Gfx::ColorSpace` object has no
dependency on objects from Skia. To that end, the only member of the
`ColorSpace` class is the opaque `ColorSpaceImpl` struct. Though, there
is on issue with that design, the code in `DisplayListPlayer.cpp` needs
access to the underlying `sk_sp<SkColorSpace>`. It is provided by a
template function, that is only specialized for this type.
Doing this work allows us to pass the following WPT tests:
- https://wpt.live/css/css-color/tagged-images-001.html
- https://wpt.live/css/css-color/tagged-images-003.html
- https://wpt.live/css/css-color/tagged-images-004.html
- https://wpt.live/css/css-color/untagged-images-001.html
Other test cases can also be found here:
- https://github.com/svgeesus/PNG-ICC-tests
Note that SkColorSpace support quite a limited amount of color spaces,
so color profiles like the ones in [1] or the v4 profiles in [2] are not
supported yet. In fact, SkColorSpace only accepts skcms_ICCProfile with
a linear conversion to XYZ D50.
[1] https://www.color.org/browsertest.xalter
[2] https://www.color.org/version4html.xalter
2024-12-02 20:55:43 -03:00
|
|
|
#include <LibGfx/ColorSpace.h>
|
2026-02-13 11:03:35 -03:00
|
|
|
#include <LibGfx/ImageFormats/ImageDecoder.h>
|
2022-02-25 07:18:30 -03:00
|
|
|
#include <LibIPC/ConnectionFromClient.h>
|
2026-06-04 19:47:10 -03:00
|
|
|
#include <LibSync/Mutex.h>
|
2020-06-22 16:35:22 -03:00
|
|
|
|
|
|
|
|
namespace ImageDecoder {
|
|
|
|
|
|
2022-02-25 07:18:30 -03:00
|
|
|
class ConnectionFromClient final
|
|
|
|
|
: public IPC::ConnectionFromClient<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint> {
|
|
|
|
|
C_OBJECT(ConnectionFromClient);
|
2020-06-22 16:35:22 -03:00
|
|
|
|
|
|
|
|
public:
|
2022-03-23 23:58:03 -03:00
|
|
|
~ConnectionFromClient() override = default;
|
2020-06-22 16:35:22 -03:00
|
|
|
|
|
|
|
|
virtual void die() override;
|
|
|
|
|
|
2024-04-23 21:58:52 -03:00
|
|
|
struct DecodeResult {
|
|
|
|
|
bool is_animated = false;
|
|
|
|
|
u32 loop_count = 0;
|
2026-02-13 11:03:35 -03:00
|
|
|
u32 frame_count = 0;
|
2024-04-23 21:58:52 -03:00
|
|
|
Gfx::FloatPoint scale { 1, 1 };
|
2024-09-18 18:37:44 -03:00
|
|
|
Gfx::BitmapSequence bitmaps;
|
2024-04-23 21:58:52 -03:00
|
|
|
Vector<u32> durations;
|
LibGfx+LibWeb: Do some color management on images with an ICC profile
This patch introduces the `Gfx::ColorSpace` class, this is basically a
serializable wrapper for skia's SkColorSpace. Creation of the instances
of this class (and thus ICC profiles parsing) is performed in the
ImageDecoder process. Then the object is serialized and sent through
IPC, to finally be handed to skia for rendering.
However, to make sure that we're not making all LibGfx's users dependent
on Skia as well, we need to ensure the `Gfx::ColorSpace` object has no
dependency on objects from Skia. To that end, the only member of the
`ColorSpace` class is the opaque `ColorSpaceImpl` struct. Though, there
is on issue with that design, the code in `DisplayListPlayer.cpp` needs
access to the underlying `sk_sp<SkColorSpace>`. It is provided by a
template function, that is only specialized for this type.
Doing this work allows us to pass the following WPT tests:
- https://wpt.live/css/css-color/tagged-images-001.html
- https://wpt.live/css/css-color/tagged-images-003.html
- https://wpt.live/css/css-color/tagged-images-004.html
- https://wpt.live/css/css-color/untagged-images-001.html
Other test cases can also be found here:
- https://github.com/svgeesus/PNG-ICC-tests
Note that SkColorSpace support quite a limited amount of color spaces,
so color profiles like the ones in [1] or the v4 profiles in [2] are not
supported yet. In fact, SkColorSpace only accepts skcms_ICCProfile with
a linear conversion to XYZ D50.
[1] https://www.color.org/browsertest.xalter
[2] https://www.color.org/version4html.xalter
2024-12-02 20:55:43 -03:00
|
|
|
Gfx::ColorSpace color_profile;
|
2026-02-13 11:03:35 -03:00
|
|
|
|
|
|
|
|
// Non-null for streaming animated sessions:
|
|
|
|
|
RefPtr<Gfx::ImageDecoder> decoder;
|
|
|
|
|
Core::AnonymousBuffer encoded_data;
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-04 19:47:10 -03:00
|
|
|
struct AnimationSession : public AtomicRefCounted<AnimationSession> {
|
2026-02-13 11:03:35 -03:00
|
|
|
Core::AnonymousBuffer encoded_data;
|
|
|
|
|
RefPtr<Gfx::ImageDecoder> decoder;
|
|
|
|
|
u32 frame_count { 0 };
|
2026-06-04 19:47:10 -03:00
|
|
|
Sync::Mutex decoder_mutex;
|
2024-04-23 21:58:52 -03:00
|
|
|
};
|
|
|
|
|
|
2020-06-22 16:35:22 -03:00
|
|
|
private:
|
2026-06-04 19:47:10 -03:00
|
|
|
struct PendingJob : public AtomicRefCounted<PendingJob> {
|
|
|
|
|
void cancel() { m_canceled.store(true, AK::MemoryOrder::memory_order_relaxed); }
|
|
|
|
|
bool is_canceled() const { return m_canceled.load(AK::MemoryOrder::memory_order_relaxed); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Atomic<bool> m_canceled { false };
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-13 11:03:35 -03:00
|
|
|
using FrameDecodeResult = Vector<Gfx::ImageFrameDescriptor>;
|
2024-04-19 17:23:16 -03:00
|
|
|
|
2025-04-08 17:01:46 -03:00
|
|
|
explicit ConnectionFromClient(NonnullOwnPtr<IPC::Transport>);
|
2021-10-31 19:38:04 -03:00
|
|
|
|
2026-02-21 17:48:14 -03:00
|
|
|
virtual void decode_image(Core::AnonymousBuffer, Optional<Gfx::IntSize> ideal_size, Optional<ByteString> mime_type, i64 request_id) override;
|
|
|
|
|
virtual void cancel_decoding(i64 request_id) override;
|
2026-02-13 11:03:35 -03:00
|
|
|
virtual void request_animation_frames(i64 session_id, u32 start_frame_index, u32 count) override;
|
|
|
|
|
virtual void stop_animation_decode(i64 session_id) override;
|
2024-06-26 16:44:42 -03:00
|
|
|
virtual Messages::ImageDecoderServer::ConnectNewClientsResponse connect_new_clients(size_t count) override;
|
2025-01-03 13:19:46 -03:00
|
|
|
virtual Messages::ImageDecoderServer::InitTransportResponse init_transport(int peer_pid) override;
|
2024-06-26 16:44:42 -03:00
|
|
|
|
2026-03-11 16:10:08 -03:00
|
|
|
ErrorOr<IPC::TransportHandle> connect_new_client();
|
2024-04-19 17:23:16 -03:00
|
|
|
|
2026-06-04 19:47:10 -03:00
|
|
|
NonnullRefPtr<PendingJob> start_decode_image_job(i64 request_id, Core::AnonymousBuffer, Optional<Gfx::IntSize> ideal_size, Optional<ByteString> mime_type);
|
|
|
|
|
NonnullRefPtr<PendingJob> start_frame_decode_job(i64 session_id, NonnullRefPtr<AnimationSession>, u32 start_frame_index, u32 end_index);
|
2024-04-19 17:23:16 -03:00
|
|
|
|
2026-02-13 11:03:35 -03:00
|
|
|
i64 m_next_session_id { 1 };
|
2026-06-04 19:47:10 -03:00
|
|
|
HashMap<i64, NonnullRefPtr<PendingJob>> m_pending_jobs;
|
|
|
|
|
HashMap<i64, NonnullRefPtr<AnimationSession>> m_animation_sessions;
|
|
|
|
|
HashMap<i64, NonnullRefPtr<PendingJob>> m_pending_frame_jobs;
|
2020-06-22 16:35:22 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|