Results 1 to 3 of 3

Thread: Best way to handle huge QImage setColorTable change

  1. #1
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Best way to handle huge QImage setColorTable change

    I'm trying to find the fastest way to convert a bunch of QPixmaps from one color table to another color table. Here is how I'm currently doing it:

    I have a huge QImage (10K pixel by 10K pixel or more) that I break up into tiles.

    The tiles are then converted into QPixmaps and added to the QGraphicsScene.

    I keep a backup of the original QImage.

    When the user decides to change the color table, this is what I do

    Qt Code:
    1. // Grab the table
    2. QVector< QRgb > table;
    3. table = colorTables.find( tableName ).value();
    4.  
    5. // Change the image now (chartImage is my entire QImage)
    6. QImage tempImage = chartImage;
    7.  
    8. // Apply the color table
    9. tempImage.setColorTable( table );
    10.  
    11. // Convert the changed image to pixmap
    12. QPixmap tempPix;
    13. tempPix = tempPix.fromImage( tempImage);
    14.  
    15. // For every tile...
    16. // Update every tile
    17. for( int ii = 0; ii < tiles.size(); ii++ )
    18. {
    19. // Update this tile's pixmap
    20. tiles[ ii ]->setPixmap( tempPix.copy( tiles[ ii ]->getTopLeft().x(),
    21. tiles[ ii ]->getTopLeft().y(), tileSize, tileSize ) );
    22. }
    To copy to clipboard, switch view to plain text mode 

    This is what setPixmap does (inside the tiles vector)

    Qt Code:
    1. void ChartTile::setPixmap( QPixmap pixmap )
    2. {
    3. // Keep a local copy of the QPixmap
    4. image = pixmap;
    5. // Set my QGraphicsPixmapItem* to point to this new QPixmap
    6. // This QGraphicsPixmapItem* is already added to the QGraphicsScene
    7. pixPoint->setPixmap( image );
    8. }
    To copy to clipboard, switch view to plain text mode 

    But as you can imagine... due to the large size of this QImage, this takes anywhere from 16 - 40 seconds to complete.

    How would you guys optimize something like this? I've tried having the QPixmaps in the tiles convert to smaller QImages, change those smaller QImages, then convert back to a QPixmap, but the result is the same. Slow.

    Any input is appreciated. Constructive input, that is.

  2. #2
    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: Best way to handle huge QImage setColorTable change

    Keep your tiles as QImage instances and apply the new colormap to each small image and then convert it to a pixmap (keeping the original image). You can optimize the whole process by using memcpy (or qmemcpy) on QVector::data() to quickly switch the color table contents.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    bruceariggs (24th September 2011)

  4. #3
    Join Date
    Aug 2011
    Posts
    19
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Best way to handle huge QImage setColorTable change

    Thanks, I'll give that a try and get back to you with the results. =)


    Added after 1 17 minutes:


    Awesome!

    Now my image loads and cuts up into tiles a lot faster, but how exactly am I suppose to use the memcpy?

    You're suggesting I memcpy the selected color table into the QImage? I must not have understood what's memcopying into what?
    Last edited by bruceariggs; 24th September 2011 at 23:47.

Similar Threads

  1. Handle QTableWidget's column width change
    By dorians58 in forum Newbie
    Replies: 0
    Last Post: 28th July 2010, 20:24
  2. Deploy the huge QtWebKit4.dll
    By ahmdsd_ostora in forum Qt Programming
    Replies: 30
    Last Post: 26th July 2010, 00:25
  3. How to change the values of the pixels in an Qimage?
    By kid17 in forum Qt Programming
    Replies: 8
    Last Post: 23rd November 2008, 21:52
  4. Huge Text File
    By mcosta in forum Qt Programming
    Replies: 3
    Last Post: 11th January 2008, 20:23

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.