37 Blur::Blur() : horizontal_radius(6.0), vertical_radius(6.0), sigma(3.0), iterations(3.0) {
39 init_effect_details();
48 init_effect_details();
52 void Blur::init_effect_details()
67 std::shared_ptr<openshot::Frame>
Blur::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
70 std::shared_ptr<QImage> frame_image = frame->GetImage();
78 int w = frame_image->width();
79 int h = frame_image->height();
82 QImage image_copy = frame_image->copy();
83 std::shared_ptr<QImage> frame_image_2 = std::make_shared<QImage>(image_copy);
86 for (
int iteration = 0; iteration < iteration_value; ++iteration)
89 if (horizontal_radius_value > 0.0) {
91 boxBlurH(frame_image->bits(), frame_image_2->bits(), w, h, horizontal_radius_value);
94 frame_image.swap(frame_image_2);
98 if (vertical_radius_value > 0.0) {
100 boxBlurT(frame_image->bits(), frame_image_2->bits(), w, h, vertical_radius_value);
103 frame_image.swap(frame_image_2);
113 void Blur::boxBlurH(
unsigned char *scl,
unsigned char *tcl,
int w,
int h,
int r) {
114 float iarr = 1.0 / (r + r + 1);
116 #pragma omp parallel for shared (scl, tcl) 117 for (
int i = 0; i < h; ++i) {
118 for (
int ch = 0; ch < 4; ++ch) {
119 int ti = i * w, li = ti, ri = ti + r;
120 int fv = scl[ti * 4 + ch], lv = scl[(ti + w - 1) * 4 + ch], val = (r + 1) * fv;
121 for (
int j = 0; j < r; ++j) {
122 val += scl[(ti + j) * 4 + ch];
124 for (
int j = 0; j <= r; ++j) {
125 val += scl[ri++ * 4 + ch] - fv;
126 tcl[ti++ * 4 + ch] = round(val * iarr);
128 for (
int j = r + 1; j < w - r; ++j) {
129 val += scl[ri++ * 4 + ch] - scl[li++ * 4 + ch];
130 tcl[ti++ * 4 + ch] = round(val * iarr);
132 for (
int j = w - r; j < w; ++j) {
133 val += lv - scl[li++ * 4 + ch];
134 tcl[ti++ * 4 + ch] = round(val * iarr);
140 void Blur::boxBlurT(
unsigned char *scl,
unsigned char *tcl,
int w,
int h,
int r) {
141 float iarr = 1.0 / (r + r + 1);
143 #pragma omp parallel for shared (scl, tcl) 144 for (
int i = 0; i < w; i++) {
145 for (
int ch = 0; ch < 4; ++ch) {
146 int ti = i, li = ti, ri = ti + r * w;
147 int fv = scl[ti * 4 + ch], lv = scl[(ti + w * (h - 1)) * 4 + ch], val = (r + 1) * fv;
148 for (
int j = 0; j < r; j++) val += scl[(ti + j * w) * 4 + ch];
149 for (
int j = 0; j <= r; j++) {
150 val += scl[ri * 4 + ch] - fv;
151 tcl[ti * 4 + ch] = round(val * iarr);
155 for (
int j = r + 1; j < h - r; j++) {
156 val += scl[ri * 4 + ch] - scl[li * 4 + ch];
157 tcl[ti * 4 + ch] = round(val * iarr);
162 for (
int j = h - r; j < h; j++) {
163 val += lv - scl[li * 4 + ch];
164 tcl[ti * 4 + ch] = round(val * iarr);
204 catch (
const std::exception& e)
207 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
218 if (!root[
"horizontal_radius"].isNull())
220 if (!root[
"vertical_radius"].isNull())
222 if (!root[
"sigma"].isNull())
224 if (!root[
"iterations"].isNull())
233 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
234 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
236 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
237 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
238 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
250 return root.toStyledString();
Header file for Blur effect class.
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.
const Json::Value stringToJson(const std::string value)
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Keyframe iterations
Iterations keyframe. The # of blur iterations per pixel. 3 iterations = Gaussian. ...
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
int GetInt(int64_t index) const
Get the rounded INT value at a specific index.
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for all Exception classes.
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 vertical_radius
Vertical blur radius keyframe. The size of the vertical blur operation in pixels. ...
std::string Json() const override
Generate JSON string of this object.
std::string class_name
The class name of the effect.
Blur()
Blank constructor, useful when using Json to load the effect properties.
std::string name
The name of the effect.
std::string PropertiesJSON(int64_t requested_frame) const override
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.
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)
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...
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.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Keyframe sigma
Sigma keyframe. The amount of spread in the blur operation. Should be larger than radius...
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Keyframe horizontal_radius
Horizontal blur radius keyframe. The size of the horizontal blur operation in pixels.
EffectInfoStruct info
Information about the current effect.