From b162425e52c4e118fe4de89371f437632c4261cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Tue, 5 Mar 2013 22:31:26 +0100 Subject: [PATCH] Added option to disable dithering --- kcc/comic2ebook.py | 5 ++++- kcc/image.py | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 0c89a6c..c39ffeb 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -257,7 +257,8 @@ def applyImgOptimization(img, isSplit=False, toRight=False): if options.cutpagenumbers: img.cutPageNumber() img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight) - img.quantizeImage() + if not options.notquantize: + img.quantizeImage() def dirImgProcess(path): @@ -401,6 +402,8 @@ def main(argv=None): help="Do not apply image preprocessing (page splitting and optimizations) [default=True]") parser.add_option("--gamma", type="float", dest="gamma", default=2.2, help="Apply gamma correction to linearize the image [default=2.2]") + parser.add_option("--nodithering", action="store_true", dest="notquantize", default=False, + help="Disable image quantization [default=False]") parser.add_option("--upscale-images", action="store_true", dest="upscale", default=False, help="Resize images smaller than device's resolution [default=False]") parser.add_option("--stretch-images", action="store_true", dest="stretch", default=False, diff --git a/kcc/image.py b/kcc/image.py index 00c1067..e856d81 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -115,15 +115,17 @@ class ComicPage: filename = os.path.basename(self.origFileName) try: self.image = self.image.convert('L') # convert to grayscale - os.remove(os.path.join(targetdir,filename)) # remove original file, copied by copytree() in comic2ebook.py -# self.image.save(os.path.join(targetdir, filename), "JPEG") - self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".png"), "PNG") # quantized images don't like JPEG + os.remove(os.path.join(targetdir,filename)) + if options.notquantize: + self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".jpg"), "JPEG") + else: + self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".png"), "PNG") except IOError as e: raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e)) def optimizeImage(self, gamma): self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: 255*(a/255.)**gamma)) -# self.image = ImageOps.autocontrast(self.image) + def quantizeImage(self): colors = len(self.palette) / 3