39 init_effect_details();
44 saturation(saturation), saturation_R(saturation_R), saturation_G(saturation_G), saturation_B(saturation_B)
47 init_effect_details();
51 void Saturation::init_effect_details()
66 std::shared_ptr<openshot::Frame>
Saturation::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
69 std::shared_ptr<QImage> frame_image = frame->GetImage();
74 int pixel_count = frame_image->width() * frame_image->height();
83 const double pR = .299;
84 const double pG = .587;
85 const double pB = .114;
88 unsigned char *pixels = (
unsigned char *) frame_image->bits();
90 #pragma omp parallel for shared (pixels) 91 for (
int pixel = 0; pixel < pixel_count; ++pixel)
94 int R = pixels[pixel * 4];
95 int G = pixels[pixel * 4 + 1];
96 int B = pixels[pixel * 4 + 2];
103 double p = sqrt( (R * R * pR) +
108 R = p + (R - p) * saturation_value;
109 G = p + (G - p) * saturation_value;
110 B = p + (B - p) * saturation_value;
127 const double p_r = sqrt(R * R * pR);
128 const double p_g = sqrt(G * G * pG);
129 const double p_b = sqrt(B * B * pB);
132 const int Rr = p_r + (R - p_r) * saturation_value_R;
133 const int Gr = p_r + (0 - p_r) * saturation_value_R;
134 const int Br = p_r + (0 - p_r) * saturation_value_R;
136 const int Rg = p_g + (0 - p_g) * saturation_value_G;
137 const int Gg = p_g + (G - p_g) * saturation_value_G;
138 const int Bg = p_g + (0 - p_g) * saturation_value_G;
140 const int Rb = p_b + (0 - p_b) * saturation_value_B;
141 const int Gb = p_b + (0 - p_b) * saturation_value_B;
142 const int Bb = p_b + (B - p_b) * saturation_value_B;
155 pixels[pixel * 4] = R;
156 pixels[pixel * 4 + 1] = G;
157 pixels[pixel * 4 + 2] = B;
196 catch (
const std::exception& e)
199 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
210 if (!root[
"saturation"].isNull())
212 if (!root[
"saturation_R"].isNull())
214 if (!root[
"saturation_G"].isNull())
216 if (!root[
"saturation_B"].isNull())
225 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
226 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
228 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
229 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
230 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
true, requested_frame);
242 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.
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.
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...
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. ...