Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
mrjt is currently offline  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):
index.php?t=getfile&id=1177&private=0
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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
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):
index.php?t=getfile&id=1177&private=0
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 #15600 is a reply to message #15589] Wed, 30 April 2008 11:23 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
To be honest it doesn't make much difference to me now since I know about the problem Smile. But IMO ImageDraw should behave in exactly the same way on both platforms, it's annoying to write code that works on Win32 but not X11.

IMO the ideal solution would be to have it undefined in Win32 too. But if you think that is a bad idea for backwards-compatability reasons then yes, ImageDraw::alpha should be initialized to 0. Perhaps this could be done on the first call to Alpha() so there is no additional overhead for none-alpha situations?
Re: Bug: ImageBuffer::alpha not initialised on X11 [message #15601 is a reply to message #15600] Wed, 30 April 2008 11:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
mrjt wrote on Wed, 30 April 2008 05:23


IMO the ideal solution would be to have it undefined in Win32 too.



Should I draw random data into alpha? Smile Win32 clears it for me.

Quote:


ImageDraw::alpha should be initialized to 0. Perhaps this could be done on the first call to Alpha() so there is no additional overhead for none-alpha situations?



Should not it be rather 255?

Mirek
Re: Bug: ImageBuffer::alpha not initialised on X11 [message #15602 is a reply to message #15601] Wed, 30 April 2008 12:56 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
luzr wrote on Wed, 30 April 2008 10:55

Should I draw random data into alpha? Smile Win32 clears it for me.

You could write in Jesus's face for a Turrin shroud effect, that'd be cool Razz

luzr wrote on Wed, 30 April 2008 10:55

Should not it be rather 255?

Windows clears it to 0 does it not? So unless you want to change that behaviour too then use 0. I agree it's more intuitive for it to be 255 but we write software, I think we can handle it Smile

[Updated on: Wed, 30 April 2008 13:04]

Report message to a moderator

Re: Bug: ImageBuffer::alpha not initialised on X11 [message #15603 is a reply to message #15602] Wed, 30 April 2008 13:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
OK then.

Image.cpp:

Draw& ImageDraw::Alpha()
{
	if(!has_alpha) {
		alpha.DrawRect(size, GrayColor(0));
		has_alpha = true;
	}
	return alpha;
}


Mirek
Re: Bug: ImageBuffer::alpha not initialised on X11 [message #15606 is a reply to message #15601] Wed, 30 April 2008 16:00 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 801
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor

luzr wrote on Wed, 30 April 2008 11:55


Should I draw random data into alpha? Smile 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.
Re: Bug: ImageBuffer::alpha not initialised on X11 [message #15608 is a reply to message #15606] Wed, 30 April 2008 16:24 Go to previous messageGo to next message
mrjt is currently offline  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? Smile 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 Go to previous message
mirek is currently offline  mirek
Messages: 12105
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? Smile 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
Previous Topic: bug in ImageBuffer::Line() and operator[]
Next Topic: .pcx images [FEATURE REQUEST]
Goto Forum:
  


Current Time: Wed Nov 20 13:46:32 CET 2019

Total time taken to generate the page: 0.03559 seconds