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
// Grab the table
QVector< QRgb > table;
table = colorTables.find( tableName ).value();
// Change the image now (chartImage is my entire QImage)
QImage tempImage
= chartImage;
// Apply the color table
tempImage.setColorTable( table );
// Convert the changed image to pixmap
tempPix = tempPix.fromImage( tempImage);
// For every tile...
// Update every tile
for( int ii = 0; ii < tiles.size(); ii++ )
{
// Update this tile's pixmap
tiles[ ii ]->setPixmap( tempPix.copy( tiles[ ii ]->getTopLeft().x(),
tiles[ ii ]->getTopLeft().y(), tileSize, tileSize ) );
}
// Grab the table
QVector< QRgb > table;
table = colorTables.find( tableName ).value();
// Change the image now (chartImage is my entire QImage)
QImage tempImage = chartImage;
// Apply the color table
tempImage.setColorTable( table );
// Convert the changed image to pixmap
QPixmap tempPix;
tempPix = tempPix.fromImage( tempImage);
// For every tile...
// Update every tile
for( int ii = 0; ii < tiles.size(); ii++ )
{
// Update this tile's pixmap
tiles[ ii ]->setPixmap( tempPix.copy( tiles[ ii ]->getTopLeft().x(),
tiles[ ii ]->getTopLeft().y(), tileSize, tileSize ) );
}
To copy to clipboard, switch view to plain text mode
This is what setPixmap does (inside the tiles vector)
void ChartTile
::setPixmap( QPixmap pixmap
) {
// Keep a local copy of the QPixmap
image = pixmap;
// Set my QGraphicsPixmapItem* to point to this new QPixmap
// This QGraphicsPixmapItem* is already added to the QGraphicsScene
pixPoint->setPixmap( image );
}
void ChartTile::setPixmap( QPixmap pixmap )
{
// Keep a local copy of the QPixmap
image = pixmap;
// Set my QGraphicsPixmapItem* to point to this new QPixmap
// This QGraphicsPixmapItem* is already added to the QGraphicsScene
pixPoint->setPixmap( image );
}
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.
Bookmarks