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 unsigned char *pixels = (
unsigned char *) frame_image->bits();
75 unsigned char *temp_image =
new unsigned char[frame_image->width() * frame_image->height() * 4]();
76 memcpy(temp_image, pixels,
sizeof(
char) * frame_image->width() * frame_image->height() * 4);
79 double time = frame_number;
87 for (
int pixel = 0, byte_index=0; pixel < frame_image->width() * frame_image->height(); pixel++, byte_index+=4)
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_X = round(pixel + waveVal) * 4;
101 if (source_X > frame_image->width() * frame_image->height() * 4 *
sizeof(char))
102 source_X = (frame_image->width() * frame_image->height() * 4 *
sizeof(char)) - (
sizeof(char) * 4);
105 memcpy(&pixels[byte_index], &temp_image[source_X],
sizeof(
char) * 4);
143 Json::CharReaderBuilder rbuilder;
144 Json::CharReader* reader(rbuilder.newCharReader());
147 bool success = reader->parse( value.c_str(),
148 value.c_str() + value.size(), &root, &errors );
153 throw InvalidJSON(
"JSON could not be parsed (or is invalid)");
160 catch (
const std::exception& e)
163 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
174 if (!root[
"wavelength"].isNull())
176 if (!root[
"amplitude"].isNull())
178 if (!root[
"multiplier"].isNull())
180 if (!root[
"shift_x"].isNull())
182 if (!root[
"speed_y"].isNull())
191 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
192 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
194 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
195 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
196 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
206 return root.toStyledString();
float End()
Get end position (in seconds) of clip (trim end of video)
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
std::string Json()
Get and Set JSON methods.
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.
void SetJson(std::string value)
Load JSON string into this object.
Keyframe wavelength
The length of the wave.
std::string Id()
Get basic properties.
float Position()
Get position on timeline (in seconds)
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
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...
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame)
Generate JSON for a property.
This namespace is the default namespace for all code in the openshot library.
Json::Value JsonValue() const
Generate Json::JsonValue for this object.
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.
Exception for invalid JSON.
double GetValue(int64_t index) const
Get the value at a specific index.
Keyframe speed_y
Speed of the wave on the Y-axis.
Keyframe shift_x
Amount to shift X-axis.
std::string PropertiesJSON(int64_t requested_frame)
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.