Skip to content

Commit 17a2258

Browse files
authored
Merge pull request #232 from OpenShot/improved-qimage-scale-caching
Improve QtImageReader caching logic (fixes performance of larger static images)
2 parents 7a93cd0 + d23197c commit 17a2258

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

include/QtImageReader.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ namespace openshot
6565
{
6666
private:
6767
string path;
68-
std::shared_ptr<QImage> image; ///> Original image (full quality)
69-
std::shared_ptr<QImage> cached_image; ///> Scaled for performance
70-
bool is_open;
68+
std::shared_ptr<QImage> image; ///> Original image (full quality)
69+
std::shared_ptr<QImage> cached_image; ///> Scaled for performance
70+
bool is_open; ///> Is Reader opened
71+
QSize max_size; ///> Current max_size as calculated with Clip properties
7172

7273
public:
7374

src/QtImageReader.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ void QtImageReader::Open()
130130
info.display_ratio.num = size.num;
131131
info.display_ratio.den = size.den;
132132

133+
// Set current max size
134+
max_size.setWidth(info.width);
135+
max_size.setHeight(info.height);
136+
133137
// Mark as "open"
134138
is_open = true;
135139
}
@@ -209,8 +213,7 @@ std::shared_ptr<Frame> QtImageReader::GetFrame(int64_t requested_frame)
209213
}
210214

211215
// Scale image smaller (or use a previous scaled image)
212-
if (!cached_image || (cached_image && cached_image->width() != max_width || cached_image->height() != max_height)) {
213-
216+
if (!cached_image || (cached_image && max_size.width() != max_width || max_size.height() != max_height)) {
214217
#if USE_RESVG == 1
215218
// If defined and found in CMake, utilize the libresvg for parsing
216219
// SVG files and rasterizing them to QImages.
@@ -239,6 +242,10 @@ std::shared_ptr<Frame> QtImageReader::GetFrame(int64_t requested_frame)
239242
cached_image = std::shared_ptr<QImage>(new QImage(image->scaled(max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
240243
cached_image = std::shared_ptr<QImage>(new QImage(cached_image->convertToFormat(QImage::Format_RGBA8888)));
241244
#endif
245+
246+
// Set max size (to later determine if max_size is changed)
247+
max_size.setWidth(max_width);
248+
max_size.setHeight(max_height);
242249
}
243250

244251
// Create or get frame object

0 commit comments

Comments
 (0)