[Qt-interest] QImage fade
Bob Seitsinger
bob.seitsinger at yahoo.com
Sat May 7 05:28:01 CEST 2011
Hi Josh,
To start, take the "*fadeval/fadeMax" and "(fadeMax-fadeval)/fadeMax" out of the
for-loop. No need to recalc those values every loop.
Also, although I haven't thought it through, I'm thinking you could probably do
what you want via bit masking, which, I believe, would be a lot faster than
multiplication.
Bob
________________________________
From: Joshua Grauman <jnfo-c at grauman.com>
To: qt-interest at qt.nokia.com
Sent: Fri, May 6, 2011 7:41:44 PM
Subject: [Qt-interest] QImage fade
Hello all,
I've written a little function to fade two QImages to a 3rd. It works fine
and the results are expected. I cycle through fadeval values to fade the
two images. I was wondering if anyone had any tricks I'm missing to *speed
it up* though...
FYI the function is dependant on all three QImages being the same size,
and they all need to be QImage::Format_ARGB32...
static int fadeMax=50;
void fadeImages(QImage *dest, QImage *src1, QImage *src2, unsigned char fadeval)
{
for(int y = 0; y < dest->height(); y++)
{
QRgb *destrow = (QRgb*)dest->scanLine(y);
QRgb *src1row = (QRgb*)src1->scanLine(y);
QRgb *src2row = (QRgb*)src2->scanLine(y);
for(int x = 0; x < dest->width(); x++)
{
((unsigned char*)&destrow[x])[0] = (((unsigned
char*)&src1row[x])[0]*fadeval/fadeMax + ((unsigned
char*)&src2row[x])[0]*(fadeMax-fadeval)/fadeMax);
((unsigned char*)&destrow[x])[1] = (((unsigned
char*)&src1row[x])[1]*fadeval/fadeMax + ((unsigned
char*)&src2row[x])[1]*(fadeMax-fadeval)/fadeMax);
((unsigned char*)&destrow[x])[2] = (((unsigned
char*)&src1row[x])[2]*fadeval/fadeMax + ((unsigned
char*)&src2row[x])[2]*(fadeMax-fadeval)/fadeMax);
((unsigned char*)&destrow[x])[3] = 255;
}
}
}
Josh
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110506/88e37858/attachment.html
More information about the Qt-interest-old
mailing list