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