22 init_effect_details();
27 width(width), color(color)
30 init_effect_details();
34void Outline::init_effect_details()
49std::shared_ptr<openshot::Frame>
Outline::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
57 if (widthValue <= 0.0 || alphaValue <= 0) {
63 std::shared_ptr<QImage> frame_image = frame->GetImage();
65 float sigmaValue = widthValue / 3.0;
66 if (sigmaValue <= 0.0)
68 cv::Mat cv_image = QImageToBGRACvMat(frame_image);
71 std::vector<cv::Mat> channels(4);
72 cv::split(cv_image, channels);
73 cv::Mat alpha_mask = channels[3].clone();
77 cv::GaussianBlur(alpha_mask, outline_mask, cv::Size(0, 0), sigmaValue, sigmaValue, cv::BorderTypes::BORDER_DEFAULT);
78 cv::threshold(outline_mask, outline_mask, 0, 255, cv::ThresholdTypes::THRESH_BINARY);
82 cv::Canny(outline_mask, edge_mask, 250, 255);
85 cv::Mat blurred_edge_mask;
86 cv::GaussianBlur(edge_mask, blurred_edge_mask, cv::Size(0, 0), 0.8, 0.8, cv::BorderTypes::BORDER_DEFAULT);
87 cv::bitwise_or(outline_mask, blurred_edge_mask, outline_mask);
92 cv::Mat solid_color_mat(cv::Size(cv_image.cols, cv_image.rows), CV_8UC4, cv::Scalar(redValue, greenValue, blueValue, alphaValue));
95 solid_color_mat.copyTo(final_image, outline_mask);
96 cv_image.copyTo(final_image, alpha_mask);
98 std::shared_ptr<QImage> new_frame_image = BGRACvMatToQImage(final_image);
101 *frame_image = *new_frame_image;
105cv::Mat Outline::QImageToBGRACvMat(std::shared_ptr<QImage>& qimage) {
106 cv::Mat cv_img(qimage->height(), qimage->width(), CV_8UC4, (uchar*)qimage->constBits(), qimage->bytesPerLine());
110std::shared_ptr<QImage> Outline::BGRACvMatToQImage(cv::Mat img) {
112 cv::cvtColor(img, final_img, cv::COLOR_RGBA2BGRA);
113 QImage qimage(final_img.data, final_img.cols, final_img.rows, final_img.step, QImage::Format_ARGB32);
114 std::shared_ptr<QImage> imgIn = std::make_shared<QImage>(qimage.convertToFormat(QImage::Format_RGBA8888_Premultiplied));
148 catch (
const std::exception& e)
151 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
162 if (!root[
"width"].isNull())
164 if (!root[
"color"].isNull())
183 return root.toStyledString();
Header file for all Exception classes.
Header file for Outline 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.
This class represents a color (used on the timeline and clips)
openshot::Keyframe blue
Curve representing the red value (0 - 255)
openshot::Keyframe red
Curve representing the red value (0 - 255)
openshot::Keyframe green
Curve representing the green value (0 - 255)
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
openshot::Keyframe alpha
Curve representing the alpha value (0 - 255)
Json::Value JsonValue() const
Generate Json::Value for this object.
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.
std::string Json() const override
Generate JSON string of this object.
Color color
Color of the outline.
Keyframe width
Width of the outline.
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.
void SetJson(const std::string value) override
Load JSON string into this object.
Outline()
Blank constructor, useful when using Json to load the effect properties.
Json::Value JsonValue() const override
Generate Json::Value for this object.
std::string PropertiesJSON(int64_t requested_frame) const override
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.