[Qt-interest] Combining alpha channels (min function)
Till Oliver Knoll
till.oliver.knoll at gmail.com
Tue Jun 14 16:23:02 CEST 2011
Hi,
Given a QImage I want to create a "reflected image" by flipping the
original image and adding a gradient alpha channel to the reflection.
In addition I also want to support alpha channels in the original
image - if present - by making sure that the reflection also contains
the (flipped) alpha channel.
Hence my task is to "combine" the flipped original alpha channel with
my alpha gradient. The final alpha channel should hence contain "the
minimum value of each channel".
Maybe the following pseudo-code (which also represents my current
"naive solution") is more descriptive:
QImage alpha;
QImage gradient; // of the same size as 'alpha'
QImage result; // as the same size as 'alpha'
// alphaChannel is obsolete!
alpha = originalImage.alphaChannel().mirrored();
// combine alpha with gradient
for (y = 0; y < alpha.height; ++y) {
for (x = 0; x < alpha.width; ++x) {
// is there a better approach to implement this "minimum function"?
if (alpha(x, y) < gradient(x, y)
result(x, y) = alpha(x, y);
else
result(x, y) = gradient(x, y);
}
}
The final result mask is then to be applied to the reflected original image.
Now my question: apart that I just realised that QImage::alphaChannel
is obsolete and the usual "byte wizardry" ("iterating over scan-lines
by incrementing pixel pointers" instead of using get/set pixel()
method): is there an obvious better (read: more performant) way to
implement this?
I thought about using one of the
http://doc.qt.nokia.com/latest/qpainter.html#CompositionMode-enum, but
at first sight none of them seems to do what I want ("minimum
function") - or is there any?
Thank you,
Oliver
More information about the Qt-interest-old
mailing list