py310: Fix #1954951 [manual trimming of cover throws exception w/ python 3.10](https://bugs.launchpad.net/calibre/+bug/1954951)

This commit is contained in:
Kovid Goyal 2021-12-16 08:06:32 +05:30
parent 0a9778caa3
commit ff1ee01b3b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 8 additions and 8 deletions

View File

@ -97,7 +97,7 @@ class Trim(Command):
img = canvas.current_image img = canvas.current_image
target = canvas.target target = canvas.target
sr = canvas.selection_state.rect sr = canvas.selection_state.rect
return img.copy(*get_selection_rect(img, sr, target)) return img.copy(*map(int, get_selection_rect(img, sr, target)))
class AutoTrim(Trim): class AutoTrim(Trim):

View File

@ -296,9 +296,9 @@ def blend_on_canvas(img, width, height, bgcolor='#ffffff'):
w, h = img.width(), img.height() w, h = img.width(), img.height()
scaled, nw, nh = fit_image(w, h, width, height) scaled, nw, nh = fit_image(w, h, width, height)
if scaled: if scaled:
img = img.scaled(nw, nh, Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation) img = img.scaled(int(nw), int(nh), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
w, h = nw, nh w, h = nw, nh
canvas = QImage(width, height, QImage.Format.Format_RGB32) canvas = QImage(int(width), int(height), QImage.Format.Format_RGB32)
canvas.fill(QColor(bgcolor)) canvas.fill(QColor(bgcolor))
overlay_image(img, canvas, (width - w)//2, (height - h)//2) overlay_image(img, canvas, (width - w)//2, (height - h)//2)
return canvas return canvas
@ -307,7 +307,7 @@ def blend_on_canvas(img, width, height, bgcolor='#ffffff'):
class Canvas: class Canvas:
def __init__(self, width, height, bgcolor='#ffffff'): def __init__(self, width, height, bgcolor='#ffffff'):
self.img = QImage(width, height, QImage.Format.Format_RGB32) self.img = QImage(int(width), int(height), QImage.Format.Format_RGB32)
self.img.fill(QColor(bgcolor)) self.img.fill(QColor(bgcolor))
def __enter__(self): def __enter__(self):
@ -326,7 +326,7 @@ class Canvas:
def create_canvas(width, height, bgcolor='#ffffff'): def create_canvas(width, height, bgcolor='#ffffff'):
'Create a blank canvas of the specified size and color ' 'Create a blank canvas of the specified size and color '
img = QImage(width, height, QImage.Format.Format_RGB32) img = QImage(int(width), int(height), QImage.Format.Format_RGB32)
img.fill(QColor(bgcolor)) img.fill(QColor(bgcolor))
return img return img
@ -363,7 +363,7 @@ def add_borders_to_image(img, left=0, top=0, right=0, bottom=0, border_color='#f
img = image_from_data(img) img = image_from_data(img)
if not (left > 0 or right > 0 or top > 0 or bottom > 0): if not (left > 0 or right > 0 or top > 0 or bottom > 0):
return img return img
canvas = QImage(img.width() + left + right, img.height() + top + bottom, QImage.Format.Format_RGB32) canvas = QImage(int(img.width() + left + right), int(img.height() + top + bottom), QImage.Format.Format_RGB32)
canvas.fill(QColor(border_color)) canvas.fill(QColor(border_color))
overlay_image(img, canvas, left, top) overlay_image(img, canvas, left, top)
return canvas return canvas
@ -376,7 +376,7 @@ def remove_borders_from_image(img, fuzz=None):
absolute intensity units). Default is from a tweak whose default value is 10. ''' absolute intensity units). Default is from a tweak whose default value is 10. '''
fuzz = tweaks['cover_trim_fuzz_value'] if fuzz is None else fuzz fuzz = tweaks['cover_trim_fuzz_value'] if fuzz is None else fuzz
img = image_from_data(img) img = image_from_data(img)
ans = imageops.remove_borders(img, max(0, fuzz)) ans = imageops.remove_borders(img, int(max(0, fuzz)))
return ans if ans.size() != img.size() else img return ans if ans.size() != img.size() else img
# }}} # }}}
@ -432,7 +432,7 @@ def crop_image(img, x, y, width, height):
img = image_from_data(img) img = image_from_data(img)
width = min(width, img.width() - x) width = min(width, img.width() - x)
height = min(height, img.height() - y) height = min(height, img.height() - y)
return img.copy(x, y, width, height) return img.copy(int(x), int(y), int(width), int(height))
# }}} # }}}