Skip to content

Commit

Permalink
Skip scaling of QtImageReader and FFmpegReader only
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffski committed Jan 16, 2022
1 parent c6f1794 commit 54d7562
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -482,6 +484,15 @@ void Clip::reverse_buffer(juce::AudioBuffer<float>* 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> frame, int64_t frame_number)
{
Expand Down Expand Up @@ -1461,7 +1472,7 @@ QTransform Clip::get_transform(std::shared_ptr<Frame> 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;
}
Expand Down Expand Up @@ -1532,7 +1543,7 @@ QTransform Clip::get_transform(std::shared_ptr<Frame> 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)) {
Expand Down
7 changes: 7 additions & 0 deletions src/Clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -150,6 +153,10 @@ namespace openshot {
/// Reverse an audio buffer
void reverse_buffer(juce::AudioBuffer<float>* 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
Expand Down

0 comments on commit 54d7562

Please sign in to comment.