OpenShot Library | libopenshot  0.2.5
Negate.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Source file for Negate class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #include "../../include/effects/Negate.h"
32 
33 using namespace openshot;
34 
35 // Default constructor
37 {
38  /// Initialize the values of the EffectInfo struct.
40 
41  /// Set the effect info
42  info.class_name = "Negate";
43  info.name = "Negative";
44  info.description = "Negates the colors, producing a negative of the image.";
45  info.has_audio = false;
46  info.has_video = true;
47 }
48 
49 // This method is required for all derived classes of EffectBase, and returns a
50 // modified openshot::Frame object
51 std::shared_ptr<Frame> Negate::GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number)
52 {
53  // Make a negative of the images pixels
54  frame->GetImage()->invertPixels();
55 
56  // return the modified frame
57  return frame;
58 }
59 
60 // Generate JSON string of this object
61 std::string Negate::Json() const {
62 
63  // Return formatted string
64  return JsonValue().toStyledString();
65 }
66 
67 // Generate Json::Value for this object
68 Json::Value Negate::JsonValue() const {
69 
70  // Create root json object
71  Json::Value root = EffectBase::JsonValue(); // get parent properties
72  root["type"] = info.class_name;
73 
74  // return JsonValue
75  return root;
76 }
77 
78 // Load JSON string into this object
79 void Negate::SetJson(const std::string value) {
80 
81  // Parse JSON string into JSON objects
82  try
83  {
84  const Json::Value root = openshot::stringToJson(value);
85  // Set all values that match
86  SetJsonValue(root);
87  }
88  catch (const std::exception& e)
89  {
90  // Error parsing JSON (or missing keys)
91  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
92  }
93 }
94 
95 // Load Json::Value into this object
96 void Negate::SetJsonValue(const Json::Value root) {
97 
98  // Set parent data
100 
101 }
102 
103 // Get all properties for a specific frame
104 std::string Negate::PropertiesJSON(int64_t requested_frame) const {
105 
106  // Generate JSON properties list
107  Json::Value root;
108  root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
109  root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
110  root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
111  root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
112  root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
113  root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 30 * 60 * 60 * 48, true, requested_frame);
114 
115  // Return formatted string
116  return root.toStyledString();
117 }
std::string Id() const
Get basic properties.
Definition: ClipBase.h:76
void SetJson(const std::string value)
Load JSON string into this object.
Definition: Negate.cpp:79
float Start() const
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:79
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Negate.cpp:104
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:33
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition: EffectBase.h:56
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition: EffectBase.cpp:117
std::shared_ptr< Frame > GetFrame(std::shared_ptr< Frame > frame, int64_t frame_number)
This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame...
Definition: Negate.cpp:51
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Negate.cpp:68
std::string class_name
The class name of the effect.
Definition: EffectBase.h:52
std::string name
The name of the effect.
Definition: EffectBase.h:53
Negate()
Default constructor.
Definition: Negate.cpp:36
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Definition: EffectBase.cpp:84
float Duration() const
Get the length of this clip (in seconds)
Definition: ClipBase.h:81
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: Negate.cpp:96
This namespace is the default namespace for all code in the openshot library.
std::string description
The description of this effect and what it does.
Definition: EffectBase.h:54
bool has_video
Determines if this effect manipulates the image of a frame.
Definition: EffectBase.h:55
Exception for invalid JSON.
Definition: Exceptions.h:205
float Position() const
Get position on timeline (in seconds)
Definition: ClipBase.h:77
float End() const
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:80
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:68
std::string Json() const override
Get and Set JSON methods.
Definition: Negate.cpp:61
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:78
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:73