mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 02:50:26 +00:00
LibGfx: Implement serialization of ParametricCurveTagData
With this, simple v4 matrix profiles using parametric curves, such as Compact-ICC-Profiles/profiles/sRGB-v4.icc, can be completely serialized and the serialized file can be read again by `icc` :^)
This commit is contained in:
parent
685e2da302
commit
ececea9a1c
Notes:
sideshowbarker
2024-07-18 00:34:07 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/ececea9a1c Pull-request: https://github.com/SerenityOS/serenity/pull/17513
2 changed files with 26 additions and 0 deletions
|
@ -60,6 +60,23 @@ static ErrorOr<ByteBuffer> encode_multi_localized_unicode(MultiLocalizedUnicodeT
|
|||
return bytes;
|
||||
}
|
||||
|
||||
static ErrorOr<ByteBuffer> encode_parametric_curve(ParametricCurveTagData const& tag_data)
|
||||
{
|
||||
// ICC v4, 10.18 parametricCurveType
|
||||
auto bytes = TRY(ByteBuffer::create_uninitialized(2 * sizeof(u32) + 2 * sizeof(u16) + tag_data.parameter_count() * sizeof(s15Fixed16Number)));
|
||||
*bit_cast<BigEndian<u32>*>(bytes.data()) = (u32)ParametricCurveTagData::Type;
|
||||
*bit_cast<BigEndian<u32>*>(bytes.data() + 4) = 0;
|
||||
|
||||
*bit_cast<BigEndian<u16>*>(bytes.data() + 8) = (u16)tag_data.function_type();
|
||||
*bit_cast<BigEndian<u16>*>(bytes.data() + 10) = 0;
|
||||
|
||||
auto* parameters = bit_cast<BigEndian<s15Fixed16Number>*>(bytes.data() + 12);
|
||||
for (size_t i = 0; i < tag_data.parameter_count(); ++i)
|
||||
parameters[i] = tag_data.parameter(i).raw();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static ErrorOr<ByteBuffer> encode_s15_fixed_array(S15Fixed16ArrayTagData const& tag_data)
|
||||
{
|
||||
// ICC v4, 10.22 s15Fixed16ArrayType
|
||||
|
@ -93,6 +110,8 @@ static ErrorOr<ByteBuffer> encode_tag_data(TagData const& tag_data)
|
|||
switch (tag_data.type()) {
|
||||
case MultiLocalizedUnicodeTagData::Type:
|
||||
return encode_multi_localized_unicode(static_cast<MultiLocalizedUnicodeTagData const&>(tag_data));
|
||||
case ParametricCurveTagData::Type:
|
||||
return encode_parametric_curve(static_cast<ParametricCurveTagData const&>(tag_data));
|
||||
case S15Fixed16ArrayTagData::Type:
|
||||
return encode_s15_fixed_array(static_cast<S15Fixed16ArrayTagData const&>(tag_data));
|
||||
case XYZTagData::Type:
|
||||
|
|
|
@ -626,6 +626,13 @@ public:
|
|||
|
||||
static unsigned parameter_count(FunctionType);
|
||||
|
||||
unsigned parameter_count() const { return parameter_count(function_type()); }
|
||||
S15Fixed16 parameter(size_t i) const
|
||||
{
|
||||
VERIFY(i < parameter_count());
|
||||
return m_parameters[i];
|
||||
}
|
||||
|
||||
S15Fixed16 g() const { return m_parameters[0]; }
|
||||
S15Fixed16 a() const
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue