OpenShot Library | libopenshot
0.2.2
|
Go to the documentation of this file.
28 #include "../../include/effects/Mask.h"
33 Mask::Mask() : reader(NULL), replace_image(false), needs_refresh(true) {
35 init_effect_details();
40 reader(mask_reader),
brightness(mask_brightness),
contrast(mask_contrast), replace_image(false), needs_refresh(true)
43 init_effect_details();
47 void Mask::init_effect_details()
54 info.
name =
"Alpha Mask / Wipe Transition";
55 info.
description =
"Uses a grayscale mask image to gradually wipe / transition between 2 images.";
62 std::shared_ptr<Frame>
Mask::GetFrame(std::shared_ptr<Frame> frame, int64_t frame_number) {
64 std::shared_ptr<QImage> frame_image = frame->GetImage();
67 #pragma omp critical (open_mask_reader)
69 if (reader && !reader->
IsOpen())
78 #pragma omp critical (open_mask_reader)
81 (original_mask && original_mask->size() != frame_image->size())) {
84 std::shared_ptr<QImage> mask_without_sizing = std::shared_ptr<QImage>(
85 new QImage(*reader->
GetFrame(frame_number)->GetImage()));
88 original_mask = std::shared_ptr<QImage>(
new QImage(
89 mask_without_sizing->scaled(frame_image->width(), frame_image->height(), Qt::IgnoreAspectRatio,
90 Qt::SmoothTransformation)));
95 needs_refresh =
false;
98 unsigned char *pixels = (
unsigned char *) frame_image->bits();
99 unsigned char *mask_pixels = (
unsigned char *) original_mask->bits();
111 for (
int pixel = 0, byte_index=0; pixel < original_mask->width() * original_mask->height(); pixel++, byte_index+=4)
114 R = mask_pixels[byte_index];
115 G = mask_pixels[byte_index + 1];
116 B = mask_pixels[byte_index + 2];
119 gray_value = qGray(R, G, B);
122 factor = (259 * (contrast_value + 255)) / (255 * (259 - contrast_value));
123 gray_value =
constrain((factor * (gray_value - 128)) + 128);
126 gray_value += (255 * brightness_value);
134 pixels[byte_index + 0] = gray_value;
135 pixels[byte_index + 1] = gray_value;
136 pixels[byte_index + 2] = gray_value;
139 A = pixels[byte_index + 3];
140 pixels[byte_index + 3] =
constrain(A - gray_value);
167 root[
"reader"] = Json::objectValue;
180 bool success = reader.parse( value, root );
183 throw InvalidJSON(
"JSON could not be parsed (or is invalid)",
"");
193 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)",
"");
204 if (!root[
"replace_image"].isNull())
206 if (!root[
"brightness"].isNull())
208 if (!root[
"contrast"].isNull())
210 if (!root[
"reader"].isNull())
212 #pragma omp critical (open_mask_reader)
215 needs_refresh =
true;
217 if (!root[
"reader"][
"type"].isNull())
228 string type = root[
"reader"][
"type"].asString();
230 if (type ==
"FFmpegReader") {
233 reader =
new FFmpegReader(root[
"reader"][
"path"].asString());
236 #ifdef USE_IMAGEMAGICK
237 }
else if (type ==
"ImageReader") {
240 reader =
new ImageReader(root[
"reader"][
"path"].asString());
244 }
else if (type ==
"QtImageReader") {
247 reader =
new QtImageReader(root[
"reader"][
"path"].asString());
250 }
else if (type ==
"ChunkReader") {
253 reader =
new ChunkReader(root[
"reader"][
"path"].asString(), (
ChunkVersion) root[
"reader"][
"chunk_version"].asInt());
269 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
270 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
272 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
273 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
274 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
true, requested_frame);
286 root[
"reader"] =
add_property_json(
"Source", 0.0,
"reader", reader->
Json(), NULL, 0, 1,
false, requested_frame);
288 root[
"reader"] =
add_property_json(
"Source", 0.0,
"reader",
"{}", NULL, 0, 1,
false, requested_frame);
291 return root.toStyledString();
EffectInfoStruct info
Information about the current effect.
Json::Value add_property_choice_json(string name, int value, int selected_value)
Generate JSON choice for a property (dropdown properties)
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
Json::Value JsonValue()
Generate Json::JsonValue for this object.
This class reads a special chunk-formatted file, which can be easily shared in a distributed environm...
string Json()
Get and Set JSON methods.
void SetJson(string value)
Load JSON string into this object.
This namespace is the default namespace for all code in the openshot library.
float Start()
Get start position (in seconds) of clip (trim start of video)
string class_name
The class name of the effect.
Keyframe contrast
Contrast keyframe to control the hardness of the wipe effect / mask.
string Id()
Get basic properties.
virtual string Json()=0
Get and Set JSON methods.
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
ReaderInfo info
Information about the current media file.
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
Mask()
Blank constructor, useful when using Json to load the effect properties.
Json::Value add_property_json(string name, float value, string type, string memo, Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame)
Generate JSON for a property.
This class uses the Qt library, to open image files, and return openshot::Frame objects containing th...
double GetValue(int64_t index)
Get the value at a specific index.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
virtual void Open()=0
Open the reader (and start consuming resources, such as images or video files)
virtual bool IsOpen()=0
Determine if reader is open or closed.
Exception for invalid JSON.
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
float Duration()
Get the length of this clip (in seconds)
This class uses the ImageMagick++ libraries, to open image files, and return openshot::Frame objects ...
bool has_audio
Determines if this effect manipulates the audio of a frame.
bool has_single_image
Determines if this file only contains a single image.
string description
The description of this effect and what it does.
Json::Value JsonValue()
Generate Json::JsonValue for this object.
This class uses the FFmpeg libraries, to open video files and audio files, and return openshot::Frame...
string name
The name of the effect.
std::shared_ptr< Frame > GetFrame(std::shared_ptr< Frame > frame, int64_t frame_number)
This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame...
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
bool replace_image
Replace the frame image with a grayscale image representing the mask. Great for debugging a mask.
bool has_video
Determines if this effect manipulates the image of a frame.
float End()
Get end position (in seconds) of clip (trim end of video)
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
int constrain(int color_value)
Constrain a color value from 0 to 255.
This abstract class is the base class, used by all readers in libopenshot.
virtual std::shared_ptr< Frame > GetFrame(int64_t number)=0
virtual void Close()=0
Close the reader (and any resources it was consuming)
string PropertiesJSON(int64_t requested_frame)
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
Keyframe brightness
Brightness keyframe to control the wipe / mask effect. A constant value here will prevent animation.
ChunkVersion
This enumeration allows the user to choose which version of the chunk they would like (low,...
float Position()
Get position on timeline (in seconds)