mirror of
https://github.com/ciromattia/kcc
synced 2025-12-13 09:46:25 +00:00
Add default gamma by profile support
This commit is contained in:
@@ -127,7 +127,7 @@ def buildNCX(dstdir, title, chapters):
|
||||
def buildOPF(profile, dstdir, title, filelist, cover=None, righttoleft=False):
|
||||
opffile = os.path.join(dstdir, 'OEBPS', 'content.opf')
|
||||
# read the first file resolution
|
||||
profilelabel, deviceres, palette = image.ProfileData.Profiles[profile]
|
||||
profilelabel, deviceres, palette, gamma = image.ProfileData.Profiles[profile]
|
||||
imgres = str(deviceres[0]) + "x" + str(deviceres[1])
|
||||
if righttoleft:
|
||||
writingmode = "horizontal-rl"
|
||||
@@ -258,7 +258,7 @@ def applyImgOptimization(img, isSplit=False, toRight=False):
|
||||
img.cutPageNumber()
|
||||
img.resizeImage(options.upscale, options.stretch, options.black_borders, isSplit, toRight)
|
||||
if not options.notquantize:
|
||||
img.quantizeImage()
|
||||
img.quantizeImage()
|
||||
|
||||
|
||||
def dirImgProcess(path):
|
||||
@@ -400,8 +400,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("--gamma", type="float", dest="gamma", default="0.0",
|
||||
help="Apply gamma correction to linearize the image [default=auto]")
|
||||
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,
|
||||
|
||||
20
kcc/gui.py
20
kcc/gui.py
@@ -23,7 +23,6 @@ __docformat__ = 'restructuredtext en'
|
||||
from Tkinter import *
|
||||
import tkFileDialog
|
||||
import tkMessageBox
|
||||
import ttk
|
||||
import comic2ebook
|
||||
import kindlestrip
|
||||
from image import ProfileData
|
||||
@@ -89,7 +88,7 @@ class MainWindow:
|
||||
'rotate': IntVar(None, 0),
|
||||
'cut_page_numbers': IntVar(None, 1),
|
||||
'mangastyle': IntVar(None, 0),
|
||||
'image_gamma': DoubleVar(None, 2.2),
|
||||
'image_gamma': DoubleVar(None, 0.0),
|
||||
'image_upscale': IntVar(None, 0),
|
||||
'image_stretch': IntVar(None, 0),
|
||||
'black_borders': IntVar(None, 0)
|
||||
@@ -102,20 +101,20 @@ class MainWindow:
|
||||
'rotate': "Rotate landscape images instead of splitting them",
|
||||
'cut_page_numbers': "Cut page numbers",
|
||||
'mangastyle': "Manga mode",
|
||||
'image_gamma': "Gamma",
|
||||
'image_gamma': "Custom gamma\n(if 0.0 the default gamma for the profile will be used)",
|
||||
'image_upscale': "Allow image upscaling",
|
||||
'image_stretch': "Stretch images",
|
||||
'black_borders': "Use black borders"
|
||||
}
|
||||
for key in self.options:
|
||||
if isinstance( self.options[key], IntVar ) or isinstance( self.options[key], BooleanVar ):
|
||||
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(columnspan=4, sticky=W + N + S)
|
||||
elif isinstance( self.options[key], DoubleVar ):
|
||||
aLabel = Label(self.master, text=self.optionlabels[key])
|
||||
aLabel.grid(column=2, sticky=W + N + S)
|
||||
elif isinstance(self.options[key], DoubleVar):
|
||||
aLabel = Label(self.master, text=self.optionlabels[key], justify=RIGHT)
|
||||
aLabel.grid(column=0, columnspan=3, sticky=W + N + S)
|
||||
aEntry = Entry(self.master, textvariable=self.options[key])
|
||||
aEntry.grid(column=3, row=(self.master.grid_size()[1]-1), sticky=W + N + S)
|
||||
aEntry.grid(column=3, row=(self.master.grid_size()[1] - 1), sticky=W + N + S)
|
||||
|
||||
self.submit = Button(self.master, text="CONVERT", command=self.start_conversion, fg="red")
|
||||
self.submit.grid(columnspan=4, sticky=W + E + N + S)
|
||||
@@ -129,8 +128,9 @@ class MainWindow:
|
||||
return
|
||||
profilekey = ProfileData.ProfileLabels[self.profile.get()]
|
||||
argv = ["-p", profilekey]
|
||||
argv.append("--gamma")
|
||||
argv.append(self.options['image_gamma'].get())
|
||||
if self.options['image_gamma'].get() != 0.0:
|
||||
argv.append("--gamma")
|
||||
argv.append(self.options['image_gamma'].get())
|
||||
if self.options['image_preprocess'].get() == 0:
|
||||
argv.append("--no-image-processing")
|
||||
if self.options['notquantize'].get() == 1:
|
||||
|
||||
23
kcc/image.py
23
kcc/image.py
@@ -77,13 +77,13 @@ class ProfileData:
|
||||
]
|
||||
|
||||
Profiles = {
|
||||
'K1': ("Kindle", (600, 800), Palette4),
|
||||
'K2': ("Kindle 2", (600, 800), Palette15),
|
||||
'K3': ("Kindle 3/Keyboard", (600, 800), Palette16),
|
||||
'K4': ("Kindle 4/NT/Touch", (600, 800), Palette16),
|
||||
'KHD': ("Kindle Paperwhite", (758, 1024), Palette16),
|
||||
'KDX': ("Kindle DX", (824, 1200), Palette15),
|
||||
'KDXG': ("Kindle DXG", (824, 1200), Palette16)
|
||||
'K1': ("Kindle", (600, 800), Palette4, 1.8),
|
||||
'K2': ("Kindle 2", (600, 800), Palette15, 1.8),
|
||||
'K3': ("Kindle 3/Keyboard", (600, 800), Palette16, 1.8),
|
||||
'K4': ("Kindle 4/NT/Touch", (600, 800), Palette16, 1.8),
|
||||
'KHD': ("Kindle Paperwhite", (758, 1024), Palette16, 1.8),
|
||||
'KDX': ("Kindle DX", (824, 1200), Palette15, 1.8),
|
||||
'KDXG': ("Kindle DXG", (824, 1200), Palette16, 1.8)
|
||||
}
|
||||
|
||||
ProfileLabels = {
|
||||
@@ -101,7 +101,7 @@ class ComicPage:
|
||||
def __init__(self, source, device):
|
||||
try:
|
||||
self.profile = device
|
||||
self.profile_label, self.size, self.palette = ProfileData.Profiles[device]
|
||||
self.profile_label, self.size, self.palette, self.gamma = ProfileData.Profiles[device]
|
||||
except KeyError:
|
||||
raise RuntimeError('Unexpected output device %s' % device)
|
||||
try:
|
||||
@@ -115,7 +115,7 @@ 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))
|
||||
os.remove(os.path.join(targetdir, filename))
|
||||
if notquantize:
|
||||
self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".jpg"), "JPEG")
|
||||
else:
|
||||
@@ -124,8 +124,9 @@ class ComicPage:
|
||||
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))
|
||||
|
||||
if gamma < 0.1:
|
||||
gamma = self.gamma
|
||||
self.image = ImageOps.autocontrast(Image.eval(self.image, lambda a: 255 * (a / 255.) ** gamma))
|
||||
|
||||
def quantizeImage(self):
|
||||
colors = len(self.palette) / 3
|
||||
|
||||
Reference in New Issue
Block a user