Comic conversion: Fix conversion of comic images that are stored as 8-bit grayscale images in JPEG format not working when converting to PDF. Fixes #1956932 [pdf convertion of 8 bit jpg](https://bugs.launchpad.net/calibre/+bug/1956932)

This commit is contained in:
Kovid Goyal 2022-01-17 21:24:27 +05:30
parent 5d15c9ded4
commit 0cf7af69ac
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 11 deletions

View File

@ -98,20 +98,15 @@ class Image: # {{{
path_or_bytes = f.read()
self.img_data = path_or_bytes
fmt, width, height = identify(path_or_bytes)
if width > 0 and height > 0 and fmt == 'jpeg':
self.fmt = fmt
self.width, self.height = width, height
self.cache_key = None
else:
self.img, self.fmt = image_and_format_from_data(path_or_bytes)
self.width, self.height = self.img.width(), self.img.height()
self.cache_key = self.img.cacheKey()
self.img, self.fmt = image_and_format_from_data(path_or_bytes)
self.width, self.height = self.img.width(), self.img.height()
self.cache_key = self.img.cacheKey()
# }}}
def draw_image_page(writer, img, preserve_aspect_ratio=True):
if img.fmt == 'jpeg':
ref = writer.add_jpeg_image(img.img_data, img.width, img.height, img.cache_key)
ref = writer.add_jpeg_image(img.img_data, img.width, img.height, img.cache_key, depth=img.img.depth())
else:
ref = writer.add_image(img.img, img.cache_key)
page_size = tuple(writer.page_size)

View File

@ -416,8 +416,8 @@ class PDFStream:
self.objects.commit(r, self.stream)
return r
def add_jpeg_image(self, img_data, w, h, cache_key=None):
return self.write_image(img_data, w, h, 32, dct=True)
def add_jpeg_image(self, img_data, w, h, cache_key=None, depth=32):
return self.write_image(img_data, w, h, depth, dct=True)
def add_image(self, img, cache_key):
ref = self.get_image(cache_key)