1
0
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:
Ciro Mattia Gonano
2013-03-06 11:32:20 +01:00
parent df41ad405e
commit ce824f4cab
3 changed files with 26 additions and 25 deletions

View File

@@ -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"
@@ -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,

View File

@@ -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,7 +101,7 @@ 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"
@@ -112,8 +111,8 @@ class MainWindow:
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)
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)
@@ -129,6 +128,7 @@ class MainWindow:
return
profilekey = ProfileData.ProfileLabels[self.profile.get()]
argv = ["-p", profilekey]
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:

View File

@@ -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:
@@ -124,9 +124,10 @@ class ComicPage:
raise RuntimeError('Cannot write image in directory %s: %s' % (targetdir, e))
def optimizeImage(self, 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
if colors < 256: