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

Method GetFrame

src/QtImageReader.cpp:151–192  ·  view source on GitHub ↗

Get an openshot::Frame object for a specific frame number of this reader.

Source from the content-addressed store, hash-verified

149
150// Get an openshot::Frame object for a specific frame number of this reader.
151std::shared_ptr<Frame> QtImageReader::GetFrame(int64_t requested_frame)
152{
153 // Check for open reader (or throw exception)
154 if (!is_open)
155 throw ReaderClosed("The Image is closed. Call Open() before calling this method.", path.toStdString());
156
157 // Create a scoped lock, allowing only a single thread to run the following code at one time
158 const std::lock_guard<std::recursive_mutex> lock(getFrameMutex);
159
160 // Calculate max image size
161 QSize current_max_size = calculate_max_size();
162
163 // Scale image smaller (or use a previous scaled image)
164 if (!cached_image || max_size != current_max_size) {
165 // Check for SVG files and rasterize them to QImages
166 if (path.toLower().endsWith(".svg") || path.toLower().endsWith(".svgz")) {
167 load_svg_path(path);
168 }
169
170 // We need to resize the original image to a smaller image (for performance reasons)
171 // Only do this once, to prevent tons of unneeded scaling operations
172 cached_image = std::make_shared<QImage>(image->scaled(
173 current_max_size,
174 Qt::KeepAspectRatio, Qt::SmoothTransformation));
175
176 // Set max size (to later determine if max_size is changed)
177 max_size = current_max_size;
178 }
179
180 auto sample_count = Frame::GetSamplesPerFrame(
181 requested_frame, info.fps, info.sample_rate, info.channels);
182 auto sz = cached_image->size();
183
184 // Create frame object
185 auto image_frame = std::make_shared<Frame>(
186 requested_frame, sz.width(), sz.height(), "#000000",
187 sample_count, info.channels);
188 image_frame->AddImage(cached_image);
189
190 // return frame object
191 return image_frame;
192}
193
194// Calculate the max_size QSize, based on parent timeline and parent clip settings
195QSize QtImageReader::calculate_max_size() {

Callers

nothing calls this directly

Calls 2

ReaderClosedClass · 0.85
AddImageMethod · 0.80

Tested by

no test coverage detected