|
OpenShot Library | libopenshot
0.5.0
|
Go to the documentation of this file.
21 init_effect_details();
28 init_effect_details();
32 void Hue::init_effect_details()
47 std::shared_ptr<openshot::Frame>
Hue::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
50 std::shared_ptr<QImage> frame_image = frame->GetImage();
52 int pixel_count = frame_image->width() * frame_image->height();
55 double degrees = 360.0 *
hue.
GetValue(frame_number);
56 float cosA = cos(degrees*3.14159265f/180);
57 float sinA = sin(degrees*3.14159265f/180);
61 cosA + (1.0f - cosA) / 3.0f,
62 1.0f/3.0f * (1.0f - cosA) - sqrtf(1.0f/3.0f) * sinA,
63 1.0f/3.0f * (1.0f - cosA) + sqrtf(1.0f/3.0f) * sinA
67 unsigned char *pixels = (
unsigned char *) frame_image->bits();
69 #pragma omp parallel for shared (pixels)
70 for (
int pixel = 0; pixel < pixel_count; ++pixel)
73 int A = pixels[pixel * 4 + 3];
74 float alpha_percent = A / 255.0;
77 int R = pixels[pixel * 4 + 0] / alpha_percent;
78 int G = pixels[pixel * 4 + 1] / alpha_percent;
79 int B = pixels[pixel * 4 + 2] / alpha_percent;
82 pixels[pixel * 4] =
constrain(R * matrix[0] + G * matrix[1] + B * matrix[2]);
83 pixels[pixel * 4 + 1] =
constrain(R * matrix[2] + G * matrix[0] + B * matrix[1]);
84 pixels[pixel * 4 + 2] =
constrain(R * matrix[1] + G * matrix[2] + B * matrix[0]);
87 pixels[pixel * 4 + 0] *= alpha_percent;
88 pixels[pixel * 4 + 1] *= alpha_percent;
89 pixels[pixel * 4 + 2] *= alpha_percent;
102 std::shared_ptr<QImage> mask_image, int64_t frame_number)
const {
104 if (!original_image || !effected_image || !mask_image)
106 if (original_image->size() != effected_image->size() || effected_image->size() != mask_image->size())
109 unsigned char* original_pixels =
reinterpret_cast<unsigned char*
>(original_image->bits());
110 unsigned char* effected_pixels =
reinterpret_cast<unsigned char*
>(effected_image->bits());
111 unsigned char* mask_pixels =
reinterpret_cast<unsigned char*
>(mask_image->bits());
112 const int pixel_count = effected_image->width() * effected_image->height();
114 #pragma omp parallel for schedule(static)
115 for (
int i = 0; i < pixel_count; ++i) {
116 const int idx = i * 4;
117 float factor =
static_cast<float>(qGray(mask_pixels[idx], mask_pixels[idx + 1], mask_pixels[idx + 2])) / 255.0f;
119 factor = 1.0f - factor;
120 factor = factor * factor;
121 const float inverse = 1.0f - factor;
123 effected_pixels[idx] =
static_cast<unsigned char>(
124 (original_pixels[idx] * inverse) + (effected_pixels[idx] * factor));
125 effected_pixels[idx + 1] =
static_cast<unsigned char>(
126 (original_pixels[idx + 1] * inverse) + (effected_pixels[idx + 1] * factor));
127 effected_pixels[idx + 2] =
static_cast<unsigned char>(
128 (original_pixels[idx + 2] * inverse) + (effected_pixels[idx + 2] * factor));
129 effected_pixels[idx + 3] = original_pixels[idx + 3];
163 catch (
const std::exception& e)
166 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
177 if (!root[
"hue"].isNull())
179 if (!root[
"mask_mode"].isNull())
196 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.
bool mask_invert
Invert grayscale mask values before blending.
This namespace is the default namespace for all code in the openshot library.
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void ApplyCustomMaskBlend(std::shared_ptr< QImage > original_image, std::shared_ptr< QImage > effected_image, std::shared_ptr< QImage > mask_image, int64_t frame_number) const override
Optional override for effects with custom mask implementation.
Json::Value JsonValue() const
Generate Json::Value for this object.
std::string PropertiesJSON(int64_t requested_frame) const override
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
Keyframe hue
Shift the hue coordinates (left or right)
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
bool UseCustomMaskBlend(int64_t frame_number) const override
Optional override for effects that need custom mask behavior.
int mask_mode
Mask behavior mode for this effect.
Exception for invalid JSON.
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...
std::string Json() const override
Generate JSON string of this object.
bool has_audio
Determines if this effect manipulates the audio of a frame.
Hue()
Default constructor, useful when using Json to load the effect properties.
This class shifts the hue of an image, and can be animated with openshot::Keyframe curves over time.
Header file for Hue effect class.
void SetJson(const std::string value) override
Load JSON string into this object.
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.
int constrain(int color_value)
Constrain a color value from 0 to 255.
std::string name
The name of the effect.
Header file for all Exception classes.
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.