From d17e8d1654f5895a05e3d68f36b14946eafffb39 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 6 Dec 2023 19:58:34 -0500 Subject: [PATCH] LibGfx/ICC: Plumb mBA conversion from profile to tag data It's still implemented on the tag data side, so no real behavior change. --- Userland/Libraries/LibGfx/ICC/Profile.cpp | 15 +++++++++++---- Userland/Libraries/LibGfx/ICC/TagTypes.h | 12 ++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGfx/ICC/Profile.cpp b/Userland/Libraries/LibGfx/ICC/Profile.cpp index f96ba6067c..9d51d404ef 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.cpp +++ b/Userland/Libraries/LibGfx/ICC/Profile.cpp @@ -1416,7 +1416,7 @@ static TagSignature backward_transform_tag_for_rendering_intent(RenderingIntent VERIFY_NOT_REACHED(); } -ErrorOr Profile::from_pcs_b_to_a(TagData const& tag_data, FloatVector3 const&, Bytes) const +ErrorOr Profile::from_pcs_b_to_a(TagData const& tag_data, FloatVector3 const& pcs, Bytes out_bytes) const { switch (tag_data.type()) { case Lut16TagData::Type: @@ -1425,9 +1425,16 @@ ErrorOr Profile::from_pcs_b_to_a(TagData const& tag_data, FloatVector3 con case Lut8TagData::Type: // FIXME return Error::from_string_literal("ICC::Profile::to_pcs: BToA*Tag handling for mft1 tags not yet implemented"); - case LutBToATagData::Type: - // FIXME - return Error::from_string_literal("ICC::Profile::to_pcs: BToA*Tag handling for mBA tags not yet implemented"); + case LutBToATagData::Type: { + auto const& b_to_a = static_cast(tag_data); + if (b_to_a.number_of_input_channels() != number_of_components_in_color_space(connection_space())) + return Error::from_string_literal("ICC::Profile::from_pcs_b_to_a: mBA input channel count does not match color space size"); + + if (b_to_a.number_of_output_channels() != number_of_components_in_color_space(data_color_space())) + return Error::from_string_literal("ICC::Profile::from_pcs_b_to_a: mBA output channel count does not match profile connection space size"); + + return b_to_a.evaluate(connection_space(), pcs, out_bytes); + } } VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.h b/Userland/Libraries/LibGfx/ICC/TagTypes.h index 2e9cbf7e78..6ac231195a 100644 --- a/Userland/Libraries/LibGfx/ICC/TagTypes.h +++ b/Userland/Libraries/LibGfx/ICC/TagTypes.h @@ -519,6 +519,9 @@ public: Optional const& clut() const { return m_clut; } Optional> const& a_curves() const { return m_a_curves; } + // Returns the result of the LUT pipeline for u8 outputs. + ErrorOr evaluate(ColorSpace connection_space, FloatVector3 const&, Bytes) const; + private: u8 m_number_of_input_channels; u8 m_number_of_output_channels; @@ -1300,6 +1303,15 @@ inline ErrorOr LutAToBTagData::evaluate(ColorSpace connection_spac return output_color; } +inline ErrorOr LutBToATagData::evaluate(ColorSpace connection_space, FloatVector3 const&, Bytes out_bytes) const +{ + VERIFY(connection_space == ColorSpace::PCSXYZ || connection_space == ColorSpace::PCSLAB); + VERIFY(number_of_input_channels() == 3); + VERIFY(number_of_output_channels() == out_bytes.size()); + + return Error::from_string_literal("LutBToATagData::evaluate: Not yet implemented"); +} + } template<>