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

Method GetFrame

src/effects/Wave.cpp:49–93  ·  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

47// This method is required for all derived classes of EffectBase, and returns a
48// modified openshot::Frame object
49std::shared_ptr<openshot::Frame> Wave::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
50{
51 // Get the frame's image
52 std::shared_ptr<QImage> frame_image = frame->GetImage();
53
54 // Copy original pixels for reference, and get a writable pointer for editing
55 QImage original = frame_image->copy();
56 const unsigned char *original_pixels = original.constBits();
57 unsigned char *pixels = frame_image->bits();
58 int pixel_count = frame_image->width() * frame_image->height();
59
60 // Get current keyframe values
61 double time = frame_number;
62 double wavelength_value = wavelength.GetValue(frame_number);
63 double amplitude_value = amplitude.GetValue(frame_number);
64 double multiplier_value = multiplier.GetValue(frame_number);
65 double shift_x_value = shift_x.GetValue(frame_number);
66 double speed_y_value = speed_y.GetValue(frame_number);
67
68 // Loop through pixels
69 #pragma omp parallel for
70 for (int pixel = 0; pixel < pixel_count; ++pixel)
71 {
72 // Calculate pixel Y value
73 int Y = pixel / frame_image->width();
74
75 // Calculate wave pixel offsets
76 float noiseVal = (100 + Y * 0.001) * multiplier_value; // Time and time multiplier (to make the wave move)
77 float noiseAmp = noiseVal * amplitude_value; // Apply amplitude / height of the wave
78 float waveformVal = sin((Y * wavelength_value) + (time * speed_y_value)); // Waveform algorithm on y-axis
79 float waveVal = (waveformVal + shift_x_value) * noiseAmp; // Shifts pixels on the x-axis
80
81 int source_px = lround(pixel + waveVal);
82 if (source_px < 0)
83 source_px = 0;
84 if (source_px >= pixel_count)
85 source_px = pixel_count - 1;
86
87 // Calculate source array location, and target array location, and copy the 4 color values
88 memcpy(&pixels[pixel * 4], &original_pixels[source_px * 4], sizeof(char) * 4);
89 }
90
91 // return the modified frame
92 return frame;
93}
94
95// Generate JSON string of this object
96std::string Wave::Json() const {

Callers

nothing calls this directly

Calls 2

GetImageMethod · 0.80
GetValueMethod · 0.80

Tested by

no test coverage detected