27 init_effect_details();
32 pixelization(pixelization), left(left), top(top), right(right), bottom(bottom)
35 init_effect_details();
39void Pixelate::init_effect_details()
47 info.
description =
"Pixelate (increase or decrease) the number of visible pixels.";
54std::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();
Header file for all Exception classes.
Header file for JSON class.
Header file for Pixelate effect class.
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.
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.
Pixelate()
Default constructor, useful when using Json to load the effect properties.
Keyframe right
Size of right margin.
std::string Json() const override
Generate JSON string of this object.
std::string PropertiesJSON(int64_t requested_frame) const override
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 pixelization
Amount of pixelization.
Keyframe left
Size of left margin.
Json::Value JsonValue() const override
Generate Json::Value for this object.
void SetJson(const std::string value) override
Load JSON string into this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Keyframe top
Size of top margin.
Keyframe bottom
Size of bottom margin.
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.