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 R = pixels[pixel * 4];
77 int G = pixels[pixel * 4 + 1];
78 int B = pixels[pixel * 4 + 2];
85 double p = sqrt( (R * R * pR) +
90 R = p + (R - p) * saturation_value;
91 G = p + (G - p) * saturation_value;
92 B = p + (B - p) * saturation_value;
109 const double p_r = sqrt(R * R * pR);
110 const double p_g = sqrt(G * G * pG);
111 const double p_b = sqrt(B * B * pB);
114 const int Rr = p_r + (R - p_r) * saturation_value_R;
115 const int Gr = p_r + (0 - p_r) * saturation_value_R;
116 const int Br = p_r + (0 - p_r) * saturation_value_R;
118 const int Rg = p_g + (0 - p_g) * saturation_value_G;
119 const int Gg = p_g + (G - p_g) * saturation_value_G;
120 const int Bg = p_g + (0 - p_g) * saturation_value_G;
122 const int Rb = p_b + (0 - p_b) * saturation_value_B;
123 const int Gb = p_b + (0 - p_b) * saturation_value_B;
124 const int Bb = p_b + (B - p_b) * saturation_value_B;
137 pixels[pixel * 4] = R;
138 pixels[pixel * 4 + 1] = G;
139 pixels[pixel * 4 + 2] = B;
178 catch (
const std::exception& e)
181 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
192 if (!root[
"saturation"].isNull())
194 if (!root[
"saturation_R"].isNull())
196 if (!root[
"saturation_G"].isNull())
198 if (!root[
"saturation_B"].isNull())
207 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
208 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
210 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
211 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
212 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
true, requested_frame);
224 return root.toStyledString();
std::string Id() const
Get the Id of this clip object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
float Start() const
Get start position (in seconds) of clip (trim start of video)
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
std::string PropertiesJSON(int64_t requested_frame) const override
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
Saturation()
Blank constructor, useful when using Json to load the effect properties.
std::string Json() const override
Generate JSON string of this object.
const Json::Value stringToJson(const std::string value)
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Keyframe saturation_R
Red color saturation.
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for all Exception classes.
Header file for Saturation class.
Keyframe saturation_G
Green color saturation.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
float Duration() const
Get the length of this clip (in seconds)
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.
Json::Value JsonValue() const
Generate Json::Value for this object.
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.
double GetValue(int64_t index) const
Get the value at a specific index.
int constrain(int color_value)
Constrain a color value from 0 to 255.
std::string parent_effect_id
Id of the parent effect (if there is one)
Keyframe saturation_B
Blue color saturation.
float Position() const
Get position on timeline (in seconds)
void SetJson(const std::string value) override
Load JSON string into this object.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
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::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...
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
EffectInfoStruct info
Information about the current effect.
Keyframe saturation
Overall color saturation: 0.0 = greyscale, 1.0 = normal, 2.0 = double saturation. ...