Page 1 of 1
Question about AlphaChannel
Posted: Mon Feb 28, 2011 7:39 pm
by Allanon
Hello all,
I've a problem
If I use the command
Polygon() directly on the display it's all fine, instead if I use
Polygon() within a brush with #SELMODE_COMBO the alpha channel of the area outside my shape is cleared and the square that surround the shape becames full transparent... any hints?
I need to preserve the alphachannel of the brush where I'm trying to execute the polygon command.
I cannot use #SELMODE_NORMAL because with
Polygon() I'd like to draw shapes with ARGB color... In few words I need to draw in the bitmap and in the alphachannel of my brush only the polygon shape and not the background
I'm lost...

Re: Question about AlphaChannel
Posted: Mon Feb 28, 2011 11:27 pm
by airsoftsoftwair
Hmm, what about this code?
Code: Select all
CreateBrush(1, 295, 295, #RED)
SelectAlphaChannel(1)
SetFillStyle(#FILLCOLOR)
SetAlphaIntensity(255)
Box(0, 0, 295, 295)
SetAlphaIntensity(128)
Polygon(#CENTER, #CENTER, {0, 100, 100, 0, 200, 100}, 3, #RED)
DisplayBrush(1, #CENTER, #CENTER)
WaitLeftMouse
End
Re: Question about AlphaChannel
Posted: Tue Mar 01, 2011 9:32 am
by Allanon
Hi Andreas,
please have a look to the following snippet to understand what I mean
Code: Select all
CreateBrush(1, 200, 200, #WHITE, { Alphachannel = True, Clear = True })
LoadBrush(2, "SampleIcon.png", { LoadAlpha = True }) ; Image with alphachannel
SelectBrush(1, #SELMODE_COMBO)
DisplayBrush(2, 10, 10)
SetFillStyle(#FILLCOLOR)
Polygon(#CENTER, #CENTER, {0, 100, 100, 0, 200, 100}, 3, $88FF0000)
EndSelect()
DisplayBrush(1, #CENTER, #CENTER)
WaitLeftMouse
End
Polygon() erases completely the alphachannel of the brush, but if I do:
Code: Select all
CreateBrush(1, 200, 200, #WHITE, { Alphachannel = True, Clear = True })
LoadBrush(2, "SampleIcon.png", { LoadAlpha = True }) ; Image with alphachannel
SelectBrush(1, #SELMODE_COMBO)
DisplayBrush(2, 10, 10)
EndSelect()
DisplayBrush(1, #CENTER, #CENTER)
SetFillStyle(#FILLCOLOR)
Polygon(#CENTER, #CENTER, {0, 100, 100, 0, 200, 100}, 3, $88FF0000)
WaitLeftMouse
End
It works has expected: the area surrounding the polygon is untouched, and the polygon itself is drawn with the $88FF0000 ARGB color
Re: Question about AlphaChannel
Posted: Thu Mar 03, 2011 10:37 am
by airsoftsoftwair
Ok, now I see what you mean. This seems to be a bug in Hollywood, too... the behaviour when specifying an alpha value in the drawing color is currently pretty much undefined when using #SELMODE_COMBO. I still have to think about how it's supposed to work in order to fix it
But: You most certainly won't be able to replicate the behaviour of onscreen alpha drawing in an offscreen brush. That's not really possible. When drawing to an offscreen brush, the old alpha values should always be overwritten *except* the invisible alpha values. Currently, invisible alpha values are also copied. This is clearly a bug. But even if this is fixed, you won't be able to achieve what you want I guess. This alpha stuff is complicated... I guess the most logical behaviour of #SELMODE_COMBO with an alpha color would be the following:
1. The color component (i.e. $ff0000) is vanilla copied to the destination brush.
2. The alpha component (i.e. $88) is vanilla copied to the destination brush.
This would be a logical behaviour but it doesn't solve your problem because then the triangular area inside sample_icon.png is getting overwritten with $88 values but I think you want to preserve the old alpha values, too. So the $88 would have to be mixed with the old alpha values but this is not really possible because alpha values can't be mixed so easily. I don't even know if there's an algorithm that could do this... it's just not possible to replicate all this in an offscreen brush

Re: Question about AlphaChannel
Posted: Thu Mar 03, 2011 9:12 pm
by Allanon
Yes, this stuff is really complicated!
I got an headache thinking about this things... another nice thing could be a modfe that mixes the two alpha channels

About this topic, I think that it's also present on TextOut command, if you change
Polygon() with
TextOut() in my sample code you will see another problem, in this case an alpha mixing mode could be really usefull

Re: Question about AlphaChannel
Posted: Sat Mar 05, 2011 12:08 am
by airsoftsoftwair
Yeah, but the problem is that it doesn't work that easily because you can't simply mix two alpha channels together because you've only a very limited range of levels (from 0 to 255). Simply doing an average calculation like
mixA = (srcA + dstA) / 2
is certainly not going to give satisfying results. You cannot really replicate the look of many different alpha drawings inside a single alpha channel. Just imagine the following code: (assuming that brush 1 has an alpha channel)
Code: Select all
For Local k = 1 To 100
DisplayBrush(1, RndF() * 320, RndF() * 240)
Next
Now this will do 100 alpha drawings to the current background. Now imagine you want to do the 100 drawings to an offscreen brush instead of the display directly, and then you want to draw this brush with a single call to DisplayBrush() and you want to have the same look as if you drew it 100 times to the display directly... that's impossible because each of the 100 drawings depends on the other because the background changes with each drawing... it's mind boggling but I think you get the idea

Alpha mixing is not really possible AFAICS.
Re: Question about AlphaChannel
Posted: Sat Mar 05, 2011 9:03 pm
by Allanon
Ok, just another couple of ideas to have more flexibility with this strange things called alpha channels
1. What about an alpha mixing mode with custom balancing, like
MixBrush() command?
2. What about a mode that write full alpha channel but excluding a custom range? For example with this mode I could blit a brush with alpha, except where alpha is 0... for example this could solve the polygon behaviuor
Re: Question about AlphaChannel
Posted: Tue Mar 08, 2011 5:49 pm
by airsoftsoftwair
Something like this is planned but I still need to work out the details

Re: Question about AlphaChannel
Posted: Tue Mar 08, 2011 9:33 pm
by Allanon
Ok, thank you
