Experiment w/ optipng...

This commit is contained in:
NiLuJe 2019-05-24 04:41:35 +02:00
parent b5554bd0da
commit d6efb350bf
3 changed files with 10 additions and 2 deletions

View File

@ -1023,7 +1023,7 @@ class KOBO(USBMS):
debug_print('FAILED to upload cover', filepath)
def _upload_cover(self, path, filename, metadata, filepath, uploadgrayscale, ditheredcovers, letterboxcovers, pngcovers):
from calibre.utils.img import save_cover_data_to
from calibre.utils.img import save_cover_data_to, optimize_png
if metadata.cover:
cover = self.normalize_path(metadata.cover.replace('/', os.sep))
@ -1077,6 +1077,9 @@ class KOBO(USBMS):
f.write(data)
fsync(f)
if pngcovers:
optimize_png(fpath)
else:
debug_print("ImageID could not be retreived from the database")
@ -2697,6 +2700,7 @@ class KOBOTOUCH(KOBO):
def _upload_cover(self, path, filename, metadata, filepath, upload_grayscale, dithered_covers=False, keep_cover_aspect=False, letterbox_fs_covers=False, png_covers=False):
from calibre.utils.imghdr import identify
from calibre.utils.img import optimize_png
debug_print("KoboTouch:_upload_cover - filename='%s' upload_grayscale='%s' dithered_covers='%s' "%(filename, upload_grayscale, dithered_covers))
if not metadata.cover:
@ -2780,6 +2784,9 @@ class KOBOTOUCH(KOBO):
with lopen(fpath, 'wb') as f:
f.write(data)
fsync(f)
if png_covers:
optimize_png(fpath)
except Exception as e:
err = unicode_type(e)
debug_print("KoboTouch:_upload_cover - Exception string: %s"%err)

View File

@ -79,6 +79,7 @@ QImage ordered_dither(const QImage &image) { // {{{
QImage img = image;
int y = 0, x = 0, width = img.width(), height = img.height();
uint8_t gray = 0, dithered = 0;
// NOTE: We went with Grayscale8 because QImageWriter was doing some weird things with an Indexed8 input...
QImage dst(width, height, QImage::Format_Grayscale8);
// We're running behind blend_image, so, we should only ever be fed RGB32 as input...

View File

@ -233,7 +233,7 @@ def save_cover_data_to(data, path=None, bgcolor='#ffffff', resize_to=None, compr
img = grayscale_image(img)
if eink:
# NOTE: Keep in mind that JPG does NOT actually support indexed colors, so the JPG algorithm will then smush everything back into a 256c mess...
# Thankfully, Nickel handles PNG just fine, and we generate smaller files to boot, because they're properly color indexed ;).
# Thankfully, Nickel handles PNG just fine, and we potentially generate smaller files to boot, because they can be properly color indexed ;).
img = eink_dither_image(img)
changed = True
if path is None: