1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:17:35 +00:00

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 :^)
This commit is contained in:
Nico Weber 2023-03-15 11:13:34 +01:00 committed by Linus Groh
parent 189ea375a5
commit fbc70eca93

View file

@ -39,12 +39,13 @@ ErrorOr<int> 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<ReadonlyBytes> 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 }));