1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-12 17:26:23 +00:00

add --mozjpeg option and GUI checkBox

This commit is contained in:
darodi
2022-04-10 17:43:21 +02:00
parent 6cd073809e
commit 79715c6a06
7 changed files with 41 additions and 6 deletions

4
.gitignore vendored
View File

@@ -7,4 +7,6 @@ other/windows/kindlegen.exe
dist/ dist/
build/ build/
KindleComicConverter.egg-info/ KindleComicConverter.egg-info/
.idea/ .idea/
/venv/
/kindlegen.exe

View File

@@ -149,6 +149,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1">
<widget class="QCheckBox" name="mozJpegBox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Unchecked - Off&lt;br/&gt;&lt;/span&gt;Faster&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; text-decoration: underline;&quot;&gt;Checked - On&lt;br/&gt;&lt;/span&gt;10-20% smaller JPEG file, with the same image quality, but processing time multiplied by 2&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>use mozJpeg</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@@ -18,6 +18,7 @@
# PERFORMANCE OF THIS SOFTWARE. # PERFORMANCE OF THIS SOFTWARE.
import os import os
import re
import sys import sys
from urllib.parse import unquote from urllib.parse import unquote
from urllib.request import urlopen, urlretrieve, Request from urllib.request import urlopen, urlretrieve, Request
@@ -143,7 +144,9 @@ class VersionThread(QtCore.QThread):
except Exception: except Exception:
return return
latestVersion = XML.childNodes[0].getElementsByTagName('LatestVersion')[0].childNodes[0].toxml() latestVersion = XML.childNodes[0].getElementsByTagName('LatestVersion')[0].childNodes[0].toxml()
if StrictVersion(latestVersion) > StrictVersion(__version__): if ("beta" not in __version__ and StrictVersion(latestVersion) > StrictVersion(__version__)) \
or ("beta" in __version__
and StrictVersion(latestVersion) >= StrictVersion(re.sub(r'-beta.*', '', __version__))):
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
self.newVersion = latestVersion self.newVersion = latestVersion
self.md5 = XML.childNodes[0].getElementsByTagName('MD5')[0].childNodes[0].toxml() self.md5 = XML.childNodes[0].getElementsByTagName('MD5')[0].childNodes[0].toxml()
@@ -279,6 +282,8 @@ class WorkerThread(QtCore.QThread):
options.forcecolor = True options.forcecolor = True
if GUI.disableProcessingBox.isChecked(): if GUI.disableProcessingBox.isChecked():
options.noprocessing = True options.noprocessing = True
if GUI.mozJpegBox.isChecked():
options.mozjpeg = True
if GUI.currentMode > 2: if GUI.currentMode > 2:
options.customwidth = str(GUI.widthBox.value()) options.customwidth = str(GUI.widthBox.value())
options.customheight = str(GUI.heightBox.value()) options.customheight = str(GUI.heightBox.value())

View File

@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'gui/KCC.ui' # Form implementation generated from reading ui file 'gui/KCC.ui'
# #
# Created by: PyQt5 UI code generator 5.15.2 # Created by: PyQt5 UI code generator 5.15.4
# #
# WARNING: Any manual changes made to this file will be lost when pyuic5 is # WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing. # run again. Do not edit this file unless you know what you are doing.
@@ -62,6 +62,9 @@ class Ui_mainWindow(object):
self.disableProcessingBox = QtWidgets.QCheckBox(self.optionWidget) self.disableProcessingBox = QtWidgets.QCheckBox(self.optionWidget)
self.disableProcessingBox.setObjectName("disableProcessingBox") self.disableProcessingBox.setObjectName("disableProcessingBox")
self.gridLayout_2.addWidget(self.disableProcessingBox, 3, 2, 1, 1) self.gridLayout_2.addWidget(self.disableProcessingBox, 3, 2, 1, 1)
self.mozJpegBox = QtWidgets.QCheckBox(self.optionWidget)
self.mozJpegBox.setObjectName("mozJpegBox")
self.gridLayout_2.addWidget(self.mozJpegBox, 3, 1, 1, 1)
self.gridLayout.addWidget(self.optionWidget, 4, 0, 1, 2) self.gridLayout.addWidget(self.optionWidget, 4, 0, 1, 2)
self.gammaWidget = QtWidgets.QWidget(self.centralWidget) self.gammaWidget = QtWidgets.QWidget(self.centralWidget)
self.gammaWidget.setVisible(False) self.gammaWidget.setVisible(False)
@@ -258,6 +261,8 @@ class Ui_mainWindow(object):
self.qualityBox.setText(_translate("mainWindow", "Panel View 4/2/HQ")) self.qualityBox.setText(_translate("mainWindow", "Panel View 4/2/HQ"))
self.disableProcessingBox.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'>Do not process any image, ignore profil and processing options</p></body></html>")) self.disableProcessingBox.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'>Do not process any image, ignore profil and processing options</p></body></html>"))
self.disableProcessingBox.setText(_translate("mainWindow", "Disable processing")) self.disableProcessingBox.setText(_translate("mainWindow", "Disable processing"))
self.mozJpegBox.setToolTip(_translate("mainWindow", "<html><head/><body><p><span style=\" font-weight:600; text-decoration: underline;\">Unchecked - Off<br/></span>Faster</p><p><span style=\" font-weight:600; text-decoration: underline;\">Checked - On<br/></span>10-20% smaller JPEG file, with the same image quality, but processing time multiplied by 2</p></body></html>"))
self.mozJpegBox.setText(_translate("mainWindow", "use mozJpeg"))
self.gammaLabel.setText(_translate("mainWindow", "Gamma: Auto")) self.gammaLabel.setText(_translate("mainWindow", "Gamma: Auto"))
self.directoryButton.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'>Add directory containing JPG, PNG or GIF files to queue.<br/><span style=\" font-weight:600;\">CBR, CBZ and CB7 files inside will not be processed!</span></p></body></html>")) self.directoryButton.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'>Add directory containing JPG, PNG or GIF files to queue.<br/><span style=\" font-weight:600;\">CBR, CBZ and CB7 files inside will not be processed!</span></p></body></html>"))
self.directoryButton.setText(_translate("mainWindow", "Add directory")) self.directoryButton.setText(_translate("mainWindow", "Add directory"))

View File

@@ -952,6 +952,8 @@ def makeParser():
help="Don't convert images to grayscale") help="Don't convert images to grayscale")
processingOptions.add_option("--forcepng", action="store_true", dest="forcepng", default=False, processingOptions.add_option("--forcepng", action="store_true", dest="forcepng", default=False,
help="Create PNG files instead JPEG") help="Create PNG files instead JPEG")
processingOptions.add_option("--mozjpeg", action="store_true", dest="mozjpeg", default=False,
help="Create JPEG files using mozJpeg")
customProfileOptions.add_option("--customwidth", type="int", dest="customwidth", default=0, customProfileOptions.add_option("--customwidth", type="int", dest="customwidth", default=0,
help="Replace screen width provided by device profile") help="Replace screen width provided by device profile")

View File

@@ -18,8 +18,9 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import io
import os import os
import mozjpeg_lossless_optimization
from PIL import Image, ImageOps, ImageStat, ImageChops, ImageFilter from PIL import Image, ImageOps, ImageStat, ImageChops, ImageFilter
from .shared import md5Checksum from .shared import md5Checksum
@@ -244,7 +245,15 @@ class ComicPage:
self.image.save(self.targetPath, 'PNG', optimize=1) self.image.save(self.targetPath, 'PNG', optimize=1)
else: else:
self.targetPath += '.jpg' self.targetPath += '.jpg'
self.image.save(self.targetPath, 'JPEG', optimize=1, quality=85) if self.opt.mozjpeg:
with io.BytesIO() as output:
self.image.save(output, format="JPEG", optimize=1, quality=85)
input_jpeg_bytes = output.getvalue()
output_jpeg_bytes = mozjpeg_lossless_optimization.optimize(input_jpeg_bytes)
with open(self.targetPath, "wb") as output_jpeg_file:
output_jpeg_file.write(output_jpeg_bytes)
else:
self.image.save(self.targetPath, 'JPEG', optimize=1, quality=85)
return [md5Checksum(self.targetPath), flags, self.orgPath] return [md5Checksum(self.targetPath), flags, self.orgPath]
except IOError as err: except IOError as err:
raise RuntimeError('Cannot save image. ' + str(err)) raise RuntimeError('Cannot save image. ' + str(err))

View File

@@ -2,4 +2,6 @@ PyQt5>=5.6.0
Pillow>=5.2.0 Pillow>=5.2.0
psutil>=5.0.0 psutil>=5.0.0
python-slugify>=1.2.1,<3.0.0 python-slugify>=1.2.1,<3.0.0
raven>=6.0.0 raven>=6.0.0
# PyQt5-tools
mozjpeg-lossless-optimization