19Blur::Blur() : horizontal_radius(6.0), vertical_radius(6.0), sigma(3.0), iterations(3.0) {
21 init_effect_details();
26 horizontal_radius(new_horizontal_radius), vertical_radius(new_vertical_radius),
27 sigma(new_sigma), iterations(new_iterations)
30 init_effect_details();
34void Blur::init_effect_details()
49std::shared_ptr<openshot::Frame>
Blur::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
52 std::shared_ptr<QImage> frame_image = frame->GetImage();
60 int w = frame_image->width();
61 int h = frame_image->height();
64 QImage image_copy = frame_image->copy();
65 std::shared_ptr<QImage> frame_image_2 = std::make_shared<QImage>(image_copy);
68 for (
int iteration = 0; iteration < iteration_value; ++iteration)
71 if (horizontal_radius_value > 0.0) {
73 boxBlurH(frame_image->bits(), frame_image_2->bits(), w, h, horizontal_radius_value);
76 frame_image.swap(frame_image_2);
80 if (vertical_radius_value > 0.0) {
82 boxBlurT(frame_image->bits(), frame_image_2->bits(), w, h, vertical_radius_value);
85 frame_image.swap(frame_image_2);
95void Blur::boxBlurH(
unsigned char *scl,
unsigned char *tcl,
int w,
int h,
int r) {
96 float iarr = 1.0 / (r + r + 1);
98 #pragma omp parallel for shared (scl, tcl)
99 for (
int i = 0; i < h; ++i) {
100 for (
int ch = 0; ch < 4; ++ch) {
101 int ti = i * w, li = ti, ri = ti + r;
102 int fv = scl[ti * 4 + ch], lv = scl[(ti + w - 1) * 4 + ch], val = (r + 1) * fv;
103 for (
int j = 0; j < r; ++j) {
104 val += scl[(ti + j) * 4 + ch];
106 for (
int j = 0; j <= r; ++j) {
107 val += scl[ri++ * 4 + ch] - fv;
108 tcl[ti++ * 4 + ch] = round(val * iarr);
110 for (
int j = r + 1; j < w - r; ++j) {
111 val += scl[ri++ * 4 + ch] - scl[li++ * 4 + ch];
112 tcl[ti++ * 4 + ch] = round(val * iarr);
114 for (
int j = w - r; j < w; ++j) {
115 val += lv - scl[li++ * 4 + ch];
116 tcl[ti++ * 4 + ch] = round(val * iarr);
122void Blur::boxBlurT(
unsigned char *scl,
unsigned char *tcl,
int w,
int h,
int r) {
123 float iarr = 1.0 / (r + r + 1);
125 #pragma omp parallel for shared (scl, tcl)
126 for (
int i = 0; i < w; i++) {
127 for (
int ch = 0; ch < 4; ++ch) {
128 int ti = i, li = ti, ri = ti + r * w;
129 int fv = scl[ti * 4 + ch], lv = scl[(ti + w * (h - 1)) * 4 + ch], val = (r + 1) * fv;
130 for (
int j = 0; j < r; j++) val += scl[(ti + j * w) * 4 + ch];
131 for (
int j = 0; j <= r; j++) {
132 val += scl[ri * 4 + ch] - fv;
133 tcl[ti * 4 + ch] = round(val * iarr);
137 for (
int j = r + 1; j < h - r; j++) {
138 val += scl[ri * 4 + ch] - scl[li * 4 + ch];
139 tcl[ti * 4 + ch] = round(val * iarr);
144 for (
int j = h - r; j < h; j++) {
145 val += lv - scl[li * 4 + ch];
146 tcl[ti * 4 + ch] = round(val * iarr);
186 catch (
const std::exception& e)
189 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
200 if (!root[
"horizontal_radius"].isNull())
202 if (!root[
"vertical_radius"].isNull())
204 if (!root[
"sigma"].isNull())
206 if (!root[
"iterations"].isNull())
215 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
216 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
218 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
219 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
220 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
232 return root.toStyledString();
Header file for Blur effect class.
Header file for all Exception classes.
Keyframe vertical_radius
Vertical blur radius keyframe. The size of the vertical blur operation in pixels.
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...
std::string Json() const override
Generate JSON string of this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Blur()
Blank constructor, useful when using Json to load the effect properties.
Keyframe iterations
Iterations keyframe. The # of blur iterations per pixel. 3 iterations = Gaussian.
std::string PropertiesJSON(int64_t requested_frame) const override
void SetJson(const std::string value) override
Load JSON string into this object.
Keyframe sigma
Sigma keyframe. The amount of spread in the blur operation. Should be larger than radius.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Keyframe horizontal_radius
Horizontal blur radius keyframe. The size of the horizontal blur operation in pixels.
float Start() const
Get start position (in seconds) of clip (trim start of video)
float Duration() const
Get the length of this clip (in seconds)
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
std::string Id() const
Get the Id of this clip object.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
float Position() const
Get position on timeline (in seconds)
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.
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.
int GetInt(int64_t index) const
Get the rounded INT value at a specific index.
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.
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.
std::string parent_effect_id
Id of the parent effect (if there is one)
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.