diff options
author | Nico Weber <thakis@chromium.org> | 2023-02-17 22:24:51 -0500 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2023-02-19 08:12:04 +0000 |
commit | 2504f2035c20e01f2cf6d75d6dc0b278a5f91671 (patch) | |
tree | 3baed94b55de1a84c32a6eb807dc0b560e9bb011 | |
parent | 933002ae5aa868ab1cfb422e7f6310a03408e346 (diff) | |
download | serenity-2504f2035c20e01f2cf6d75d6dc0b278a5f91671.zip |
LibGfx: Implement serialization of ViewingConditionsTagData
-rw-r--r-- | Userland/Libraries/LibGfx/ICC/BinaryWriter.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/ICC/BinaryWriter.cpp b/Userland/Libraries/LibGfx/ICC/BinaryWriter.cpp index d08b89d381..6af21719d5 100644 --- a/Userland/Libraries/LibGfx/ICC/BinaryWriter.cpp +++ b/Userland/Libraries/LibGfx/ICC/BinaryWriter.cpp @@ -180,6 +180,21 @@ static ErrorOr<ByteBuffer> encode_text(TextTagData const& tag_data) return bytes; } +static ErrorOr<ByteBuffer> encode_viewing_conditions(ViewingConditionsTagData const& tag_data) +{ + // ICC v4, 10.30 viewingConditionsType + auto bytes = TRY(ByteBuffer::create_uninitialized(2 * sizeof(u32) + sizeof(ViewingConditionsHeader))); + *bit_cast<BigEndian<u32>*>(bytes.data()) = (u32)ViewingConditionsTagData::Type; + *bit_cast<BigEndian<u32>*>(bytes.data() + 4) = 0; + + auto& header = *bit_cast<ViewingConditionsHeader*>(bytes.data() + 8); + header.unnormalized_ciexyz_values_for_illuminant = tag_data.unnormalized_ciexyz_values_for_illuminant(); + header.unnormalized_ciexyz_values_for_surround = tag_data.unnormalized_ciexyz_values_for_surround(); + header.illuminant_type = tag_data.illuminant_type(); + + return bytes; +} + static ErrorOr<ByteBuffer> encode_xyz(XYZTagData const& tag_data) { // ICC v4, 10.31 XYZType @@ -215,6 +230,8 @@ static ErrorOr<ByteBuffer> encode_tag_data(TagData const& tag_data) return encode_signature(static_cast<SignatureTagData const&>(tag_data)); case TextTagData::Type: return encode_text(static_cast<TextTagData const&>(tag_data)); + case ViewingConditionsTagData::Type: + return encode_viewing_conditions(static_cast<ViewingConditionsTagData const&>(tag_data)); case XYZTagData::Type: return encode_xyz(static_cast<XYZTagData const&>(tag_data)); } |