mirror of
https://github.com/ciromattia/kcc
synced 2026-01-29 00:18:24 +00:00
save dithered images as PNG, and linearize (inverse gamma) before dithering
This commit is contained in:
@@ -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()
|
||||
@@ -396,6 +396,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,
|
||||
|
||||
14
kcc/gui.py
14
kcc/gui.py
@@ -92,6 +92,7 @@ class MainWindow:
|
||||
'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)
|
||||
@@ -102,13 +103,20 @@ class MainWindow:
|
||||
'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")
|
||||
@@ -138,6 +146,8 @@ class MainWindow:
|
||||
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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user