37ChromaKey::ChromaKey() : fuzz(5.0) {
42 init_effect_details();
51 init_effect_details();
55void ChromaKey::init_effect_details()
62 info.
name =
"Chroma Key (Greenscreen)";
63 info.
description =
"Replaces the color (or chroma) of the frame with transparency (i.e. keys out the color).";
70std::shared_ptr<openshot::Frame>
ChromaKey::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
73 int threshold = fuzz.
GetInt(frame_number);
74 long mask_R = color.
red.
GetInt(frame_number);
79 std::shared_ptr<QImage> image = frame->GetImage();
80 unsigned char *pixels = (
unsigned char *) image->bits();
83 for (
int pixel = 0, byte_index=0; pixel < image->width() * image->height(); pixel++, byte_index+=4)
87 float A = float(pixels[byte_index + 3]);
88 unsigned char R = (pixels[byte_index] / A) * 255.0;
89 unsigned char G = (pixels[byte_index + 1] / A) * 255.0;
90 unsigned char B = (pixels[byte_index + 2] / A) * 255.0;
95 if (distance <= threshold) {
99 pixels[byte_index] = 0;
100 pixels[byte_index + 1] = 0;
101 pixels[byte_index + 2] = 0;
102 pixels[byte_index + 3] = 0;
140 catch (
const std::exception& e)
143 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
154 if (!root[
"color"].isNull())
156 if (!root[
"fuzz"].isNull())
165 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
166 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
168 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
169 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
170 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
true, requested_frame);
173 root[
"color"] =
add_property_json(
"Key Color", 0.0,
"color",
"", &color.
red, 0, 255,
false, requested_frame);
177 root[
"fuzz"] =
add_property_json(
"Fuzz", fuzz.
GetValue(requested_frame),
"float",
"", &fuzz, 0, 125,
false, requested_frame);
183 return root.toStyledString();
Header file for ChromaKey class.
Header file for all Exception classes.
void SetJson(const std::string value) override
Load JSON string into this object.
ChromaKey()
Blank constructor, useful when using Json to load the effect properties.
std::string Json() const override
Generate JSON string of this object.
std::string PropertiesJSON(int64_t requested_frame) const override
Json::Value JsonValue() const override
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...
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
float End() const
Get end position (in seconds) of clip (trim end of video)
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)
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.
This class represents a color (used on the timeline and clips)
openshot::Keyframe blue
Curve representing the red value (0 - 255)
openshot::Keyframe red
Curve representing the red value (0 - 255)
openshot::Keyframe green
Curve representing the green value (0 - 255)
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
static long GetDistance(long R1, long G1, long B1, long R2, long G2, long B2)
Get the distance between 2 RGB pairs. (0=identical colors, 10=very close colors, 760=very different c...
Json::Value JsonValue() const
Generate Json::Value for this object.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
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.
int GetInt(int64_t index) const
Get the rounded INT value at a specific index.
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.
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.