mirror of
https://github.com/ciromattia/kcc
synced 2026-10-12 04:22:32 +00:00
Merge branch 'master' of https://github.com/devernay/kcc into kcc-gamma
This commit is contained in:
+9
-2
@@ -252,7 +252,7 @@ def isInFilelist(filename, filelist):
|
|||||||
|
|
||||||
|
|
||||||
def applyImgOptimization(img, isSplit=False, toRight=False):
|
def applyImgOptimization(img, isSplit=False, toRight=False):
|
||||||
img.optimizeImage()
|
img.optimizeImage(options.gamma)
|
||||||
img.cropWhiteSpace(10.0)
|
img.cropWhiteSpace(10.0)
|
||||||
if options.cutpagenumbers:
|
if options.cutpagenumbers:
|
||||||
img.cutPageNumber()
|
img.cutPageNumber()
|
||||||
@@ -277,7 +277,10 @@ def dirImgProcess(path):
|
|||||||
else:
|
else:
|
||||||
print ".",
|
print ".",
|
||||||
img = image.ComicPage(os.path.join(dirpath, afile), options.profile)
|
img = image.ComicPage(os.path.join(dirpath, afile), options.profile)
|
||||||
split = img.splitPage(dirpath, options.righttoleft, options.rotate)
|
if options.nosplitrotate:
|
||||||
|
split = None
|
||||||
|
else:
|
||||||
|
split = img.splitPage(dirpath, options.righttoleft, options.rotate)
|
||||||
if split is not None:
|
if split is not None:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print "Splitted " + afile
|
print "Splitted " + afile
|
||||||
@@ -396,6 +399,8 @@ def main(argv=None):
|
|||||||
help="Verbose output [default=False]")
|
help="Verbose output [default=False]")
|
||||||
parser.add_option("--no-image-processing", action="store_false", dest="imgproc", default=True,
|
parser.add_option("--no-image-processing", action="store_false", dest="imgproc", default=True,
|
||||||
help="Do not apply image preprocessing (page splitting and optimizations) [default=True]")
|
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("--upscale-images", action="store_true", dest="upscale", default=False,
|
parser.add_option("--upscale-images", action="store_true", dest="upscale", default=False,
|
||||||
help="Resize images smaller than device's resolution [default=False]")
|
help="Resize images smaller than device's resolution [default=False]")
|
||||||
parser.add_option("--stretch-images", action="store_true", dest="stretch", default=False,
|
parser.add_option("--stretch-images", action="store_true", dest="stretch", default=False,
|
||||||
@@ -405,6 +410,8 @@ def main(argv=None):
|
|||||||
+ "is not like the device's one [default=False]")
|
+ "is not like the device's one [default=False]")
|
||||||
parser.add_option("--no-cut-page-numbers", action="store_false", dest="cutpagenumbers", default=True,
|
parser.add_option("--no-cut-page-numbers", action="store_false", dest="cutpagenumbers", default=True,
|
||||||
help="Do not try to cut page numbering on images [default=True]")
|
help="Do not try to cut page numbering on images [default=True]")
|
||||||
|
parser.add_option("--nosplitrotate", action="store_true", dest="nosplitrotate", default=False,
|
||||||
|
help="Disable splitting and rotation [default=False]")
|
||||||
parser.add_option("--rotate", action="store_true", dest="rotate", default=False,
|
parser.add_option("--rotate", action="store_true", dest="rotate", default=False,
|
||||||
help="Rotate landscape pages instead of splitting them [default=False]")
|
help="Rotate landscape pages instead of splitting them [default=False]")
|
||||||
parser.add_option("-o", "--output", action="store", dest="output", default=None,
|
parser.add_option("-o", "--output", action="store", dest="output", default=None,
|
||||||
|
|||||||
+16
-2
@@ -89,9 +89,11 @@ class MainWindow:
|
|||||||
self.options = {
|
self.options = {
|
||||||
'epub_only': IntVar(None, 0),
|
'epub_only': IntVar(None, 0),
|
||||||
'image_preprocess': IntVar(None, 1),
|
'image_preprocess': IntVar(None, 1),
|
||||||
|
'nosplitrotate': IntVar(None, 0),
|
||||||
'rotate': IntVar(None, 0),
|
'rotate': IntVar(None, 0),
|
||||||
'cut_page_numbers': IntVar(None, 1),
|
'cut_page_numbers': IntVar(None, 1),
|
||||||
'mangastyle': IntVar(None, 0),
|
'mangastyle': IntVar(None, 0),
|
||||||
|
'image_gamma': DoubleVar(None, 2.2),
|
||||||
'image_upscale': IntVar(None, 0),
|
'image_upscale': IntVar(None, 0),
|
||||||
'image_stretch': IntVar(None, 0),
|
'image_stretch': IntVar(None, 0),
|
||||||
'black_borders': IntVar(None, 0)
|
'black_borders': IntVar(None, 0)
|
||||||
@@ -99,16 +101,24 @@ class MainWindow:
|
|||||||
self.optionlabels = {
|
self.optionlabels = {
|
||||||
'epub_only': "Generate ePub only (does not call 'kindlegen')",
|
'epub_only': "Generate ePub only (does not call 'kindlegen')",
|
||||||
'image_preprocess': "Apply image optimizations",
|
'image_preprocess': "Apply image optimizations",
|
||||||
|
'nosplitrotate': "Disable splitting and rotation",
|
||||||
'rotate': "Rotate landscape images instead of splitting them",
|
'rotate': "Rotate landscape images instead of splitting them",
|
||||||
'cut_page_numbers': "Cut page numbers",
|
'cut_page_numbers': "Cut page numbers",
|
||||||
'mangastyle': "Manga-style (right-to-left reading, applies to reading and splitting)",
|
'mangastyle': "Manga-style (right-to-left reading, applies to reading and splitting)",
|
||||||
|
'image_gamma': "Gamma value",
|
||||||
'image_upscale': "Allow image upscaling",
|
'image_upscale': "Allow image upscaling",
|
||||||
'image_stretch': "Stretch images",
|
'image_stretch': "Stretch images",
|
||||||
'black_borders': "Use black borders"
|
'black_borders': "Use black borders"
|
||||||
}
|
}
|
||||||
for key in self.options:
|
for key in self.options:
|
||||||
aCheckButton = Checkbutton(self.master, text=self.optionlabels[key], variable=self.options[key])
|
if isinstance( self.options[key], IntVar ) or isinstance( self.options[key], BooleanVar ):
|
||||||
aCheckButton.grid(column=3, sticky='w')
|
aCheckButton = Checkbutton(self.master, text=self.optionlabels[key], variable=self.options[key])
|
||||||
|
aCheckButton.grid(column=3, sticky='w')
|
||||||
|
elif isinstance( self.options[key], DoubleVar ):
|
||||||
|
aLabel = Label(self.master, text=self.optionlabels[key])
|
||||||
|
aLabel.grid(column=2, sticky='w')
|
||||||
|
aEntry = Entry(self.master, textvariable=self.options[key])
|
||||||
|
aEntry.grid(column=3, row=(self.master.grid_size()[1]-1), sticky='w')
|
||||||
self.progressbar = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate')
|
self.progressbar = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate')
|
||||||
|
|
||||||
self.submit = Button(self.master, text="Execute!", command=self.start_conversion, fg="red")
|
self.submit = Button(self.master, text="Execute!", command=self.start_conversion, fg="red")
|
||||||
@@ -132,12 +142,16 @@ class MainWindow:
|
|||||||
argv = ["-p", profilekey]
|
argv = ["-p", profilekey]
|
||||||
if self.options['image_preprocess'].get() == 0:
|
if self.options['image_preprocess'].get() == 0:
|
||||||
argv.append("--no-image-processing")
|
argv.append("--no-image-processing")
|
||||||
|
if self.options['nosplitrotate'].get() == 1:
|
||||||
|
argv.append("--nosplitrotate")
|
||||||
if self.options['rotate'].get() == 1:
|
if self.options['rotate'].get() == 1:
|
||||||
argv.append("--rotate")
|
argv.append("--rotate")
|
||||||
if self.options['cut_page_numbers'].get() == 0:
|
if self.options['cut_page_numbers'].get() == 0:
|
||||||
argv.append("--no-cut-page-numbers")
|
argv.append("--no-cut-page-numbers")
|
||||||
if self.options['mangastyle'].get() == 1:
|
if self.options['mangastyle'].get() == 1:
|
||||||
argv.append("-m")
|
argv.append("-m")
|
||||||
|
argv.append("--gamma")
|
||||||
|
argv.append(self.options['image_gamma'].get())
|
||||||
if self.options['image_upscale'].get() == 1:
|
if self.options['image_upscale'].get() == 1:
|
||||||
argv.append("--upscale-images")
|
argv.append("--upscale-images")
|
||||||
if self.options['image_stretch'].get() == 1:
|
if self.options['image_stretch'].get() == 1:
|
||||||
|
|||||||
+6
-3
@@ -115,12 +115,15 @@ class ComicPage:
|
|||||||
filename = os.path.basename(self.origFileName)
|
filename = os.path.basename(self.origFileName)
|
||||||
try:
|
try:
|
||||||
self.image = self.image.convert('L') # convert to grayscale
|
self.image = self.image.convert('L') # convert to grayscale
|
||||||
self.image.save(os.path.join(targetdir, filename), "JPEG")
|
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
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
|
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
|
||||||
|
|
||||||
def optimizeImage(self):
|
def optimizeImage(self, gamma):
|
||||||
self.image = ImageOps.autocontrast(self.image)
|
self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: 255*(a/255.)**gamma))
|
||||||
|
# self.image = ImageOps.autocontrast(self.image)
|
||||||
|
|
||||||
def quantizeImage(self):
|
def quantizeImage(self):
|
||||||
colors = len(self.palette) / 3
|
colors = len(self.palette) / 3
|
||||||
|
|||||||
Reference in New Issue
Block a user