OpenShot Library | libopenshot 0.3.3
Loading...
Searching...
No Matches
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
16using 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
34std::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
44std::string Negate::Json() const {
45
46 // Return formatted string
47 return JsonValue().toStyledString();
48}
49
50// Generate Json::Value for this object
51Json::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
62void 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
79void Negate::SetJsonValue(const Json::Value root) {
80
81 // Set parent data
83
84}
85
86// Get all properties for a specific frame
87std::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}
Header file for all Exception classes.
Header file for Negate class.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
EffectInfoStruct info
Information about the current effect.
Definition EffectBase.h:69
Exception for invalid JSON.
Definition Exceptions.h:218
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
void SetJson(const std::string value) override
Load JSON string into this object.
Definition Negate.cpp:62
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition Negate.cpp:51
Negate()
Default constructor.
Definition Negate.cpp:19
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition Negate.cpp:79
std::string Json() const override
Generate JSON string of this object.
Definition Negate.cpp:44
std::string PropertiesJSON(int64_t requested_frame) const override
Definition Negate.cpp:87
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
const Json::Value stringToJson(const std::string value)
Definition Json.cpp:16
bool has_video
Determines if this effect manipulates the image of a frame.
Definition EffectBase.h:40
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition EffectBase.h:41
std::string class_name
The class name of the effect.
Definition EffectBase.h:36
std::string name
The name of the effect.
Definition EffectBase.h:37
std::string description
The description of this effect and what it does.
Definition EffectBase.h:38