mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09:00
LibGfx: Add a size-less CurveTagData::from_bytes() overload in ICC code
The curve data in lutAToBType and lutBToAType can store 'curv' 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
38ce053296
commit
8ed3f7c4c2
Notes:
sideshowbarker
2024-07-18 00:54:03 +09:00
Author: https://github.com/nico
Commit: 8ed3f7c4c2
Pull-request: https://github.com/SerenityOS/serenity/pull/17453
Reviewed-by: https://github.com/linusg
2 changed files with 27 additions and 4 deletions
|
@ -167,17 +167,25 @@ ErrorOr<NonnullRefPtr<CicpTagData>> CicpTagData::from_bytes(ReadonlyBytes bytes,
|
|||
return try_make_ref_counted<CicpTagData>(offset, size, color_primaries, transfer_characteristics, matrix_coefficients, video_full_range_flag);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<CurveTagData>> CurveTagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size)
|
||||
namespace {
|
||||
|
||||
struct CurveData {
|
||||
u32 computed_size;
|
||||
Vector<u16> values;
|
||||
};
|
||||
|
||||
ErrorOr<CurveData> curve_data_from_bytes(ReadonlyBytes bytes)
|
||||
{
|
||||
// ICC v4, 10.6 curveType
|
||||
VERIFY(tag_type(bytes) == Type);
|
||||
VERIFY(tag_type(bytes) == CurveTagData::Type);
|
||||
TRY(check_reserved(bytes));
|
||||
|
||||
if (bytes.size() < 3 * sizeof(u32))
|
||||
return Error::from_string_literal("ICC::Profile: curveType has not enough data for count");
|
||||
u32 count = *bit_cast<BigEndian<u32> const*>(bytes.data() + 8);
|
||||
|
||||
if (bytes.size() < 3 * sizeof(u32) + count * sizeof(u16))
|
||||
u32 computed_size = 3 * sizeof(u32) + count * sizeof(u16);
|
||||
if (bytes.size() < computed_size)
|
||||
return Error::from_string_literal("ICC::Profile: curveType has not enough data for curve points");
|
||||
|
||||
auto* raw_values = bit_cast<BigEndian<u16> const*>(bytes.data() + 12);
|
||||
|
@ -187,7 +195,21 @@ ErrorOr<NonnullRefPtr<CurveTagData>> CurveTagData::from_bytes(ReadonlyBytes byte
|
|||
for (u32 i = 0; i < count; ++i)
|
||||
values[i] = raw_values[i];
|
||||
|
||||
return try_make_ref_counted<CurveTagData>(offset, size, move(values));
|
||||
return CurveData { computed_size, move(values) };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<CurveTagData>> CurveTagData::from_bytes(ReadonlyBytes bytes, u32 offset)
|
||||
{
|
||||
auto curve_data = TRY(curve_data_from_bytes(bytes));
|
||||
return try_make_ref_counted<CurveTagData>(offset, curve_data.computed_size, move(curve_data.values));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<CurveTagData>> CurveTagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size)
|
||||
{
|
||||
auto curve_data = TRY(curve_data_from_bytes(bytes));
|
||||
return try_make_ref_counted<CurveTagData>(offset, size, move(curve_data.values));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Lut16TagData>> Lut16TagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size)
|
||||
|
|
|
@ -137,6 +137,7 @@ class CurveTagData : public TagData {
|
|||
public:
|
||||
static constexpr TagTypeSignature Type { 0x63757276 }; // 'curv'
|
||||
|
||||
static ErrorOr<NonnullRefPtr<CurveTagData>> from_bytes(ReadonlyBytes, u32 offset);
|
||||
static ErrorOr<NonnullRefPtr<CurveTagData>> from_bytes(ReadonlyBytes, u32 offset, u32 size);
|
||||
|
||||
CurveTagData(u32 offset, u32 size, Vector<u16> values)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue