|
OpenShot Library | libopenshot
0.5.0
|
Go to the documentation of this file.
28 init_effect_details();
33 pixelization(pixelization), left(left), top(top), right(right), bottom(bottom),
37 init_effect_details();
41 void Pixelate::init_effect_details()
49 info.
description =
"Pixelate (increase or decrease) the number of visible pixels.";
56 std::shared_ptr<openshot::Frame>
60 std::shared_ptr<QImage> frame_image = frame->GetImage();
63 double pixelization_value = std::min(pow(0.001, fabs(
pixelization.
GetValue(frame_number))), 1.0);
69 if (pixelization_value > 0.0) {
70 int w = frame_image->width();
71 int h = frame_image->height();
74 QRect area(QPoint(0,0), frame_image->size());
75 area = area.marginsRemoved({int(left_value * w), int(top_value * h), int(right_value * w), int(bottom_value * h)});
77 int scale_to = (int) (area.width() * pixelization_value);
82 auto frame_scaled = frame_image->copy(area).scaledToWidth(scale_to, Qt::SmoothTransformation);
85 QPainter painter(frame_image.get());
86 painter.drawImage(area, frame_scaled);
100 std::shared_ptr<QImage> mask_image, int64_t frame_number)
const {
102 if (!original_image || !effected_image || !mask_image)
104 if (original_image->size() != effected_image->size() || effected_image->size() != mask_image->size())
107 unsigned char* original_pixels =
reinterpret_cast<unsigned char*
>(original_image->bits());
108 unsigned char* effected_pixels =
reinterpret_cast<unsigned char*
>(effected_image->bits());
109 unsigned char* mask_pixels =
reinterpret_cast<unsigned char*
>(mask_image->bits());
110 const int pixel_count = effected_image->width() * effected_image->height();
112 #pragma omp parallel for schedule(static)
113 for (
int i = 0; i < pixel_count; ++i) {
114 const int idx = i * 4;
115 float factor =
static_cast<float>(qGray(mask_pixels[idx], mask_pixels[idx + 1], mask_pixels[idx + 2])) / 255.0f;
117 factor = 1.0f - factor;
118 factor = factor * factor;
119 const float inverse = 1.0f - factor;
121 effected_pixels[idx] =
static_cast<unsigned char>(
122 (original_pixels[idx] * inverse) + (effected_pixels[idx] * factor));
123 effected_pixels[idx + 1] =
static_cast<unsigned char>(
124 (original_pixels[idx + 1] * inverse) + (effected_pixels[idx + 1] * factor));
125 effected_pixels[idx + 2] =
static_cast<unsigned char>(
126 (original_pixels[idx + 2] * inverse) + (effected_pixels[idx + 2] * factor));
127 effected_pixels[idx + 3] = original_pixels[idx + 3];
165 catch (
const std::exception& e)
168 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
179 if (!root[
"pixelization"].isNull())
181 if (!root[
"left"].isNull())
183 if (!root[
"top"].isNull())
185 if (!root[
"right"].isNull())
187 if (!root[
"bottom"].isNull())
189 if (!root[
"mask_mode"].isNull())
210 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.
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...
const Json::Value stringToJson(const std::string value)
EffectInfoStruct info
Information about the current effect.
std::string PropertiesJSON(int64_t requested_frame) const override
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.
Keyframe pixelization
Amount of pixelization.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
@ PIXELATE_MASK_LIMIT_TO_AREA
bool UseCustomMaskBlend(int64_t frame_number) const override
Optional override for effects that need custom mask behavior.
std::string Json() const override
Generate JSON string of 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)
Keyframe bottom
Size of bottom margin.
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.
Keyframe right
Size of right margin.
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.
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.
Keyframe left
Size of left margin.
Pixelate()
Default constructor, useful when using Json to load the effect properties.
std::string name
The name of the effect.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Header file for Pixelate effect class.
Header file for JSON class.
Keyframe top
Size of top margin.
@ PIXELATE_MASK_VARY_STRENGTH
Header file for all Exception classes.
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void SetJson(const std::string value) override
Load JSON string into this object.
double GetValue(int64_t index) const
Get the value at a specific index.
int mask_mode
Mask behavior mode for this effect.