PDA

View Full Version : Qtimeline and Pixmap Memory Cache



Nfrancisj
5th May 2016, 08:26
I'm creating a small image sequence program. I have a library of image sequences, each image is about 8-20 kilobytes. I'm using an array to store the image sequence, then using Qtimeline to iterate through the index and displaying the image using a Pixmap by Qlable at playback at 24 frames a second.

The issue I'm having is that the playback stutters for the first few loops, then plays fine. How would I go about loading/caching each image in the sequence into memory then having the Qtimeline play, and when I load another set of image sequence, I unload the first set, and cache the second, and so on...

Thanks!

Nik

anda_skoa
5th May 2016, 10:31
If you currently store an array of QImage, try using an array of QPixmap.

That would make the image -> pixmap conversion happen before you start the replay.

Cheers,
_

Nfrancisj
6th May 2016, 03:02
I dont understand what you mean anda. Can you explain a bit more please?

this is how my code is setup:


def setImage():

self.Pixmap = QtGui.QPixmap(DIRECTORY + '/' + self.imageFiles[self.time_slider.value()])
self.viewer.setPixmap(self.Pixmap)



This function is called every time QTimeline changes value.
Line 3: self.time_slider.value() is driven by Qtimeline that runs at 24 fps

This is not the correct way, as it loads a frame as it playing. How would I load the all the images before it starts playing. (assume its 300 images in the sequence)


Is there something like this in Qt:
http://pillow.readthedocs.io/en/3.2.x/reference/ImageSequence.html

Where I can load all the images in a folder into memory, and iterate through them via an index or something similar.

anda_skoa
6th May 2016, 09:24
Ah, I had assumed you at least load the images before you start the playback.

Right, so instead of loading the image when you need to display it, try loading all image in advance and store them in a sequential container.
E.g. in a list or vector or whatever Python uses for that (probably some form of array).

Cheers,
_

Nfrancisj
6th May 2016, 09:50
Can you give my a quick c++ example please? How would I store each image in an array? That's the part I'm blanking on. Hahaha! It's been a loooong work week and my brain can't think.

What do I store in the array? A qImage? or qPixmap maybe? Which Object type should I use store the images?

Thanks!

anda_skoa
6th May 2016, 10:52
Well, in C++ this would look something like this



// assuming "pixmaps" is a member of the class, like "imageFiles" seems to be
// type in C++ would be QVector<QPixmap>

pixmaps.resize(imageFiles.size());
for (int i = 0; i < pixmaps.count(); ++i) {
pixmaps[i] = QPixmap(DIRECTORY + '/' + imageFiles[i]);
}


Cheers,
_

Nfrancisj
6th May 2016, 17:07
Awesome! Thank you very much! I understand that perfectly. :)