OpenShot Library | libopenshot  0.3.2
Negate.cpp
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #include "Negate.h"
14 #include "Exceptions.h"
15 
16 using namespace openshot;
17 
18 // Default constructor
20 {
23 
25  info.class_name = "Negate";
26  info.name = "Negative";
27  info.description = "Negates the colors, producing a negative of the image.";
28  info.has_audio = false;
29  info.has_video = true;
30 }
31 
32 // This method is required for all derived classes of EffectBase, and returns a
33 // modified openshot::Frame object
34 std::shared_ptr<openshot::Frame> Negate::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
35 {
36  // Make a negative of the images pixels
37  frame->GetImage()->invertPixels();
38 
39  // return the modified frame
40  return frame;
41 }
42 
43 // Generate JSON string of this object
44 std::string Negate::Json() const {
45 
46  // Return formatted string
47  return JsonValue().toStyledString();
48 }
49 
50 // Generate Json::Value for this object
51 Json::Value Negate::JsonValue() const {
52 
53  // Create root json object
54  Json::Value root = EffectBase::JsonValue(); // get parent properties
55  root["type"] = info.class_name;
56 
57  // return JsonValue
58  return root;
59 }
60 
61 // Load JSON string into this object
62 void Negate::SetJson(const std::string value) {
63 
64  // Parse JSON string into JSON objects
65  try
66  {
67  const Json::Value root = openshot::stringToJson(value);
68  // Set all values that match
69  SetJsonValue(root);
70  }
71  catch (const std::exception& e)
72  {
73  // Error parsing JSON (or missing keys)
74  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
75  }
76 }
77 
78 // Load Json::Value into this object
79 void Negate::SetJsonValue(const Json::Value root) {
80 
81  // Set parent data
83 
84 }
85 
86 // Get all properties for a specific frame
87 std::string Negate::PropertiesJSON(int64_t requested_frame) const {
88 
89  // Generate JSON properties list
90  Json::Value root;
91  root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
92  root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
93  root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
94  root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
95  root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
96  root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 30 * 60 * 60 * 48, true, requested_frame);
97 
98  // Set the parent effect which properties this effect will inherit
99  root["parent_effect_id"] = add_property_json("Parent", 0.0, "string", info.parent_effect_id, NULL, -1, -1, false, requested_frame);
100 
101  // Return formatted string
102  return root.toStyledString();
103 }
Header file for all Exception classes.
Header file for Negate class.
float Start() const
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:88
float Duration() const
Get the length of this clip (in seconds)
Definition: ClipBase.h:90
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:89
std::string Id() const
Get the Id of this clip object.
Definition: ClipBase.h:85
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:87
float Position() const
Get position on timeline (in seconds)
Definition: ClipBase.h:86
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.
Definition: ClipBase.cpp:96
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: EffectBase.cpp:77
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: EffectBase.cpp:112
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:69
Exception for invalid JSON.
Definition: Exceptions.h:218
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: Negate.cpp:62
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Negate.cpp:51
Negate()
Default constructor.
Definition: Negate.cpp:19
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...
Definition: Negate.h:47
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Negate.cpp:79
std::string Json() const override
Generate JSON string of this object.
Definition: Negate.cpp:44
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Negate.cpp:87
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:29
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:16
bool has_video
Determines if this effect manipulates the image of a frame.
Definition: EffectBase.h:40
std::string parent_effect_id
Id of the parent effect (if there is one)
Definition: EffectBase.h:39
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition: EffectBase.h:41
std::string class_name
The class name of the effect.
Definition: EffectBase.h:36
std::string name
The name of the effect.
Definition: EffectBase.h:37
std::string description
The description of this effect and what it does.
Definition: EffectBase.h:38