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