OpenShot Library | libopenshot
0.4.0
|
Go to the documentation of this file.
27 init_effect_details();
32 pixelization(pixelization), left(left), top(top), right(right), bottom(bottom)
35 init_effect_details();
39 void Pixelate::init_effect_details()
47 info.
description =
"Pixelate (increase or decrease) the number of visible pixels.";
54 std::shared_ptr<openshot::Frame>
58 std::shared_ptr<QImage> frame_image = frame->GetImage();
61 double pixelization_value = std::min(pow(0.001, fabs(
pixelization.
GetValue(frame_number))), 1.0);
67 if (pixelization_value > 0.0) {
68 int w = frame_image->width();
69 int h = frame_image->height();
72 QRect area(QPoint(0,0), frame_image->size());
73 area = area.marginsRemoved({int(left_value * w), int(top_value * h), int(right_value * w), int(bottom_value * h)});
75 int scale_to = (int) (area.width() * pixelization_value);
80 auto frame_scaled = frame_image->copy(area).scaledToWidth(scale_to, Qt::SmoothTransformation);
83 QPainter painter(frame_image.get());
84 painter.drawImage(area, frame_scaled);
125 catch (
const std::exception& e)
128 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
139 if (!root[
"pixelization"].isNull())
141 if (!root[
"left"].isNull())
143 if (!root[
"top"].isNull())
145 if (!root[
"right"].isNull())
147 if (!root[
"bottom"].isNull())
165 return root.toStyledString();
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.
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...
const Json::Value stringToJson(const std::string value)
EffectInfoStruct info
Information about the current effect.
std::string PropertiesJSON(int64_t requested_frame) const override
This namespace is the default namespace for all code in the openshot library.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Keyframe pixelization
Amount of pixelization.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
std::string Json() const override
Generate JSON string of this object.
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)
Keyframe bottom
Size of bottom margin.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Exception for invalid JSON.
bool has_audio
Determines if this effect manipulates the audio of a frame.
Keyframe right
Size of right margin.
std::string class_name
The class name of the effect.
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.
Keyframe left
Size of left margin.
Pixelate()
Default constructor, useful when using Json to load the effect properties.
std::string name
The name of the effect.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Header file for Pixelate effect class.
Header file for JSON class.
Keyframe top
Size of top margin.
Header file for all Exception classes.
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void SetJson(const std::string value) override
Load JSON string into this object.
double GetValue(int64_t index) const
Get the value at a specific index.