37Crop::Crop() : left(0.0), top(0.0), right(0.0), bottom(0.0), x(0.0), y(0.0) {
39 init_effect_details();
44 left(left), top(top), right(right), bottom(bottom), x(0.0), y(0.0)
47 init_effect_details();
51void Crop::init_effect_details()
66std::shared_ptr<openshot::Frame>
Crop::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
69 std::shared_ptr<QImage> frame_image = frame->GetImage();
72 auto cropped_image = std::make_shared<QImage>(
73 frame_image->width(), frame_image->height(), QImage::Format_RGBA8888_Premultiplied);
74 cropped_image->fill(QColor(QString::fromStdString(
"transparent")));
83 double x_shift =
x.
GetValue(frame_number);
84 double y_shift =
y.
GetValue(frame_number);
87 unsigned char *pixels = (
unsigned char *) frame_image->bits();
88 unsigned char *cropped_pixels = (
unsigned char *) cropped_image->bits();
91 int top_bar_height = top_value * frame_image->height();
92 int bottom_bar_height = bottom_value * frame_image->height();
93 int left_bar_width = left_value * frame_image->width();
94 int right_bar_width = right_value * frame_image->width();
95 int column_offset = x_shift * frame_image->width();
96 int row_offset = y_shift * frame_image->height();
99 int image_width = frame_image->width();
100 int src_start = left_bar_width;
101 int dst_start = left_bar_width;
102 int copy_length = frame_image->width() - right_bar_width - left_bar_width;
107 if (column_offset < 0) {
109 src_start += column_offset;
111 int diff = 0 - src_start;
121 src_start += column_offset;
122 if (image_width - src_start >= copy_length) {
127 copy_offset = (image_width - src_start) - copy_length;
132 for (
int row = 0; row < frame_image->height(); row++) {
133 int adjusted_row = row - row_offset;
135 if (adjusted_row >= top_bar_height && adjusted_row < (frame_image->height() - bottom_bar_height) && (copy_length + copy_offset > 0)) {
137 memcpy(&cropped_pixels[((adjusted_row * frame_image->width()) + dst_start) * 4],
138 &pixels[((row * frame_image->width()) + src_start) * 4],
139 sizeof(
char) * (copy_length + copy_offset) * 4);
144 frame->AddImage(cropped_image);
184 catch (
const std::exception& e)
187 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
198 if (!root[
"left"].isNull())
200 if (!root[
"top"].isNull())
202 if (!root[
"right"].isNull())
204 if (!root[
"bottom"].isNull())
206 if (!root[
"x"].isNull())
208 if (!root[
"y"].isNull())
217 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
218 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
220 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
221 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
222 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
236 return root.toStyledString();
Header file for Crop effect class.
Header file for all Exception classes.
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 the Id of this clip object.
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.
void SetJson(const std::string value) override
Load JSON string into this object.
Keyframe right
Size of right bar.
std::string PropertiesJSON(int64_t requested_frame) const override
Json::Value JsonValue() const override
Generate Json::Value for this object.
Keyframe left
Size of left bar.
Crop()
Blank constructor, useful when using Json to load the effect properties.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Keyframe bottom
Size of bottom bar.
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...
Keyframe top
Size of top bar.
std::string Json() const override
Generate JSON string of this object.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into 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.
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.
std::string parent_effect_id
Id of the parent effect (if there is one)
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.