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 img_path = placeholder_path
print "[debug] Sprite not found: ", p_char, p_emote, emote_prefix print "[debug] Sprite not found: ", p_char, p_emote, emote_prefix
else: else:
img_path = "" img_path = "placeholder.png"
else: else:
self.prev_gif_path = img_path self.prev_gif_path = img_path
@ -441,6 +441,7 @@ class AOCharMovie(QtGui.QLabel):
self.set_pillow_frame() self.set_pillow_frame()
elif self.use_pillow == 2: # webp elif self.use_pillow == 2: # webp
try:
self.pillow_frames = images.load_webp(webp_path) self.pillow_frames = images.load_webp(webp_path)
if len(self.pillow_frames) > 1: if len(self.pillow_frames) > 1:
self.pillow_timer.start(int(self.pillow_frames[0][1] * self.pillow_speed)) self.pillow_timer.start(int(self.pillow_frames[0][1] * self.pillow_speed))
@ -448,6 +449,14 @@ class AOCharMovie(QtGui.QLabel):
self.pillow_timer.start(int(single_frame_duration * self.pillow_speed)) self.pillow_timer.start(int(single_frame_duration * self.pillow_speed))
self.set_pillow_frame() 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: if self.show_on_play:
self.show() self.show()
@ -545,11 +554,22 @@ class AOCharMovie(QtGui.QLabel):
else: else:
return QtCore.Qt.FastTransformation 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) @QtCore.pyqtSlot(int)
def frame_change(self, n_frame): def frame_change(self, n_frame):
f_img = self.m_movie.currentImage().mirrored(self.m_flipped, False) f_img = self.get_scaled_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_pixmap = QtGui.QPixmap.fromImage(f_img) f_pixmap = QtGui.QPixmap.fromImage(f_img)
self.setPixmap(f_pixmap) self.setPixmap(f_pixmap)
@ -574,9 +594,7 @@ class AOCharMovie(QtGui.QLabel):
self.set_pillow_frame() self.set_pillow_frame()
def set_pillow_frame(self): def set_pillow_frame(self):
f_img = self.pillow_frames[self.pillow_frame][0].mirrored(self.m_flipped, False) f_img = self.get_scaled_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_pixmap = QtGui.QPixmap.fromImage(f_img) f_pixmap = QtGui.QPixmap.fromImage(f_img)
self.setPixmap(f_pixmap) self.setPixmap(f_pixmap)