37Wave::Wave() : wavelength(0.06), amplitude(0.3), multiplier(0.2), shift_x(0.0), speed_y(0.2) {
39 init_effect_details();
44 : wavelength(wavelength), amplitude(amplitude), multiplier(multiplier), shift_x(shift_x), speed_y(speed_y)
47 init_effect_details();
51void Wave::init_effect_details()
67std::shared_ptr<openshot::Frame>
Wave::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
70 std::shared_ptr<QImage> frame_image = frame->GetImage();
73 const unsigned char *original_pixels = (
unsigned char *) frame_image->constBits();
74 unsigned char *pixels = (
unsigned char *) frame_image->bits();
75 int pixel_count = frame_image->width() * frame_image->height();
78 double time = frame_number;
86 #pragma omp parallel for
87 for (
int pixel = 0; pixel < pixel_count; ++pixel)
90 int Y = pixel / frame_image->width();
93 float noiseVal = (100 + Y * 0.001) * multiplier_value;
94 float noiseAmp = noiseVal * amplitude_value;
95 float waveformVal = sin((Y * wavelength_value) + (time * speed_y_value));
96 float waveVal = (waveformVal + shift_x_value) * noiseAmp;
98 long unsigned int source_px = round(pixel + waveVal);
101 if (source_px >= pixel_count)
102 source_px = pixel_count - 1;
105 memcpy(&pixels[pixel * 4], &original_pixels[source_px * 4],
sizeof(
char) * 4);
145 catch (
const std::exception& e)
148 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
159 if (!root[
"wavelength"].isNull())
161 if (!root[
"amplitude"].isNull())
163 if (!root[
"multiplier"].isNull())
165 if (!root[
"shift_x"].isNull())
167 if (!root[
"speed_y"].isNull())
176 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
177 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
179 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
180 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
181 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
194 return root.toStyledString();
Header file for all Exception classes.
Header file for Wave effect class.
float End() const
Get end position (in seconds) of clip (trim end of video)
float Start() const
Get start position (in seconds) of clip (trim start of video)
float Duration() const
Get the length of this clip (in seconds)
std::string Id() const
Get the Id of this clip object.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
float Position() const
Get position on timeline (in seconds)
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.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
EffectInfoStruct info
Information about the current effect.
Exception for invalid JSON.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
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.
Json::Value JsonValue() const
Generate Json::Value for this object.
Keyframe shift_x
Amount to shift X-axis.
Wave()
Default constructor, useful when using Json to load the effect properties.
std::string PropertiesJSON(int64_t requested_frame) const override
std::string Json() const override
Generate JSON string of this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
void SetJson(const std::string value) override
Load JSON string into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Keyframe amplitude
The height of the wave.
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...
Keyframe multiplier
Amount to multiply the wave (make it bigger)
Keyframe speed_y
Speed of the wave on the Y-axis.
This namespace is the default namespace for all code in the openshot library.
const Json::Value stringToJson(const std::string value)
bool has_video
Determines if this effect manipulates the image of a frame.
std::string parent_effect_id
Id of the parent effect (if there is one)
bool has_audio
Determines if this effect manipulates the audio of a frame.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
std::string description
The description of this effect and what it does.