28 #include "../../include/effects/Shift.h"
35 init_effect_details();
42 init_effect_details();
46 void Shift::init_effect_details()
54 info.
description =
"Shift the image up, down, left, and right (with infinite wrapping).";
61 std::shared_ptr<Frame>
Shift::GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number)
64 std::shared_ptr<QImage> frame_image = frame->GetImage();
65 unsigned char *pixels = (
unsigned char *) frame_image->bits();
68 double x_shift =
x.
GetValue(frame_number);
69 double x_shift_limit = fmod(abs(x_shift), 1.0);
70 double y_shift =
y.
GetValue(frame_number);
71 double y_shift_limit = fmod(abs(y_shift), 1.0);
74 unsigned char *temp_row =
new unsigned char[frame_image->width() * 4]();
78 for (
int row = 0; row < frame_image->height(); row++) {
80 int starting_row_pixel = row * frame_image->width();
81 memcpy(temp_row, &pixels[starting_row_pixel * 4],
sizeof(
char) * frame_image->width() * 4);
86 int relative_pixel_start = (int)round(frame_image->width() * x_shift_limit);
87 memcpy(&pixels[(starting_row_pixel + relative_pixel_start) * 4], &temp_row[0],
sizeof(
char) * (frame_image->width() - relative_pixel_start) * 4);
90 memcpy(&pixels[starting_row_pixel * 4], &temp_row[(frame_image->width() - relative_pixel_start) * 4],
sizeof(
char) * relative_pixel_start * 4);
91 }
else if (x_shift < 0.0) {
93 int relative_pixel_start = (int)round(frame_image->width() * x_shift_limit);
94 memcpy(&pixels[starting_row_pixel * 4], &temp_row[relative_pixel_start * 4],
sizeof(
char) * (frame_image->width() - relative_pixel_start) * 4);
97 memcpy(&pixels[(starting_row_pixel + (frame_image->width() - relative_pixel_start)) * 4], &temp_row[0],
sizeof(char) * relative_pixel_start * 4);
102 unsigned char *temp_image =
new unsigned char[frame_image->width() * frame_image->height() * 4]();
103 memcpy(temp_image, pixels,
sizeof(
char) * frame_image->width() * frame_image->height() * 4);
109 int relative_pixel_start = frame_image->width() * (int)round(frame_image->height() * y_shift_limit);
110 memcpy(&pixels[relative_pixel_start * 4], temp_image,
sizeof(
char) * ((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4);
113 memcpy(pixels, &temp_image[((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4],
sizeof(char) * relative_pixel_start * 4);
115 }
else if (y_shift < 0.0) {
117 int relative_pixel_start = frame_image->width() * (int)round(frame_image->height() * y_shift_limit);
118 memcpy(pixels, &temp_image[relative_pixel_start * 4],
sizeof(
char) * ((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4);
121 memcpy(&pixels[((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4], temp_image,
sizeof(char) * relative_pixel_start * 4);
158 bool success = reader.parse( value, root );
161 throw InvalidJSON(
"JSON could not be parsed (or is invalid)",
"");
171 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)",
"");
182 if (!root[
"x"].isNull())
184 if (!root[
"y"].isNull())
193 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
194 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
196 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
197 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
198 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
205 return root.toStyledString();
Json::Value JsonValue()
Generate Json::JsonValue for this object.
string Json()
Get and Set JSON methods.
Json::Value JsonValue()
Generate Json::JsonValue for 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...
Keyframe x
Shift the X coordinates (left or right)
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.
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.
string Id()
Get basic properties.
float Position()
Get position on timeline (in seconds)
string name
The name of the effect.
string description
The description of this effect and what it does.
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
Shift()
Blank constructor, useful when using Json to load the effect properties.
double GetValue(int64_t index)
Get the value at a specific index.
This namespace is the default namespace for all code in the openshot library.
bool has_video
Determines if this effect manipulates the image of a frame.
Exception for invalid JSON.
void SetJson(string value)
Load JSON string into this object.
Keyframe y
Shift the Y coordinates (up or down)
string PropertiesJSON(int64_t requested_frame)
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
float Duration()
Get the length of this clip (in seconds)
float Start()
Get start position (in seconds) of clip (trim start of video)
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
EffectInfoStruct info
Information about the current effect.