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 » Paint problems when using transparency
Paint problems when using transparency [message #41462] Thu, 19 December 2013 23:57 Go to next message
Didier is currently offline  Didier
Messages: 488
Registered: November 2008
Location: France
Senior Member
Hi all,

I have a problem that is driving me nuts Dead Dead

I am trying to make my GraphCtrl package as fast as possible and to do so I am trying to take advantage of the fast drawing of images when directly draw with native Draw instance passed to Ctrls.

The speed difference is very high (80 times faster) and everything works fine until:
  • transparency comes in
  • SUBPIXEL is used


So I made a test case hoping that someone could help me.
The test case basically does the following for each Ctrl
  • create a BufferPainter
  • fill the buffer painter with transparent background (in case you want to see behind the Ctrl)
  • Paint a white rectagle on upper half of the Ctrl
  • Paint an image containg green circle : half opaque, and half transparent (partially transparent)
  • draw a red line accross the Ctrl
  • draw the resulting image on the Ctrl area

There are 4 different flavors (testCtrl_1,2,3,4) and 4 different Painter modes used (antialiased, ...)
The defaults encountered are the following:
  • Transparent green becomes violet when overlapping the white rectangle
  • red line is not drawn properly when overlapping transparent area AND in SUBPIXEL mode


I know that a Premultiply() will probably correct the violet issue, but I can't find where to put it.
For the other problem ... I have no Idea what is going wrong

The result is in the following image
index.php?t=getfile&id=4376&private=0

The code of the test case is joined

Hopping to get some help
Re: Paint problems when using transparency [message #41502 is a reply to message #41462] Mon, 23 December 2013 11:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
I am yet working on subpixel issue, but the reason for violet is both apparent and weird: The problem is in .iml itself. If you edit .iml, you will see that it displays it violet over white too. Apparently, there is something wrong with that color. If you replace that with 'proper green with alpha', violet issue disappears.

In order to track the issue (which quite likely is in IconDes), may I ask how you have created that Image?
Re: Paint problems when using transparency [message #41503 is a reply to message #41502] Mon, 23 December 2013 14:24 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 488
Registered: November 2008
Location: France
Senior Member
Hi Mirek,

To make the image I created it completely with IML designer:
* new empty image
* draw a green opaque circle
* select half of the circle and apply alpha opertor on it

I created another image using the same process ... and didn't get the same result and violet color still appears

I am working on Linux (Fedora 19), it seems that I don't get the same behaviour in the IML designer than you : I don't get the violet color in IML when background is white (see joined images).

1 - ORIGINAL IMAGE:
Starngely, the transparent part looks green in drawing while it appears to be yellow or orange in the color selection part
index.php?t=getfile&id=4379&private=0

2 - SECOND IMAGE re-created from scratch
index.php?t=getfile&id=4380&private=0


The application result, when using the new image is the following:
* Violet color is still visible and green+white => grey ???
* Another thing I noticed is that when there is a White background in the layout, the result isn't the same : maybe a painter only issue ?
index.php?t=getfile&id=4382&private=0
Re: Paint problems when using transparency [message #41504 is a reply to message #41503] Mon, 23 December 2013 14:47 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
Subpixel issue: subpixel is kind of problem when the canvas is not opaque. It is quite evident from the basis of subpixel rendering: each subpixel has got its individual alpha - but this alpha is impossible to store anywhere, as we only have single alpha value for 3 subpixels... Anyway, Painter resorted to not quite correct fallback there, so I have fixed it to at least look ok (but the result is normal rendering, not subpixel).

Well, everything works for me now with color problems.. but I have to admit to perform some fixes in Painter (fixed some rounding error issue).

I am posting my version of testcase. Please, sync svn and check my testcase, then perhaps zip and send yours if you still experience problems.

Mirek
Re: Paint problems when using transparency [message #41505 is a reply to message #41504] Mon, 23 December 2013 17:09 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
..aah, now thinking about it, I have also removed one Premultiply from your testcase (there should be none). Perhaps that might have fixed the color issue...
Re: Paint problems when using transparency [message #41506 is a reply to message #41505] Mon, 23 December 2013 23:30 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 488
Registered: November 2008
Location: France
Senior Member
Hi Mirek,

SUBPIXEL issue is now corrected.
Thanks for the correction Smile

I extracted you're version of the test case, and here is what I get:
==>The Violet/grey part is still there.
index.php?t=getfile&id=4384&private=0

  • Attachment: mirek1.png
    (Size: 11.47KB, Downloaded 288 times)

[Updated on: Mon, 23 December 2013 23:31]

Report message to a moderator

Re: Paint problems when using transparency [message #41508 is a reply to message #41506] Tue, 24 December 2013 09:42 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
Now that is really weird. I have tested in Win32 and Linux and both look OK now.

Do you have latest svn sources?

You can also try to add

	void Paint2(Draw& dw, ImageBuffer& ib) {
		RGBA bckgColor;   bckgColor.r = 0; bckgColor.g = 0; bckgColor.b = 0; bckgColor.a = 0;
		Upp::Fill( ib.Begin(), bckgColor, ib.GetLength() );
		//Premultiply(ib);
		BufferPainter bp(ib, _drawMode);
		bp.Clear(RGBAZero());
	//	bp.Clear(White());
		bp.DrawRect(Rect(Point(0,0), Point( GetSize().cx, GetSize().cy/2)), White());
	//	bp.DrawLine(Point(0,GetSize().cy*3/4), Point(GetSize().cx,GetSize().cy*3/4), 4, White() );
		ChPaint(bp, GetSize(), _ctrlBckgndStyle );
		bp.DrawLine( Point(0,0), Point( GetSize().cx, GetSize().cy), 1 , Red() );
		
		for(const RGBA *s = ~ib; s != ib.End(); ++s) {
			ASSERT(s->r <= s->a && s->g <= s->a && s->b <= s->a);
		}
	}



... that is basically a test that ensures that ib is correctly premultiplied...

Mirek
Re: Paint problems when using transparency [message #41511 is a reply to message #41508] Tue, 24 December 2013 12:12 Go to previous message
Didier is currently offline  Didier
Messages: 488
Registered: November 2008
Location: France
Senior Member
Hi Mirek,

Yes the test was done with the latest svn sources but I have local modifications concerning MT that were encountered with ARM ( sMutexLock() issue ) : nothing concerning drawing( I verified ).

I have a recent ide ( 01/12/2013 built from tar.gz sources, sorry I don't have the svn version number anymore ) but I just rebuilt it from last SVN sources :
==> you're version of the code now works fine but my version still fails Question

My version gives the following log:
*s =RGBA(0, 255, 0, 239)
****************** ASSERT FAILED: Assertion failed in /home/didier/MyApps/Test_painting/Test_painting.h, line 53
s->r <= s->a && s->g <= s->a && s->b <= s->a


After creating a new img with iml designer (just the same way that the previous ones were made) ... my version also works
==> My conclusion is that there was a bug in my previous theIde making bad iml files

Idea Maybe it would be a good thing to have a checking process for iml files in order to detect bad files : if I stumbleded on the problem maybe there are other bad iml files laying around and that just haven't been detected as bad yet (as long as there is no underlying transparency everything seems fine )


I joined my code in order for you to see the contents of the bad iml files
* testImg and testImg2 are BAD
* testImg3 and testImg4 are OK

[Updated on: Tue, 24 December 2013 12:15]

Report message to a moderator

Previous Topic: Clickable SetImage in Button
Next Topic: Transparent Background - Image control
Goto Forum:
  


Current Time: Mon Nov 18 08:15:33 CET 2019

Total time taken to generate the page: 0.01716 seconds