fix scaling on sprites taller than wider

This commit is contained in:
cidoku 2025-06-29 22:35:34 -04:00
parent 26e03b813c
commit b51eed6c03

View File

@ -423,7 +423,7 @@ class AOCharMovie(QtGui.QLabel):
img_path = placeholder_path
print "[debug] Sprite not found: ", p_char, p_emote, emote_prefix
else:
img_path = ""
img_path = "placeholder.png"
else:
self.prev_gif_path = img_path
@ -441,13 +441,22 @@ class AOCharMovie(QtGui.QLabel):
self.set_pillow_frame()
elif self.use_pillow == 2: # webp
self.pillow_frames = images.load_webp(webp_path)
if len(self.pillow_frames) > 1:
self.pillow_timer.start(int(self.pillow_frames[0][1] * self.pillow_speed))
else:
self.pillow_timer.start(int(single_frame_duration * self.pillow_speed))
self.set_pillow_frame()
try:
self.pillow_frames = images.load_webp(webp_path)
if len(self.pillow_frames) > 1:
self.pillow_timer.start(int(self.pillow_frames[0][1] * self.pillow_speed))
else:
self.pillow_timer.start(int(single_frame_duration * self.pillow_speed))
self.set_pillow_frame()
except:
if exists(placeholder_path):
img_path = placeholder_path
print "[debug] Couldn't load webp sprite!"
else:
img_path = "placeholder.png"
self.m_movie.setFileName(img_path)
self.m_movie.start()
if self.show_on_play:
self.show()
@ -544,12 +553,23 @@ class AOCharMovie(QtGui.QLabel):
return QtCore.Qt.SmoothTransformation
else:
return QtCore.Qt.FastTransformation
def get_aspect(self, taller):
if taller:
return QtCore.Qt.KeepAspectRatio
else:
return QtCore.Qt.KeepAspectRatioByExpanding
def get_scaled_img(self, f_img):
if not f_img.isNull():
transform = self.get_transform(f_img.size().height() > self.size().height())
aspect = self.get_aspect(f_img.size().height() > f_img.size().width())
return f_img.scaled(self.size(), aspect, transform)
return f_img
@QtCore.pyqtSlot(int)
def frame_change(self, n_frame):
f_img = self.m_movie.currentImage().mirrored(self.m_flipped, False)
if not f_img.isNull():
f_img = f_img.scaled(self.size().width(), self.size().height(), QtCore.Qt.KeepAspectRatioByExpanding, self.get_transform(f_img.size().height() > self.size().height()))
f_img = self.get_scaled_img(self.m_movie.currentImage().mirrored(self.m_flipped, False))
f_pixmap = QtGui.QPixmap.fromImage(f_img)
self.setPixmap(f_pixmap)
@ -574,10 +594,8 @@ class AOCharMovie(QtGui.QLabel):
self.set_pillow_frame()
def set_pillow_frame(self):
f_img = self.pillow_frames[self.pillow_frame][0].mirrored(self.m_flipped, False)
if not f_img.isNull():
f_img = f_img.scaled(self.size().width(), self.size().height(), QtCore.Qt.KeepAspectRatioByExpanding, self.get_transform(f_img.size().height() > self.size().height()))
f_img = self.get_scaled_img(self.pillow_frames[self.pillow_frame][0].mirrored(self.m_flipped, False))
f_pixmap = QtGui.QPixmap.fromImage(f_img)
self.setPixmap(f_pixmap)