OpenShot Library | libopenshot
0.3.3
|
Go to the documentation of this file.
19 Wave::Wave() : wavelength(0.06), amplitude(0.3), multiplier(0.2), shift_x(0.0), speed_y(0.2) {
21 init_effect_details();
26 : wavelength(wavelength), amplitude(amplitude), multiplier(multiplier), shift_x(shift_x), speed_y(speed_y)
29 init_effect_details();
33 void Wave::init_effect_details()
49 std::shared_ptr<openshot::Frame>
Wave::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
52 std::shared_ptr<QImage> frame_image = frame->GetImage();
55 const unsigned char *original_pixels = (
unsigned char *) frame_image->constBits();
56 unsigned char *pixels = (
unsigned char *) frame_image->bits();
57 int pixel_count = frame_image->width() * frame_image->height();
60 double time = frame_number;
68 #pragma omp parallel for
69 for (
int pixel = 0; pixel < pixel_count; ++pixel)
72 int Y = pixel / frame_image->width();
75 float noiseVal = (100 + Y * 0.001) * multiplier_value;
76 float noiseAmp = noiseVal * amplitude_value;
77 float waveformVal = sin((Y * wavelength_value) + (time * speed_y_value));
78 float waveVal = (waveformVal + shift_x_value) * noiseAmp;
80 long unsigned int source_px = round(pixel + waveVal);
83 if (source_px >= pixel_count)
84 source_px = pixel_count - 1;
87 memcpy(&pixels[pixel * 4], &original_pixels[source_px * 4],
sizeof(
char) * 4);
127 catch (
const std::exception& e)
130 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
141 if (!root[
"wavelength"].isNull())
143 if (!root[
"amplitude"].isNull())
145 if (!root[
"multiplier"].isNull())
147 if (!root[
"shift_x"].isNull())
149 if (!root[
"speed_y"].isNull())
167 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.
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
This namespace is the default namespace for all code in the openshot library.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Keyframe speed_y
Speed of the wave on the Y-axis.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Json::Value JsonValue() const
Generate Json::Value for this object.
Keyframe shift_x
Amount to shift X-axis.
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
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)
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for Wave effect class.
std::string PropertiesJSON(int64_t requested_frame) const override
void SetJson(const std::string value) override
Load JSON string into this object.
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()
Default constructor, useful when using Json to load the effect properties.
std::string Json() const override
Generate JSON string of this object.
std::string name
The name of the effect.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Header file for all Exception classes.
virtual 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.