Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMYK JPEGs appearing inverted in PDF output #2179

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions weasyprint/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, pillow_image, image_id, image_data, filename=None,
self.height = pillow_image.height
self.ratio = (self.width / self.height) if self.height != 0 else inf
self.optimize = optimize = options['optimize_images']
self.app14 = getattr(original_pillow_image, 'app', {}).get('APP14')

if pillow_image.format in ('JPEG', 'MPO'):
self.format = 'JPEG'
Expand Down Expand Up @@ -150,6 +151,11 @@ def get_x_object(self, interpolate, dpi_ratio):
})

if self.format == 'JPEG':
if self.mode == 'CMYK' and self.app14 is not None:
# The presence of the APP14 segment indicates an Adobe image
# with inverted CMYK data. Specify a Decode Array to invert
# it again back to normal.
extra['Decode'] = '[1 0 1 0 1 0 1 0]'
extra['Filter'] = '/DCTDecode'
return pydyf.Stream([self.image_data], extra)

Expand Down
Loading