1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 16:37:47 +03:00

Run color inversion logic code when image instance is created

The attribute name is more readable this way.
This commit is contained in:
Guillaume Ayoub 2024-06-08 21:57:54 +02:00
parent 4ce48a4214
commit 1efe1b6b0a

View File

@ -66,7 +66,12 @@ class RasterImage:
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')
# 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. See https://github.com/Kozea/WeasyPrint/pull/2179.
app14 = getattr(original_pillow_image, 'app', {}).get('APP14')
self.invert_colors = self.mode == 'CMYK' and app14 is not None
if pillow_image.format in ('JPEG', 'MPO'):
self.format = 'JPEG'
@ -151,11 +156,8 @@ class RasterImage:
})
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]'
if self.invert_colors:
extra['Decode'] = pydyf.Array((1, 0) * 4)
extra['Filter'] = '/DCTDecode'
return pydyf.Stream([self.image_data], extra)