Page 1 of 1

New Function for erase with all alpha at the same time

Posted: Thu Mar 15, 2018 4:09 pm
by sinisrus
Hello,

Is it possible for next release of hollywood to make a similar function of my function p_EraseBrushAlpha() (see my script)
currently is it too slow if I use my function

Thank you

Code: Select all

BeginDoubleBuffer(True)

/********************************************************************************************************************/

; Brush 0
SizeDamier = 5
Color1 = "$5D5D5D"
Color2 = "$3D3D3D"
SetFillStyle(#FILLCOLOR)
Damier=CreateBrush(NIL,SizeDamier*2,SizeDamier*2)

    SelectBrush(Damier)
    BOX(0,0,SizeDamier,SizeDamier,Color1)
    BOX(SizeDamier,0,SizeDamier,SizeDamier,Color2)
    BOX(0,SizeDamier,SizeDamier,SizeDamier,Color2)
    BOX(SizeDamier,SizeDamier,SizeDamier,SizeDamier,Color1)
    EndSelect

Background=CreateBrush(NIL,640,480)
SelectBrush(Background)
SetFillStyle(#FILLTEXTURE,Damier)
BOX(0,0,640,480)
EndSelect

; Brush 1
BackBrush=Createbrush(NIL,300,300,#RED,{AlphaChannel=True})
SelectBrush(BackBrush)
SetFont(#SANS,20)
SetFontColor(#BLACK)
SetFontStyle(#ANTIALIAS)
TextOut(#CENTER,#CENTER,"Function\n [b]p_EraseBrushAlpha()[/b]\n for erase with all alpha at the same time",{align=#CENTER})
EndSelect
BackBrushW$=GetAttribute(#BRUSH,BackBrush,#ATTRWIDTH)  ; Width brush
BackBrushH$=GetAttribute(#BRUSH,BackBrush,#ATTRHEIGHT) ; Height brush

; Brush 2
MouseBrush=Createbrush(NIL,50,50,#BLACK,{AlphaChannel=True, Clear=True})
SelectBrush(MouseBrush,#SELMODE_COMBO,2)
SetFormStyle(#ANTIALIAS)
SetFillStyle(#FILLCOLOR)
Circle(#CENTER,#CENTER,10,#BLUE)
EndSelect

BlurBrush(MouseBrush,15)
TrimBrush(MouseBrush)

MouseBrushW$=GetAttribute(#BRUSH,MouseBrush,#ATTRWIDTH)  ; Width brush
MouseBrushH$=GetAttribute(#BRUSH,MouseBrush,#ATTRHEIGHT) ; Height brush

/********************************************************************************************************************/

Function p_EraseBrushAlpha(Bsh,PosX,PosY)

ArrayBrush=BrushToRGBArray(Bsh,1)

For Local Y=0 TO MouseBrushH$-1
    Local OffsetY=Y*MouseBrushW$
    IF (PosY+Y>=0)&(PosY+Y<BackBrushH$)
        For Local X=0 TO MouseBrushW$-1
            Local tempAlpha = (ArrayBrush[X+OffsetY]>>24)
            Local A, BrushAlphaDest=ReadBrushPixel(BackBrush,PosX+X,PosY+Y)
            IF (PosX+X>=0)&(PosX+X<BackBrushW$)
                FinalAlpha=((tempAlpha)*BrushAlphaDest)>>8
                SetAlphaIntensity(FinalAlpha)
                Plot(PosX+X,PosY+Y, #BLACK)
            EndIF
        NEXT
    EndIF
NEXT

EndFunction

/********************************************************************************************************************/

Function p_Move(msg)
  Cls()
  SelectAlphaChannel(BackBrush)
  p_EraseBrushAlpha(MouseBrush, MouseX()-(MouseBrushW$>>1)-150, MouseY()-(MouseBrushH$>>1)-50)
  EndSelect

  DisplayBrush(Background,0,0)
  DisplayBrush(BackBrush,150,50)

  Flip()
Endfunction

IntervalDessin=SetInterval(NIL, p_Move, 1000/100) ; 100fps

/********************************************************************************************************************/

EscapeQuit(True)

/* Boucle infinie */
Repeat
        WaitEvent
Forever


Re: New Function for erase with all alpha at the same time

Posted: Sat Mar 17, 2018 4:01 pm
by airsoftsoftwair
What does this do? Is such a function of general interest or is it only useful for your specific project?

Re: New Function for erase with all alpha at the same time

Posted: Sat Mar 17, 2018 4:17 pm
by sinisrus
My english is not good enough to explain. But it's important for pixel drawing projects it's an erase function that takes into account all alphachannel levels at the same time.

I'm working on a project that needs this feature

Did you try the script?

Re: New Function for erase with all alpha at the same time

Posted: Tue Mar 20, 2018 7:31 pm
by airsoftsoftwair
Yes, I see what it does but the question is if that is something that is of general interest or just for your project. If it is only good for your particular project, it doesn't make sense to add it as a Hollywood feature. That's why I'd need some plausible reasons as to why this is a feature that is worth adding.

Re: New Function for erase with all alpha at the same time

Posted: Wed Mar 21, 2018 1:00 am
by sinisrus
This is very useful for drawing software. Not only for my projects

Re: New Function for erase with all alpha at the same time

Posted: Wed Mar 21, 2018 8:10 am
by sinisrus
And for make Cinemagraph is really indispensable

Cinemagraph animation exemple : https://timverdouw.com/reviews/create-e ... graphitii/

Re: New Function for erase with all alpha at the same time

Posted: Fri Mar 23, 2018 10:19 pm
by PEB
I'm not sure how hard this would be to add, but I think a feature that might help sinisrus (and also be useful for many others) would be a new mode for SetAlphaIntensity() that would allow for more true drawing/painting to a brush's alpha-channel.

Take, for example, the following demonstration:

Code: Select all

SetFormStyle(#ANTIALIAS)

Createbrush(1,200,200,#RED)
SelectBrush(1)
Circle(50, 50, 50)
Circle(70, 70, 50)
DisplayBrush(1, #LEFT, #TOP)

Createbrush(1,200,200,#RED,{AlphaChannel=True})
SelectAlphaChannel(1)
SetAlphaIntensity(0)
Circle(50, 50, 50)
Circle(70, 70, 50)
DisplayBrush(1, #RIGHT, #TOP)

Createbrush(1,200,200,#RED,{AlphaChannel=True})
SelectAlphaChannel(1)
SetAlphaIntensity(#VANILLACOPY)
Circle(50, 50, 50)
Circle(70, 70, 50)
DisplayBrush(1, #LEFT, #BOTTOM)

Createbrush(1,200,200,#RED,{AlphaChannel=True})
InvertAlphaChannel(1)
SelectAlphaChannel(1)
SetAlphaIntensity(#VANILLACOPY)
Circle(50, 50, 50)
Circle(70, 70, 50)
EndSelect
InvertAlphaChannel(1)
DisplayBrush(1, #RIGHT, #BOTTOM)
The brush in the upper-left corner is the one that we want to match, but by targeting the alpha-channel. The brush in the upper-right corner loses antialiasing. The brush in the lower-left corner makes use of the #VANILLACOPY mode to keep the antialiasing, but is the inverse of what we want. The brush in the lower-right corner gets the closest, but still doesn't achieve the desired look because the opacity from the second circle obscures the first.

As far as I know, there is no way currently to do this (apart from a pixel by pixel analysis).

Re: New Function for erase with all alpha at the same time

Posted: Sun Mar 25, 2018 11:15 pm
by airsoftsoftwair
Well, I'll think about it when I have some more time :-)

Re: New Function for erase with all alpha at the same time

Posted: Sun Mar 25, 2018 11:36 pm
by sinisrus
Nice!! Thank you