2020-06-22 21:35:22 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
2020-06-22 21:35:22 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-22 21:35:22 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
|
#include <ImageDecoder/ImageDecoderClientEndpoint.h>
|
|
|
|
|
#include <ImageDecoder/ImageDecoderServerEndpoint.h>
|
2024-04-19 14:23:16 -06:00
|
|
|
#include <LibCore/Promise.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 18:55:43 -05:00
|
|
|
#include <LibGfx/ColorSpace.h>
|
2022-02-25 12:27:37 +02:00
|
|
|
#include <LibIPC/ConnectionToServer.h>
|
2020-06-22 21:35:22 +02:00
|
|
|
|
|
|
|
|
namespace ImageDecoderClient {
|
|
|
|
|
|
2021-01-29 22:30:48 +01:00
|
|
|
struct Frame {
|
2023-10-01 19:56:19 +01:00
|
|
|
NonnullRefPtr<Gfx::Bitmap> bitmap;
|
2021-01-29 22:30:48 +01:00
|
|
|
u32 duration { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct DecodedImage {
|
|
|
|
|
bool is_animated { false };
|
2024-02-14 01:15:06 -05:00
|
|
|
Gfx::FloatPoint scale { 1, 1 };
|
2021-01-29 22:30:48 +01:00
|
|
|
u32 loop_count { 0 };
|
2026-02-13 15:03:45 +01:00
|
|
|
u32 frame_count { 0 };
|
2021-01-29 22:30:48 +01:00
|
|
|
Vector<Frame> frames;
|
2026-02-13 15:03:45 +01:00
|
|
|
Vector<u32> all_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 18:55:43 -05:00
|
|
|
Gfx::ColorSpace color_space;
|
2026-02-13 15:03:45 +01:00
|
|
|
i64 session_id { 0 };
|
2021-01-29 22:30:48 +01:00
|
|
|
};
|
|
|
|
|
|
2021-02-20 11:35:00 +01:00
|
|
|
class Client final
|
2022-02-25 12:27:37 +02:00
|
|
|
: public IPC::ConnectionToServer<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint>
|
2020-06-22 21:35:22 +02:00
|
|
|
, public ImageDecoderClientEndpoint {
|
2024-11-21 12:46:45 -07:00
|
|
|
C_OBJECT_ABSTRACT(Client);
|
2020-06-22 21:35:22 +02:00
|
|
|
|
|
|
|
|
public:
|
2025-01-03 21:19:46 +05:00
|
|
|
using InitTransport = Messages::ImageDecoderServer::InitTransport;
|
|
|
|
|
|
2025-04-08 22:01:46 +02:00
|
|
|
Client(NonnullOwnPtr<IPC::Transport>);
|
2023-09-08 06:30:50 -04:00
|
|
|
|
2024-04-19 14:23:16 -06:00
|
|
|
NonnullRefPtr<Core::Promise<DecodedImage>> decode_image(ReadonlyBytes, Function<ErrorOr<void>(DecodedImage&)> on_resolved, Function<void(Error&)> on_rejected, Optional<Gfx::IntSize> ideal_size = {}, Optional<ByteString> mime_type = {});
|
|
|
|
|
|
2026-02-13 15:03:45 +01:00
|
|
|
void request_animation_frames(i64 session_id, u32 start_frame_index, u32 count);
|
|
|
|
|
void stop_animation_decode(i64 session_id);
|
|
|
|
|
|
2021-02-20 11:35:00 +01:00
|
|
|
Function<void()> on_death;
|
2026-02-13 15:03:45 +01:00
|
|
|
Function<void(i64 session_id, Vector<NonnullRefPtr<Gfx::Bitmap>>)> on_animation_frames_decoded;
|
|
|
|
|
Function<void(i64 session_id, String error_message)> on_animation_decode_failed;
|
2021-02-20 11:35:00 +01:00
|
|
|
|
2020-06-22 21:35:22 +02:00
|
|
|
private:
|
2021-02-20 11:35:00 +01:00
|
|
|
virtual void die() override;
|
2024-04-19 14:23:16 -06:00
|
|
|
|
2026-02-13 15:03:45 +01:00
|
|
|
virtual void did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Gfx::BitmapSequence bitmap_sequence, Vector<u32> durations, Gfx::FloatPoint scale, Gfx::ColorSpace color_space, i64 session_id) override;
|
2025-03-08 12:22:39 -05:00
|
|
|
virtual void did_fail_to_decode_image(i64 image_id, String error_message) override;
|
2024-04-19 14:23:16 -06:00
|
|
|
|
2026-02-13 15:03:45 +01:00
|
|
|
virtual void did_decode_animation_frames(i64 session_id, Gfx::BitmapSequence bitmaps) override;
|
|
|
|
|
virtual void did_fail_animation_decode(i64 session_id, String error_message) override;
|
|
|
|
|
|
2024-04-19 14:23:16 -06:00
|
|
|
HashMap<i64, NonnullRefPtr<Core::Promise<DecodedImage>>> m_pending_decoded_images;
|
2020-06-22 21:35:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|