Skip to content

Commit

Permalink
Exponential regression rule for Pixelate scale
Browse files Browse the repository at this point in the history
  • Loading branch information
SuslikV committed Apr 27, 2020
1 parent 15c3efb commit 4f60f45
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/effects/Pixelate.cpp
Expand Up @@ -33,7 +33,7 @@
using namespace openshot;

/// Blank constructor, useful when using Json to load the effect properties
Pixelate::Pixelate() : pixelization(0.7), left(0.0), top(0.0), right(0.0), bottom(0.0) {
Pixelate::Pixelate() : pixelization(0.5), left(0.0), top(0.0), right(0.0), bottom(0.0) {
// Init effect properties
init_effect_details();
}
Expand Down Expand Up @@ -68,7 +68,7 @@ std::shared_ptr<Frame> Pixelate::GetFrame(std::shared_ptr<Frame> frame, int64_t
std::shared_ptr<QImage> frame_image = frame->GetImage();

// Get current keyframe values
double pixelization_value = 1.0 - std::min(fabs(pixelization.GetValue(frame_number)), 1.0);
double pixelization_value = std::min(pow(0.001, fabs(pixelization.GetValue(frame_number))), 1.0);
double left_value = left.GetValue(frame_number);
double top_value = top.GetValue(frame_number);
double right_value = right.GetValue(frame_number);
Expand All @@ -82,8 +82,12 @@ std::shared_ptr<Frame> Pixelate::GetFrame(std::shared_ptr<Frame> frame, int64_t
QRect area(QPoint(0,0), frame_image->size());
area = area.marginsRemoved({int(left_value * w), int(top_value * h), int(right_value * w), int(bottom_value * h)});

int scale_to = (int) (area.width() * pixelization_value);
if (scale_to < 1) {
scale_to = 1; // Not less than one pixel
}
// Copy and scale pixels in area to be pixelated
auto frame_scaled = frame_image->copy(area).scaledToWidth(area.width() * pixelization_value, Qt::SmoothTransformation);
auto frame_scaled = frame_image->copy(area).scaledToWidth(scale_to, Qt::SmoothTransformation);

// Draw pixelated image back over original
QPainter painter(frame_image.get());
Expand Down

0 comments on commit 4f60f45

Please sign in to comment.