28 #include "../../include/effects/Mask.h" 35 init_effect_details();
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 unsigned char *pixels = (
unsigned char *) frame_image->bits();
96 unsigned char *mask_pixels = (
unsigned char *) original_mask->bits();
108 for (
int pixel = 0, byte_index=0; pixel < original_mask->width() * original_mask->height(); pixel++, byte_index+=4)
111 R = mask_pixels[byte_index];
112 G = mask_pixels[byte_index + 1];
113 B = mask_pixels[byte_index + 2];
116 gray_value = qGray(R, G, B);
119 factor = (259 * (contrast_value + 255)) / (255 * (259 - contrast_value));
120 gray_value =
constrain((factor * (gray_value - 128)) + 128);
123 gray_value += (255 * brightness_value);
131 pixels[byte_index + 0] = gray_value;
132 pixels[byte_index + 1] = gray_value;
133 pixels[byte_index + 2] = gray_value;
136 A = pixels[byte_index + 3];
137 pixels[byte_index + 3] =
constrain(A - gray_value);
164 root[
"reader"] = Json::objectValue;
177 bool success = reader.parse( value, root );
180 throw InvalidJSON(
"JSON could not be parsed (or is invalid)",
"");
190 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)",
"");
201 if (!root[
"replace_image"].isNull())
203 if (!root[
"brightness"].isNull())
205 if (!root[
"contrast"].isNull())
207 if (!root[
"reader"].isNull())
210 if (!root[
"reader"][
"type"].isNull())
222 string type = root[
"reader"][
"type"].asString();
224 if (type ==
"FFmpegReader") {
227 reader =
new FFmpegReader(root[
"reader"][
"path"].asString());
230 #ifdef USE_IMAGEMAGICK 231 }
else if (type ==
"ImageReader") {
234 reader =
new ImageReader(root[
"reader"][
"path"].asString());
238 }
else if (type ==
"QtImageReader") {
241 reader =
new QtImageReader(root[
"reader"][
"path"].asString());
244 }
else if (type ==
"ChunkReader") {
247 reader =
new ChunkReader(root[
"reader"][
"path"].asString(), (
ChunkVersion) root[
"reader"][
"chunk_version"].asInt());
262 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
263 root[
"position"] =
add_property_json(
"Position",
Position(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
265 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
266 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
false, requested_frame);
267 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 30 * 60 * 60 * 48,
true, requested_frame);
279 return root.toStyledString();
This class reads a special chunk-formatted file, which can be easily shared in a distributed environm...
Json::Value JsonValue()
Generate Json::JsonValue for this object.
bool replace_image
Replace the frame image with a grayscale image representing the mask. Great for debugging a mask...
Json::Value JsonValue()
Generate Json::JsonValue for this object.
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...
float End()
Get end position (in seconds) of clip (trim end of video)
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.
virtual void Close()=0
Close the reader (and any resources it was consuming)
This abstract class is the base class, used by all readers in libopenshot.
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
string class_name
The class name of the effect.
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
bool has_audio
Determines if this effect manipulates the audio of a frame.
This class uses the ImageMagick++ libraries, to open image files, and return openshot::Frame objects ...
virtual std::shared_ptr< Frame > GetFrame(int64_t number)=0
This class uses the FFmpeg libraries, to open video files and audio files, and return openshot::Frame...
Keyframe contrast
Contrast keyframe to control the hardness of the wipe effect / mask.
Json::Value add_property_choice_json(string name, int value, int selected_value)
Generate JSON choice for a property (dropdown properties)
string Id()
Get basic properties.
float Position()
Get position on timeline (in seconds)
string Json()
Get and Set JSON methods.
string name
The name of the effect.
string description
The description of this effect and what it does.
bool has_single_image
Determines if this file only contains a single image.
string PropertiesJSON(int64_t requested_frame)
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
ChunkVersion
This enumeration allows the user to choose which version of the chunk they would like (low...
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
Mask()
Blank constructor, useful when using Json to load the effect properties.
ReaderInfo info
Information about the current media file.
double GetValue(int64_t index)
Get the value at a specific index.
This namespace is the default namespace for all code in the openshot library.
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...
bool has_video
Determines if this effect manipulates the image of a frame.
Exception for invalid JSON.
void SetJson(string value)
Load JSON string into this object.
int constrain(int color_value)
Constrain a color value from 0 to 255.
This class uses the Qt library, to open image files, and return openshot::Frame objects containing th...
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
float Duration()
Get the length of this clip (in seconds)
float Start()
Get start position (in seconds) of clip (trim start of video)
virtual void Open()=0
Open the reader (and start consuming resources, such as images or video files)
EffectInfoStruct info
Information about the current effect.
virtual bool IsOpen()=0
Determine if reader is open or closed.