21 init_effect_details();
28 init_effect_details();
32 void Shift::init_effect_details()
40 info.
description =
"Shift the image up, down, left, and right (with infinite wrapping).";
47 std::shared_ptr<openshot::Frame>
Shift::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
50 std::shared_ptr<QImage> frame_image = frame->GetImage();
51 unsigned char *pixels = (
unsigned char *) frame_image->bits();
54 double x_shift =
x.
GetValue(frame_number);
55 double x_shift_limit = fmod(fabs(x_shift), 1.0);
56 double y_shift =
y.
GetValue(frame_number);
57 double y_shift_limit = fmod(fabs(y_shift), 1.0);
60 unsigned char *temp_row =
new unsigned char[frame_image->width() * 4]();
64 for (
int row = 0; row < frame_image->height(); row++) {
66 int starting_row_pixel = row * frame_image->width();
67 memcpy(temp_row, &pixels[starting_row_pixel * 4],
sizeof(
char) * frame_image->width() * 4);
72 int relative_pixel_start = (int)round(frame_image->width() * x_shift_limit);
73 memcpy(&pixels[(starting_row_pixel + relative_pixel_start) * 4], &temp_row[0],
sizeof(
char) * (frame_image->width() - relative_pixel_start) * 4);
76 memcpy(&pixels[starting_row_pixel * 4], &temp_row[(frame_image->width() - relative_pixel_start) * 4],
sizeof(
char) * relative_pixel_start * 4);
77 }
else if (x_shift < 0.0) {
79 int relative_pixel_start = (int)round(frame_image->width() * x_shift_limit);
80 memcpy(&pixels[starting_row_pixel * 4], &temp_row[relative_pixel_start * 4],
sizeof(
char) * (frame_image->width() - relative_pixel_start) * 4);
83 memcpy(&pixels[(starting_row_pixel + (frame_image->width() - relative_pixel_start)) * 4], &temp_row[0],
sizeof(char) * relative_pixel_start * 4);
88 unsigned char *temp_image =
new unsigned char[frame_image->width() * frame_image->height() * 4]();
89 memcpy(temp_image, pixels,
sizeof(
char) * frame_image->width() * frame_image->height() * 4);
95 int relative_pixel_start = frame_image->width() * (int)round(frame_image->height() * y_shift_limit);
96 memcpy(&pixels[relative_pixel_start * 4], temp_image,
sizeof(
char) * ((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4);
99 memcpy(pixels, &temp_image[((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4],
sizeof(char) * relative_pixel_start * 4);
101 }
else if (y_shift < 0.0) {
103 int relative_pixel_start = frame_image->width() * (int)round(frame_image->height() * y_shift_limit);
104 memcpy(pixels, &temp_image[relative_pixel_start * 4],
sizeof(
char) * ((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4);
107 memcpy(&pixels[((frame_image->width() * frame_image->height()) - relative_pixel_start) * 4], temp_image,
sizeof(char) * relative_pixel_start * 4);
148 catch (
const std::exception& e)
151 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
162 if (!root[
"x"].isNull())
164 if (!root[
"y"].isNull())
173 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
174 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
176 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
177 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
178 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
188 return root.toStyledString();
std::string Id() const
Get the Id of this clip object.
float Start() const
Get start position (in seconds) of clip (trim start of video)
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
Keyframe x
Shift the X coordinates (left or right)
const Json::Value stringToJson(const std::string value)
Header file for Shift effect class.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
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...
std::string PropertiesJSON(int64_t requested_frame) const override
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for all Exception classes.
std::string Json() const override
Generate JSON string of this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Shift()
Blank constructor, useful when using Json to load the effect properties.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
float Duration() const
Get the length of this clip (in seconds)
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
This namespace is the default namespace for all code in the openshot library.
Json::Value JsonValue() const
Generate Json::Value 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.
std::string parent_effect_id
Id of the parent effect (if there is one)
float Position() const
Get position on timeline (in seconds)
Keyframe y
Shift the Y coordinates (up or down)
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
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.
void SetJson(const std::string value) override
Load JSON string into this object.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
EffectInfoStruct info
Information about the current effect.