Using alpha does incongruous things

Here you can discuss and share functionality improvements and helper programs to make Context Free better.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
User avatar
Guigui
Posts: 50
Joined: Sat Aug 05, 2006 5:28 pm
Location: Annecy, France

Using alpha does incongruous things

Post by Guigui »

Just look what this CF code draws :roll: :

Code: Select all

startshape WHITE
rule WHITE {
CIRCLE{alpha -.99 b 1}
WHITE{s .99}
}
It should draw white circles on white background but it doesn't:
Image
(rendered with the Version 2.0 (14) on a mac)
Is it a known bug? :(

MLDaeni
Posts: 5
Joined: Fri Oct 20, 2006 6:38 am

Post by MLDaeni »

Indeed, you can see the white circles on a red background:

Code: Select all

startshape WHITE

background { sat 1 b 1}

rule WHITE {
	CIRCLE{alpha -0.9 b 1}
	WHITE{s .9}
}
However, changing to alpha -0.99 and size 0.99 as in your script... no white circles anymore.

User avatar
Guigui
Posts: 50
Joined: Sat Aug 05, 2006 5:28 pm
Location: Annecy, France

Post by Guigui »

No white circles anymore, yes :| .
For me, it's a kind of bug. I hope the devlopers can fixe it one day :oops: (I'm so sorry I can't help). Lots of new works would be possible with a more efficient alpha. :wink:

User avatar
Guigui
Posts: 50
Joined: Sat Aug 05, 2006 5:28 pm
Location: Annecy, France

Post by Guigui »

I've just read the topic called 'Color bug' and I'm asking myself if that can be the same kind of problem.

Can it be a Floating point bug?

… a bug in the HSB to RGB color space conversion code :roll: ?

Does it happen also with Windows and Unix software :? (I'm on Mac) ?

Is there realy a bug?

All this questions I can't answer :cry: (well, I will watch on windows, just in case)

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post by MtnViewJohn »

It isn't like the color bug. Even if you take out the recursion and just draw one circle the color of that circle is (253,253,253) instead of (255,255,255). The HSBA color is correctly converted to RGBA. The problem happens inside of the AGG template library.

I don't know for sure, but I think that the AGG library might have several off-by-one errors in its alpha-blending. There are several places where AGG does a fast '>> 8' when it seems to me that the slower '/ 255' is more correct. I replaced several '>> 8' with '/ 255' in the color pre-multiplier and pixel blender functions and the gray circles changed to pure white (255,255,255). I am pursuing this issue in the AGG mailing list.

User avatar
Guigui
Posts: 50
Joined: Sat Aug 05, 2006 5:28 pm
Location: Annecy, France

Post by Guigui »

:lol: Yo !!!
Thank you for having a look on it.
If this AGG library is used for several project, that will be very usefull.

I'm a graphic designer and I learn so much things with context free and this forum (and wikipedia to partly understand you :!: ).

Have a good time!

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post by MtnViewJohn »

I have confirmed that the AGG graphics template library that Context Free uses fudges alpha blending in the way that I described earlier, in order to run faster. But I did get a pointer to a 1995 research paper on how to do exact alpha blending using only shifts and adds, with no slow divides. I have updated AGG for the 2.1beta version here with with this technique. The above cfdg code renders perfectly white using the new alpha blending code. There is a 5-10% slow-down in drawing. I think it is worth it.

Unfortunately some people have compensated for the darkened alpha blending bug by lightening there shape colors. With 2.1beta (and beyond) these will seem to be too light.

User avatar
Guigui
Posts: 50
Joined: Sat Aug 05, 2006 5:28 pm
Location: Annecy, France

Post by Guigui »

:D Good work ! I'll try stuff using massive alpha blending :wink:. See ya !!! :)
8^)

User avatar
Guigui
Posts: 50
Joined: Sat Aug 05, 2006 5:28 pm
Location: Annecy, France

Hey! something else about alpha:

Post by Guigui »

Hey! something else about alpha:

with this code:

Code: Select all

startshape TEST

rule TEST {
	CIRCLE{alpha -.5}
	TEST{x .993 r 12 s .993 alpha -.01}
}
I get this:
Image
Allright!!!

but with this:

Code: Select all

startshape TEST

rule TEST {
	CIRCLE{alpha -.5}
	TEST{x .993 r 12 s .993 alpha .01}
}
I get this:
Image
Souldn't the CIRCLES be more and more opaque? :shock:

Is it a bug or there is no way to opacify shapes?
(tested with Version 2.0 (16) and Version 2.1beta (16))[/b]
8^)

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post by MtnViewJohn »

No the circles should all be 50% transparent. The alpha for rule TEST starts at 1. When you do TEST{x .993 r 12 s .993 alpha .01}, you are making alpha 10% more opaque, but the alpha is already at 100% opacity so the alpha .01 does nothing. What you want is to use another rule to change alpha for TEST to 50%:

Code: Select all

startshape TEST2

rule TEST2 { TEST {a -.5}} 

rule TEST { 
   CIRCLE{} 
   TEST{x .993 r 12 s .993 alpha .01} 
}
which should give you what you want.

User avatar
Guigui
Posts: 50
Joined: Sat Aug 05, 2006 5:28 pm
Location: Annecy, France

Post by Guigui »

OK, I get it. Thank you. :)
8^)

User avatar
zol
Posts: 40
Joined: Sun Mar 23, 2008 4:14 pm

Drat.

Post by zol »

This is basically the same thing from a different angle...

CF 2.2 has the 'transparent means black' syndrome.

Code: Select all

rule test1{100* {} SQUARE{r 25 b 1 sat -1 a -.9}}
Image
Note that it affects both solid areas and anti-aliasing.

It's pretty common, but given AGG's declared goals I don't know why they discard colour information in the first place. Or why the background isn't used to supply it.

Many images for which CF would be ideally suited also involve situations in which this error becomes prominent.

Seriously compromised my latest idea, anyway. *grumble*

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post by MtnViewJohn »

If you get rid of the sat -1 then the problem goes away. If you make the background slightly transparent then the problem goes away. It turns out that when I fixed alpha in AGG I forgot to do it for the 24-bit pixel formats. I only did it for 8 and 32-bit pixel formats. I will fix 24-bit pixels in the next beta release.

User avatar
zol
Posts: 40
Joined: Sun Mar 23, 2008 4:14 pm

Post by zol »

Hooray!
Thanks. I was going to ask about an interim fix, but couldn't see that anything would get around it. (Hm, internal mode switch perhaps?)

The transparent background trick works brilliantly.
Also, a -.001 renders as opaque, so there's never any need to compensate elsewhere.

No amount of fiddling with sat made any difference for me, though -- Removing "sat -1" (which is only the default made explicit), or increasing sat to any value (including 1).

But I can think of no situation for which the first fix isn't preferable anyway.

casseysmith
Posts: 1
Joined: Fri Aug 29, 2008 3:30 am

zol

Post by casseysmith »

Yes, as you said the transparent background trick works brilliantly. Increasing sat to any value including one.
================================================
casseysmith

spamholes

Post Reply