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 = BasePropertiesJSON(requested_frame);
91 
92  // Return formatted string
93  return root.toStyledString();
94 }
openshot::stringToJson
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:16
openshot::Negate::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: Negate.cpp:51
openshot::EffectBase::info
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:69
Negate.h
Header file for Negate class.
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::EffectBase::JsonValue
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: EffectBase.cpp:79
openshot::Negate::Json
std::string Json() const override
Generate JSON string of this object.
Definition: Negate.cpp:44
openshot::EffectBase::BasePropertiesJSON
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
Definition: EffectBase.cpp:179
openshot::InvalidJSON
Exception for invalid JSON.
Definition: Exceptions.h:217
openshot::Negate::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: Negate.cpp:62
openshot::EffectBase::InitEffectInfo
void InitEffectInfo()
Definition: EffectBase.cpp:24
openshot::EffectInfoStruct::has_audio
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition: EffectBase.h:41
openshot::Negate::Negate
Negate()
Default constructor.
Definition: Negate.cpp:19
openshot::EffectInfoStruct::class_name
std::string class_name
The class name of the effect.
Definition: EffectBase.h:36
openshot::EffectInfoStruct::description
std::string description
The description of this effect and what it does.
Definition: EffectBase.h:38
openshot::Negate::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: Negate.cpp:79
openshot::EffectInfoStruct::has_video
bool has_video
Determines if this effect manipulates the image of a frame.
Definition: EffectBase.h:40
openshot::EffectInfoStruct::name
std::string name
The name of the effect.
Definition: EffectBase.h:37
openshot::Negate::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: Negate.cpp:87
Exceptions.h
Header file for all Exception classes.
openshot::EffectBase::SetJsonValue
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: EffectBase.cpp:115
openshot::Negate::GetFrame
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