diff --git a/Userland/Libraries/LibGfx/ICC/Profile.cpp b/Userland/Libraries/LibGfx/ICC/Profile.cpp index ccc0335506..bff08ccce6 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.cpp +++ b/Userland/Libraries/LibGfx/ICC/Profile.cpp @@ -574,33 +574,34 @@ DeviceAttributes::DeviceAttributes(u64 bits) { } -ErrorOr Profile::read_header(ReadonlyBytes bytes) +static ErrorOr read_header(ReadonlyBytes bytes) { if (bytes.size() < sizeof(ICCHeader)) return Error::from_string_literal("ICC::Profile: Not enough data for header"); - auto header = *bit_cast(bytes.data()); + ProfileHeader header; + auto raw_header = *bit_cast(bytes.data()); - TRY(parse_file_signature(header)); - m_on_disk_size = TRY(parse_size(header, bytes)); - m_preferred_cmm_type = parse_preferred_cmm_type(header); - m_version = TRY(parse_version(header)); - m_device_class = TRY(parse_device_class(header)); - m_data_color_space = TRY(parse_data_color_space(header)); - m_connection_space = TRY(parse_connection_space(header)); - m_creation_timestamp = TRY(parse_creation_date_time(header)); - m_primary_platform = TRY(parse_primary_platform(header)); - m_flags = Flags { header.profile_flags }; - m_device_manufacturer = parse_device_manufacturer(header); - m_device_model = parse_device_model(header); - m_device_attributes = TRY(parse_device_attributes(header)); - m_rendering_intent = TRY(parse_rendering_intent(header)); - m_pcs_illuminant = TRY(parse_pcs_illuminant(header)); - m_creator = parse_profile_creator(header); - m_id = TRY(parse_profile_id(header, bytes)); - TRY(parse_reserved(header)); + TRY(parse_file_signature(raw_header)); + header.on_disk_size = TRY(parse_size(raw_header, bytes)); + header.preferred_cmm_type = parse_preferred_cmm_type(raw_header); + header.version = TRY(parse_version(raw_header)); + header.device_class = TRY(parse_device_class(raw_header)); + header.data_color_space = TRY(parse_data_color_space(raw_header)); + header.connection_space = TRY(parse_connection_space(raw_header)); + header.creation_timestamp = TRY(parse_creation_date_time(raw_header)); + header.primary_platform = TRY(parse_primary_platform(raw_header)); + header.flags = Flags { raw_header.profile_flags }; + header.device_manufacturer = parse_device_manufacturer(raw_header); + header.device_model = parse_device_model(raw_header); + header.device_attributes = TRY(parse_device_attributes(raw_header)); + header.rendering_intent = TRY(parse_rendering_intent(raw_header)); + header.pcs_illuminant = TRY(parse_pcs_illuminant(raw_header)); + header.creator = parse_profile_creator(raw_header); + header.id = TRY(parse_profile_id(raw_header, bytes)); + TRY(parse_reserved(raw_header)); - return {}; + return header; } static ErrorOr> read_tag(ReadonlyBytes bytes, u32 offset_to_beginning_of_tag_data_element, u32 size_of_tag_data_element) @@ -1377,7 +1378,7 @@ ErrorOr Profile::check_tag_types() ErrorOr> Profile::try_load_from_externally_owned_memory(ReadonlyBytes bytes) { auto profile = TRY(try_make_ref_counted()); - TRY(profile->read_header(bytes)); + profile->m_header = TRY(read_header(bytes)); bytes = bytes.trim(profile->on_disk_size()); profile->m_tag_table = TRY(read_tag_table(bytes)); diff --git a/Userland/Libraries/LibGfx/ICC/Profile.h b/Userland/Libraries/LibGfx/ICC/Profile.h index ef0ac60901..ac081abd68 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.h +++ b/Userland/Libraries/LibGfx/ICC/Profile.h @@ -187,29 +187,48 @@ private: u64 m_bits = 0; }; +struct ProfileHeader { + u32 on_disk_size { 0 }; + Optional preferred_cmm_type; + Version version; + DeviceClass device_class {}; + ColorSpace data_color_space {}; + ColorSpace connection_space {}; + time_t creation_timestamp { 0 }; + Optional primary_platform {}; + Flags flags; + Optional device_manufacturer; + Optional device_model; + DeviceAttributes device_attributes; + RenderingIntent rendering_intent {}; + XYZ pcs_illuminant; + Optional creator; + Optional id; +}; + class Profile : public RefCounted { public: static ErrorOr> try_load_from_externally_owned_memory(ReadonlyBytes); - Optional preferred_cmm_type() const { return m_preferred_cmm_type; } - Version version() const { return m_version; } - DeviceClass device_class() const { return m_device_class; } - ColorSpace data_color_space() const { return m_data_color_space; } + Optional preferred_cmm_type() const { return m_header.preferred_cmm_type; } + Version version() const { return m_header.version; } + DeviceClass device_class() const { return m_header.device_class; } + ColorSpace data_color_space() const { return m_header.data_color_space; } // For non-DeviceLink profiles, always PCSXYZ or PCSLAB. - ColorSpace connection_space() const { return m_connection_space; } + ColorSpace connection_space() const { return m_header.connection_space; } - u32 on_disk_size() const { return m_on_disk_size; } - time_t creation_timestamp() const { return m_creation_timestamp; } - Optional primary_platform() const { return m_primary_platform; } - Flags flags() const { return m_flags; } - Optional device_manufacturer() const { return m_device_manufacturer; } - Optional device_model() const { return m_device_model; } - DeviceAttributes device_attributes() const { return m_device_attributes; } - RenderingIntent rendering_intent() const { return m_rendering_intent; } - XYZ const& pcs_illuminant() const { return m_pcs_illuminant; } - Optional creator() const { return m_creator; } - Optional const& id() const { return m_id; } + u32 on_disk_size() const { return m_header.on_disk_size; } + time_t creation_timestamp() const { return m_header.creation_timestamp; } + Optional primary_platform() const { return m_header.primary_platform; } + Flags flags() const { return m_header.flags; } + Optional device_manufacturer() const { return m_header.device_manufacturer; } + Optional device_model() const { return m_header.device_model; } + DeviceAttributes device_attributes() const { return m_header.device_attributes; } + RenderingIntent rendering_intent() const { return m_header.rendering_intent; } + XYZ const& pcs_illuminant() const { return m_header.pcs_illuminant; } + Optional creator() const { return m_header.creator; } + Optional const& id() const { return m_header.id; } static Crypto::Hash::MD5::DigestType compute_id(ReadonlyBytes); @@ -225,27 +244,10 @@ public: bool is_v4() const { return version().major_version() == 4; } private: - ErrorOr read_header(ReadonlyBytes); ErrorOr check_required_tags(); ErrorOr check_tag_types(); - u32 m_on_disk_size { 0 }; - Optional m_preferred_cmm_type; - Version m_version; - DeviceClass m_device_class {}; - ColorSpace m_data_color_space {}; - ColorSpace m_connection_space {}; - time_t m_creation_timestamp { 0 }; - Optional m_primary_platform {}; - Flags m_flags; - Optional m_device_manufacturer; - Optional m_device_model; - DeviceAttributes m_device_attributes; - RenderingIntent m_rendering_intent {}; - XYZ m_pcs_illuminant; - Optional m_creator; - Optional m_id; - + ProfileHeader m_header; OrderedHashMap> m_tag_table; };