MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / GetFrame

Method GetFrame

src/effects/Caption.cpp:108–369  ·  view source on GitHub ↗

This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame object

Source from the content-addressed store, hash-verified

106// This method is required for all derived classes of EffectBase, and returns a
107// modified openshot::Frame object
108std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
109{
110 // Process regex (if needed)
111 process_regex();
112
113 // Get the Clip and Timeline pointers (if available)
114 Clip* clip = (Clip*) ParentClip();
115 Timeline* timeline = NULL;
116 Fraction fps;
117 QSize image_size(1, 1);
118
119 if (clip && clip->ParentTimeline() != NULL) {
120 timeline = (Timeline*) clip->ParentTimeline();
121 } else if (this->ParentTimeline() != NULL) {
122 timeline = (Timeline*) this->ParentTimeline();
123 }
124
125 // Get the FPS from the parent object (Timeline or Clip's Reader)
126 if (timeline != NULL) {
127 fps = timeline->info.fps;
128 image_size = QSize(timeline->info.width, timeline->info.height);
129 } else if (clip != NULL && clip->Reader() != NULL) {
130 fps = clip->Reader()->info.fps;
131 image_size = QSize(clip->Reader()->info.width, clip->Reader()->info.height);
132 }
133
134 if (!frame->has_image_data) {
135 // Give audio-only files a full frame image of solid color
136 frame->AddColor(image_size.width(), image_size.height(), "#000000");
137 }
138
139 // Get the frame's image
140 std::shared_ptr<QImage> frame_image = frame->GetImage();
141
142 // Calculate scale factor, to keep different resolutions from
143 // having dramatically different font sizes
144 double timeline_scale_factor = frame_image->width() / 600.0;
145
146 // Load timeline's new frame image into a QPainter
147 QPainter painter(frame_image.get());
148 painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing, true);
149
150 // Composite a new layer onto the image
151 painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
152
153 // Font options and metrics for caption text
154 double font_size_value = font_size.GetValue(frame_number) * timeline_scale_factor;
155 QFont font(QString(font_name.c_str()), int(font_size_value));
156 font.setPixelSize(std::max(font_size_value, 1.0));
157 QFontMetricsF metrics = QFontMetricsF(font);
158
159 // Get current keyframe values
160 double left_value = left.GetValue(frame_number);
161 double top_value = top.GetValue(frame_number);
162 double fade_in_value = fade_in.GetValue(frame_number) * fps.ToDouble();
163 double fade_out_value = fade_out.GetValue(frame_number) * fps.ToDouble();
164 double right_value = right.GetValue(frame_number);
165 double background_corner_value = background_corner.GetValue(frame_number) * timeline_scale_factor;

Callers

nothing calls this directly

Calls 9

AddColorMethod · 0.80
GetImageMethod · 0.80
GetValueMethod · 0.80
ToDoubleMethod · 0.80
ToFloatMethod · 0.80
GetColorHexMethod · 0.80
ParentTimelineMethod · 0.45
ReaderMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected