Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: QGraphicsPixmapItem performance

  1. #1
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QGraphicsPixmapItem performance

    Hi.

    I'm new to here, and my English may be bad, so, please, don't pay attention to it.

    Here is my problem:

    I've created a QGraphicsPixmapItem with a big (~4500/3600 pix) pixmap. When it's not scaled, the scrolling of the QGraphicsView is very fast. When it's scaled (no matter how much - 1.01 or 2.0 times, etc), scrolling it VERY slow (about 1-2 seconds per each click on the slider).

    No matter how to scale: view->scale() or pixmapItem->scale()

    As far as I understand, Qt should repaint only the visible regions. Which means that if I make a visible region smaller, scrolling will be fasted.

    However, if I make my window very small (eg. 100x100 pix), scrolling is still very slow. Which makes me think that Qt repaints (and scales) not only the visible region.

    My PC is Celeron 2.4, 512 Mb, Qt 4.2.3, Mandriva 2007

    Could you please help me, or point any existing topic on this issue.

    Thanks!

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsPixmapItem performance


  3. #3
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem performance

    Unfortunately, I don't have any of these in my Qt 4.2.3

    As far as I understood, both of them were introduced in Qt 4.3

    Still, Thanks for an advice.

  4. #4
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem performance

    I've installed Qt 4.3 and tried these.

    It makes very slight difference, but not what I expect.

    Do you have any other thoughts?

    Thanks.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsPixmapItem performance

    In my opinion it is the scaling that takes that long. Try different transform modes (Fast and Smooth) and see if it makes a difference.

  6. #6
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem performance

    For sure it's scaling that takes so long.

    I've started from Fast mode, which has already been slow, now I have to use Smooth since it's one of the requirements. Smooth and Fast make not much difference.

    Now I'm trying to make some time measurements in the paint() method of the view.
    It seems like there is some expence on scaling, which depends linearly on the size of the whole image, but not the rect to be redrawn (scaled).

    The bigger the image I load, the slower the scrolling. However, I'd say that scaling a part (rect) of an image "on-the-fly" should depend on the size of the rect, but not the whole image.

    I guess I'll try to handle updates on my own to ensure I update a part of an image, or use my own algorithm to scale, and see if it makes difference...

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsPixmapItem performance

    Maybe this is the way the view paints items.
    What about splitting the bigger image in smaller images, add all of them to the scene so they appear they form a single image(even in an item group, to make them behave as one )?
    This way when you scroll or scale, the view will update only visible items. The other tiles that are out of view won't be scaled/updated.

    Regards

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsPixmapItem performance

    The pixmap will be scaled during every repaint because in reality it is not the pixmap item that is scaled, but the painter and it gets scaled on every repaint. My suggestion is not to use a large pixmap at all or optimize the item, for example by composing it of more (4, 9, 16) smaller pixmaps. This way smaller pixmaps will be scaled and only those that are actually visible in the view.

  9. #9
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem performance

    Good idea! Thanks.

    I'll try this, for sure.

  10. #10
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem performance

    Quote Originally Posted by wysota View Post
    The pixmap will be scaled during every repaint because in reality it is not the pixmap item that is scaled, but the painter and it gets scaled on every repaint.
    Well, using drawPixmap() with target rect being a part of a whole image should make painter draw (and scale) only a part of it...

    Still, splitting a big pixmap is a good idea. I'll try it ob monday, I guess.

  11. #11
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsPixmapItem performance

    Before you try optimizing low level rendering routines, try the following program:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char* argv[])
    4. {
    5. QApplication app(argc, argv);
    6. if(argc<2){
    7. QMessageBox::information(0, "No Arguments provided", "Usage: bigimage <imagefile> [scaleToX scaleToY]");
    8. return 0;
    9. }
    10. QPixmap pix(argv[1]);
    11. if(argc>3)
    12. pix=pix.scaled(atoi(argv[2]), atoi(argv[3]));
    13.  
    14. scene.addPixmap(pix)->scale(1.1,1.1);
    15. QGraphicsView view(&scene);
    16. view.show();
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    I didn't have any really big images so I scaled a smaller one before adding it to the scene.
    Qt Code:
    1. ./bigimage image.tif 10000 10000
    To copy to clipboard, switch view to plain text mode 
    On windows with Qt 4.3.0 scrolling was smooth as butter with a 10,000 x 10,000 image. Perhaps your problem lies elsewhere?

  12. #12
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsPixmapItem performance

    Before you try optimizing low level rendering routines, try the following program:
    This really depends on the machine performances.
    I am sure that using tiles will move even faster on a fast computer.

    Anyway, he's not gonna optimize nothing. He will just implement a drawing mechanism.

    Regards

  13. #13
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem performance

    I didn't have any really big images so I scaled a smaller one before adding it to the scene.
    That's the point!
    I don't need to prepare a big image before adding it to scene, I need Qt to scale it "on-the-fly" while scrolling.

    Think about an amount of memory required to store an image e.g. 4500x3500 with 32 bit depth scaled e.g. by 3.0 . It's over 550 Mb, which is unexceptable. Not to speak about storing two such pixmaps, required to draw my scene...

    I'm working on splitting pixmap, the results will be soon.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsPixmapItem performance

    It's 540MB to be precise But you have a wrong assumption. Pixmaps are stored in a compressed state so only the part that is actually drawn should be decompressed. But the first thing you could try is to get rid of the alpha channel and use 25b (24b of colour and a single bit transparency mask) or even 24b (no alpha). Of course splitting the image as suggested earlier is the first thing to try. It should really help much.

  15. #15
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem performance

    My precision is 4500*3500*3*3*4 = 567 Mb

    I haven't heard anything about compressed state of pixmaps. Where can I get more info on that?

    By the may, simply using "top" utility gives me a reason to think that pixmaps are not compressed. Of course, I might be wrong.

    I can't use 24 or 25 bit color, since I need semi-transparency.

    It's the first time I hear about 25 bit pixmaps in Qt. Where can I get more info on that?

    Thanks.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsPixmapItem performance

    Quote Originally Posted by cerber View Post
    My precision is 4500*3500*3*3*4 = 567 Mb
    1MB = 1024 * 1024 B so you should divide your result by 1.048 which will give circa 540.7MB.

    I haven't heard anything about compressed state of pixmaps. Where can I get more info on that?
    Google? Or X.org or something similar... Pixmaps are generally images stored on the X server (so they are probably compressed).

    It's the first time I hear about 25 bit pixmaps in Qt. Where can I get more info on that?
    There are no 25bit pixmaps. The bitmap is 24b deep and you additionally apply a 1 bit mask (like using QPixmap::setMask) which gives a total of 25 bits. Of course you can't apply the mask directly.

  17. #17
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsPixmapItem performance

    Quote Originally Posted by cerber View Post
    That's the point!
    I don't need to prepare a big image before adding it to scene, I need Qt to scale it "on-the-fly" while scrolling.

    Think about an amount of memory required to store an image e.g. 4500x3500 with 32 bit depth scaled e.g. by 3.0 . It's over 550 Mb, which is unexceptable. Not to speak about storing two such pixmaps, required to draw my scene...

    I'm working on splitting pixmap, the results will be soon.
    I'm afraid you missed the point. I only provided the means of scaling the pixmap for people like me, who don't happen to have 10,000x10,000 images lying around. I add the pixmap to the scene and then I scale the Item by (1.1, 1.1). For all intents and purposes this is the same as loading a 10,000x10,000 image to begin with. It also doesn't matter if i scale the item, the view or the scene. The example runs perfectly smooth on my low end PC(using about 400MB of RAM, but thats expected since 10 000 * 10 000 * (25 bits) = ~300 MB).
    So, could you try the example with your image and tell us how it works. If
    a) It runs smoothly: You seem to have a problem elsewhere in your code.
    or
    b) Scrolling is as slow as before: The problem would be Qt 4.2.3, where the whole image is scaled, regardless of the viewport.

    I am not saying that splitting the image isn't a good idea. Especially in conjuncture with the QPixmapCache, in case the whole image won't fit to memory. But a 4500x3000 image really isn't that large(~40MB) and should work smoothly even on a very low end PC.

    use the following extended example to test the speed of "live" scaling with the mousewheel.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class GraphicsView : public QGraphicsView
    4. {
    5. public:
    6. GraphicsView(QGraphicsScene* scene=0)
    7. : QGraphicsView(scene)
    8. {
    9. }
    10. virtual void wheelEvent(QWheelEvent* event)
    11. {
    12. if (event->delta()>0)
    13. scale(2.0, 2.0);
    14. else
    15. scale(0.5, 0.5);
    16. }
    17. };
    18.  
    19. int main(int argc, char* argv[])
    20. {
    21. QApplication app(argc, argv);
    22. if(argc<2){
    23. QMessageBox::information(0, "No Arguments provided", "Usage: bigimage <imagefile> [scaleToX scaleToY]");
    24. return 0;
    25. }
    26. QPixmap pix(argv[1]);
    27. if(argc>3)
    28. pix=pix.scaled(atoi(argv[2]), atoi(argv[3]));
    29.  
    30. scene.addPixmap(pix);
    31. GraphicsView view(&scene);
    32. view.show();
    33. return app.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 

    regards
    Last edited by spud; 13th August 2007 at 13:01. Reason: added extended code example

  18. #18
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem performance

    I'm afraid you missed the point. I only provided the means of scaling the pixmap for people like me, who don't happen to have 10,000x10,000 images lying around.
    Sorry, I did miss what you ment.

    However, no matter what example I run, no matter Qt 4.2.3 or Qt 4.3 it is, scrolling the scaled image is as slow as I told before. I guess that Windows may behave very differently, so you don't see my problem.

    There is no problem elsewhere in my code.

    I think that splitting the pixmap will make the difference.

    Thanks for your help.


    To Wysota: Thanks for explanations.

  19. #19
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsPixmapItem performance

    Quote Originally Posted by wysota View Post
    But you have a wrong assumption. Pixmaps are stored in a compressed state so only the part that is actually drawn should be decompressed.
    That doesn't seem to be the case, at least not for all platforms:
    QGrapicsPixmapItem has a member QPixmap pixmap;
    QPixmap has a member QImage image;
    QImage has a member unsigned char data.
    data is an array the size of width x height x depth.

    The following is the memory footprint of a QPixmap on windows:
    Qt Code:
    1. [member] [value] [type]
    2. --------------------------------------------------------------------------
    3. -d 0x00b24108 QGraphicsPixmapItemPrivate * const
    4. pixmap {...} QPixmap
    5. -data 0x00b13430 QPixmapData *
    6. count 2 int
    7. detach_no 0 int
    8. -image {...} QImage
    9. -d 0x00b26e58 QImageData *
    10. +ref {...} QAtomic
    11. width 1300 int
    12. height 1300 int
    13. depth 32 int
    14. nbytes 6760000 int
    15. +colortable {...} QVector<unsigned int>
    16. +data 0x00c20040 unsigned char*
    17. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by spud; 13th August 2007 at 13:59.

  20. #20
    Join Date
    Aug 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsPixmapItem performance

    That doesn't seem to be the case, at least not for all platforms:
    Wysota was talking about X server, which has no meaning for Windows.

Similar Threads

  1. GraphicsView performance problems
    By Gopala Krishna in forum Qt Programming
    Replies: 79
    Last Post: 8th August 2007, 17:32
  2. Rotate QGraphicsPixmapItem
    By durbrak in forum Qt Programming
    Replies: 7
    Last Post: 15th April 2007, 14:51
  3. Replies: 1
    Last Post: 4th October 2006, 16:05
  4. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  5. Increasing performance from Qtextedit, listview, etc?
    By taylor34 in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 10:20

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.