28 #include "../../include/effects/Wave.h"
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);
184 root[
"layer"] =
add_property_json(
"Track", Layer(),
"int",
"", NULL, 0, 20,
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();