mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibGfx: Add a size-less ParametricCurveTagData::from_bytes() overload
The curve data in lutAToBType and lutBToAType can store 'para' data, but other than in the main ICC tag table, the size of the tag data isn't explicitly stored. So it must be computed from the data contents. Extract the function body into a helper can call that from both variants.
This commit is contained in:
parent
8ed3f7c4c2
commit
bb19dc00af
Notes:
sideshowbarker
2024-07-17 03:19:14 +09:00
Author: https://github.com/nico
Commit: bb19dc00af
Pull-request: https://github.com/SerenityOS/serenity/pull/17453
Reviewed-by: https://github.com/linusg
2 changed files with 30 additions and 6 deletions
|
@ -805,10 +805,18 @@ ErrorOr<String> NamedColor2TagData::color_name(u32 index)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<ParametricCurveTagData>> ParametricCurveTagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size)
|
||||
namespace {
|
||||
|
||||
struct ParametricCurveData {
|
||||
u32 computed_size;
|
||||
ParametricCurveTagData::FunctionType function_type;
|
||||
Array<S15Fixed16, 7> parameters;
|
||||
};
|
||||
|
||||
ErrorOr<ParametricCurveData> parametric_curve_data_from_bytes(ReadonlyBytes bytes)
|
||||
{
|
||||
// ICC v4, 10.18 parametricCurveType
|
||||
VERIFY(tag_type(bytes) == Type);
|
||||
VERIFY(tag_type(bytes) == ParametricCurveTagData::Type);
|
||||
TRY(check_reserved(bytes));
|
||||
|
||||
// "The parametricCurveType describes a one-dimensional curve by specifying one of a predefined set of functions
|
||||
|
@ -825,10 +833,11 @@ ErrorOr<NonnullRefPtr<ParametricCurveTagData>> ParametricCurveTagData::from_byte
|
|||
if (raw_function_type > 4)
|
||||
return Error::from_string_literal("ICC::Profile: parametricCurveType unknown function type");
|
||||
|
||||
FunctionType function_type = (FunctionType)raw_function_type;
|
||||
unsigned count = parameter_count(function_type);
|
||||
auto function_type = (ParametricCurveTagData::FunctionType)raw_function_type;
|
||||
unsigned count = ParametricCurveTagData::parameter_count(function_type);
|
||||
|
||||
if (bytes.size() < 2 * sizeof(u32) + 2 * sizeof(u16) + count * sizeof(s15Fixed16Number))
|
||||
u32 computed_size = 2 * sizeof(u32) + 2 * sizeof(u16) + count * sizeof(s15Fixed16Number);
|
||||
if (bytes.size() < computed_size)
|
||||
return Error::from_string_literal("ICC::Profile: parametricCurveType has not enough data for parameters");
|
||||
|
||||
auto* raw_parameters = bit_cast<BigEndian<s15Fixed16Number> const*>(bytes.data() + 12);
|
||||
|
@ -837,7 +846,21 @@ ErrorOr<NonnullRefPtr<ParametricCurveTagData>> ParametricCurveTagData::from_byte
|
|||
for (size_t i = 0; i < count; ++i)
|
||||
parameters[i] = S15Fixed16::create_raw(raw_parameters[i]);
|
||||
|
||||
return try_make_ref_counted<ParametricCurveTagData>(offset, size, function_type, move(parameters));
|
||||
return ParametricCurveData { computed_size, function_type, move(parameters) };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<ParametricCurveTagData>> ParametricCurveTagData::from_bytes(ReadonlyBytes bytes, u32 offset)
|
||||
{
|
||||
auto curve_data = TRY(parametric_curve_data_from_bytes(bytes));
|
||||
return try_make_ref_counted<ParametricCurveTagData>(offset, curve_data.computed_size, curve_data.function_type, move(curve_data.parameters));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<ParametricCurveTagData>> ParametricCurveTagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size)
|
||||
{
|
||||
auto curve_data = TRY(parametric_curve_data_from_bytes(bytes));
|
||||
return try_make_ref_counted<ParametricCurveTagData>(offset, size, curve_data.function_type, move(curve_data.parameters));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<S15Fixed16ArrayTagData>> S15Fixed16ArrayTagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size)
|
||||
|
|
|
@ -608,6 +608,7 @@ public:
|
|||
|
||||
static constexpr TagTypeSignature Type { 0x70617261 }; // 'para'
|
||||
|
||||
static ErrorOr<NonnullRefPtr<ParametricCurveTagData>> from_bytes(ReadonlyBytes, u32 offset);
|
||||
static ErrorOr<NonnullRefPtr<ParametricCurveTagData>> from_bytes(ReadonlyBytes, u32 offset, u32 size);
|
||||
|
||||
ParametricCurveTagData(u32 offset, u32 size, FunctionType function_type, Array<S15Fixed16, 7> parameters)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue