1
0
mirror of https://github.com/ciromattia/kcc synced 2026-02-19 18:48:57 +00:00

Merge branch 'master' of https://github.com/devernay/kcc into kcc-gamma

This commit is contained in:
Paweł Jastrzębski
2013-03-05 21:49:24 +01:00
3 changed files with 31 additions and 7 deletions

View File

@@ -252,7 +252,7 @@ def isInFilelist(filename, filelist):
def applyImgOptimization(img, isSplit=False, toRight=False):
img.optimizeImage()
img.optimizeImage(options.gamma)
img.cropWhiteSpace(10.0)
if options.cutpagenumbers:
img.cutPageNumber()
@@ -277,7 +277,10 @@ def dirImgProcess(path):
else:
print ".",
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 options.verbose:
print "Splitted " + afile
@@ -396,6 +399,8 @@ def main(argv=None):
help="Verbose output [default=False]")
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]")
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,
help="Resize images smaller than device's resolution [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]")
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]")
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,
help="Rotate landscape pages instead of splitting them [default=False]")
parser.add_option("-o", "--output", action="store", dest="output", default=None,

View File

@@ -89,9 +89,11 @@ class MainWindow:
self.options = {
'epub_only': IntVar(None, 0),
'image_preprocess': IntVar(None, 1),
'nosplitrotate': IntVar(None, 0),
'rotate': IntVar(None, 0),
'cut_page_numbers': IntVar(None, 1),
'mangastyle': IntVar(None, 0),
'image_gamma': DoubleVar(None, 2.2),
'image_upscale': IntVar(None, 0),
'image_stretch': IntVar(None, 0),
'black_borders': IntVar(None, 0)
@@ -99,16 +101,24 @@ class MainWindow:
self.optionlabels = {
'epub_only': "Generate ePub only (does not call 'kindlegen')",
'image_preprocess': "Apply image optimizations",
'nosplitrotate': "Disable splitting and rotation",
'rotate': "Rotate landscape images instead of splitting them",
'cut_page_numbers': "Cut page numbers",
'mangastyle': "Manga-style (right-to-left reading, applies to reading and splitting)",
'image_gamma': "Gamma value",
'image_upscale': "Allow image upscaling",
'image_stretch': "Stretch images",
'black_borders': "Use black borders"
}
for key in self.options:
aCheckButton = Checkbutton(self.master, text=self.optionlabels[key], variable=self.options[key])
aCheckButton.grid(column=3, sticky='w')
if isinstance( self.options[key], IntVar ) or isinstance( self.options[key], BooleanVar ):
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.submit = Button(self.master, text="Execute!", command=self.start_conversion, fg="red")
@@ -132,12 +142,16 @@ class MainWindow:
argv = ["-p", profilekey]
if self.options['image_preprocess'].get() == 0:
argv.append("--no-image-processing")
if self.options['nosplitrotate'].get() == 1:
argv.append("--nosplitrotate")
if self.options['rotate'].get() == 1:
argv.append("--rotate")
if self.options['cut_page_numbers'].get() == 0:
argv.append("--no-cut-page-numbers")
if self.options['mangastyle'].get() == 1:
argv.append("-m")
argv.append("--gamma")
argv.append(self.options['image_gamma'].get())
if self.options['image_upscale'].get() == 1:
argv.append("--upscale-images")
if self.options['image_stretch'].get() == 1:

View File

@@ -115,12 +115,15 @@ class ComicPage:
filename = os.path.basename(self.origFileName)
try:
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:
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
def optimizeImage(self):
self.image = ImageOps.autocontrast(self.image)
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