Results 1 to 7 of 7

Thread: Qtimeline and Pixmap Memory Cache

  1. #1
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Qtimeline and Pixmap Memory Cache

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qtimeline and Pixmap Memory Cache

    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,
    _

  3. #3
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qtimeline and Pixmap Memory Cache

    I dont understand what you mean anda. Can you explain a bit more please?

    this is how my code is setup:

    Qt Code:
    1. def setImage():
    2.  
    3. self.Pixmap = QtGui.QPixmap(DIRECTORY + '/' + self.imageFiles[self.time_slider.value()])
    4. self.viewer.setPixmap(self.Pixmap)
    To copy to clipboard, switch view to plain text mode 
    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....eSequence.html

    Where I can load all the images in a folder into memory, and iterate through them via an index or something similar.
    Last edited by Nfrancisj; 6th May 2016 at 06:17.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qtimeline and Pixmap Memory Cache

    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,
    _

  5. #5
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qtimeline and Pixmap Memory Cache

    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!

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qtimeline and Pixmap Memory Cache

    Well, in C++ this would look something like this

    Qt Code:
    1. // assuming "pixmaps" is a member of the class, like "imageFiles" seems to be
    2. // type in C++ would be QVector<QPixmap>
    3.  
    4. pixmaps.resize(imageFiles.size());
    5. for (int i = 0; i < pixmaps.count(); ++i) {
    6. pixmaps[i] = QPixmap(DIRECTORY + '/' + imageFiles[i]);
    7. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  7. #7
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qtimeline and Pixmap Memory Cache

    Awesome! Thank you very much! I understand that perfectly.

Similar Threads

  1. QTimer and QTimeLine
    By martisho in forum Qt Programming
    Replies: 3
    Last Post: 24th November 2009, 14:29
  2. QPixmap: X11 "memory leak" due to shared pixmap data?
    By chezifresh in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2009, 19:53
  3. QTimeLine
    By babu198649 in forum Newbie
    Replies: 6
    Last Post: 31st January 2008, 10:32
  4. QGraphicsItemAnimation and QTimeLine
    By babu198649 in forum Newbie
    Replies: 13
    Last Post: 31st December 2007, 11:34
  5. Pixmap memory consumption
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 29th November 2007, 15:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.