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())
156 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
157 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
159 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
160 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
161 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
174 return root.toStyledString();
Pixelate()
Default constructor, useful when using Json to load the effect properties.
Keyframe bottom
Size of bottom margin.
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.
void SetJson(const std::string value) override
Load JSON string into this object.
Keyframe pixelization
Amount of pixelization.
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.
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for all Exception classes.
Keyframe right
Size of right margin.
Header file for JSON class.
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.
float Duration() const
Get the length of this clip (in seconds)
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.
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.
Json::Value JsonValue() const override
Generate Json::Value for this object.
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)
std::string Json() const override
Generate JSON string of this object.
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.
Header file for Pixelate 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...
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Keyframe left
Size of left margin.
EffectInfoStruct info
Information about the current effect.