mirror of
https://github.com/ciromattia/kcc
synced 2026-10-14 21:42:32 +00:00
color images are always saved as JPG by default (#1272)
* use jpg for color images always * add colorOutput variable * fix typos * remove dither * add box * clarify png * remove debug code * remove unneeded check
This commit is contained in:
@@ -272,7 +272,8 @@ PROCESSING:
|
|||||||
--whiteborders Disable autodetection and force white borders
|
--whiteborders Disable autodetection and force white borders
|
||||||
--coverfill Center-crop only the cover to fill target device screen
|
--coverfill Center-crop only the cover to fill target device screen
|
||||||
--forcecolor Don't convert images to grayscale
|
--forcecolor Don't convert images to grayscale
|
||||||
--forcepng Create PNG files instead JPEG
|
--forcepng Create PNG files instead JPEG for black and white images
|
||||||
|
--force-png-rgb Force color images to be saved as PNG
|
||||||
--pnglegacy Use a more compatible 8 bit PNG instead of 4 bit.
|
--pnglegacy Use a more compatible 8 bit PNG instead of 4 bit.
|
||||||
--noquantize Don't quantize PNG images to 16 colors
|
--noquantize Don't quantize PNG images to 16 colors
|
||||||
--mozjpeg Create JPEG files using mozJpeg
|
--mozjpeg Create JPEG files using mozJpeg
|
||||||
|
|||||||
+11
-1
@@ -801,7 +801,7 @@ Useful for really weird PDFs.</string>
|
|||||||
<item row="4" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QCheckBox" name="mozJpegBox">
|
<widget class="QCheckBox" name="mozJpegBox">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><html><head/><body><p><span style=" font-weight:600; text-decoration: underline;">Unchecked - JPEG<br/></span>Use JPEG files</p><p><span style=" font-weight:600; text-decoration: underline;">Indeterminate - force PNG<br/></span>Create PNG files instead JPEG</p><p><span style=" font-weight:600; text-decoration: underline;">Checked - mozJpeg<br/></span>10-20% smaller JPEG file, with the same image quality, but processing time multiplied by 2</p></body></html></string>
|
<string><html><head/><body><p><span style=" font-weight:600; text-decoration: underline;">Unchecked - JPEG<br/></span>Use JPEG files</p><p><span style=" font-weight:600; text-decoration: underline;">Indeterminate - force PNG<br/></span>Create PNG files instead JPEG for black and white images</p><p><span style=" font-weight:600; text-decoration: underline;">Checked - mozJpeg<br/></span>10-20% smaller JPEG file, with the same image quality, but processing time multiplied by 2</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>JPEG/PNG/mozJpeg</string>
|
<string>JPEG/PNG/mozJpeg</string>
|
||||||
@@ -965,6 +965,16 @@ May crop top/bottom or left/right depending on source aspect ratio. Not implemen
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="11" column="2">
|
||||||
|
<widget class="QCheckBox" name="forcePngRgbBox">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Force full color images to be saved in lossless PNG format, dramatically increases the filesize.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Force PNG RGB</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -351,6 +351,8 @@ class WorkerThread(QThread):
|
|||||||
options.rotateright = True
|
options.rotateright = True
|
||||||
if GUI.rotateFirstBox.isChecked():
|
if GUI.rotateFirstBox.isChecked():
|
||||||
options.rotatefirst = True
|
options.rotatefirst = True
|
||||||
|
if GUI.forcePngRgbBox.isChecked():
|
||||||
|
options.force_png_rgb = True
|
||||||
if GUI.mozJpegBox.checkState() == Qt.CheckState.PartiallyChecked:
|
if GUI.mozJpegBox.checkState() == Qt.CheckState.PartiallyChecked:
|
||||||
options.forcepng = True
|
options.forcepng = True
|
||||||
elif GUI.mozJpegBox.checkState() == Qt.CheckState.Checked:
|
elif GUI.mozJpegBox.checkState() == Qt.CheckState.Checked:
|
||||||
@@ -1054,6 +1056,7 @@ class KCCGUI(KCC_ui.Ui_mainWindow):
|
|||||||
'coverFillBox': GUI.coverFillBox.checkState(),
|
'coverFillBox': GUI.coverFillBox.checkState(),
|
||||||
'metadataTitleBox': GUI.metadataTitleBox.checkState(),
|
'metadataTitleBox': GUI.metadataTitleBox.checkState(),
|
||||||
'mozJpegBox': GUI.mozJpegBox.checkState(),
|
'mozJpegBox': GUI.mozJpegBox.checkState(),
|
||||||
|
'forcePngRgbBox': GUI.forcePngRgbBox.checkState(),
|
||||||
'pngLegacyBox': GUI.pngLegacyBox.checkState(),
|
'pngLegacyBox': GUI.pngLegacyBox.checkState(),
|
||||||
'noQuantizeBox': GUI.noQuantizeBox.checkState(),
|
'noQuantizeBox': GUI.noQuantizeBox.checkState(),
|
||||||
'jpegQualityBox': GUI.jpegQualityBox.checkState(),
|
'jpegQualityBox': GUI.jpegQualityBox.checkState(),
|
||||||
|
|||||||
@@ -492,6 +492,11 @@ class Ui_mainWindow(object):
|
|||||||
|
|
||||||
self.gridLayout_2.addWidget(self.pngLegacyBox, 11, 0, 1, 1)
|
self.gridLayout_2.addWidget(self.pngLegacyBox, 11, 0, 1, 1)
|
||||||
|
|
||||||
|
self.forcePngRgbBox = QCheckBox(self.optionWidget)
|
||||||
|
self.forcePngRgbBox.setObjectName(u"forcePngRgbBox")
|
||||||
|
|
||||||
|
self.gridLayout_2.addWidget(self.forcePngRgbBox, 11, 2, 1, 1)
|
||||||
|
|
||||||
|
|
||||||
self.gridLayout.addWidget(self.optionWidget, 5, 0, 1, 2)
|
self.gridLayout.addWidget(self.optionWidget, 5, 0, 1, 2)
|
||||||
|
|
||||||
@@ -745,7 +750,7 @@ class Ui_mainWindow(object):
|
|||||||
#endif // QT_CONFIG(tooltip)
|
#endif // QT_CONFIG(tooltip)
|
||||||
self.qualityBox.setText(QCoreApplication.translate("mainWindow", u"Panel View 4/2/HQ", None))
|
self.qualityBox.setText(QCoreApplication.translate("mainWindow", u"Panel View 4/2/HQ", None))
|
||||||
#if QT_CONFIG(tooltip)
|
#if QT_CONFIG(tooltip)
|
||||||
self.mozJpegBox.setToolTip(QCoreApplication.translate("mainWindow", u"<html><head/><body><p><span style=\" font-weight:600; text-decoration: underline;\">Unchecked - JPEG<br/></span>Use JPEG files</p><p><span style=\" font-weight:600; text-decoration: underline;\">Indeterminate - force PNG<br/></span>Create PNG files instead JPEG</p><p><span style=\" font-weight:600; text-decoration: underline;\">Checked - mozJpeg<br/></span>10-20% smaller JPEG file, with the same image quality, but processing time multiplied by 2</p></body></html>", None))
|
self.mozJpegBox.setToolTip(QCoreApplication.translate("mainWindow", u"<html><head/><body><p><span style=\" font-weight:600; text-decoration: underline;\">Unchecked - JPEG<br/></span>Use JPEG files</p><p><span style=\" font-weight:600; text-decoration: underline;\">Indeterminate - force PNG<br/></span>Create PNG files instead JPEG for black and white images</p><p><span style=\" font-weight:600; text-decoration: underline;\">Checked - mozJpeg<br/></span>10-20% smaller JPEG file, with the same image quality, but processing time multiplied by 2</p></body></html>", None))
|
||||||
#endif // QT_CONFIG(tooltip)
|
#endif // QT_CONFIG(tooltip)
|
||||||
self.mozJpegBox.setText(QCoreApplication.translate("mainWindow", u"JPEG/PNG/mozJpeg", None))
|
self.mozJpegBox.setText(QCoreApplication.translate("mainWindow", u"JPEG/PNG/mozJpeg", None))
|
||||||
#if QT_CONFIG(tooltip)
|
#if QT_CONFIG(tooltip)
|
||||||
@@ -797,6 +802,10 @@ class Ui_mainWindow(object):
|
|||||||
self.pngLegacyBox.setToolTip(QCoreApplication.translate("mainWindow", u"Use a more compatible 8 bit PNG instead of 4 bit.", None))
|
self.pngLegacyBox.setToolTip(QCoreApplication.translate("mainWindow", u"Use a more compatible 8 bit PNG instead of 4 bit.", None))
|
||||||
#endif // QT_CONFIG(tooltip)
|
#endif // QT_CONFIG(tooltip)
|
||||||
self.pngLegacyBox.setText(QCoreApplication.translate("mainWindow", u"PNG Legacy Mode", None))
|
self.pngLegacyBox.setText(QCoreApplication.translate("mainWindow", u"PNG Legacy Mode", None))
|
||||||
|
#if QT_CONFIG(tooltip)
|
||||||
|
self.forcePngRgbBox.setToolTip(QCoreApplication.translate("mainWindow", u"Force full color images to be saved in lossless PNG format, dramatically increases the filesize.", None))
|
||||||
|
#endif // QT_CONFIG(tooltip)
|
||||||
|
self.forcePngRgbBox.setText(QCoreApplication.translate("mainWindow", u"Force PNG RGB", None))
|
||||||
self.gammaLabel.setText(QCoreApplication.translate("mainWindow", u"Gamma: Auto", None))
|
self.gammaLabel.setText(QCoreApplication.translate("mainWindow", u"Gamma: Auto", None))
|
||||||
self.jpegQualityLabel.setText(QCoreApplication.translate("mainWindow", u"JPEG Quality:", None))
|
self.jpegQualityLabel.setText(QCoreApplication.translate("mainWindow", u"JPEG Quality:", None))
|
||||||
# retranslateUi
|
# retranslateUi
|
||||||
|
|||||||
@@ -689,7 +689,6 @@ def imgFileProcessing(work):
|
|||||||
workImg = image.ComicPageParser((dirpath, afile), opt)
|
workImg = image.ComicPageParser((dirpath, afile), opt)
|
||||||
for i in workImg.payload:
|
for i in workImg.payload:
|
||||||
img = image.ComicPage(opt, *i)
|
img = image.ComicPage(opt, *i)
|
||||||
is_color = (opt.forcecolor and img.color)
|
|
||||||
if opt.cropping == 2 and not opt.webtoon:
|
if opt.cropping == 2 and not opt.webtoon:
|
||||||
img.cropPageNumber(opt.croppingp, opt.croppingm)
|
img.cropPageNumber(opt.croppingp, opt.croppingm)
|
||||||
if opt.cropping == 1 and not opt.webtoon:
|
if opt.cropping == 1 and not opt.webtoon:
|
||||||
@@ -701,9 +700,9 @@ def imgFileProcessing(work):
|
|||||||
|
|
||||||
img.autocontrastImage()
|
img.autocontrastImage()
|
||||||
img.resizeImage()
|
img.resizeImage()
|
||||||
img.optimizeForDisplay(opt.eraserainbow, is_color)
|
img.optimizeForDisplay(opt.eraserainbow, img.colorOutput)
|
||||||
|
|
||||||
if is_color:
|
if img.colorOutput:
|
||||||
pass
|
pass
|
||||||
elif opt.forcepng:
|
elif opt.forcepng:
|
||||||
img.convertToGrayscale()
|
img.convertToGrayscale()
|
||||||
@@ -1412,7 +1411,9 @@ def makeParser():
|
|||||||
output_options.add_argument("--eraserainbow", action="store_true", dest="eraserainbow", default=False,
|
output_options.add_argument("--eraserainbow", action="store_true", dest="eraserainbow", default=False,
|
||||||
help="Erase rainbow effect on color eink screen by attenuating interfering frequencies")
|
help="Erase rainbow effect on color eink screen by attenuating interfering frequencies")
|
||||||
processing_options.add_argument("--forcepng", action="store_true", dest="forcepng", default=False,
|
processing_options.add_argument("--forcepng", action="store_true", dest="forcepng", default=False,
|
||||||
help="Create PNG files instead JPEG")
|
help="Create PNG files instead JPEG for black and white images")
|
||||||
|
processing_options.add_argument("--force-png-rgb", action="store_true", dest="force_png_rgb", default=False,
|
||||||
|
help="Force color images to be saved as PNG")
|
||||||
processing_options.add_argument("--pnglegacy", action="store_true", dest="pnglegacy", default=False,
|
processing_options.add_argument("--pnglegacy", action="store_true", dest="pnglegacy", default=False,
|
||||||
help="Use a more compatible 8 bit png instead of 4 bit")
|
help="Use a more compatible 8 bit png instead of 4 bit")
|
||||||
processing_options.add_argument("--noquantize", action="store_true", dest="noquantize", default=False,
|
processing_options.add_argument("--noquantize", action="store_true", dest="noquantize", default=False,
|
||||||
|
|||||||
@@ -277,6 +277,8 @@ class ComicPage:
|
|||||||
self.original_color_mode = image.mode
|
self.original_color_mode = image.mode
|
||||||
# TODO: color check earlier
|
# TODO: color check earlier
|
||||||
self.image = image.convert("RGB")
|
self.image = image.convert("RGB")
|
||||||
|
self.color = self.colorCheck()
|
||||||
|
self.colorOutput = self.color and self.opt.forcecolor
|
||||||
self.fill = fill
|
self.fill = fill
|
||||||
self.rotated = False
|
self.rotated = False
|
||||||
self.orgPath = os.path.join(path[0], path[1])
|
self.orgPath = os.path.join(path[0], path[1])
|
||||||
@@ -295,8 +297,7 @@ class ComicPage:
|
|||||||
if not hasattr(Image, 'Resampling'):
|
if not hasattr(Image, 'Resampling'):
|
||||||
Image.Resampling = Image
|
Image.Resampling = Image
|
||||||
|
|
||||||
@cached_property
|
def colorCheck(self):
|
||||||
def color(self):
|
|
||||||
if self.original_color_mode in ("L", "1"):
|
if self.original_color_mode in ("L", "1"):
|
||||||
return False
|
return False
|
||||||
if self.opt.webtoon:
|
if self.opt.webtoon:
|
||||||
@@ -405,7 +406,7 @@ class ComicPage:
|
|||||||
raise RuntimeError('Cannot save image. ' + str(err))
|
raise RuntimeError('Cannot save image. ' + str(err))
|
||||||
|
|
||||||
def save_with_codec(self, image, targetPath):
|
def save_with_codec(self, image, targetPath):
|
||||||
if self.opt.forcepng:
|
if self.opt.forcepng and (not self.colorOutput or self.opt.force_png_rgb):
|
||||||
image.info.pop('transparency', None)
|
image.info.pop('transparency', None)
|
||||||
if self.opt.iskindle and ('MOBI' in self.opt.format or 'EPUB' in self.opt.format):
|
if self.opt.iskindle and ('MOBI' in self.opt.format or 'EPUB' in self.opt.format):
|
||||||
targetPath += '.gif'
|
targetPath += '.gif'
|
||||||
|
|||||||
Reference in New Issue
Block a user