Refactor display dimension calculations in VideoEditor
This commit simplifies the calculation of display dimensions by utilizing the transformed display frame directly, eliminating redundant width and height calculations based on rotation and crop. It enhances the overall efficiency of the display handling process, ensuring accurate scaling and improved performance during video editing.
This commit is contained in:
@@ -2252,6 +2252,12 @@ class VideoEditor:
|
||||
if self.current_display_frame is None:
|
||||
return None
|
||||
|
||||
# Use the same approach as screen_to_video_coords but in reverse
|
||||
# First, apply the same transformations as the frame
|
||||
display_frame = self.apply_crop_zoom_and_rotation(self.current_display_frame.copy())
|
||||
if display_frame is None:
|
||||
return None
|
||||
|
||||
# Get the original frame dimensions
|
||||
original_height, original_width = self.current_display_frame.shape[:2]
|
||||
available_height = self.window_height - (0 if self.is_image_mode else self.TIMELINE_HEIGHT)
|
||||
@@ -2294,24 +2300,7 @@ class VideoEditor:
|
||||
display_y *= self.zoom_factor
|
||||
|
||||
# Step 4: Calculate final display dimensions and scale
|
||||
if self.rotation_angle in [90, 270]:
|
||||
# Width and height are swapped after rotation
|
||||
display_width = int(original_height * self.zoom_factor)
|
||||
display_height = int(original_width * self.zoom_factor)
|
||||
else:
|
||||
display_width = int(original_width * self.zoom_factor)
|
||||
display_height = int(original_height * self.zoom_factor)
|
||||
|
||||
# Apply crop dimensions if there's a crop
|
||||
if self.crop_rect:
|
||||
if self.rotation_angle in [90, 270]:
|
||||
display_width = int(self.crop_rect[3] * self.zoom_factor) # crop height
|
||||
display_height = int(self.crop_rect[2] * self.zoom_factor) # crop width
|
||||
else:
|
||||
display_width = int(self.crop_rect[2] * self.zoom_factor) # crop width
|
||||
display_height = int(self.crop_rect[3] * self.zoom_factor) # crop height
|
||||
|
||||
# Calculate scale for the display frame
|
||||
display_height, display_width = display_frame.shape[:2]
|
||||
scale = min(self.window_width / display_width, available_height / display_height)
|
||||
if scale < 1.0:
|
||||
final_display_width = int(display_width * scale)
|
||||
|
Reference in New Issue
Block a user