28 #include "../../include/effects/Wave.h"
30 using namespace openshot;
33 Wave::Wave() : wavelength(0.06), amplitude(0.3), multiplier(0.2), shift_x(0.0), speed_y(0.2) {
35 init_effect_details();
40 : wavelength(wavelength), amplitude(amplitude), multiplier(multiplier), shift_x(shift_x), speed_y(speed_y)
43 init_effect_details();
47 void Wave::init_effect_details()
63 std::shared_ptr<Frame>
Wave::GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number)
66 std::shared_ptr<QImage> frame_image = frame->GetImage();
69 unsigned char *pixels = (
unsigned char *) frame_image->bits();
72 unsigned char *temp_image =
new unsigned char[frame_image->width() * frame_image->height() * 4]();
73 memcpy(temp_image, pixels,
sizeof(
char) * frame_image->width() * frame_image->height() * 4);
76 double time = frame_number;
84 for (
int pixel = 0, byte_index=0; pixel < frame_image->width() * frame_image->height(); pixel++, byte_index+=4)
87 int Y = pixel / frame_image->width();
90 float noiseVal = (100 + Y * 0.001) * multiplier_value;
91 float noiseAmp = noiseVal * amplitude_value;
92 float waveformVal = sin((Y * wavelength_value) + (time * speed_y_value));
93 float waveVal = (waveformVal + shift_x_value) * noiseAmp;
95 int source_X = round(pixel + waveVal) * 4;
98 if (source_X > frame_image->width() * frame_image->height() * 4 *
sizeof(char))
99 source_X = (frame_image->width() * frame_image->height() * 4 *
sizeof(char)) - (
sizeof(char) * 4);
102 memcpy(&pixels[byte_index], &temp_image[source_X],
sizeof(
char) * 4);
141 bool success = reader.parse( value, root );
144 throw InvalidJSON(
"JSON could not be parsed (or is invalid)",
"");
154 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)",
"");
165 if (!root[
"wavelength"].isNull())
167 if (!root[
"amplitude"].isNull())
169 if (!root[
"multiplier"].isNull())
171 if (!root[
"shift_x"].isNull())
173 if (!root[
"speed_y"].isNull())
182 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
183 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
185 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
186 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
187 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
197 return root.toStyledString();
void SetJson(string value)
Load JSON string into this object.
Json::Value JsonValue()
Generate Json::JsonValue for this object.
string Json()
Get and Set JSON methods.
float End()
Get end position (in seconds) of clip (trim end of video)
Json::Value add_property_json(string name, float value, string type, string memo, Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame)
Generate JSON for a property.
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
string class_name
The class name of the effect.
Wave()
Blank constructor, useful when using Json to load the effect properties.
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
bool has_audio
Determines if this effect manipulates the audio of a frame.
Keyframe wavelength
The length of the wave.
string Id()
Get basic properties.
float Position()
Get position on timeline (in seconds)
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
string name
The name of the effect.
string PropertiesJSON(int64_t requested_frame)
string description
The description of this effect and what it does.
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue 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...
double GetValue(int64_t index)
Get the value at a specific index.
bool has_video
Determines if this effect manipulates the image of a frame.
Exception for invalid JSON.
Keyframe speed_y
Speed of the wave on the Y-axis.
Keyframe shift_x
Amount to shift X-axis.
Keyframe amplitude
The height of the wave.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
Keyframe multiplier
Amount to multiply the wave (make it bigger)
Json::Value JsonValue()
Generate Json::JsonValue for this object.
float Duration()
Get the length of this clip (in seconds)
float Start()
Get start position (in seconds) of clip (trim start of video)
EffectInfoStruct info
Information about the current effect.