31 #include "../../include/effects/Shift.h"
38 init_effect_details();
45 init_effect_details();
49 void Shift::init_effect_details()
57 info.
description =
"Shift the image up, down, left, and right (with infinite wrapping).";
64 std::shared_ptr<Frame>
Shift::GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number)
67 std::shared_ptr<QImage> frame_image = frame->GetImage();
68 unsigned char *pixels = (
unsigned char *) frame_image->bits();
71 double x_shift =
x.
GetValue(frame_number);
72 double x_shift_limit = fmod(fabs(x_shift), 1.0);
73 double y_shift =
y.
GetValue(frame_number);
74 double y_shift_limit = fmod(fabs(y_shift), 1.0);
77 unsigned char *temp_row =
new unsigned char[frame_image->width() * 4]();
81 for (
int row = 0; row < frame_image->height(); row++) {
83 int starting_row_pixel = row * frame_image->width();
84 memcpy(temp_row, &pixels[starting_row_pixel * 4],
sizeof(
char) * frame_image->width() * 4);
89 int relative_pixel_start = (int)round(frame_image->width() * x_shift_limit);
90 memcpy(&pixels[(starting_row_pixel + relative_pixel_start) * 4], &temp_row[0],
sizeof(
char) * (frame_image->width() - relative_pixel_start) * 4);
93 memcpy(&pixels[starting_row_pixel * 4], &temp_row[(frame_image->width() - relative_pixel_start) * 4],
sizeof(
char) * relative_pixel_start * 4);
94 }
else if (x_shift < 0.0) {
96 int relative_pixel_start = (int)round(frame_image->width() * x_shift_limit);
97 memcpy(&pixels[starting_row_pixel * 4], &temp_row[relative_pixel_start * 4],
sizeof(
char) * (frame_image->width() - relative_pixel_start) * 4);
100 memcpy(&pixels[(starting_row_pixel + (frame_image->width() - relative_pixel_start)) * 4], &temp_row[0],
sizeof(
char) * relative_pixel_start * 4);
105 unsigned char *temp_image =
new unsigned char[frame_image->width() * frame_image->height() * 4]();
106 memcpy(temp_image, pixels,
sizeof(
char) * frame_image->width() * frame_image->height() * 4);
112 int relative_pixel_start = frame_image->width() * (int)round(frame_image->height() * y_shift_limit);
113 memcpy(&pixels[relative_pixel_start * 4], temp_image,
sizeof(
char) * ((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4);
116 memcpy(pixels, &temp_image[((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4],
sizeof(
char) * relative_pixel_start * 4);
118 }
else if (y_shift < 0.0) {
120 int relative_pixel_start = frame_image->width() * (int)round(frame_image->height() * y_shift_limit);
121 memcpy(pixels, &temp_image[relative_pixel_start * 4],
sizeof(
char) * ((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4);
124 memcpy(&pixels[((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4], temp_image,
sizeof(
char) * relative_pixel_start * 4);
165 catch (
const std::exception& e)
168 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
179 if (!root[
"x"].isNull())
181 if (!root[
"y"].isNull())
190 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
191 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
193 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
194 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
195 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
202 return root.toStyledString();
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 basic properties.
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 void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
virtual Json::Value JsonValue() const =0
Generate Json::Value for 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 y
Shift the Y coordinates (up or down)
std::string Json() const override
Get and Set JSON methods.
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...
Json::Value JsonValue() const override
Generate Json::Value for this object.
Keyframe x
Shift the X coordinates (left or right)
void SetJson(const std::string value)
Load JSON string into this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
std::string PropertiesJSON(int64_t requested_frame) const override
Shift()
Blank constructor, useful when using Json to load the effect properties.
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.
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.