35 init_effect_details();
39void Crop::init_effect_details()
54std::shared_ptr<openshot::Frame>
Crop::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
57 std::shared_ptr<QImage> frame_image = frame->GetImage();
60 double left_value =
left.GetValue(frame_number);
61 double top_value =
top.GetValue(frame_number);
62 double right_value =
right.GetValue(frame_number);
63 double bottom_value =
bottom.GetValue(frame_number);
66 double x_shift =
x.GetValue(frame_number);
67 double y_shift =
y.GetValue(frame_number);
69 QSize sz = frame_image->size();
73 left_value * sz.width(), top_value * sz.height(),
74 std::max(0.0, 1.0 - left_value - right_value) * sz.width(),
75 std::max(0.0, 1.0 - top_value - bottom_value) * sz.height());
78 QRectF copy_r = paint_r;
79 copy_r.translate(x_shift * sz.width(), y_shift * sz.height());
82 if (copy_r.left() < 0) {
83 paint_r.setLeft(paint_r.left() - copy_r.left());
86 if (copy_r.right() > sz.width()) {
87 paint_r.setRight(paint_r.right() - (copy_r.right() - sz.width()));
88 copy_r.setRight(sz.width());
90 if (copy_r.top() < 0) {
91 paint_r.setTop(paint_r.top() - copy_r.top());
94 if (copy_r.bottom() > sz.height()) {
95 paint_r.setBottom(paint_r.bottom() - (copy_r.bottom() - sz.height()));
96 copy_r.setBottom(sz.height());
99 QImage cropped(sz, QImage::Format_RGBA8888_Premultiplied);
100 cropped.fill(Qt::transparent);
102 QPainter p(&cropped);
103 p.drawImage(paint_r, *frame_image, copy_r);
108 frame->AddImage(std::make_shared<QImage>(cropped.copy(paint_r.toRect())));
111 frame->AddImage(std::make_shared<QImage>(cropped.copy()));
130 root[
"type"] =
info.class_name;
131 root[
"left"] =
left.JsonValue();
132 root[
"top"] =
top.JsonValue();
133 root[
"right"] =
right.JsonValue();
134 root[
"bottom"] =
bottom.JsonValue();
135 root[
"x"] =
x.JsonValue();
136 root[
"y"] =
y.JsonValue();
153 catch (
const std::exception& e)
156 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
167 if (!root[
"left"].isNull())
168 left.SetJsonValue(root[
"left"]);
169 if (!root[
"top"].isNull())
170 top.SetJsonValue(root[
"top"]);
171 if (!root[
"right"].isNull())
172 right.SetJsonValue(root[
"right"]);
173 if (!root[
"bottom"].isNull())
174 bottom.SetJsonValue(root[
"bottom"]);
175 if (!root[
"x"].isNull())
176 x.SetJsonValue(root[
"x"]);
177 if (!root[
"y"].isNull())
178 y.SetJsonValue(root[
"y"]);
179 if (!root[
"resize"].isNull())
180 resize = root[
"resize"].asBool();
190 root[
"left"] =
add_property_json(
"Left Size",
left.GetValue(requested_frame),
"float",
"", &
left, 0.0, 1.0,
false, requested_frame);
191 root[
"top"] =
add_property_json(
"Top Size",
top.GetValue(requested_frame),
"float",
"", &
top, 0.0, 1.0,
false, requested_frame);
192 root[
"right"] =
add_property_json(
"Right Size",
right.GetValue(requested_frame),
"float",
"", &
right, 0.0, 1.0,
false, requested_frame);
194 root[
"x"] =
add_property_json(
"X Offset",
x.GetValue(requested_frame),
"float",
"", &
x, -1.0, 1.0,
false, requested_frame);
195 root[
"y"] =
add_property_json(
"Y Offset",
y.GetValue(requested_frame),
"float",
"", &
y, -1.0, 1.0,
false, requested_frame);
203 return root.toStyledString();
Header file for Crop effect class.
Header file for all Exception classes.
Header file for the Keyframe class.
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties).
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.
bool resize
Auto-resize image after crop operation.
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.
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects).
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.
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.