PDA

View Full Version : QImage pixel manipulation access time/performance question



Talei
12th November 2010, 06:54
Hello,
I have a small problem with the performance of my pixel manipulation approach.
Currently I use something like this:

QImage img;
int valR = 0, value = 0;
for( int i = 0; i < img.height(); ++i)
{
QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( i ) );

for( int j = 0; j < img.width(); ++j)
{
valR = qRed(scL[j]) + value;

scL[j] = qRgb( valR, valG, valB );
}
}
to access pixel data to manipulate.
I use this code to show "preview" and I can see, while changing slider (connected to the value), that image changes not as fast as i.e. Photoshop (practically real time preview) or Gimp (little slower then PH but much faster then this). (I know that Ph probably use threads to utilize full cpu power, but even with my old cpu with only 1 core speed is much faster).

Basically what I do is:
1. load the data
2. cpy data to QImage tmp
3. manipulate
4. change to QPixmap
5. setPixmap on the QLabel

Test shows me that execution is around 15-30ms for these 5 steps above so in theory I should have a smooth colour change while moving slider. (qDebug of time.elapsed). But that's don't happens (even with signal blocking for slider while this code execute).

The question is what can cause such lag?
Any suggestion are more then welcome.

Best regards
PS. sorry if this is wrong forum to post such a question.

Rembobo
12th November 2010, 09:28
Try "repaint" the QLabel right after setting the pixmap. "update" (imo called internally in "setPixmap" function) is not applied immediately.
QWidget update (http://doc.qt.nokia.com/4.7/qwidget.html#update)
repaint (http://doc.qt.nokia.com/4.7/qwidget.html#repaint)

high_flyer
12th November 2010, 09:34
I use this code to show "preview" and I can see, while changing slider (connected to the value)
It also can be that you are running the slot for each value change which will restart your loop again and again.
Try to build in some logic either time based on mouse release, to only run the preview loop when its more or less certain that the current slider value is the value that needs to be previewed.

Talei
12th November 2010, 17:08
Thanks for reply. I will try to mess around with repaint in widget.

@high_flyer

(even with signal blocking for slider while this code execute).

I already did that, and it's not working.