1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:57:45 +00:00

LibPDF+LibGfx: Don't invert CMYK channels in JPEG data in PDFs

This is a hack: Ideally we'd have a CMYK Bitmap pixel format,
and we'd convert to rgb at blit time. Then we could also apply color
profiles (which for CMYK images are CMYK-based).

Also, the colors for our CMYK->RGB conversion are off for PDFs,
and we have distinct codepaths for this in Gfx::Color (for paths)
and JPEGs. So when we fix that, we'll have to fix it in two places.

But this doesn't require a lot of code and it's a huge visual
progression, so let's go with it for now.
This commit is contained in:
Nico Weber 2023-11-15 12:58:06 -05:00 committed by Sam Atkins
parent bd7ae7f91e
commit bfe27228a3
3 changed files with 26 additions and 6 deletions

View file

@ -271,7 +271,7 @@ PDFErrorOr<ByteBuffer> Filter::decode_jbig2(ReadonlyBytes)
PDFErrorOr<ByteBuffer> Filter::decode_dct(ReadonlyBytes bytes)
{
if (Gfx::JPEGImageDecoderPlugin::sniff({ bytes.data(), bytes.size() })) {
auto decoder = TRY(Gfx::JPEGImageDecoderPlugin::create({ bytes.data(), bytes.size() }));
auto decoder = TRY(Gfx::JPEGImageDecoderPlugin::create_with_options({ bytes.data(), bytes.size() }, { .cmyk = Gfx::JPEGDecoderOptions::CMYK::PDF }));
auto frame = TRY(decoder->frame(0));
return TRY(frame.image->serialize_to_byte_buffer());
}