From fbc70eca93415373c76307bfe24284b32230de13 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 15 Mar 2023 11:13:34 +0100 Subject: [PATCH] image: Preserve ICC profiles in PNG output This probably does strange things for CMYK jpegs, since JPEGLoader converts those from CMYK to RGB but the ICC profile is still an CMYK profile. The Right Fix for that is probably for JPEGLoader to consume the profile when it does CMYK->RGB conversion and then not hand out the profile data. (Or we could add a CMYK bitmap type.) But most of the time, this is a progression :^) --- Userland/Utilities/image.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/image.cpp b/Userland/Utilities/image.cpp index 134455871d..579fdfc082 100644 --- a/Userland/Utilities/image.cpp +++ b/Userland/Utilities/image.cpp @@ -39,12 +39,13 @@ ErrorOr serenity_main(Main::Arguments arguments) // This uses ImageDecoder instead of Bitmap::load_from_file() to have more control // over selecting a frame, access color profile data, and so on in the future. auto frame = TRY(decoder->frame(0)).image; + Optional icc_data = TRY(decoder->icc_data()); ByteBuffer bytes; if (out_path.ends_with(".bmp"sv, CaseSensitivity::CaseInsensitive)) { bytes = TRY(Gfx::BMPWriter::encode(*frame)); } else if (out_path.ends_with(".png"sv, CaseSensitivity::CaseInsensitive)) { - bytes = TRY(Gfx::PNGWriter::encode(*frame)); + bytes = TRY(Gfx::PNGWriter::encode(*frame, { .icc_data = icc_data })); } else if (out_path.ends_with(".ppm"sv, CaseSensitivity::CaseInsensitive)) { auto const format = ppm_ascii ? Gfx::PortableFormatWriter::Options::Format::ASCII : Gfx::PortableFormatWriter::Options::Format::Raw; bytes = TRY(Gfx::PortableFormatWriter::encode(*frame, Gfx::PortableFormatWriter::Options { .format = format }));