2022-12-26 13:21:54 +00:00
|
|
|
/*
|
2023-01-21 01:24:55 +00:00
|
|
|
* Copyright (c) 2022-2023, Nico Weber <thakis@chromium.org>
|
2022-12-26 13:21:54 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <LibCore/ArgsParser.h>
|
2022-12-27 18:38:08 +00:00
|
|
|
#include <LibCore/DateTime.h>
|
2022-12-26 13:21:54 +00:00
|
|
|
#include <LibCore/MappedFile.h>
|
|
|
|
#include <LibGfx/ICCProfile.h>
|
|
|
|
|
2023-01-06 20:57:31 +00:00
|
|
|
template<class T>
|
|
|
|
static void out_optional(char const* label, Optional<T> optional)
|
|
|
|
{
|
|
|
|
out("{}: ", label);
|
|
|
|
if (optional.has_value())
|
|
|
|
outln("{}", *optional);
|
|
|
|
else
|
|
|
|
outln("(not set)");
|
|
|
|
}
|
|
|
|
|
2022-12-26 13:21:54 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
|
|
{
|
|
|
|
Core::ArgsParser args_parser;
|
|
|
|
|
|
|
|
static StringView icc_path;
|
|
|
|
args_parser.add_positional_argument(icc_path, "Path to ICC profile", "FILE");
|
|
|
|
args_parser.parse(arguments);
|
|
|
|
|
|
|
|
auto icc_file = TRY(Core::MappedFile::map(icc_path));
|
|
|
|
auto profile = TRY(Gfx::ICC::Profile::try_load_from_externally_owned_memory(icc_file->bytes()));
|
|
|
|
|
2023-01-21 01:24:55 +00:00
|
|
|
out_optional(" preferred CMM type", profile->preferred_cmm_type());
|
|
|
|
outln(" version: {}", profile->version());
|
|
|
|
outln(" device class: {}", Gfx::ICC::device_class_name(profile->device_class()));
|
|
|
|
outln(" data color space: {}", Gfx::ICC::data_color_space_name(profile->data_color_space()));
|
|
|
|
outln(" connection space: {}", Gfx::ICC::profile_connection_space_name(profile->connection_space()));
|
2023-01-21 01:46:39 +00:00
|
|
|
outln("creation date and time: {}", Core::DateTime::from_timestamp(profile->creation_timestamp()));
|
2023-01-21 01:24:55 +00:00
|
|
|
outln(" primary platform: {}", Gfx::ICC::primary_platform_name(profile->primary_platform()));
|
2022-12-31 18:50:52 +00:00
|
|
|
|
|
|
|
auto flags = profile->flags();
|
2023-01-21 01:24:55 +00:00
|
|
|
outln(" flags: 0x{:08x}", flags.bits());
|
|
|
|
outln(" - {}embedded in file", flags.is_embedded_in_file() ? "" : "not ");
|
|
|
|
outln(" - can{} be used independently of embedded color data", flags.can_be_used_independently_of_embedded_color_data() ? "" : "not");
|
2022-12-31 18:50:52 +00:00
|
|
|
if (auto unknown_icc_bits = flags.icc_bits() & ~Gfx::ICC::Flags::KnownBitsMask)
|
2023-01-21 01:24:55 +00:00
|
|
|
outln(" other unknown ICC bits: 0x{:04x}", unknown_icc_bits);
|
2022-12-31 18:50:52 +00:00
|
|
|
if (auto color_management_module_bits = flags.color_management_module_bits())
|
2023-01-21 01:24:55 +00:00
|
|
|
outln(" CMM bits: 0x{:04x}", color_management_module_bits);
|
2022-12-31 18:50:52 +00:00
|
|
|
|
2023-01-21 01:24:55 +00:00
|
|
|
out_optional(" device manufacturer", profile->device_manufacturer());
|
|
|
|
out_optional(" device model", profile->device_model());
|
2023-01-06 20:57:45 +00:00
|
|
|
|
2023-01-06 20:06:30 +00:00
|
|
|
auto device_attributes = profile->device_attributes();
|
2023-01-21 01:24:55 +00:00
|
|
|
outln(" device attributes: 0x{:016x}", device_attributes.bits());
|
|
|
|
outln(" media is:");
|
|
|
|
outln(" - {}",
|
|
|
|
device_attributes.media_reflectivity() == Gfx::ICC::DeviceAttributes::MediaReflectivity::Reflective ? "reflective" : "transparent");
|
|
|
|
outln(" - {}",
|
|
|
|
device_attributes.media_glossiness() == Gfx::ICC::DeviceAttributes::MediaGlossiness::Glossy ? "glossy" : "matte");
|
|
|
|
outln(" - {}",
|
|
|
|
device_attributes.media_polarity() == Gfx::ICC::DeviceAttributes::MediaPolarity::Positive ? "of positive polarity" : "of negative polarity");
|
|
|
|
outln(" - {}",
|
2023-01-06 20:06:30 +00:00
|
|
|
device_attributes.media_color() == Gfx::ICC::DeviceAttributes::MediaColor::Colored ? "colored" : "black and white");
|
|
|
|
VERIFY((flags.icc_bits() & ~Gfx::ICC::DeviceAttributes::KnownBitsMask) == 0);
|
|
|
|
if (auto vendor_bits = device_attributes.vendor_bits())
|
2023-01-21 01:24:55 +00:00
|
|
|
outln(" vendor bits: 0x{:08x}", vendor_bits);
|
2023-01-06 20:06:30 +00:00
|
|
|
|
2023-01-21 01:24:55 +00:00
|
|
|
outln(" rendering intent: {}", Gfx::ICC::rendering_intent_name(profile->rendering_intent()));
|
|
|
|
outln(" pcs illuminant: {}", profile->pcs_illuminant());
|
|
|
|
out_optional(" creator", profile->creator());
|
|
|
|
out_optional(" id", profile->id());
|
2023-01-04 19:56:27 +00:00
|
|
|
|
2023-01-08 12:07:21 +00:00
|
|
|
size_t profile_disk_size = icc_file->size();
|
|
|
|
if (profile_disk_size != profile->on_disk_size()) {
|
|
|
|
VERIFY(profile_disk_size > profile->on_disk_size());
|
|
|
|
outln("{} trailing bytes after profile data", profile_disk_size - profile->on_disk_size());
|
|
|
|
}
|
|
|
|
|
2023-01-20 19:37:25 +00:00
|
|
|
outln("");
|
|
|
|
|
|
|
|
outln("tags:");
|
|
|
|
profile->for_each_tag([](auto tag_signature, auto tag_data) {
|
|
|
|
outln("{}: {}, offset {}, size {}", tag_signature, tag_data->type(), tag_data->offset(), tag_data->size());
|
|
|
|
});
|
|
|
|
|
2022-12-26 13:21:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|