1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:07:45 +00:00

LibGfx: Write ICC tag table

All offsets and sizes are set to 0 for now, so this still doesn't
produce a valid icc file. It gets closer, though.
This commit is contained in:
Nico Weber 2023-02-17 15:59:48 -05:00 committed by Andreas Kling
parent 9bd7048519
commit 1457e36b79
2 changed files with 25 additions and 2 deletions

View file

@ -9,8 +9,27 @@
#include <LibGfx/ICC/Profile.h> #include <LibGfx/ICC/Profile.h>
#include <time.h> #include <time.h>
#pragma GCC diagnostic ignored "-Warray-bounds"
namespace Gfx::ICC { namespace Gfx::ICC {
static ErrorOr<void> encode_tag_table(ByteBuffer& bytes, Profile const& profile)
{
VERIFY(bytes.size() >= sizeof(ICCHeader) + sizeof(u32) + profile.tag_count() * sizeof(TagTableEntry));
*bit_cast<BigEndian<u32>*>(bytes.data() + sizeof(ICCHeader)) = profile.tag_count();
TagTableEntry* tag_table_entry = bit_cast<TagTableEntry*>(bytes.data() + sizeof(ICCHeader) + sizeof(u32));
profile.for_each_tag([&tag_table_entry](auto tag_signature, auto) {
tag_table_entry->tag_signature = tag_signature;
tag_table_entry->offset_to_beginning_of_tag_data_element = 0; // FIXME
tag_table_entry->size_of_tag_data_element = 0; // FIXME
++tag_table_entry;
});
return {};
}
static ErrorOr<void> encode_header(ByteBuffer& bytes, Profile const& profile) static ErrorOr<void> encode_header(ByteBuffer& bytes, Profile const& profile)
{ {
VERIFY(bytes.size() >= sizeof(ICCHeader)); VERIFY(bytes.size() >= sizeof(ICCHeader));
@ -63,9 +82,11 @@ static ErrorOr<void> encode_header(ByteBuffer& bytes, Profile const& profile)
ErrorOr<ByteBuffer> encode(Profile const& profile) ErrorOr<ByteBuffer> encode(Profile const& profile)
{ {
// Leaves enough room for the profile header and the tag table count. // Leaves enough room for the profile header and the tag table count.
// FIXME: Serialize tag data and write tag table and tag data too. // FIXME: Serialize tag data and write tag data too.
auto bytes = TRY(ByteBuffer::create_zeroed(sizeof(ICCHeader) + sizeof(u32))); size_t tag_table_size = sizeof(u32) + profile.tag_count() * sizeof(TagTableEntry);
auto bytes = TRY(ByteBuffer::create_zeroed(sizeof(ICCHeader) + tag_table_size));
TRY(encode_tag_table(bytes, profile));
TRY(encode_header(bytes, profile)); TRY(encode_header(bytes, profile));
return bytes; return bytes;

View file

@ -247,6 +247,8 @@ public:
callback(tag.key, tag.value); callback(tag.key, tag.value);
} }
size_t tag_count() const { return m_tag_table.size(); }
// Only versions 2 and 4 are in use. // Only versions 2 and 4 are in use.
bool is_v2() const { return version().major_version() == 2; } bool is_v2() const { return version().major_version() == 2; }
bool is_v4() const { return version().major_version() == 4; } bool is_v4() const { return version().major_version() == 4; }