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:
@@ -77,14 +77,15 @@ def main(argv=None):
|
||||
return 0
|
||||
|
||||
|
||||
def buildHTML(path, imgfile):
|
||||
def buildHTML(path, imgfile, imgfilepath):
|
||||
key = pathlib.Path(imgfilepath).name
|
||||
filename = getImageFileName(imgfile)
|
||||
deviceres = options.profileData[1]
|
||||
if not options.noprocessing and "Rotated" in imgfile:
|
||||
if not options.noprocessing and "Rotated" in options.imgMetadata[key]:
|
||||
rotatedPage = True
|
||||
else:
|
||||
rotatedPage = False
|
||||
if not options.noprocessing and "BlackBackground" in imgfile:
|
||||
if not options.noprocessing and "BlackBackground" in options.imgMetadata[key]:
|
||||
additionalStyle = 'background-color:#000000;'
|
||||
else:
|
||||
additionalStyle = ''
|
||||
@@ -517,7 +518,7 @@ def buildEPUB(path, chapternames, tomenumber, ischunked):
|
||||
if not chapter:
|
||||
chapterlist.append((dirpath.replace('Images', 'Text'), afile))
|
||||
chapter = True
|
||||
filelist.append(buildHTML(dirpath, afile))
|
||||
filelist.append(buildHTML(dirpath, afile, os.path.join(dirpath, afile)))
|
||||
build_html_end = perf_counter()
|
||||
print(f"buildHTML: {build_html_end - build_html_start} seconds")
|
||||
# Overwrite chapternames if tree is flat and ComicInfo.xml has bookmarks
|
||||
@@ -556,6 +557,7 @@ def imgDirectoryProcessing(path):
|
||||
global workerPool, workerOutput
|
||||
workerPool = Pool(maxtasksperchild=100)
|
||||
workerOutput = []
|
||||
options.imgMetadata = {}
|
||||
work = []
|
||||
pagenumber = 0
|
||||
for dirpath, _, filenames in os.walk(path):
|
||||
@@ -587,7 +589,10 @@ def imgFileProcessingTick(output):
|
||||
if isinstance(output, tuple):
|
||||
workerOutput.append(output)
|
||||
workerPool.terminate()
|
||||
|
||||
else:
|
||||
for page in output:
|
||||
if page is not None:
|
||||
options.imgMetadata[page[0]] = page[1]
|
||||
if GUI:
|
||||
GUI.progressBarTick.emit('tick')
|
||||
if not GUI.conversionAlive:
|
||||
|
||||
@@ -299,12 +299,13 @@ class ComicPage:
|
||||
|
||||
def saveToDir(self):
|
||||
try:
|
||||
flags = []
|
||||
if not self.opt.forcecolor and not self.opt.forcepng:
|
||||
self.image = self.image.convert('L')
|
||||
if self.rotated:
|
||||
self.targetPath += '-Rotated'
|
||||
flags.append('Rotated')
|
||||
if self.fill != 'white':
|
||||
self.targetPath += '-BlackBackground'
|
||||
flags.append('BlackBackground')
|
||||
if self.opt.forcepng:
|
||||
self.image.info["transparency"] = None
|
||||
self.targetPath += '.png'
|
||||
@@ -322,7 +323,7 @@ class ComicPage:
|
||||
self.image.save(self.targetPath, 'JPEG', optimize=1, quality=85)
|
||||
if os.path.isfile(self.orgPath):
|
||||
os.remove(self.orgPath)
|
||||
return Path(self.targetPath).name
|
||||
return [Path(self.targetPath).name, flags]
|
||||
except IOError as err:
|
||||
raise RuntimeError('Cannot save image. ' + str(err))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user