bug in wxAlphaPixelData in wxMac and wxGTK?
Andrew Trevorrow
andrew at trevorrow.com
Thu Mar 1 21:44:59 PST 2007
I'm trying to use wxAlphaPixelData to create a semi-transparent bitmap
for use as a selection rectangle, but for some reason I'm getting
different results on each platform (Win XP, Mac OS 10.4.8 Intel, and
Debian Linux):
http://www.trevorrow.com/wx/alpha-bug.png
Note that I'm using wxWidgets 2.8.0 on each platform. Only the wxMSW
result looks correct. The wxMac and wxGTK results look similar but
are slightly different shades of green.
In each case, the same green color (rgb = 75,175,0) was passed into
the following routine which is based on code in the image sample.
The bitmap passed in was created with a depth of 32 so it has
an alpha channel.
void SetSelectionPixels(wxBitmap* bitmap, int selwd, int selht,
const wxColor* color)
{
// set color and alpha of pixels in given bitmap
wxAlphaPixelData data(*bitmap, wxPoint(0,0), wxSize(selwd,selht));
if (data) {
int alpha = 128; // 50% opaque
// note that RGB must be premultiplied by alpha
int r = color->Red() * alpha / 256;
int g = color->Green() * alpha / 256;
int b = color->Blue() * alpha / 256;
data.UseAlpha();
wxAlphaPixelData::Iterator p(data);
for ( int y = 0; y < selht; y++ ) {
wxAlphaPixelData::Iterator rowStart = p;
for ( int x = 0; x < selwd; x++ ) {
p.Red() = r;
p.Green() = g;
p.Blue() = b;
p.Alpha() = alpha;
p++;
}
p = rowStart;
p.OffsetY(data, 1);
}
}
}
It makes no difference whether I use DrawBitmap() or Blit() to draw
the resulting bitmap.
Am I doing something wrong, or are there bugs in the wxMac and wxGTK
implementations of wxAlphaPixelData?
Andrew
More information about the wx-dev
mailing list