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: 680
Registered: November 2008
Location: France
Contributor
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: 13975
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: 680
Registered: November 2008
Location: France
Contributor
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: 13975
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: 13975
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: 680
Registered: November 2008
Location: France
Contributor
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 719 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: 13975
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 messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
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

Re: Paint problems when using transparency [message #54176 is a reply to message #41511] Fri, 05 June 2020 11:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
This might need retesting after recent SIMD alpha-blend changes....
Re: Paint problems when using transparency [message #54180 is a reply to message #54176] Fri, 05 June 2020 17:08 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello Mirek,

I will check this evening

But I still envounter problems with IML images that get corrupted and I have no idea how and when they corrupt ?

I regularly rebuild Theide


Re: Paint problems when using transparency [message #54182 is a reply to message #54180] Fri, 05 June 2020 19:48 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hello Mirek,

I just checked, not with the test case, but with the code the test case was made for and everything works fine
No glitches

I will also try to reboot the test case
Re: Paint problems when using transparency [message #54187 is a reply to message #54182] Fri, 05 June 2020 23:31 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
I rebooted the test, and there seems to be a problem with subpixel
The red lines appear when the backgnd is white

index.php?t=getfile&id=6098&private=0
Re: Paint problems when using transparency [message #54188 is a reply to message #54187] Fri, 05 June 2020 23:34 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Here is the code I used

[Updated on: Fri, 05 June 2020 23:35]

Report message to a moderator

Re: Paint problems when using transparency [message #54190 is a reply to message #54188] Sat, 06 June 2020 10:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hi,

I think the issue was with invalid .iml (that must have been pretty old) - some values of green were not premultiplied...

I am attaching "fixed" test. Can you check please?

Mirek
Re: Paint problems when using transparency [message #54193 is a reply to message #54180] Sat, 06 June 2020 10:31 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Didier wrote on Fri, 05 June 2020 17:08
Hello Mirek,

I will check this evening

But I still envounter problems with IML images that get corrupted and I have no idea how and when they corrupt ?

I regularly rebuild Theide




I think it is because of old transition to premultiplied alpha... (but that is like 10 years ago)
Re: Paint problems when using transparency [message #54195 is a reply to message #54193] Sat, 06 June 2020 21:12 Go to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Just checked,

Everything is ok now : it was the IML file that was corrupted
Previous Topic: BufferPainter::Fill(Image,...) optimization question
Next Topic: What is the U++ way to replace a missing font glyph?
Goto Forum:
  


Current Time: Fri Mar 29 00:24:26 CET 2024

Total time taken to generate the page: 0.02031 seconds