MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / GetFrame

Method GetFrame

src/effects/Pixelate.cpp:56–92  ·  view source on GitHub ↗

This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame object

Source from the content-addressed store, hash-verified

54// This method is required for all derived classes of EffectBase, and returns a
55// modified openshot::Frame object
56std::shared_ptr<openshot::Frame>
57Pixelate::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
58{
59 // Get the frame's image
60 std::shared_ptr<QImage> frame_image = frame->GetImage();
61
62 // Get current keyframe values
63 double pixelization_value = std::min(pow(0.001, fabs(pixelization.GetValue(frame_number))), 1.0);
64 double left_value = left.GetValue(frame_number);
65 double top_value = top.GetValue(frame_number);
66 double right_value = right.GetValue(frame_number);
67 double bottom_value = bottom.GetValue(frame_number);
68
69 if (pixelization_value > 0.0) {
70 int w = frame_image->width();
71 int h = frame_image->height();
72
73 // Define area we're working on in terms of a QRect with QMargins applied
74 QRect area(QPoint(0,0), frame_image->size());
75 area = area.marginsRemoved({int(left_value * w), int(top_value * h), int(right_value * w), int(bottom_value * h)});
76
77 int scale_to = (int) (area.width() * pixelization_value);
78 if (scale_to < 1) {
79 scale_to = 1; // Not less than one pixel
80 }
81 // Copy and scale pixels in area to be pixelated
82 auto frame_scaled = frame_image->copy(area).scaledToWidth(scale_to, Qt::SmoothTransformation);
83
84 // Draw pixelated image back over original
85 QPainter painter(frame_image.get());
86 painter.drawImage(area, frame_scaled);
87 painter.end();
88 }
89
90 // return the modified frame
91 return frame;
92}
93
94bool Pixelate::UseCustomMaskBlend(int64_t frame_number) const {
95 (void) frame_number;

Callers

nothing calls this directly

Calls 3

GetImageMethod · 0.80
GetValueMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected