OpenShot Library | libopenshot
0.2.5
|
Go to the documentation of this file.
31 #include "../../include/effects/Wave.h"
36 Wave::Wave() : wavelength(0.06), amplitude(0.3), multiplier(0.2), shift_x(0.0), speed_y(0.2) {
38 init_effect_details();
43 : wavelength(wavelength), amplitude(amplitude), multiplier(multiplier), shift_x(shift_x), speed_y(speed_y)
46 init_effect_details();
50 void Wave::init_effect_details()
66 std::shared_ptr<Frame>
Wave::GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number)
69 std::shared_ptr<QImage> frame_image = frame->
GetImage();
72 const unsigned char *original_pixels = (
unsigned char *) frame_image->constBits();
73 unsigned char *pixels = (
unsigned char *) frame_image->bits();
74 int pixel_count = frame_image->width() * frame_image->height();
77 double time = frame_number;
85 #pragma omp parallel for
86 for (
int pixel = 0; pixel < pixel_count; ++pixel)
89 int Y = pixel / frame_image->width();
92 float noiseVal = (100 + Y * 0.001) * multiplier_value;
93 float noiseAmp = noiseVal * amplitude_value;
94 float waveformVal = sin((Y * wavelength_value) + (time * speed_y_value));
95 float waveVal = (waveformVal + shift_x_value) * noiseAmp;
97 long unsigned int source_px = round(pixel + waveVal);
100 if (source_px >= pixel_count)
101 source_px = pixel_count - 1;
104 memcpy(&pixels[pixel * 4], &original_pixels[source_px * 4],
sizeof(
char) * 4);
144 catch (
const std::exception& e)
147 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
158 if (!root[
"wavelength"].isNull())
160 if (!root[
"amplitude"].isNull())
162 if (!root[
"multiplier"].isNull())
164 if (!root[
"shift_x"].isNull())
166 if (!root[
"speed_y"].isNull())
175 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
176 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
178 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
179 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
180 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
190 return root.toStyledString();
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const
Generate JSON for a property.
const Json::Value stringToJson(const std::string value)
EffectInfoStruct info
Information about the current effect.
Keyframe wavelength
The length of the wave.
This namespace is the default namespace for all code in the openshot library.
float End() const
Get end position (in seconds) of clip (trim end of video)
Keyframe speed_y
Speed of the wave on the Y-axis.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
std::shared_ptr< Frame > GetFrame(std::shared_ptr< Frame > frame, int64_t frame_number)
This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame...
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Json::Value JsonValue() const
Generate Json::Value for this object.
Keyframe shift_x
Amount to shift X-axis.
std::string Id() const
Get basic properties.
Json::Value JsonValue() const override
Generate Json::Value for this object.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Keyframe amplitude
The height of the wave.
Exception for invalid JSON.
Keyframe multiplier
Amount to multiply the wave (make it bigger)
void SetJson(const std::string value)
Load JSON string into this object.
bool has_audio
Determines if this effect manipulates the audio of a frame.
float Duration() const
Get the length of this clip (in seconds)
std::string PropertiesJSON(int64_t requested_frame) const override
std::string class_name
The class name of the effect.
std::string description
The description of this effect and what it does.
bool has_video
Determines if this effect manipulates the image of a frame.
Wave()
Blank constructor, useful when using Json to load the effect properties.
std::string Json() const override
Get and Set JSON methods.
std::shared_ptr< QImage > GetImage()
Get pointer to Qt QImage image object.
float Position() const
Get position on timeline (in seconds)
std::string name
The name of the effect.
float Start() const
Get start position (in seconds) of clip (trim start of video)
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
double GetValue(int64_t index) const
Get the value at a specific index.