diff --git a/croppa/main.py b/croppa/main.py index ffa613d..17c8bce 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -128,7 +128,7 @@ class VideoEditor: # Feedback message state self.feedback_message = "" self.feedback_message_time = None - self.feedback_message_duration = 0.7 # seconds to show message + self.feedback_message_duration = 0.5 # seconds to show message # Crop adjustment settings self.crop_size_step = self.CROP_SIZE_STEP @@ -1145,18 +1145,50 @@ class VideoEditor: display_h = min(display_h, display_height - display_y) # Convert display frame coordinates back to original frame coordinates - # This is the inverse of apply_crop_and_zoom - # The order in apply_crop_and_zoom is: crop first, then zoom - # So we need to reverse: zoom first, then crop + # This is the inverse of apply_crop_zoom_and_rotation + # The order is: crop -> rotation -> zoom + # So we need to reverse: zoom -> rotation -> crop - # Step 1: Reverse zoom (zoom is applied to the cropped frame) + # Step 1: Reverse zoom (zoom is applied to the rotated frame) if self.zoom_factor != 1.0: display_x = display_x / self.zoom_factor display_y = display_y / self.zoom_factor display_w = display_w / self.zoom_factor display_h = display_h / self.zoom_factor - # Step 2: Reverse crop (crop is applied to the original frame) + # Step 2: Reverse rotation (rotation is applied to the cropped frame) + if self.rotation_angle != 0: + # Get the dimensions after crop but before rotation + if self.crop_rect: + crop_w, crop_h = int(self.crop_rect[2]), int(self.crop_rect[3]) + else: + crop_w, crop_h = original_width, original_height + + # Apply inverse rotation to coordinates + if self.rotation_angle == 90: + # 90° clockwise -> 270° counter-clockwise + new_x = display_y + new_y = crop_w - display_x - display_w + new_w = display_h + new_h = display_w + elif self.rotation_angle == 180: + # 180° -> 180° (same) + new_x = crop_w - display_x - display_w + new_y = crop_h - display_y - display_h + new_w = display_w + new_h = display_h + elif self.rotation_angle == 270: + # 270° clockwise -> 90° counter-clockwise + new_x = crop_h - display_y - display_h + new_y = display_x + new_w = display_h + new_h = display_w + else: + new_x, new_y, new_w, new_h = display_x, display_y, display_w, display_h + + display_x, display_y, display_w, display_h = new_x, new_y, new_w, new_h + + # Step 3: Reverse crop (crop is applied to the original frame) original_x = display_x original_y = display_y original_w = display_w