From b56a145a67c56b7d7058cdaeef7233a87d2ff91f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 21 Jan 2023 16:14:39 -0500 Subject: [PATCH] LibGfx+icc: Make device manufacturer and device model clickable --- Userland/Libraries/LibGfx/ICCProfile.cpp | 12 ++++++++++++ Userland/Libraries/LibGfx/ICCProfile.h | 4 ++++ Userland/Utilities/icc.cpp | 15 +++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/ICCProfile.cpp b/Userland/Libraries/LibGfx/ICCProfile.cpp index 36f5ed9d692..21917009259 100644 --- a/Userland/Libraries/LibGfx/ICCProfile.cpp +++ b/Userland/Libraries/LibGfx/ICCProfile.cpp @@ -388,6 +388,18 @@ ErrorOr parse_reserved(ICCHeader const& header) } } +URL device_manufacturer_url(DeviceManufacturer device_manufacturer) +{ + return URL(DeprecatedString::formatted("https://www.color.org/signatureRegistry/?entityEntry={:c}{:c}{:c}{:c}-{:08X}", + device_manufacturer.c0(), device_manufacturer.c1(), device_manufacturer.c2(), device_manufacturer.c3(), device_manufacturer.value)); +} + +URL device_model_url(DeviceModel device_model) +{ + return URL(DeprecatedString::formatted("https://www.color.org/signatureRegistry/deviceRegistry/?entityEntry={:c}{:c}{:c}{:c}-{:08X}", + 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) { diff --git a/Userland/Libraries/LibGfx/ICCProfile.h b/Userland/Libraries/LibGfx/ICCProfile.h index 7771f5d4fc7..062b93b7112 100644 --- a/Userland/Libraries/LibGfx/ICCProfile.h +++ b/Userland/Libraries/LibGfx/ICCProfile.h @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace Gfx::ICC { @@ -53,6 +54,9 @@ using Creator = DistinctFourCC; // IC using TagSignature = DistinctFourCC; // ICC v4, "9.2 Tag listing" using TagTypeSignature = DistinctFourCC; // ICC v4, "10 Tag type definitions" +URL device_manufacturer_url(DeviceManufacturer); +URL device_model_url(DeviceModel); + // ICC v4, 7.2.4 Profile version field class Version { public: diff --git a/Userland/Utilities/icc.cpp b/Userland/Utilities/icc.cpp index c8044e1275f..05b0f9a981a 100644 --- a/Userland/Utilities/icc.cpp +++ b/Userland/Utilities/icc.cpp @@ -4,12 +4,19 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include #include #include +template +static ErrorOr hyperlink(URL const& target, T const& label) +{ + return String::formatted("\033]8;;{}\033\\{}\033]8;;\033\\", target, label); +} + template static void out_optional(char const* label, Optional optional) { @@ -48,8 +55,12 @@ ErrorOr serenity_main(Main::Arguments arguments) if (auto color_management_module_bits = flags.color_management_module_bits()) outln(" CMM bits: 0x{:04x}", color_management_module_bits); - out_optional(" device manufacturer", profile->device_manufacturer()); - out_optional(" device model", profile->device_model()); + out_optional(" device manufacturer", TRY(profile->device_manufacturer().map([](auto device_manufacturer) { + return hyperlink(device_manufacturer_url(device_manufacturer), device_manufacturer); + }))); + out_optional(" device model", TRY(profile->device_model().map([](auto device_model) { + return hyperlink(device_model_url(device_model), device_model); + }))); auto device_attributes = profile->device_attributes(); outln(" device attributes: 0x{:016x}", device_attributes.bits());