[Qt-interest] QImage fade
Joshua Grauman
jnfo-c at grauman.com
Sat May 7 07:08:00 CEST 2011
Thanks Bob, but I'm thinking I can't take these out of the loop trivially.
Unless I'm missing something, if I precalculate fadeval/fadeMax it will
always be 0, unless I go to floating point, which doesn't seem like a good
idea? I'm guessing a floating point multiply would cost as much as an
integer divide? Am I missing something?
I'll have to think about bit operations as well. I can choose fadeMax to
be a power of 2, but I'll have to think if there is a way to do it via bit
masking...
Thanks!
Josh
> 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
>
More information about the Qt-interest-old
mailing list