mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
LibGfx: Allow ImageDecoders to expose their color space through CICP
This introduces a new API in ImageDecoderPlugins that allow an image decoder to return a CICP struct. Also, we use this API in ImageDecoder::color_space() to create a color space corresponding to these CICP.
This commit is contained in:
parent
2e3bd988ef
commit
cffc8678d8
Notes:
github-actions[bot]
2025-02-12 17:26:15 +00:00
Author: https://github.com/LucasChollet
Commit: cffc8678d8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3502
Reviewed-by: https://github.com/trflynn89
4 changed files with 36 additions and 0 deletions
|
@ -47,6 +47,34 @@ ColorSpace::ColorSpace(NonnullOwnPtr<Details::ColorSpaceImpl>&& color_space)
|
|||
{
|
||||
}
|
||||
|
||||
ErrorOr<ColorSpace> ColorSpace::from_cicp(Media::CodingIndependentCodePoints cicp)
|
||||
{
|
||||
// FIXME: Bail on invalid input
|
||||
|
||||
skcms_Matrix3x3 gamut = SkNamedGamut::kSRGB;
|
||||
switch (cicp.color_primaries()) {
|
||||
case Media::ColorPrimaries::BT709:
|
||||
gamut = SkNamedGamut::kSRGB;
|
||||
break;
|
||||
case Media::ColorPrimaries::SMPTE432:
|
||||
gamut = SkNamedGamut::kDisplayP3;
|
||||
break;
|
||||
default:
|
||||
return Error::from_string_literal("FIXME: Unsupported color primaries");
|
||||
}
|
||||
|
||||
skcms_TransferFunction transfer_function = SkNamedTransferFn::kSRGB;
|
||||
switch (cicp.transfer_characteristics()) {
|
||||
case Media::TransferCharacteristics::SRGB:
|
||||
transfer_function = SkNamedTransferFn::kSRGB;
|
||||
break;
|
||||
default:
|
||||
return Error::from_string_literal("FIXME: Unsupported transfer function");
|
||||
}
|
||||
|
||||
return ColorSpace { make<Details::ColorSpaceImpl>(SkColorSpace::MakeRGB(transfer_function, gamut)) };
|
||||
}
|
||||
|
||||
ErrorOr<ColorSpace> ColorSpace::load_from_icc_bytes(ReadonlyBytes icc_bytes)
|
||||
{
|
||||
if (icc_bytes.size() != 0) {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <AK/Noncopyable.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
#include <LibMedia/Color/CodingIndependentCodePoints.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
|
@ -28,6 +29,7 @@ public:
|
|||
ColorSpace& operator=(ColorSpace&&);
|
||||
~ColorSpace();
|
||||
|
||||
static ErrorOr<ColorSpace> from_cicp(Media::CodingIndependentCodePoints);
|
||||
static ErrorOr<ColorSpace> load_from_icc_bytes(ReadonlyBytes);
|
||||
|
||||
// In order to keep this file free of Skia types, this function can't return
|
||||
|
|
|
@ -49,6 +49,10 @@ static ErrorOr<OwnPtr<ImageDecoderPlugin>> probe_and_sniff_for_appropriate_plugi
|
|||
|
||||
ErrorOr<ColorSpace> ImageDecoder::color_space()
|
||||
{
|
||||
auto maybe_cicp = TRY(m_plugin->cicp());
|
||||
if (maybe_cicp.has_value())
|
||||
return ColorSpace::from_cicp(*maybe_cicp);
|
||||
|
||||
auto maybe_icc_data = TRY(icc_data());
|
||||
if (!maybe_icc_data.has_value())
|
||||
return ColorSpace {};
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <LibGfx/ColorSpace.h>
|
||||
#include <LibGfx/Size.h>
|
||||
#include <LibGfx/VectorGraphic.h>
|
||||
#include <LibMedia/Color/CodingIndependentCodePoints.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
|
@ -86,6 +87,7 @@ public:
|
|||
|
||||
virtual Optional<Metadata const&> metadata() { return OptionalNone {}; }
|
||||
|
||||
virtual ErrorOr<Optional<Media::CodingIndependentCodePoints>> cicp() { return OptionalNone {}; }
|
||||
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() { return OptionalNone {}; }
|
||||
|
||||
virtual NaturalFrameFormat natural_frame_format() const { return NaturalFrameFormat::RGB; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue