Add: do not split images that do not need to

Some pictures (like the front in a scan) can be not double pages, so for
theses pictures, try to detect if width> height, and if not remove split
flags for this specific source picture.
This commit is contained in:
Gabès Jean 2015-10-05 21:30:28 +02:00
parent 0cc17438e9
commit 1608f10fbd
2 changed files with 25 additions and 3 deletions

View File

@ -121,8 +121,18 @@ class DialogConvert(QtGui.QProgressDialog):
archive = self.archive archive = self.archive
pdf = self.pdf pdf = self.pdf
# For right page (if requested)
if(self.book.imageFlags & ImageFlags.Split): # Maybe the user ask for a split, but the picture is not a large one, so skip
# it but only for this picture
if (flags & ImageFlags.Split) or (flags & ImageFlags.SplitInverse):
if not image.isSplitable(source):
# remove split flags
splitFlags= [ImageFlags.Split, ImageFlags.SplitInverse, ImageFlags.SplitRight, ImageFlags.SplitLeft]
for f in splitFlags:
flags &= ~f
# For right page (if requested in options and need for this image)
if(flags & ImageFlags.Split):
# New path based on modified index # New path based on modified index
target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 0)) target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 0))
self.convertAndSave(source, target, device, flags ^ ImageFlags.Split | ImageFlags.SplitRight, archive, pdf) self.convertAndSave(source, target, device, flags ^ ImageFlags.Split | ImageFlags.SplitRight, archive, pdf)
@ -130,7 +140,7 @@ class DialogConvert(QtGui.QProgressDialog):
target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 1)) target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 1))
# For right page (if requested), but in inverted mode # For right page (if requested), but in inverted mode
if(self.book.imageFlags & ImageFlags.SplitInverse): if(flags & ImageFlags.SplitInverse):
# New path based on modified index # New path based on modified index
target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 0)) target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 0))
self.convertAndSave(source, target, device, flags ^ ImageFlags.SplitInverse | ImageFlags.SplitLeft, archive, pdf) self.convertAndSave(source, target, device, flags ^ ImageFlags.SplitInverse | ImageFlags.SplitLeft, archive, pdf)

View File

@ -221,6 +221,18 @@ def saveImage(image, target):
raise RuntimeError('Cannot write image file %s' % target) raise RuntimeError('Cannot write image file %s' % target)
# Look if the image is more width than hight, if not, means
# it's should not be split (like the front page of a manga,
# when all the inner pages are double)
def isSplitable(source):
image = loadImage(source)
try:
widthImg, heightImg = image.size
return widthImg > heightImg
except IOError:
raise RuntimeError('Cannot read image file %s' % source)
def convertImage(source, target, device, flags): def convertImage(source, target, device, flags):
try: try:
size, palette = KindleData.Profiles[device] size, palette = KindleData.Profiles[device]