From fa2ac22f9ff55356571fe1c919c45a5841c906e1 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 26 Sep 2025 19:04:54 +0200 Subject: [PATCH] Refactor video scaling logic in VideoEditor to improve display handling This commit updates the video scaling logic to ensure that videos are scaled down to fit the screen bounds instead of resizing the window. The previous logic for window resizing has been removed, streamlining the display process and enhancing the user experience during video editing sessions. The changes also include adjustments to maintain the aspect ratio of the video while scaling. --- croppa/main.py | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/croppa/main.py b/croppa/main.py index 5e0ae60..fde60fd 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -3071,39 +3071,19 @@ class VideoEditor: height, width = display_frame.shape[:2] available_height = self.window_height - (0 if self.is_image_mode else self.TIMELINE_HEIGHT) - # Don't downscale - keep original video quality - # If video is larger than window, we'll handle it by resizing the window + # Scale video to fit screen bounds scale = min(self.window_width / width, available_height / height) if scale < 1.0: - # Resize window to fit video instead of downscaling video - new_window_width = int(width * 1.1) # Add 10% padding - new_window_height = int(height * 1.1) + (0 if self.is_image_mode else self.TIMELINE_HEIGHT) - - # Update window size - self.window_width = new_window_width - self.window_height = new_window_height - - # Resize the OpenCV window - window_title = "Image Editor" if self.is_image_mode else "Video Editor" - cv2.resizeWindow(window_title, self.window_width, self.window_height) + # Scale down video to fit screen + new_width = int(width * scale) + new_height = int(height * scale) + display_frame = cv2.resize(display_frame, (new_width, new_height), interpolation=cv2.INTER_LINEAR) # Create canvas with timeline space canvas = np.zeros((self.window_height, self.window_width, 3), dtype=np.uint8) # Center the frame on canvas frame_height, frame_width = display_frame.shape[:2] - available_height = self.window_height - (0 if self.is_image_mode else self.TIMELINE_HEIGHT) - - # Simple fullscreen fix: scale down if video is too large for screen - if self.is_fullscreen and (frame_height > available_height or frame_width > self.window_width): - scale_x = self.window_width / frame_width - scale_y = available_height / frame_height - scale = min(scale_x, scale_y) - if scale < 1.0: - new_width = int(frame_width * scale) - new_height = int(frame_height * scale) - display_frame = cv2.resize(display_frame, (new_width, new_height), interpolation=cv2.INTER_LINEAR) - frame_height, frame_width = display_frame.shape[:2] start_y = (available_height - frame_height) // 2 start_x = (self.window_width - frame_width) // 2