OpenShot Library | libopenshot  0.2.5
EffectBase.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for EffectBase 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 #ifndef OPENSHOT_EFFECT_BASE_H
32 #define OPENSHOT_EFFECT_BASE_H
33 
34 #include <iostream>
35 #include <iomanip>
36 #include <memory>
37 #include "ClipBase.h"
38 #include "Json.h"
39 #include "Frame.h"
40 
41 namespace openshot
42 {
43  /**
44  * @brief This struct contains info about an effect, such as the name, video or audio effect, etc...
45  *
46  * Each derived class of EffectBase is responsible for updating this struct to reflect accurate information
47  * about the underlying effect. Derived classes of EffectBase should call the InitEffectInfo() method to initialize the
48  * default values of this struct.
49  */
51  {
52  std::string class_name; ///< The class name of the effect
53  std::string name; ///< The name of the effect
54  std::string description; ///< The description of this effect and what it does
55  bool has_video; ///< Determines if this effect manipulates the image of a frame
56  bool has_audio; ///< Determines if this effect manipulates the audio of a frame
57  };
58 
59  /**
60  * @brief This abstract class is the base class, used by all effects in libopenshot.
61  *
62  * Effects are types of classes that manipulate the image or audio data of an openshot::Frame object.
63  * The only requirements for an 'effect', is to derive from this base class, implement the Apply()
64  * method, and call the InitEffectInfo() method.
65  */
66  class EffectBase : public ClipBase
67  {
68  private:
69  int order; ///< The order to evaluate this effect. Effects are processed in this order (when more than one overlap).
70  public:
71 
72  /// Information about the current effect
74 
75  /// Display effect information in the standard output stream (stdout)
76  void DisplayInfo();
77 
78  /// Constrain a color value from 0 to 255
79  int constrain(int color_value);
80 
81  /// @brief This method is required for all derived classes of EffectBase, and returns a
82  /// modified openshot::Frame object
83  ///
84  /// The frame object is passed into this method, and a frame_number is passed in which
85  /// tells the effect which settings to use from its keyframes (starting at 1).
86  ///
87  /// @returns The modified openshot::Frame object
88  /// @param frame The frame object that needs the effect applied to it
89  /// @param frame_number The frame number (starting at 1) of the effect on the timeline.
90  virtual std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) = 0;
91 
92  /// Initialize the values of the EffectInfo struct. It is important for derived classes to call
93  /// this method, or the EffectInfo struct values will not be initialized.
94  void InitEffectInfo();
95 
96  /// Get and Set JSON methods
97  virtual std::string Json() const = 0; ///< Generate JSON string of this object
98  virtual void SetJson(const std::string value) = 0; ///< Load JSON string into this object
99  virtual Json::Value JsonValue() const = 0; ///< Generate Json::Value for this object
100  virtual void SetJsonValue(const Json::Value root) = 0; ///< Load Json::Value into this object
101  Json::Value JsonInfo() const; ///< Generate JSON object of meta data / info
102 
103  /// Get the order that this effect should be executed.
104  int Order() const { return order; }
105 
106  /// Set the order that this effect should be executed.
107  void Order(int new_order) { order = new_order; }
108  virtual ~EffectBase() = default;
109  };
110 
111 }
112 
113 #endif
Header file for ClipBase class.
Header file for Frame class.
Header file for JSON class.
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:49
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:67
void DisplayInfo()
Display effect information in the standard output stream (stdout)
Definition: EffectBase.cpp:52
virtual std::string Json() const =0
Get and Set JSON methods.
Definition: EffectBase.cpp:77
Json::Value JsonInfo() const
Generate JSON object of meta data / info.
Definition: EffectBase.cpp:128
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition: EffectBase.cpp:117
virtual ~EffectBase()=default
int constrain(int color_value)
Constrain a color value from 0 to 255.
Definition: EffectBase.cpp:65
virtual void SetJson(const std::string value)=0
Load JSON string into this object.
Definition: EffectBase.cpp:100
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Definition: EffectBase.cpp:84
virtual std::shared_ptr< openshot::Frame > GetFrame(std::shared_ptr< openshot::Frame > frame, int64_t frame_number)=0
This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame...
int Order() const
Get the order that this effect should be executed.
Definition: EffectBase.h:104
void Order(int new_order)
Set the order that this effect should be executed.
Definition: EffectBase.h:107
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:73
This namespace is the default namespace for all code in the openshot library.
This struct contains info about an effect, such as the name, video or audio effect,...
Definition: EffectBase.h:51
bool has_video
Determines if this effect manipulates the image of a frame.
Definition: EffectBase.h:55
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition: EffectBase.h:56
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
std::string description
The description of this effect and what it does.
Definition: EffectBase.h:54