Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Bug: ImageBuffer::alpha not initialised on X11
Bug: ImageBuffer::alpha not initialised on X11 [message #15575] |
Tue, 29 April 2008 14:34  |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
The alpha channel is not correctly initialised on X11. This causes corruption (second image is what it should look like):

Everything works correctly for Win32. The code below exibits the problem:
class ImageDrawTest : public TopWindow {
public:
typedef ImageDrawTest CLASSNAME;
Image img;
ImageDrawTest() {
Sizeable();
GenerateImage();
}
void GenerateImage() {
Size sz(100, 100);
ImageDraw w(sz);
// w.Alpha().DrawRect(sz, Black());
w.Alpha().DrawRect(30, 30, 40, 40, White());
w.DrawRect(sz, Red);
img = w;
}
virtual void Paint(Draw &w) {
w.DrawRect(GetSize(), SColorFace());
w.DrawImage(0, 0, img);
}
virtual void LeftUp(Point p, dword keyflags) {
GenerateImage();
Refresh();
}
};
If you uncomment the line above, the channel is initialised and everything works correctly.
Edit: Looking at the manual for XCreatePixmap, it says the pixmap contents are undefined, which I guess is fair enough. My main issue here is the inconsistency between Win32/Linux, both should be either defined or undefined.
[Updated on: Tue, 29 April 2008 14:43] Report message to a moderator
|
|
|
Re: Bug: ImageBuffer::alpha not initialised on X11 [message #15589 is a reply to message #15575] |
Tue, 29 April 2008 19:33   |
 |
mirek
Messages: 14258 Registered: November 2005
|
Ultimate Member |
|
|
mrjt wrote on Tue, 29 April 2008 08:34 | The alpha channel is not correctly initialised on X11. This causes corruption (second image is what it should look like):

Everything works correctly for Win32. The code below exibits the problem:
class ImageDrawTest : public TopWindow {
public:
typedef ImageDrawTest CLASSNAME;
Image img;
ImageDrawTest() {
Sizeable();
GenerateImage();
}
void GenerateImage() {
Size sz(100, 100);
ImageDraw w(sz);
// w.Alpha().DrawRect(sz, Black());
w.Alpha().DrawRect(30, 30, 40, 40, White());
w.DrawRect(sz, Red);
img = w;
}
virtual void Paint(Draw &w) {
w.DrawRect(GetSize(), SColorFace());
w.DrawImage(0, 0, img);
}
virtual void LeftUp(Point p, dword keyflags) {
GenerateImage();
Refresh();
}
};
If you uncomment the line above, the channel is initialised and everything works correctly.
Edit: Looking at the manual for XCreatePixmap, it says the pixmap contents are undefined, which I guess is fair enough. My main issue here is the inconsistency between Win32/Linux, both should be either defined or undefined.
|
Well, this is rather missing docs... It was intended to have both "body" and "alpha" uninitialized, the same situation as with e.g. Paint. After all, you never know whether for specific use it is better to have alpha =0 or 255 (or even something else).
OTOH, if you believe it should be initialized, we can do that too.
Mirek
|
|
|
|
|
|
|
|
Re: Bug: ImageBuffer::alpha not initialised on X11 [message #15608 is a reply to message #15606] |
Wed, 30 April 2008 16:24   |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
mr_ped wrote on Wed, 30 April 2008 15:00 |
luzr wrote on Wed, 30 April 2008 11:55 |
Should I draw random data into alpha? Win32 clears it for me.
|
In case it is supposed to be uninitialized, and the OS does initialize it for you, I suggest to use random bytes in DEBUG mode trough #ifdef.
That will make such errors to appear in debug mode, yet it will not slow down release.
|
I hadn't thought of that, it's a good compromise IMO.
[Updated on: Wed, 30 April 2008 16:24] Report message to a moderator
|
|
|
Re: Bug: ImageBuffer::alpha not initialised on X11 [message #15773 is a reply to message #15608] |
Wed, 07 May 2008 17:07  |
 |
mirek
Messages: 14258 Registered: November 2005
|
Ultimate Member |
|
|
mrjt wrote on Wed, 30 April 2008 10:24 |
mr_ped wrote on Wed, 30 April 2008 15:00 |
luzr wrote on Wed, 30 April 2008 11:55 |
Should I draw random data into alpha? Win32 clears it for me.
|
In case it is supposed to be uninitialized, and the OS does initialize it for you, I suggest to use random bytes in DEBUG mode trough #ifdef.
That will make such errors to appear in debug mode, yet it will not slow down release.
|
I hadn't thought of that, it's a good compromise IMO.
|
Well whatever, it is now cleared in X11. I guess it does not hurt much, ImageDraw is not supposed to be the performance king anyway.
Mirek
|
|
|
Goto Forum:
Current Time: Tue May 13 14:20:19 CEST 2025
Total time taken to generate the page: 0.02941 seconds
|