Skip to content

Commit ad02c82

Browse files
authored
feat(cli): add resize mode option (#59)
This adds a new option that allows to control how the video is going to be scaled. By default, we now use a smooth rescaling, but fast mode with no interpolation can be used (previously default).
1 parent 0778ceb commit ad02c82

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

manim_slides/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,6 @@ def animation_indices_match_files(cls, values):
148148
)
149149

150150
return values
151+
152+
153+
DEFAULT_CONFIG = Config()

manim_slides/present.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from tqdm import tqdm
1717

1818
from .commons import config_path_option, verbosity_option
19-
from .config import Config, PresentationConfig, SlideConfig, SlideType
19+
from .config import DEFAULT_CONFIG, Config, PresentationConfig, SlideConfig, SlideType
2020
from .defaults import FOLDER_PATH
2121
from .manim import logger
2222

@@ -33,6 +33,11 @@
3333
"keep": Qt.KeepAspectRatio,
3434
}
3535

36+
RESIZE_MODES = {
37+
"fast": Qt.FastTransformation,
38+
"smooth": Qt.SmoothTransformation,
39+
}
40+
3641

3742
@unique
3843
class State(IntEnum):
@@ -284,7 +289,7 @@ class Display(QThread):
284289
def __init__(
285290
self,
286291
presentations,
287-
config: Config = Config(),
292+
config: Config = DEFAULT_CONFIG,
288293
start_paused=False,
289294
skip_all=False,
290295
record_to=None,
@@ -517,18 +522,20 @@ class App(QWidget):
517522
def __init__(
518523
self,
519524
*args,
520-
config: Config = Config(),
525+
config: Config = DEFAULT_CONFIG,
521526
fullscreen: bool = False,
522527
resolution: Tuple[int, int] = (1980, 1080),
523528
hide_mouse: bool = False,
524529
aspect_ratio: Qt.AspectRatioMode = Qt.IgnoreAspectRatio,
530+
resize_mode: Qt.TransformationMode = Qt.SmoothTransformation,
525531
**kwargs,
526532
):
527533
super().__init__()
528534

529535
self.setWindowTitle(WINDOW_NAME)
530536
self.display_width, self.display_height = resolution
531537
self.aspect_ratio = aspect_ratio
538+
self.resize_mode = resize_mode
532539
self.hide_mouse = hide_mouse
533540
self.config = config
534541
if self.hide_mouse:
@@ -584,7 +591,9 @@ def closeAll(self):
584591
self.deleteLater()
585592

586593
def resizeEvent(self, event):
587-
self.pixmap = self.pixmap.scaled(self.width(), self.height(), self.aspect_ratio)
594+
self.pixmap = self.pixmap.scaled(
595+
self.width(), self.height(), self.aspect_ratio, self.resize_mode
596+
)
588597
self.label.setPixmap(self.pixmap)
589598
self.label.resize(self.width(), self.height())
590599

@@ -615,6 +624,7 @@ def convert_cv_qt(self, cv_img):
615624
self.width(),
616625
self.height(),
617626
self.aspect_ratio,
627+
self.resize_mode,
618628
)
619629
return QPixmap.fromImage(p)
620630

@@ -708,6 +718,13 @@ def _list_scenes(folder) -> List[str]:
708718
help="Set the aspect ratio mode to be used when rescaling video.",
709719
show_default=True,
710720
)
721+
@click.option(
722+
"--resize-mode",
723+
type=click.Choice(RESIZE_MODES.keys(), case_sensitive=False),
724+
default="smooth",
725+
help="Set the resize (i.e., transformation) mode to be used when rescaling video.",
726+
show_default=True,
727+
)
711728
@click.help_option("-h", "--help")
712729
@verbosity_option
713730
def present(
@@ -722,6 +739,7 @@ def present(
722739
exit_after_last_slide,
723740
hide_mouse,
724741
aspect_ratio,
742+
resize_mode,
725743
) -> None:
726744
"""
727745
Present SCENE(s), one at a time, in order.
@@ -813,6 +831,7 @@ def value_proc(value: str) -> List[str]:
813831
exit_after_last_slide=exit_after_last_slide,
814832
hide_mouse=hide_mouse,
815833
aspect_ratio=ASPECT_RATIO_MODES[aspect_ratio],
834+
resize_mode=RESIZE_MODES[resize_mode],
816835
)
817836
a.show()
818837
sys.exit(app.exec_())

0 commit comments

Comments
 (0)