32 left(left), top(top), right(right), bottom(bottom), x(x), y(y), resize(false)
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();
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()));
153 catch (
const std::exception& e)
156 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
167 if (!root[
"left"].isNull())
169 if (!root[
"top"].isNull())
171 if (!root[
"right"].isNull())
173 if (!root[
"bottom"].isNull())
175 if (!root[
"x"].isNull())
177 if (!root[
"y"].isNull())
179 if (!root[
"resize"].isNull())
180 resize = root[
"resize"].asBool();
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.
This class crops a frame image (from any side), and can be animated with openshot::Keyframe curves ov...
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.
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.
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.