From 572e1422bf08bc0b580548c86cfdf7fbac81d070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Wed, 4 Dec 2013 18:30:19 +0100 Subject: [PATCH] Gamma auto mode is now even more automatic --- KCC-Linux.ui | 6 ------ KCC-OSX.ui | 6 ------ KCC.ui | 6 ------ README.md | 1 - kcc/KCC_gui.py | 2 +- kcc/KCC_ui.py | 4 +--- kcc/KCC_ui_linux.py | 4 +--- kcc/KCC_ui_osx.py | 4 +--- kcc/image.py | 29 ++++++++++++++++++++++++++++- 9 files changed, 32 insertions(+), 30 deletions(-) diff --git a/KCC-Linux.ui b/KCC-Linux.ui index 8034019..9ce0221 100644 --- a/KCC-Linux.ui +++ b/KCC-Linux.ui @@ -543,9 +543,6 @@ p, li { white-space: pre-wrap; } DejaVu Sans - - <html><head/><body><p>When converting color images setting this option to 1.0 <span style=" font-weight:600;">might</span> improve readability.</p></body></html> - Gamma: Auto @@ -567,9 +564,6 @@ p, li { white-space: pre-wrap; } Qt::ClickFocus - - <html><head/><body><p>When converting color images setting this option to 1.0 <span style=" font-weight:600;">might</span> improve readability.</p></body></html> - 500 diff --git a/KCC-OSX.ui b/KCC-OSX.ui index 1c7c5ae..775ab4a 100644 --- a/KCC-OSX.ui +++ b/KCC-OSX.ui @@ -543,9 +543,6 @@ false - - <html><head/><body><p><span style=" font-size:12pt;">When converting color images setting this option to 1.0 </span><span style=" font-size:12pt; font-weight:600;">might</span><span style=" font-size:12pt;"> improve readability.</span></p></body></html> - Gamma: Auto @@ -567,9 +564,6 @@ Qt::ClickFocus - - <html><head/><body><p><span style=" font-size:12pt;">When converting color images setting this option to 1.0 </span><span style=" font-size:12pt; font-weight:600;">might</span><span style=" font-size:12pt;"> improve readability.</span></p></body></html> - 500 diff --git a/KCC.ui b/KCC.ui index edb433a..bd09379 100644 --- a/KCC.ui +++ b/KCC.ui @@ -469,9 +469,6 @@ p, li { white-space: pre-wrap; } 40 - - When converting color images setting this option to 1.0 MIGHT improve readability. - Gamma: Auto @@ -488,9 +485,6 @@ p, li { white-space: pre-wrap; } Qt::ClickFocus - - <html><head/><body><p>When converting color images setting this option to 1.0 <span style=" font-weight:600;">might</span> improve readability.</p></body></html> - 500 diff --git a/README.md b/README.md index 196b847..27b8ee0 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,6 @@ You can find the latest released binary at the following links: * Read tooltip of _High/Ultra quality_ option. There are many important informations there. * When converting images smaller than device resolution remember to enable upscaling. * Panel View (auto zooming every part of page) can be disabled directly on Kindle. There is no KCC option to do that. -* If you're converting color images and the end result is not satisfactory, experiment with gamma correction option (check 1.0 setting first). * Check our [wiki](https://github.com/ciromattia/kcc/wiki/Other-devices) for a list of tested Non-Kindle E-Readers. * The first image found will be set as the comic's cover. * All files/directories will be added to EPUB in alphabetical order. diff --git a/kcc/KCC_gui.py b/kcc/KCC_gui.py index 3713f65..1420f16 100644 --- a/kcc/KCC_gui.py +++ b/kcc/KCC_gui.py @@ -372,6 +372,7 @@ class WorkerThread(QtCore.QThread): if GUI.WebtoonBox.isChecked(): argv.append("--webtoon") if float(GUI.GammaValue) > 0.09: + # noinspection PyTypeChecker argv.append("--gamma=" + GUI.GammaValue) if str(GUI.FormatBox.currentText()) == 'CBZ': argv.append("--cbz-output") @@ -715,7 +716,6 @@ class KCCGUI(KCC_ui.Ui_KCC): GUI.QualityBox.setChecked(False) GUI.MangaBox.setEnabled(False) GUI.MangaBox.setChecked(False) - self.addMessage('If images will be too dark after conversion: Set Gamma to 1.0.', 'info') else: if not GUI.ProcessingBox.isChecked(): GUI.NoRotateBox.setEnabled(True) diff --git a/kcc/KCC_ui.py b/kcc/KCC_ui.py index a491c89..60e4672 100644 --- a/kcc/KCC_ui.py +++ b/kcc/KCC_ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'KCC.ui' # -# Created: Tue Nov 12 14:31:48 2013 +# Created: Wed Dec 04 18:28:13 2013 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! @@ -305,9 +305,7 @@ class Ui_KCC(object): self.RotateBox.setText(_translate("KCC", "Horizontal mode", None)) self.BasicModeButton.setText(_translate("KCC", "Basic", None)) self.AdvModeButton.setText(_translate("KCC", "Advanced", None)) - self.GammaLabel.setToolTip(_translate("KCC", "When converting color images setting this option to 1.0 MIGHT improve readability.", None)) self.GammaLabel.setText(_translate("KCC", "Gamma: Auto", None)) - self.GammaSlider.setToolTip(_translate("KCC", "

When converting color images setting this option to 1.0 might improve readability.

", None)) self.ColorBox.setToolTip(_translate("KCC", "Do not convert images to grayscale.", None)) self.ColorBox.setText(_translate("KCC", "Color mode", None)) self.wLabel.setToolTip(_translate("KCC", "Resolution of target device.", None)) diff --git a/kcc/KCC_ui_linux.py b/kcc/KCC_ui_linux.py index 9fbdea3..372006a 100644 --- a/kcc/KCC_ui_linux.py +++ b/kcc/KCC_ui_linux.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'KCC-Linux.ui' # -# Created: Tue Nov 12 14:32:11 2013 +# Created: Wed Dec 04 18:27:52 2013 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! @@ -374,9 +374,7 @@ class Ui_KCC(object): self.RotateBox.setText(_translate("KCC", "Horizontal mode", None)) self.BasicModeButton.setText(_translate("KCC", "Basic", None)) self.AdvModeButton.setText(_translate("KCC", "Advanced", None)) - self.GammaLabel.setToolTip(_translate("KCC", "

When converting color images setting this option to 1.0 might improve readability.

", None)) self.GammaLabel.setText(_translate("KCC", "Gamma: Auto", None)) - self.GammaSlider.setToolTip(_translate("KCC", "

When converting color images setting this option to 1.0 might improve readability.

", None)) self.ColorBox.setToolTip(_translate("KCC", "Do not convert images to grayscale.", None)) self.ColorBox.setText(_translate("KCC", "Color mode", None)) self.wLabel.setToolTip(_translate("KCC", "Resolution of target device.", None)) diff --git a/kcc/KCC_ui_osx.py b/kcc/KCC_ui_osx.py index c0910b8..b8e8d15 100644 --- a/kcc/KCC_ui_osx.py +++ b/kcc/KCC_ui_osx.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'KCC-OSX.ui' # -# Created: Tue Nov 12 14:31:59 2013 +# Created: Wed Dec 04 18:28:04 2013 # by: PyQt4 UI code generator 4.10.3 # # WARNING! All changes made in this file will be lost! @@ -392,9 +392,7 @@ class Ui_KCC(object): self.RotateBox.setText(_translate("KCC", "Horizontal mode", None)) self.BasicModeButton.setText(_translate("KCC", "Basic", None)) self.AdvModeButton.setText(_translate("KCC", "Advanced", None)) - self.GammaLabel.setToolTip(_translate("KCC", "

When converting color images setting this option to 1.0 might improve readability.

", None)) self.GammaLabel.setText(_translate("KCC", "Gamma: Auto", None)) - self.GammaSlider.setToolTip(_translate("KCC", "

When converting color images setting this option to 1.0 might improve readability.

", None)) self.ColorBox.setToolTip(_translate("KCC", "

Do not convert images to grayscale.

", None)) self.ColorBox.setText(_translate("KCC", "Color mode", None)) self.wLabel.setToolTip(_translate("KCC", "

Resolution of target device.

", None)) diff --git a/kcc/image.py b/kcc/image.py index 3c80d74..3e848c3 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -214,6 +214,8 @@ class ComicPage: def optimizeImage(self, gamma): if gamma < 0.1: gamma = self.gamma + if self.gamma != 1.0 and self.isImageColor(self.image): + gamma = 1.0 if gamma == 1.0: self.image = ImageOps.autocontrast(self.image) else: @@ -519,4 +521,29 @@ class ComicPage: if fill > 0: self.fill = 'black' else: - self.fill = 'white' \ No newline at end of file + self.fill = 'white' + + def isImageColor(self, image): + v = ImageStat.Stat(image).var + isMonochromatic = reduce(lambda x, y: x and y < 0.005, v, True) + if isMonochromatic: + # Monochromatic + return False + else: + if len(v) == 3: + maxmin = abs(max(v) - min(v)) + if maxmin > 1000: + # Color + return True + elif maxmin > 100: + # Probably color + return True + else: + # Grayscale + return False + elif len(v) == 1: + # Black and white + return False + else: + # Detection failed + return False