32 left(left), top(top), right(right), bottom(bottom), x(x), y(y)
35 init_effect_details();
39 void Crop::init_effect_details()
54 std::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 const QImage src(*frame_image);
104 QPainter p(&cropped);
105 p.drawImage(paint_r, src, copy_r);
109 frame->AddImage(std::make_shared<QImage>(cropped.copy()));
149 catch (
const std::exception& e)
152 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
163 if (!root[
"left"].isNull())
165 if (!root[
"top"].isNull())
167 if (!root[
"right"].isNull())
169 if (!root[
"bottom"].isNull())
171 if (!root[
"x"].isNull())
173 if (!root[
"y"].isNull())
182 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
183 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
185 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
186 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
187 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
201 return root.toStyledString();
Keyframe top
Size of top bar.
This class crops a frame image (from any side), and can be animated with openshot::Keyframe curves ov...
Keyframe right
Size of right bar.
void SetJson(const std::string value) override
Load JSON string into this object.
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.
Keyframe left
Size of left bar.
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
const Json::Value stringToJson(const std::string value)
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Header file for the Keyframe class.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Header file for Crop effect class.
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...
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for all Exception classes.
std::string PropertiesJSON(int64_t requested_frame) const override
Keyframe bottom
Size of bottom bar.
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)
std::string Json() const override
Generate JSON string of this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Crop()
Blank constructor, useful when using Json to load the effect properties.
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)
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.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
EffectInfoStruct info
Information about the current effect.