diff --git a/Userland/Libraries/LibGfx/ICC/BinaryFormat.h b/Userland/Libraries/LibGfx/ICC/BinaryFormat.h new file mode 100644 index 0000000000..4e6771b67c --- /dev/null +++ b/Userland/Libraries/LibGfx/ICC/BinaryFormat.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2023, Nico Weber + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Gfx::ICC { + +// ICC V4, 4.2 dateTimeNumber +// "All the dateTimeNumber values in a profile shall be in Coordinated Universal Time [...]." +struct DateTimeNumber { + BigEndian year; + BigEndian month; + BigEndian day; + BigEndian hours; + BigEndian minutes; + BigEndian seconds; +}; + +// ICC V4, 4.6 s15Fixed16Number +using s15Fixed16Number = i32; + +// ICC V4, 4.7 u16Fixed16Number +using u16Fixed16Number = u32; + +// ICC V4, 4.14 XYZNumber +struct XYZNumber { + BigEndian x; + BigEndian y; + BigEndian z; + + operator XYZ() const + { + return XYZ { x / (double)0x1'0000, y / (double)0x1'0000, z / (double)0x1'0000 }; + } +}; + +// ICC V4, 7.2 Profile header +struct ICCHeader { + BigEndian profile_size; + BigEndian preferred_cmm_type; + + u8 profile_version_major; + u8 profile_version_minor_bugfix; + BigEndian profile_version_zero; + + BigEndian profile_device_class; + BigEndian data_color_space; + BigEndian profile_connection_space; // "PCS" in the spec. + + DateTimeNumber profile_creation_time; + + BigEndian profile_file_signature; + BigEndian primary_platform; + + BigEndian profile_flags; + BigEndian device_manufacturer; + BigEndian device_model; + BigEndian device_attributes; + BigEndian rendering_intent; + + XYZNumber pcs_illuminant; + + BigEndian profile_creator; + + u8 profile_id[16]; + u8 reserved[28]; +}; +static_assert(AssertSize()); + +// Common bits of ICC v4, Table 40 — lut16Type encoding and Table 44 — lut8Type encoding +struct LUTHeader { + u8 number_of_input_channels; + u8 number_of_output_channels; + u8 number_of_clut_grid_points; + u8 reserved_for_padding; + BigEndian e_parameters[9]; +}; +static_assert(AssertSize()); + +// Common bits of ICC v4, Table 45 — lutAToBType encoding and Table 47 — lutBToAType encoding +struct AdvancedLUTHeader { + u8 number_of_input_channels; + u8 number_of_output_channels; + BigEndian reserved_for_padding; + BigEndian offset_to_b_curves; + BigEndian offset_to_matrix; + BigEndian offset_to_m_curves; + BigEndian offset_to_clut; + BigEndian offset_to_a_curves; +}; +static_assert(AssertSize()); + +// ICC v4, Table 46 — lutAToBType CLUT encoding +// ICC v4, Table 48 — lutBToAType CLUT encoding +// (They're identical.) +struct CLUTHeader { + u8 number_of_grid_points_in_dimension[16]; + u8 precision_of_data_elements; // 1 for u8 entries, 2 for u16 entries. + u8 reserved_for_padding[3]; +}; +static_assert(AssertSize()); + +} diff --git a/Userland/Libraries/LibGfx/ICC/Profile.cpp b/Userland/Libraries/LibGfx/ICC/Profile.cpp index 0b06e06a09..993b96484a 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.cpp +++ b/Userland/Libraries/LibGfx/ICC/Profile.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -17,32 +18,6 @@ namespace Gfx::ICC { namespace { -// ICC V4, 4.2 dateTimeNumber -// "All the dateTimeNumber values in a profile shall be in Coordinated Universal Time [...]." -struct DateTimeNumber { - BigEndian year; - BigEndian month; - BigEndian day; - BigEndian hours; - BigEndian minutes; - BigEndian seconds; -}; - -// ICC V4, 4.6 s15Fixed16Number -using s15Fixed16Number = i32; - -// ICC V4, 4.14 XYZNumber -struct XYZNumber { - BigEndian x; - BigEndian y; - BigEndian z; - - operator XYZ() const - { - return XYZ { x / (double)0x1'0000, y / (double)0x1'0000, z / (double)0x1'0000 }; - } -}; - ErrorOr parse_date_time_number(DateTimeNumber const& date_time) { // ICC V4, 4.2 dateTimeNumber @@ -84,39 +59,6 @@ ErrorOr parse_date_time_number(DateTimeNumber const& date_time) return timestamp; } -// ICC V4, 7.2 Profile header -struct ICCHeader { - BigEndian profile_size; - BigEndian preferred_cmm_type; - - u8 profile_version_major; - u8 profile_version_minor_bugfix; - BigEndian profile_version_zero; - - BigEndian profile_device_class; - BigEndian data_color_space; - BigEndian profile_connection_space; // "PCS" in the spec. - - DateTimeNumber profile_creation_time; - - BigEndian profile_file_signature; - BigEndian primary_platform; - - BigEndian profile_flags; - BigEndian device_manufacturer; - BigEndian device_model; - BigEndian device_attributes; - BigEndian rendering_intent; - - XYZNumber pcs_illuminant; - - BigEndian profile_creator; - - u8 profile_id[16]; - u8 reserved[28]; -}; -static_assert(AssertSize()); - ErrorOr parse_size(ICCHeader const& header, ReadonlyBytes icc_bytes) { // ICC v4, 7.2.2 Profile size field diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp index 2346c5a82e..0f92fc189f 100644 --- a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp +++ b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -14,57 +15,6 @@ namespace Gfx::ICC { namespace { -// ICC V4, 4.6 s15Fixed16Number -using s15Fixed16Number = i32; - -// ICC V4, 4.7 u16Fixed16Number -using u16Fixed16Number = u32; - -// ICC V4, 4.14 XYZNumber -struct XYZNumber { - BigEndian x; - BigEndian y; - BigEndian z; - - operator XYZ() const - { - return XYZ { x / (double)0x1'0000, y / (double)0x1'0000, z / (double)0x1'0000 }; - } -}; - -// Common bits of ICC v4, Table 40 — lut16Type encoding and Table 44 — lut8Type encoding -struct LUTHeader { - u8 number_of_input_channels; - u8 number_of_output_channels; - u8 number_of_clut_grid_points; - u8 reserved_for_padding; - BigEndian e_parameters[9]; -}; -static_assert(AssertSize()); - -// Common bits of ICC v4, Table 45 — lutAToBType encoding and Table 47 — lutBToAType encoding -struct AdvancedLUTHeader { - u8 number_of_input_channels; - u8 number_of_output_channels; - BigEndian reserved_for_padding; - BigEndian offset_to_b_curves; - BigEndian offset_to_matrix; - BigEndian offset_to_m_curves; - BigEndian offset_to_clut; - BigEndian offset_to_a_curves; -}; -static_assert(AssertSize()); - -// ICC v4, Table 46 — lutAToBType CLUT encoding -// ICC v4, Table 48 — lutBToAType CLUT encoding -// (They're identical.) -struct CLUTHeader { - u8 number_of_grid_points_in_dimension[16]; - u8 precision_of_data_elements; // 1 for u8 entries, 2 for u16 entries. - u8 reserved_for_padding[3]; -}; -static_assert(AssertSize()); - ErrorOr check_reserved(ReadonlyBytes tag_bytes) { if (tag_bytes.size() < 2 * sizeof(u32))