OpenShot Library | libopenshot
0.3.3
|
Go to the documentation of this file.
21 init_effect_details();
26 saturation(saturation), saturation_R(saturation_R), saturation_G(saturation_G), saturation_B(saturation_B)
29 init_effect_details();
33 void Saturation::init_effect_details()
48 std::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())
219 return root.toStyledString();
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.
const Json::Value stringToJson(const std::string value)
EffectInfoStruct info
Information about the current effect.
std::string Json() const override
Generate JSON string of this object.
This namespace is the default namespace for all code in the openshot library.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Keyframe saturation_R
Red color saturation.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
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)
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Exception for invalid JSON.
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 description
The description of this effect and what it does.
bool has_video
Determines if this effect manipulates the image of a frame.
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.
Keyframe saturation_B
Blue color saturation.
int constrain(int color_value)
Constrain a color value from 0 to 255.
Header file for Saturation class.
std::string name
The name of the effect.
std::string PropertiesJSON(int64_t requested_frame) const override
Saturation()
Blank constructor, useful when using Json to load the effect properties.
void SetJson(const std::string value) override
Load JSON string into this object.
Header file for all Exception classes.
Keyframe saturation
Overall color saturation: 0.0 = greyscale, 1.0 = normal, 2.0 = double saturation.
virtual 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.