video_widget.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 9748a13268d66a5949aebc970637b5903756d018 Mon Sep 17 00:00:00 2001
  2. From: Jonathan Thomas <jonathan@openshot.org>
  3. Date: Thu, 7 Oct 2021 13:53:09 -0500
  4. Subject: [PATCH] Support for previewing anamorphic video profiles, including a
  5. few code clean-ups.
  6. ---
  7. src/windows/video_widget.py | 22 +++++++---------------
  8. 1 file changed, 7 insertions(+), 15 deletions(-)
  9. diff --git a/src/windows/video_widget.py b/src/windows/video_widget.py
  10. index 7326598d34..842deb3ba0 100644
  11. --- a/src/windows/video_widget.py
  12. +++ b/src/windows/video_widget.py
  13. @@ -77,28 +77,20 @@ def changed(self, action):
  14. if action.type == "load" and action.values.get("pixel_ratio"):
  15. pixel_ratio_changed = True
  16. self.pixel_ratio = openshot.Fraction(
  17. - action.values.get("pixel_ratio").get("num", 16),
  18. - action.values.get("pixel_ratio").get("den", 9))
  19. + action.values.get("pixel_ratio").get("num", 1),
  20. + action.values.get("pixel_ratio").get("den", 1))
  21. log.info(
  22. "Set video widget pixel aspect ratio to: %s",
  23. self.pixel_ratio.ToFloat())
  24. elif action.key and action.key[0] == "pixel_ratio":
  25. pixel_ratio_changed = True
  26. self.pixel_ratio = openshot.Fraction(
  27. - action.values.get("num", 16),
  28. - action.values.get("den", 9))
  29. + action.values.get("num", 1),
  30. + action.values.get("den", 1))
  31. log.info(
  32. "Update: Set video widget pixel aspect ratio to: %s",
  33. self.pixel_ratio.ToFloat())
  34. - # Update max size (to size of video preview viewport)
  35. - if display_ratio_changed or pixel_ratio_changed:
  36. - timeline = get_app().window.timeline_sync.timeline
  37. - timeline.SetMaxSize(
  38. - round(self.width() * self.pixel_ratio.ToFloat()),
  39. - round(self.height() * self.pixel_ratio.ToFloat())
  40. - )
  41. -
  42. def drawTransformHandler(self, painter, sx, sy, source_width, source_height, origin_x, origin_y,
  43. x1=None, y1=None, x2=None, y2=None, rotation = None):
  44. @@ -236,7 +228,7 @@ def paintEvent(self, event, *args):
  45. # Determine original size of clip's reader
  46. source_width = self.transforming_clip.data['reader']['width']
  47. source_height = self.transforming_clip.data['reader']['height']
  48. - source_size = QSize(source_width, source_height)
  49. + source_size = QSize(source_width, source_height * self.pixel_ratio.Reciprocal().ToDouble())
  50. # Determine scale of clip
  51. scale = self.transforming_clip.data['scale']
  52. @@ -405,7 +397,7 @@ def paintEvent(self, event, *args):
  53. self.mutex.unlock()
  54. def centeredViewport(self, width, height):
  55. - """ Calculate size of viewport to maintain apsect ratio """
  56. + """ Calculate size of viewport to maintain aspect ratio """
  57. # Calculate padding
  58. top_padding = (height - (height * self.zoom)) / 2.0
  59. @@ -416,7 +408,7 @@ def centeredViewport(self, width, height):
  60. height = height * self.zoom
  61. # Calculate which direction to scale (for perfect centering)
  62. - aspectRatio = self.aspect_ratio.ToFloat() * self.pixel_ratio.ToFloat()
  63. + aspectRatio = self.aspect_ratio.ToFloat()
  64. heightFromWidth = width / aspectRatio
  65. widthFromHeight = height * aspectRatio