1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 01:36:27 +00:00

restore imgMetadata dict (#858)

* Revert "memory optimization: store metadata in filenames, not a global dict (…"

This reverts commit 9a2a09eab9.

* only remove imgOld
This commit is contained in:
Alex Xu
2025-03-11 09:57:11 -07:00
committed by GitHub
parent b8b7926366
commit 561951a349
2 changed files with 14 additions and 8 deletions

View File

@@ -77,14 +77,15 @@ def main(argv=None):
return 0 return 0
def buildHTML(path, imgfile): def buildHTML(path, imgfile, imgfilepath):
key = pathlib.Path(imgfilepath).name
filename = getImageFileName(imgfile) filename = getImageFileName(imgfile)
deviceres = options.profileData[1] deviceres = options.profileData[1]
if not options.noprocessing and "Rotated" in imgfile: if not options.noprocessing and "Rotated" in options.imgMetadata[key]:
rotatedPage = True rotatedPage = True
else: else:
rotatedPage = False rotatedPage = False
if not options.noprocessing and "BlackBackground" in imgfile: if not options.noprocessing and "BlackBackground" in options.imgMetadata[key]:
additionalStyle = 'background-color:#000000;' additionalStyle = 'background-color:#000000;'
else: else:
additionalStyle = '' additionalStyle = ''
@@ -517,7 +518,7 @@ def buildEPUB(path, chapternames, tomenumber, ischunked):
if not chapter: if not chapter:
chapterlist.append((dirpath.replace('Images', 'Text'), afile)) chapterlist.append((dirpath.replace('Images', 'Text'), afile))
chapter = True chapter = True
filelist.append(buildHTML(dirpath, afile)) filelist.append(buildHTML(dirpath, afile, os.path.join(dirpath, afile)))
build_html_end = perf_counter() build_html_end = perf_counter()
print(f"buildHTML: {build_html_end - build_html_start} seconds") print(f"buildHTML: {build_html_end - build_html_start} seconds")
# Overwrite chapternames if tree is flat and ComicInfo.xml has bookmarks # Overwrite chapternames if tree is flat and ComicInfo.xml has bookmarks
@@ -556,6 +557,7 @@ def imgDirectoryProcessing(path):
global workerPool, workerOutput global workerPool, workerOutput
workerPool = Pool(maxtasksperchild=100) workerPool = Pool(maxtasksperchild=100)
workerOutput = [] workerOutput = []
options.imgMetadata = {}
work = [] work = []
pagenumber = 0 pagenumber = 0
for dirpath, _, filenames in os.walk(path): for dirpath, _, filenames in os.walk(path):
@@ -587,7 +589,10 @@ def imgFileProcessingTick(output):
if isinstance(output, tuple): if isinstance(output, tuple):
workerOutput.append(output) workerOutput.append(output)
workerPool.terminate() workerPool.terminate()
else:
for page in output:
if page is not None:
options.imgMetadata[page[0]] = page[1]
if GUI: if GUI:
GUI.progressBarTick.emit('tick') GUI.progressBarTick.emit('tick')
if not GUI.conversionAlive: if not GUI.conversionAlive:

View File

@@ -299,12 +299,13 @@ class ComicPage:
def saveToDir(self): def saveToDir(self):
try: try:
flags = []
if not self.opt.forcecolor and not self.opt.forcepng: if not self.opt.forcecolor and not self.opt.forcepng:
self.image = self.image.convert('L') self.image = self.image.convert('L')
if self.rotated: if self.rotated:
self.targetPath += '-Rotated' flags.append('Rotated')
if self.fill != 'white': if self.fill != 'white':
self.targetPath += '-BlackBackground' flags.append('BlackBackground')
if self.opt.forcepng: if self.opt.forcepng:
self.image.info["transparency"] = None self.image.info["transparency"] = None
self.targetPath += '.png' self.targetPath += '.png'
@@ -322,7 +323,7 @@ class ComicPage:
self.image.save(self.targetPath, 'JPEG', optimize=1, quality=85) self.image.save(self.targetPath, 'JPEG', optimize=1, quality=85)
if os.path.isfile(self.orgPath): if os.path.isfile(self.orgPath):
os.remove(self.orgPath) os.remove(self.orgPath)
return Path(self.targetPath).name return [Path(self.targetPath).name, flags]
except IOError as err: except IOError as err:
raise RuntimeError('Cannot save image. ' + str(err)) raise RuntimeError('Cannot save image. ' + str(err))