OpenShot Library | libopenshot  0.2.4
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() {
62 
63  // Return formatted string
64  return JsonValue().toStyledString();
65 }
66 
67 // Generate Json::JsonValue for this object
68 Json::Value Negate::JsonValue() {
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(std::string value) {
80 
81  // Parse JSON string into JSON objects
82  Json::Value root;
83  Json::CharReaderBuilder rbuilder;
84  Json::CharReader* reader(rbuilder.newCharReader());
85 
86  std::string errors;
87  bool success = reader->parse( value.c_str(),
88  value.c_str() + value.size(), &root, &errors );
89  delete reader;
90 
91  if (!success)
92  // Raise exception
93  throw InvalidJSON("JSON could not be parsed (or is invalid)");
94 
95  try
96  {
97  // Set all values that match
98  SetJsonValue(root);
99  }
100  catch (const std::exception& e)
101  {
102  // Error parsing JSON (or missing keys)
103  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
104  }
105 }
106 
107 // Load Json::JsonValue into this object
108 void Negate::SetJsonValue(Json::Value root) {
109 
110  // Set parent data
112 
113 }
114 
115 // Get all properties for a specific frame
116 std::string Negate::PropertiesJSON(int64_t requested_frame) {
117 
118  // Generate JSON properties list
119  Json::Value root;
120  root["id"] = add_property_json("ID", 0.0, "string", Id(), NULL, -1, -1, true, requested_frame);
121  root["position"] = add_property_json("Position", Position(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
122  root["layer"] = add_property_json("Track", Layer(), "int", "", NULL, 0, 20, false, requested_frame);
123  root["start"] = add_property_json("Start", Start(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
124  root["end"] = add_property_json("End", End(), "float", "", NULL, 0, 30 * 60 * 60 * 48, false, requested_frame);
125  root["duration"] = add_property_json("Duration", Duration(), "float", "", NULL, 0, 30 * 60 * 60 * 48, true, requested_frame);
126 
127  // Return formatted string
128  return root.toStyledString();
129 }
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
Definition: Negate.cpp:108
std::string Json()
Get and Set JSON methods.
Definition: Negate.cpp:61
float End()
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:80
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:78
void SetJson(std::string value)
Load JSON string into this object.
Definition: Negate.cpp:79
Json::Value JsonValue()
Generate Json::JsonValue for this object.
Definition: Negate.cpp:68
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
Definition: EffectBase.cpp:84
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition: EffectBase.h:56
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
std::string Id()
Get basic properties.
Definition: ClipBase.h:76
float Position()
Get position on timeline (in seconds)
Definition: ClipBase.h:77
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
Definition: EffectBase.cpp:129
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
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame)
Generate JSON for a property.
Definition: ClipBase.cpp:68
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
std::string PropertiesJSON(int64_t requested_frame)
Definition: Negate.cpp:116
float Duration()
Get the length of this clip (in seconds)
Definition: ClipBase.h:81
float Start()
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:79
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:73