21double clamp_margin(
double value) {
33 init_effect_details();
41 init_effect_details();
45void Bars::init_effect_details()
60std::shared_ptr<openshot::Frame>
Bars::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
63 std::shared_ptr<QImage> frame_image = frame->GetImage();
64 const int width = frame_image->width();
65 const int height = frame_image->height();
66 if (width <= 0 || height <= 0)
70 auto tempColor = std::make_shared<QImage>(
71 width, 1, QImage::Format_RGBA8888_Premultiplied);
72 tempColor->fill(QColor(QString::fromStdString(
color.GetColorHex(frame_number))));
75 double left_value =
left.GetValue(frame_number);
76 double top_value =
top.GetValue(frame_number);
77 double right_value =
right.GetValue(frame_number);
78 double bottom_value =
bottom.GetValue(frame_number);
81 unsigned char *pixels = (
unsigned char *) frame_image->bits();
82 unsigned char *color_pixels = (
unsigned char *) tempColor->bits();
85 int top_bar_height = clamp_margin(top_value) * height;
86 int bottom_bar_height = clamp_margin(bottom_value) * height;
87 int left_bar_width = clamp_margin(left_value) * width;
88 int right_bar_width = clamp_margin(right_value) * width;
91 for (
int row = 0; row < height; row++) {
94 if ((top_bar_height > 0.0 && row <= top_bar_height) || (bottom_bar_height > 0.0 && row >= height - bottom_bar_height)) {
95 memcpy(&pixels[row * width * 4], color_pixels,
sizeof(
char) * width * 4);
98 if (left_bar_width > 0.0) {
99 memcpy(&pixels[row * width * 4], color_pixels,
sizeof(
char) * left_bar_width * 4);
103 if (right_bar_width > 0.0) {
104 memcpy(&pixels[((row * width) + (width - right_bar_width)) * 4], color_pixels,
sizeof(
char) * right_bar_width * 4);
128 root[
"type"] =
info.class_name;
129 root[
"color"] =
color.JsonValue();
130 root[
"left"] =
left.JsonValue();
131 root[
"top"] =
top.JsonValue();
132 root[
"right"] =
right.JsonValue();
133 root[
"bottom"] =
bottom.JsonValue();
149 catch (
const std::exception& e)
152 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
163 if (!root[
"color"].isNull())
164 color.SetJsonValue(root[
"color"]);
165 if (!root[
"left"].isNull())
166 left.SetJsonValue(root[
"left"]);
167 if (!root[
"top"].isNull())
168 top.SetJsonValue(root[
"top"]);
169 if (!root[
"right"].isNull())
170 right.SetJsonValue(root[
"right"]);
171 if (!root[
"bottom"].isNull())
172 bottom.SetJsonValue(root[
"bottom"]);
182 root[
"color"] =
add_property_json(
"Bar Color", 0.0,
"color",
"", &
color.red, 0, 255,
false, requested_frame);
183 root[
"color"][
"red"] =
add_property_json(
"Red",
color.red.GetValue(requested_frame),
"float",
"", &
color.red, 0, 255,
false, requested_frame);
184 root[
"color"][
"blue"] =
add_property_json(
"Blue",
color.blue.GetValue(requested_frame),
"float",
"", &
color.blue, 0, 255,
false, requested_frame);
185 root[
"color"][
"green"] =
add_property_json(
"Green",
color.green.GetValue(requested_frame),
"float",
"", &
color.green, 0, 255,
false, requested_frame);
186 root[
"left"] =
add_property_json(
"Margin: Left",
left.GetValue(requested_frame),
"float",
"", &
left, 0.0, 0.5,
false, requested_frame);
187 root[
"top"] =
add_property_json(
"Margin: Top",
top.GetValue(requested_frame),
"float",
"", &
top, 0.0, 0.5,
false, requested_frame);
188 root[
"right"] =
add_property_json(
"Margin: Right",
right.GetValue(requested_frame),
"float",
"", &
right, 0.0, 0.5,
false, requested_frame);
189 root[
"bottom"] =
add_property_json(
"Margin: Bottom",
bottom.GetValue(requested_frame),
"float",
"", &
bottom, 0.0, 0.5,
false, requested_frame);
192 return root.toStyledString();
Header file for Bars effect class.
Header file for all Exception classes.
std::string PropertiesJSON(int64_t requested_frame) const override
Keyframe right
Size of right bar.
Keyframe top
Size of top bar.
std::string Json() const override
Generate JSON string of this object.
void SetJson(const std::string value) override
Load JSON string into this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Bars()
Blank constructor, useful when using Json to load the effect properties.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Keyframe bottom
Size of bottom bar.
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 left
Size of left bar.
Color color
Color of bars.
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).
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.
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.