21 init_effect_details();
29 init_effect_details();
33void Bars::init_effect_details()
48std::shared_ptr<openshot::Frame>
Bars::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
51 std::shared_ptr<QImage> frame_image = frame->GetImage();
54 auto tempColor = std::make_shared<QImage>(
55 frame_image->width(), 1, QImage::Format_RGBA8888_Premultiplied);
56 tempColor->fill(QColor(QString::fromStdString(
color.GetColorHex(frame_number))));
59 double left_value =
left.GetValue(frame_number);
60 double top_value =
top.GetValue(frame_number);
61 double right_value =
right.GetValue(frame_number);
62 double bottom_value =
bottom.GetValue(frame_number);
65 unsigned char *pixels = (
unsigned char *) frame_image->bits();
66 unsigned char *color_pixels = (
unsigned char *) tempColor->bits();
69 int top_bar_height = top_value * frame_image->height();
70 int bottom_bar_height = bottom_value * frame_image->height();
71 int left_bar_width = left_value * frame_image->width();
72 int right_bar_width = right_value * frame_image->width();
75 for (
int row = 0; row < frame_image->height(); row++) {
78 if ((top_bar_height > 0.0 && row <= top_bar_height) || (bottom_bar_height > 0.0 && row >= frame_image->height() - bottom_bar_height)) {
79 memcpy(&pixels[row * frame_image->width() * 4], color_pixels,
sizeof(
char) * frame_image->width() * 4);
82 if (left_bar_width > 0.0) {
83 memcpy(&pixels[row * frame_image->width() * 4], color_pixels,
sizeof(
char) * left_bar_width * 4);
87 if (right_bar_width > 0.0) {
88 memcpy(&pixels[((row * frame_image->width()) + (frame_image->width() - right_bar_width)) * 4], color_pixels,
sizeof(
char) * right_bar_width * 4);
112 root[
"type"] =
info.class_name;
113 root[
"color"] =
color.JsonValue();
114 root[
"left"] =
left.JsonValue();
115 root[
"top"] =
top.JsonValue();
116 root[
"right"] =
right.JsonValue();
117 root[
"bottom"] =
bottom.JsonValue();
133 catch (
const std::exception& e)
136 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
147 if (!root[
"color"].isNull())
148 color.SetJsonValue(root[
"color"]);
149 if (!root[
"left"].isNull())
150 left.SetJsonValue(root[
"left"]);
151 if (!root[
"top"].isNull())
152 top.SetJsonValue(root[
"top"]);
153 if (!root[
"right"].isNull())
154 right.SetJsonValue(root[
"right"]);
155 if (!root[
"bottom"].isNull())
156 bottom.SetJsonValue(root[
"bottom"]);
166 root[
"color"] =
add_property_json(
"Bar Color", 0.0,
"color",
"", &
color.red, 0, 255,
false, requested_frame);
167 root[
"color"][
"red"] =
add_property_json(
"Red",
color.red.GetValue(requested_frame),
"float",
"", &
color.red, 0, 255,
false, requested_frame);
168 root[
"color"][
"blue"] =
add_property_json(
"Blue",
color.blue.GetValue(requested_frame),
"float",
"", &
color.blue, 0, 255,
false, requested_frame);
169 root[
"color"][
"green"] =
add_property_json(
"Green",
color.green.GetValue(requested_frame),
"float",
"", &
color.green, 0, 255,
false, requested_frame);
170 root[
"left"] =
add_property_json(
"Left Size",
left.GetValue(requested_frame),
"float",
"", &
left, 0.0, 0.5,
false, requested_frame);
171 root[
"top"] =
add_property_json(
"Top Size",
top.GetValue(requested_frame),
"float",
"", &
top, 0.0, 0.5,
false, requested_frame);
172 root[
"right"] =
add_property_json(
"Right Size",
right.GetValue(requested_frame),
"float",
"", &
right, 0.0, 0.5,
false, requested_frame);
176 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.