Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix none double scaling #797

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 24 additions & 7 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 @@ -1459,8 +1470,12 @@ QTransform Clip::get_transform(std::shared_ptr<Frame> 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 (shouldScale()) {
scaled_source_width *= sx;
scaled_source_height *= sy;
}

switch (gravity)
{
Expand Down Expand Up @@ -1528,11 +1543,13 @@ 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)
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 (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)) {
transform.scale(source_width_scale, source_height_scale);
}
}

return transform;
return transform;
}
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