From 64ffae9c55b90acfd10c598e00003652b2634cf1 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 3 Dec 2023 04:21:50 +0900 Subject: [PATCH] LibGfx/ICC: Move enums to dedicated Enums.{cpp,h} We will need to use ColorSpace in TagTypes.h, and it can't include Profile.h. Also makes Profile.cpp a bit smaller. No behavior change, pure code move. --- Userland/Libraries/LibGfx/CMakeLists.txt | 1 + .../Libraries/LibGfx/ICC/DistinctFourCC.h | 2 +- Userland/Libraries/LibGfx/ICC/Enums.cpp | 178 ++++++++++++++++++ Userland/Libraries/LibGfx/ICC/Enums.h | 77 ++++++++ Userland/Libraries/LibGfx/ICC/Profile.cpp | 167 ---------------- Userland/Libraries/LibGfx/ICC/Profile.h | 64 ------- Userland/Libraries/LibGfx/ICC/TagTypes.h | 1 + 7 files changed, 258 insertions(+), 232 deletions(-) create mode 100644 Userland/Libraries/LibGfx/ICC/Enums.cpp create mode 100644 Userland/Libraries/LibGfx/ICC/Enums.h diff --git a/Userland/Libraries/LibGfx/CMakeLists.txt b/Userland/Libraries/LibGfx/CMakeLists.txt index 9271ecfab8..643b8b7b66 100644 --- a/Userland/Libraries/LibGfx/CMakeLists.txt +++ b/Userland/Libraries/LibGfx/CMakeLists.txt @@ -28,6 +28,7 @@ set(SOURCES Font/WOFF2/Font.cpp GradientPainting.cpp ICC/BinaryWriter.cpp + ICC/Enums.cpp ICC/Profile.cpp ICC/Tags.cpp ICC/TagTypes.cpp diff --git a/Userland/Libraries/LibGfx/ICC/DistinctFourCC.h b/Userland/Libraries/LibGfx/ICC/DistinctFourCC.h index 7b23f28933..34815630c6 100644 --- a/Userland/Libraries/LibGfx/ICC/DistinctFourCC.h +++ b/Userland/Libraries/LibGfx/ICC/DistinctFourCC.h @@ -13,7 +13,7 @@ namespace Gfx::ICC { // The ICC spec uses FourCCs for many different things. // This is used to give FourCCs for different roles distinct types, so that they can only be compared to the correct constants. -// (FourCCs that have only a small and fixed set of values should use an enum class instead, see e.g. DeviceClass and ColorSpace in Profile.h.) +// (FourCCs that have only a small and fixed set of values should use an enum class instead, see e.g. DeviceClass and ColorSpace in Enums.h.) enum class FourCCType { PreferredCMMType, DeviceManufacturer, diff --git a/Userland/Libraries/LibGfx/ICC/Enums.cpp b/Userland/Libraries/LibGfx/ICC/Enums.cpp new file mode 100644 index 0000000000..fbcc7c721b --- /dev/null +++ b/Userland/Libraries/LibGfx/ICC/Enums.cpp @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2023, Nico Weber + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Gfx::ICC { + +StringView device_class_name(DeviceClass device_class) +{ + switch (device_class) { + case DeviceClass::InputDevice: + return "InputDevice"sv; + case DeviceClass::DisplayDevice: + return "DisplayDevice"sv; + case DeviceClass::OutputDevice: + return "OutputDevice"sv; + case DeviceClass::DeviceLink: + return "DeviceLink"sv; + case DeviceClass::ColorSpace: + return "ColorSpace"sv; + case DeviceClass::Abstract: + return "Abstract"sv; + case DeviceClass::NamedColor: + return "NamedColor"sv; + } + VERIFY_NOT_REACHED(); +} + +StringView data_color_space_name(ColorSpace color_space) +{ + switch (color_space) { + case ColorSpace::nCIEXYZ: + return "nCIEXYZ"sv; + case ColorSpace::CIELAB: + return "CIELAB"sv; + case ColorSpace::CIELUV: + return "CIELUV"sv; + case ColorSpace::YCbCr: + return "YCbCr"sv; + case ColorSpace::CIEYxy: + return "CIEYxy"sv; + case ColorSpace::RGB: + return "RGB"sv; + case ColorSpace::Gray: + return "Gray"sv; + case ColorSpace::HSV: + return "HSV"sv; + case ColorSpace::HLS: + return "HLS"sv; + case ColorSpace::CMYK: + return "CMYK"sv; + case ColorSpace::CMY: + return "CMY"sv; + case ColorSpace::TwoColor: + return "2 color"sv; + case ColorSpace::ThreeColor: + return "3 color (other than XYZ, Lab, Luv, YCbCr, CIEYxy, RGB, HSV, HLS, CMY)"sv; + case ColorSpace::FourColor: + return "4 color (other than CMYK)"sv; + case ColorSpace::FiveColor: + return "5 color"sv; + case ColorSpace::SixColor: + return "6 color"sv; + case ColorSpace::SevenColor: + return "7 color"sv; + case ColorSpace::EightColor: + return "8 color"sv; + case ColorSpace::NineColor: + return "9 color"sv; + case ColorSpace::TenColor: + return "10 color"sv; + case ColorSpace::ElevenColor: + return "11 color"sv; + case ColorSpace::TwelveColor: + return "12 color"sv; + case ColorSpace::ThirteenColor: + return "13 color"sv; + case ColorSpace::FourteenColor: + return "14 color"sv; + case ColorSpace::FifteenColor: + return "15 color"sv; + } + VERIFY_NOT_REACHED(); +} + +StringView profile_connection_space_name(ColorSpace color_space) +{ + switch (color_space) { + case ColorSpace::PCSXYZ: + return "PCSXYZ"sv; + case ColorSpace::PCSLAB: + return "PCSLAB"sv; + default: + return data_color_space_name(color_space); + } +} + +unsigned number_of_components_in_color_space(ColorSpace color_space) +{ + switch (color_space) { + case ColorSpace::Gray: + return 1; + case ColorSpace::TwoColor: + return 2; + case ColorSpace::nCIEXYZ: + case ColorSpace::CIELAB: + case ColorSpace::CIELUV: + case ColorSpace::YCbCr: + case ColorSpace::CIEYxy: + case ColorSpace::RGB: + case ColorSpace::HSV: + case ColorSpace::HLS: + case ColorSpace::CMY: + case ColorSpace::ThreeColor: + return 3; + case ColorSpace::CMYK: + case ColorSpace::FourColor: + return 4; + case ColorSpace::FiveColor: + return 5; + case ColorSpace::SixColor: + return 6; + case ColorSpace::SevenColor: + return 7; + case ColorSpace::EightColor: + return 8; + case ColorSpace::NineColor: + return 9; + case ColorSpace::TenColor: + return 10; + case ColorSpace::ElevenColor: + return 11; + case ColorSpace::TwelveColor: + return 12; + case ColorSpace::ThirteenColor: + return 13; + case ColorSpace::FourteenColor: + return 14; + case ColorSpace::FifteenColor: + return 15; + } + VERIFY_NOT_REACHED(); +} + +StringView primary_platform_name(PrimaryPlatform primary_platform) +{ + switch (primary_platform) { + case PrimaryPlatform::Apple: + return "Apple"sv; + case PrimaryPlatform::Microsoft: + return "Microsoft"sv; + case PrimaryPlatform::SiliconGraphics: + return "Silicon Graphics"sv; + case PrimaryPlatform::Sun: + return "Sun"sv; + } + VERIFY_NOT_REACHED(); +} + +StringView rendering_intent_name(RenderingIntent rendering_intent) +{ + switch (rendering_intent) { + case RenderingIntent::Perceptual: + return "Perceptual"sv; + case RenderingIntent::MediaRelativeColorimetric: + return "Media-relative colorimetric"sv; + case RenderingIntent::Saturation: + return "Saturation"sv; + case RenderingIntent::ICCAbsoluteColorimetric: + return "ICC-absolute colorimetric"sv; + } + VERIFY_NOT_REACHED(); +} + +} diff --git a/Userland/Libraries/LibGfx/ICC/Enums.h b/Userland/Libraries/LibGfx/ICC/Enums.h new file mode 100644 index 0000000000..1c298dbe9a --- /dev/null +++ b/Userland/Libraries/LibGfx/ICC/Enums.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023, Nico Weber + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Gfx::ICC { + +// ICC v4, 7.2.5 Profile/device class field +enum class DeviceClass : u32 { + InputDevice = 0x73636E72, // 'scnr' + DisplayDevice = 0x6D6E7472, // 'mntr' + OutputDevice = 0x70727472, // 'prtr' + DeviceLink = 0x6C696E6B, // 'link' + ColorSpace = 0x73706163, // 'spac' + Abstract = 0x61627374, // 'abst' + NamedColor = 0x6E6D636C, // 'nmcl' +}; +StringView device_class_name(DeviceClass); + +// ICC v4, 7.2.6 Data colour space field, Table 19 — Data colour space signatures +enum class ColorSpace : u32 { + nCIEXYZ = 0x58595A20, // 'XYZ ', used in data color spaces. + PCSXYZ = nCIEXYZ, // Used in profile connection space instead. + CIELAB = 0x4C616220, // 'Lab ', used in data color spaces. + PCSLAB = CIELAB, // Used in profile connection space instead. + CIELUV = 0x4C757620, // 'Luv ' + YCbCr = 0x59436272, // 'YCbr' + CIEYxy = 0x59787920, // 'Yxy ' + RGB = 0x52474220, // 'RGB ' + Gray = 0x47524159, // 'GRAY' + HSV = 0x48535620, // 'HSV ' + HLS = 0x484C5320, // 'HLS ' + CMYK = 0x434D594B, // 'CMYK' + CMY = 0x434D5920, // 'CMY ' + TwoColor = 0x32434C52, // '2CLR' + ThreeColor = 0x33434C52, // '3CLR' + FourColor = 0x34434C52, // '4CLR' + FiveColor = 0x35434C52, // '5CLR' + SixColor = 0x36434C52, // '6CLR' + SevenColor = 0x37434C52, // '7CLR' + EightColor = 0x38434C52, // '8CLR' + NineColor = 0x39434C52, // '9CLR' + TenColor = 0x41434C52, // 'ACLR' + ElevenColor = 0x42434C52, // 'BCLR' + TwelveColor = 0x43434C52, // 'CCLR' + ThirteenColor = 0x44434C52, // 'DCLR' + FourteenColor = 0x45434C52, // 'ECLR' + FifteenColor = 0x46434C52, // 'FCLR' +}; +StringView data_color_space_name(ColorSpace); +StringView profile_connection_space_name(ColorSpace); +unsigned number_of_components_in_color_space(ColorSpace); + +// ICC v4, 7.2.10 Primary platform field, Table 20 — Primary platforms +enum class PrimaryPlatform : u32 { + Apple = 0x4150504C, // 'APPL' + Microsoft = 0x4D534654, // 'MSFT' + SiliconGraphics = 0x53474920, // 'SGI ' + Sun = 0x53554E57, // 'SUNW' +}; +StringView primary_platform_name(PrimaryPlatform); + +// ICC v4, 7.2.15 Rendering intent field +enum class RenderingIntent { + Perceptual, + MediaRelativeColorimetric, + Saturation, + ICCAbsoluteColorimetric, +}; +StringView rendering_intent_name(RenderingIntent); + +} diff --git a/Userland/Libraries/LibGfx/ICC/Profile.cpp b/Userland/Libraries/LibGfx/ICC/Profile.cpp index 2a520d9419..ebef73ded5 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.cpp +++ b/Userland/Libraries/LibGfx/ICC/Profile.cpp @@ -345,173 +345,6 @@ URL device_model_url(DeviceModel device_model) device_model.c0(), device_model.c1(), device_model.c2(), device_model.c3(), device_model.value)); } -StringView device_class_name(DeviceClass device_class) -{ - switch (device_class) { - case DeviceClass::InputDevice: - return "InputDevice"sv; - case DeviceClass::DisplayDevice: - return "DisplayDevice"sv; - case DeviceClass::OutputDevice: - return "OutputDevice"sv; - case DeviceClass::DeviceLink: - return "DeviceLink"sv; - case DeviceClass::ColorSpace: - return "ColorSpace"sv; - case DeviceClass::Abstract: - return "Abstract"sv; - case DeviceClass::NamedColor: - return "NamedColor"sv; - } - VERIFY_NOT_REACHED(); -} - -StringView data_color_space_name(ColorSpace color_space) -{ - switch (color_space) { - case ColorSpace::nCIEXYZ: - return "nCIEXYZ"sv; - case ColorSpace::CIELAB: - return "CIELAB"sv; - case ColorSpace::CIELUV: - return "CIELUV"sv; - case ColorSpace::YCbCr: - return "YCbCr"sv; - case ColorSpace::CIEYxy: - return "CIEYxy"sv; - case ColorSpace::RGB: - return "RGB"sv; - case ColorSpace::Gray: - return "Gray"sv; - case ColorSpace::HSV: - return "HSV"sv; - case ColorSpace::HLS: - return "HLS"sv; - case ColorSpace::CMYK: - return "CMYK"sv; - case ColorSpace::CMY: - return "CMY"sv; - case ColorSpace::TwoColor: - return "2 color"sv; - case ColorSpace::ThreeColor: - return "3 color (other than XYZ, Lab, Luv, YCbCr, CIEYxy, RGB, HSV, HLS, CMY)"sv; - case ColorSpace::FourColor: - return "4 color (other than CMYK)"sv; - case ColorSpace::FiveColor: - return "5 color"sv; - case ColorSpace::SixColor: - return "6 color"sv; - case ColorSpace::SevenColor: - return "7 color"sv; - case ColorSpace::EightColor: - return "8 color"sv; - case ColorSpace::NineColor: - return "9 color"sv; - case ColorSpace::TenColor: - return "10 color"sv; - case ColorSpace::ElevenColor: - return "11 color"sv; - case ColorSpace::TwelveColor: - return "12 color"sv; - case ColorSpace::ThirteenColor: - return "13 color"sv; - case ColorSpace::FourteenColor: - return "14 color"sv; - case ColorSpace::FifteenColor: - return "15 color"sv; - } - VERIFY_NOT_REACHED(); -} - -StringView profile_connection_space_name(ColorSpace color_space) -{ - switch (color_space) { - case ColorSpace::PCSXYZ: - return "PCSXYZ"sv; - case ColorSpace::PCSLAB: - return "PCSLAB"sv; - default: - return data_color_space_name(color_space); - } -} - -unsigned number_of_components_in_color_space(ColorSpace color_space) -{ - switch (color_space) { - case ColorSpace::Gray: - return 1; - case ColorSpace::TwoColor: - return 2; - case ColorSpace::nCIEXYZ: - case ColorSpace::CIELAB: - case ColorSpace::CIELUV: - case ColorSpace::YCbCr: - case ColorSpace::CIEYxy: - case ColorSpace::RGB: - case ColorSpace::HSV: - case ColorSpace::HLS: - case ColorSpace::CMY: - case ColorSpace::ThreeColor: - return 3; - case ColorSpace::CMYK: - case ColorSpace::FourColor: - return 4; - case ColorSpace::FiveColor: - return 5; - case ColorSpace::SixColor: - return 6; - case ColorSpace::SevenColor: - return 7; - case ColorSpace::EightColor: - return 8; - case ColorSpace::NineColor: - return 9; - case ColorSpace::TenColor: - return 10; - case ColorSpace::ElevenColor: - return 11; - case ColorSpace::TwelveColor: - return 12; - case ColorSpace::ThirteenColor: - return 13; - case ColorSpace::FourteenColor: - return 14; - case ColorSpace::FifteenColor: - return 15; - } - VERIFY_NOT_REACHED(); -} - -StringView primary_platform_name(PrimaryPlatform primary_platform) -{ - switch (primary_platform) { - case PrimaryPlatform::Apple: - return "Apple"sv; - case PrimaryPlatform::Microsoft: - return "Microsoft"sv; - case PrimaryPlatform::SiliconGraphics: - return "Silicon Graphics"sv; - case PrimaryPlatform::Sun: - return "Sun"sv; - } - VERIFY_NOT_REACHED(); -} - -StringView rendering_intent_name(RenderingIntent rendering_intent) -{ - switch (rendering_intent) { - case RenderingIntent::Perceptual: - return "Perceptual"sv; - case RenderingIntent::MediaRelativeColorimetric: - return "Media-relative colorimetric"sv; - case RenderingIntent::Saturation: - return "Saturation"sv; - case RenderingIntent::ICCAbsoluteColorimetric: - return "ICC-absolute colorimetric"sv; - } - VERIFY_NOT_REACHED(); -} - Flags::Flags() = default; Flags::Flags(u32 bits) : m_bits(bits) diff --git a/Userland/Libraries/LibGfx/ICC/Profile.h b/Userland/Libraries/LibGfx/ICC/Profile.h index b91c7f2322..5090bd8058 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.h +++ b/Userland/Libraries/LibGfx/ICC/Profile.h @@ -46,70 +46,6 @@ private: u8 m_minor_and_bugfix_version = 0; }; -// ICC v4, 7.2.5 Profile/device class field -enum class DeviceClass : u32 { - InputDevice = 0x73636E72, // 'scnr' - DisplayDevice = 0x6D6E7472, // 'mntr' - OutputDevice = 0x70727472, // 'prtr' - DeviceLink = 0x6C696E6B, // 'link' - ColorSpace = 0x73706163, // 'spac' - Abstract = 0x61627374, // 'abst' - NamedColor = 0x6E6D636C, // 'nmcl' -}; -StringView device_class_name(DeviceClass); - -// ICC v4, 7.2.6 Data colour space field, Table 19 — Data colour space signatures -enum class ColorSpace : u32 { - nCIEXYZ = 0x58595A20, // 'XYZ ', used in data color spaces. - PCSXYZ = nCIEXYZ, // Used in profile connection space instead. - CIELAB = 0x4C616220, // 'Lab ', used in data color spaces. - PCSLAB = CIELAB, // Used in profile connection space instead. - CIELUV = 0x4C757620, // 'Luv ' - YCbCr = 0x59436272, // 'YCbr' - CIEYxy = 0x59787920, // 'Yxy ' - RGB = 0x52474220, // 'RGB ' - Gray = 0x47524159, // 'GRAY' - HSV = 0x48535620, // 'HSV ' - HLS = 0x484C5320, // 'HLS ' - CMYK = 0x434D594B, // 'CMYK' - CMY = 0x434D5920, // 'CMY ' - TwoColor = 0x32434C52, // '2CLR' - ThreeColor = 0x33434C52, // '3CLR' - FourColor = 0x34434C52, // '4CLR' - FiveColor = 0x35434C52, // '5CLR' - SixColor = 0x36434C52, // '6CLR' - SevenColor = 0x37434C52, // '7CLR' - EightColor = 0x38434C52, // '8CLR' - NineColor = 0x39434C52, // '9CLR' - TenColor = 0x41434C52, // 'ACLR' - ElevenColor = 0x42434C52, // 'BCLR' - TwelveColor = 0x43434C52, // 'CCLR' - ThirteenColor = 0x44434C52, // 'DCLR' - FourteenColor = 0x45434C52, // 'ECLR' - FifteenColor = 0x46434C52, // 'FCLR' -}; -StringView data_color_space_name(ColorSpace); -StringView profile_connection_space_name(ColorSpace); -unsigned number_of_components_in_color_space(ColorSpace); - -// ICC v4, 7.2.10 Primary platform field, Table 20 — Primary platforms -enum class PrimaryPlatform : u32 { - Apple = 0x4150504C, // 'APPL' - Microsoft = 0x4D534654, // 'MSFT' - SiliconGraphics = 0x53474920, // 'SGI ' - Sun = 0x53554E57, // 'SUNW' -}; -StringView primary_platform_name(PrimaryPlatform); - -// ICC v4, 7.2.15 Rendering intent field -enum class RenderingIntent : u32 { - Perceptual = 0, - MediaRelativeColorimetric = 1, - Saturation = 2, - ICCAbsoluteColorimetric = 3, -}; -StringView rendering_intent_name(RenderingIntent); - // ICC v4, 7.2.11 Profile flags field class Flags { public: diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.h b/Userland/Libraries/LibGfx/ICC/TagTypes.h index 3f8887a9f1..c601383e42 100644 --- a/Userland/Libraries/LibGfx/ICC/TagTypes.h +++ b/Userland/Libraries/LibGfx/ICC/TagTypes.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include