mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibGfx: Implement serialization of ChromaticityTagData
This commit is contained in:
parent
ececea9a1c
commit
fd590fe55d
Notes:
sideshowbarker
2024-07-17 17:38:29 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/fd590fe55d Pull-request: https://github.com/SerenityOS/serenity/pull/17513
1 changed files with 22 additions and 0 deletions
|
@ -14,6 +14,26 @@
|
|||
|
||||
namespace Gfx::ICC {
|
||||
|
||||
static ErrorOr<ByteBuffer> encode_chromaticity(ChromaticityTagData const& tag_data)
|
||||
{
|
||||
// ICC v4, 10.2 chromaticityType
|
||||
auto bytes = TRY(ByteBuffer::create_uninitialized(2 * sizeof(u32) + 2 * sizeof(u16) + tag_data.xy_coordinates().size() * 2 * sizeof(u16Fixed16Number)));
|
||||
|
||||
*bit_cast<BigEndian<u32>*>(bytes.data()) = (u32)ChromaticityTagData::Type;
|
||||
*bit_cast<BigEndian<u32>*>(bytes.data() + 4) = 0;
|
||||
|
||||
*bit_cast<BigEndian<u16>*>(bytes.data() + 8) = tag_data.xy_coordinates().size();
|
||||
*bit_cast<BigEndian<u16>*>(bytes.data() + 10) = (u16)tag_data.phosphor_or_colorant_type();
|
||||
|
||||
auto* coordinates = bit_cast<BigEndian<u16Fixed16Number>*>(bytes.data() + 12);
|
||||
for (size_t i = 0; i < tag_data.xy_coordinates().size(); ++i) {
|
||||
coordinates[2 * i] = tag_data.xy_coordinates()[i].x.raw();
|
||||
coordinates[2 * i + 1] = tag_data.xy_coordinates()[i].y.raw();
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static ErrorOr<ByteBuffer> encode_multi_localized_unicode(MultiLocalizedUnicodeTagData const& tag_data)
|
||||
{
|
||||
// ICC v4, 10.15 multiLocalizedUnicodeType
|
||||
|
@ -108,6 +128,8 @@ static ErrorOr<ByteBuffer> encode_xyz(XYZTagData const& tag_data)
|
|||
static ErrorOr<ByteBuffer> encode_tag_data(TagData const& tag_data)
|
||||
{
|
||||
switch (tag_data.type()) {
|
||||
case ChromaticityTagData::Type:
|
||||
return encode_chromaticity(static_cast<ChromaticityTagData const&>(tag_data));
|
||||
case MultiLocalizedUnicodeTagData::Type:
|
||||
return encode_multi_localized_unicode(static_cast<MultiLocalizedUnicodeTagData const&>(tag_data));
|
||||
case ParametricCurveTagData::Type:
|
||||
|
|
Loading…
Reference in a new issue