19Saturation::Saturation() : saturation(1.0), saturation_R(1.0), saturation_G(1.0), saturation_B(1.0) {
21 init_effect_details();
26 saturation(saturation), saturation_R(saturation_R), saturation_G(saturation_G), saturation_B(saturation_B)
29 init_effect_details();
33void Saturation::init_effect_details()
48std::shared_ptr<openshot::Frame>
Saturation::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
51 std::shared_ptr<QImage> frame_image = frame->GetImage();
56 int pixel_count = frame_image->width() * frame_image->height();
65 const double pR = .299;
66 const double pG = .587;
67 const double pB = .114;
70 unsigned char *pixels = (
unsigned char *) frame_image->bits();
72 #pragma omp parallel for shared (pixels)
73 for (
int pixel = 0; pixel < pixel_count; ++pixel)
76 int A = pixels[pixel * 4 + 3];
77 float alpha_percent = A / 255.0;
80 int R = pixels[pixel * 4 + 0] / alpha_percent;
81 int G = pixels[pixel * 4 + 1] / alpha_percent;
82 int B = pixels[pixel * 4 + 2] / alpha_percent;
89 double p = sqrt( (R * R * pR) +
94 R =
constrain(p + (R - p) * saturation_value);
95 G =
constrain(p + (G - p) * saturation_value);
96 B =
constrain(p + (B - p) * saturation_value);
108 const double p_r = sqrt(R * R * pR);
109 const double p_g = sqrt(G * G * pG);
110 const double p_b = sqrt(B * B * pB);
113 const int Rr = p_r + (R - p_r) * saturation_value_R;
114 const int Gr = p_r + (0 - p_r) * saturation_value_R;
115 const int Br = p_r + (0 - p_r) * saturation_value_R;
117 const int Rg = p_g + (0 - p_g) * saturation_value_G;
118 const int Gg = p_g + (G - p_g) * saturation_value_G;
119 const int Bg = p_g + (0 - p_g) * saturation_value_G;
121 const int Rb = p_b + (0 - p_b) * saturation_value_B;
122 const int Gb = p_b + (0 - p_b) * saturation_value_B;
123 const int Bb = p_b + (B - p_b) * saturation_value_B;
136 pixels[pixel * 4 + 0] = R;
137 pixels[pixel * 4 + 1] = G;
138 pixels[pixel * 4 + 2] = B;
141 pixels[pixel * 4 + 0] *= alpha_percent;
142 pixels[pixel * 4 + 1] *= alpha_percent;
143 pixels[pixel * 4 + 2] *= alpha_percent;
182 catch (
const std::exception& e)
185 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
196 if (!root[
"saturation"].isNull())
198 if (!root[
"saturation_R"].isNull())
200 if (!root[
"saturation_G"].isNull())
202 if (!root[
"saturation_B"].isNull())
211 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
212 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
214 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
215 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
216 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
true, requested_frame);
228 return root.toStyledString();
Header file for all Exception classes.
Header file for Saturation class.
float Start() const
Get start position (in seconds) of clip (trim start of video)
float Duration() const
Get the length of this clip (in seconds)
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
std::string Id() const
Get the Id of this clip object.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
float Position() const
Get position on timeline (in seconds)
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.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
int constrain(int color_value)
Constrain a color value from 0 to 255.
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
EffectInfoStruct info
Information about the current effect.
Exception for invalid JSON.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
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.
Json::Value JsonValue() const
Generate Json::Value for this object.
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...
Keyframe saturation_G
Green color saturation.
std::string Json() const override
Generate JSON string of this object.
Keyframe saturation_B
Blue color saturation.
Saturation()
Blank constructor, useful when using Json to load the effect properties.
std::string PropertiesJSON(int64_t requested_frame) const override
Json::Value JsonValue() const override
Generate Json::Value for this object.
Keyframe saturation_R
Red color saturation.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
void SetJson(const std::string value) override
Load JSON string into this object.
Keyframe saturation
Overall color saturation: 0.0 = greyscale, 1.0 = normal, 2.0 = double saturation.
This namespace is the default namespace for all code in the openshot library.
const Json::Value stringToJson(const std::string value)
bool has_video
Determines if this effect manipulates the image of a frame.
std::string parent_effect_id
Id of the parent effect (if there is one)
bool has_audio
Determines if this effect manipulates the audio of a frame.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
std::string description
The description of this effect and what it does.