New Function for erase with all alpha at the same time

Feature requests for future versions of Hollywood can be voiced here
Post Reply
sinisrus
Posts: 241
Joined: Tue Apr 21, 2015 5:43 pm

New Function for erase with all alpha at the same time

Post by sinisrus » Thu Mar 15, 2018 5:09 pm

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


User avatar
airsoftsoftwair
Posts: 2570
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

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

Post by airsoftsoftwair » Sat Mar 17, 2018 5:01 pm

What does this do? Is such a function of general interest or is it only useful for your specific project?

sinisrus
Posts: 241
Joined: Tue Apr 21, 2015 5:43 pm

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

Post by sinisrus » Sat Mar 17, 2018 5:17 pm

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?

User avatar
airsoftsoftwair
Posts: 2570
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

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

Post by airsoftsoftwair » Tue Mar 20, 2018 8:31 pm

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.

sinisrus
Posts: 241
Joined: Tue Apr 21, 2015 5:43 pm

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

Post by sinisrus » Wed Mar 21, 2018 2:00 am

This is very useful for drawing software. Not only for my projects

sinisrus
Posts: 241
Joined: Tue Apr 21, 2015 5:43 pm

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

Post by sinisrus » Wed Mar 21, 2018 9:10 am

And for make Cinemagraph is really indispensable

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

PEB
Posts: 176
Joined: Sun Feb 21, 2010 2:28 am

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

Post by PEB » Fri Mar 23, 2018 11:19 pm

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).

User avatar
airsoftsoftwair
Posts: 2570
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany
Contact:

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

Post by airsoftsoftwair » Sun Mar 25, 2018 11:15 pm

Well, I'll think about it when I have some more time :-)

sinisrus
Posts: 241
Joined: Tue Apr 21, 2015 5:43 pm

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

Post by sinisrus » Sun Mar 25, 2018 11:36 pm

Nice!! Thank you

Post Reply