From c6f1794f437b92506c23c3e42258513170f0a180 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Thu, 13 Jan 2022 15:22:29 +1100 Subject: [PATCH 1/2] Fix double scaling issue when using SCALE_NONE --- src/Clip.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Clip.cpp b/src/Clip.cpp index 7fdd9555f..9a7db5c6e 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -1459,8 +1459,12 @@ QTransform Clip::get_transform(std::shared_ptr frame, int width, int heig sy*= parentObject_scale_y; } - float scaled_source_width = source_size.width() * sx; - float scaled_source_height = source_size.height() * sy; + float scaled_source_width = source_size.width(); + float scaled_source_height = source_size.height(); + if (scale != SCALE_NONE) { + scaled_source_width *= sx; + scaled_source_height *= sy; + } switch (gravity) { @@ -1528,11 +1532,13 @@ QTransform Clip::get_transform(std::shared_ptr frame, int width, int heig transform.translate(-origin_x_offset,-origin_y_offset); } // SCALE CLIP (if needed) - float source_width_scale = (float(source_size.width()) / float(source_image->width())) * sx; - float source_height_scale = (float(source_size.height()) / float(source_image->height())) * sy; - if (!isEqual(source_width_scale, 1.0) || !isEqual(source_height_scale, 1.0)) { - transform.scale(source_width_scale, source_height_scale); + if (scale != SCALE_NONE) { + float source_width_scale = (float(source_size.width()) / float(source_image->width())) * sx; + float source_height_scale = (float(source_size.height()) / float(source_image->height())) * sy; + if (!isEqual(source_width_scale, 1.0) || !isEqual(source_height_scale, 1.0)) { + transform.scale(source_width_scale, source_height_scale); + } } - return transform; + return transform; } From 54d75625b2f9df86da893236b92e5c1d22f7c7d2 Mon Sep 17 00:00:00 2001 From: Jeff Shillitto Date: Mon, 17 Jan 2022 10:27:26 +1100 Subject: [PATCH 2/2] Skip scaling of QtImageReader and FFmpegReader only --- src/Clip.cpp | 15 +++++++++++++-- src/Clip.h | 7 +++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Clip.cpp b/src/Clip.cpp index 9a7db5c6e..326be8b35 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -149,6 +149,7 @@ Clip::Clip(ReaderBase* new_reader) : resampler(NULL), reader(new_reader), alloca if (reader) { End(reader->info.duration); reader->ParentClip(this); + reader_type = reader->Name(); // Init reader info struct init_reader_settings(); } @@ -208,6 +209,7 @@ Clip::Clip(std::string path) : resampler(NULL), reader(NULL), allocated_reader(N if (reader) { End(reader->info.duration); reader->ParentClip(this); + reader_type = reader->Name(); allocated_reader = reader; // Init reader info struct init_reader_settings(); @@ -482,6 +484,15 @@ void Clip::reverse_buffer(juce::AudioBuffer* buffer) reversed = nullptr; } +bool Clip::shouldScale() const +{ + if (scale == SCALE_NONE && (reader_type == "QtImageReader" || reader_type == "FFmpegReader")) { + return false; + } + + return true; +} + // Adjust the audio and image of a time mapped frame void Clip::get_time_mapped_frame(std::shared_ptr frame, int64_t frame_number) { @@ -1461,7 +1472,7 @@ QTransform Clip::get_transform(std::shared_ptr frame, int width, int heig float scaled_source_width = source_size.width(); float scaled_source_height = source_size.height(); - if (scale != SCALE_NONE) { + if (shouldScale()) { scaled_source_width *= sx; scaled_source_height *= sy; } @@ -1532,7 +1543,7 @@ QTransform Clip::get_transform(std::shared_ptr frame, int width, int heig transform.translate(-origin_x_offset,-origin_y_offset); } // SCALE CLIP (if needed) - if (scale != SCALE_NONE) { + if (shouldScale()) { float source_width_scale = (float(source_size.width()) / float(source_image->width())) * sx; float source_height_scale = (float(source_size.height()) / float(source_image->height())) * sy; if (!isEqual(source_width_scale, 1.0) || !isEqual(source_height_scale, 1.0)) { diff --git a/src/Clip.h b/src/Clip.h index c6dffbd2f..04d7fdd82 100644 --- a/src/Clip.h +++ b/src/Clip.h @@ -120,6 +120,9 @@ namespace openshot { /// (reader member variable itself may have been replaced) openshot::ReaderBase* allocated_reader; + /// The type of reader passed to the clip + std::string reader_type; + /// Adjust frame number minimum value int64_t adjust_frame_number_minimum(int64_t frame_number); @@ -150,6 +153,10 @@ namespace openshot { /// Reverse an audio buffer void reverse_buffer(juce::AudioBuffer* buffer); + /// When scale mode is SCALE_NONE, we don't need to scale QtImageReader/FFmpegReader again + /// because those readers already scaled before. + bool shouldScale() const; + public: openshot::GravityType gravity; ///< The gravity of a clip determines where it snaps to its parent