31 #include "../../include/effects/Pixelate.h"
38 init_effect_details();
43 pixelization(pixelization), left(left), top(top), right(right), bottom(bottom)
46 init_effect_details();
50 void Pixelate::init_effect_details()
58 info.
description =
"Pixelate (increase or decrease) the number of visible pixels.";
68 std::shared_ptr<QImage> frame_image = frame->GetImage();
77 if (pixelization_value > 0.0) {
78 int w = frame_image->width();
79 int h = frame_image->height();
82 QRect area(QPoint(0,0), frame_image->size());
83 area = area.marginsRemoved({int(left_value * w), int(top_value * h), int(right_value * w), int(bottom_value * h)});
86 auto frame_scaled = frame_image->copy(area).scaledToWidth(area.width() * pixelization_value, Qt::SmoothTransformation);
89 QPainter painter(frame_image.get());
90 painter.drawImage(area, frame_scaled);
131 catch (
const std::exception& e)
134 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
145 if (!root[
"pixelization"].isNull())
147 if (!root[
"left"].isNull())
149 if (!root[
"top"].isNull())
151 if (!root[
"right"].isNull())
153 if (!root[
"bottom"].isNull())
162 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
163 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
165 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
166 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
167 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
177 return root.toStyledString();
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Pixelate()
Blank constructor, useful when using Json to load the effect properties.
Keyframe bottom
Size of bottom margin.
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.
Keyframe pixelization
Amount of pixelization.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Json::Value JsonValue() const
Generate Json::Value for this object.
const Json::Value stringToJson(const std::string value)
std::shared_ptr< Frame > GetFrame(std::shared_ptr< Frame > frame, int64_t frame_number)
This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame...
float Position() const
Get position on timeline (in seconds)
bool has_audio
Determines if this effect manipulates the audio of a frame.
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Keyframe right
Size of right margin.
double GetValue(int64_t index) const
Get the value at a specific index.
std::string Id() const
Get basic properties.
std::string PropertiesJSON(int64_t requested_frame) const override
Keyframe top
Size of top margin.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
void SetJson(const std::string value)
Load JSON string into this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
This namespace is the default namespace for all code in the openshot library.
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.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Exception for invalid JSON.
float Duration() const
Get the length of this clip (in seconds)
std::string Json() const override
Get and Set JSON methods.
float End() const
Get end position (in seconds) of clip (trim end of video)
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
float Start() const
Get start position (in seconds) of clip (trim start of video)
Keyframe left
Size of left margin.
EffectInfoStruct info
Information about the current effect.