31 #include "../../include/effects/Saturation.h"
38 init_effect_details();
45 init_effect_details();
49 void Saturation::init_effect_details()
67 std::shared_ptr<QImage> frame_image = frame->GetImage();
72 int pixel_count = frame_image->width() * frame_image->height();
78 const double pR = .299;
79 const double pG = .587;
80 const double pB = .114;
83 unsigned char *pixels = (
unsigned char *) frame_image->bits();
85 #pragma omp parallel for shared (pixels)
86 for (
int pixel = 0; pixel < pixel_count; ++pixel)
89 int R = pixels[pixel * 4];
90 int G = pixels[pixel * 4 + 1];
91 int B = pixels[pixel * 4 + 2];
94 double p = sqrt( (R * R * pR) +
99 pixels[pixel * 4] =
constrain(p + (R - p) * saturation_value);
100 pixels[pixel * 4 + 1] =
constrain(p + (G - p) * saturation_value);
101 pixels[pixel * 4 + 2] =
constrain(p + (B - p) * saturation_value);
137 catch (
const std::exception& e)
140 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
151 if (!root[
"saturation"].isNull())
160 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
161 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
163 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
164 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
165 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
true, requested_frame);
171 return root.toStyledString();
Json::Value JsonValue() const override
Generate Json::Value for this object.
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.
std::string PropertiesJSON(int64_t requested_frame) const override
Saturation()
Blank constructor, useful when using Json to load the effect properties.
std::string Json() const override
Get and Set JSON methods.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Json::Value JsonValue() const
Generate Json::Value for this object.
const Json::Value stringToJson(const std::string value)
void SetJson(const std::string value)
Load JSON string into this object.
float Position() const
Get position on timeline (in seconds)
bool has_audio
Determines if this effect manipulates the audio of a frame.
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
double GetValue(int64_t index) const
Get the value at a specific index.
std::string Id() const
Get basic properties.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
This namespace is the default namespace for all code in the openshot library.
std::string description
The description of this effect and what it does.
bool has_video
Determines if this effect manipulates the image of a frame.
Exception for invalid JSON.
float Duration() const
Get the length of this clip (in seconds)
int constrain(int color_value)
Constrain a color value from 0 to 255.
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...
float End() const
Get end position (in seconds) of clip (trim end of video)
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
float Start() const
Get start position (in seconds) of clip (trim start of video)
EffectInfoStruct info
Information about the current effect.
Keyframe saturation
The color saturation: 0.0 = black and white, 1.0 = normal, 2.0 = double saturation.