How to program a fast graphics filter operation

Find quick help here to get you started with Hollywood
Post Reply
zylesea
Posts: 212
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

How to program a fast graphics filter operation

Post by zylesea »

I was thinking of programming a transparency tool - 1st item for that tool should providesmooth transparency according to a color range. I've played a bit around but wonder whether I just don't know the right approach. Generally I went the brush route, as I think there are not many alternatives. I tried with adding an alpha channel and plotting calculated alpha values into that alpha chanel, Or by adding values to an RGBArray.
But that is all pixelwise and pretty slow. Takes several seconds for a picture of 600*600 pixels (my small test picture) on my G4/1500.
I am afraid to be generally on a wrong track with that approach, Anyone an idea how to do such operations fast and efficient?

User avatar
jPV
Posts: 383
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: How to program a fast graphics filter operation

Post by jPV »

How about putting the plotting between DisableLineHook() and EnableLineHook()? It should improve performance in this kind of situations at least. Didn't think better yet, but just a quick suggestion ;)

PEB
Posts: 548
Joined: Sun Feb 21, 2010 1:28 am

Re: How to program a fast graphics filter operation

Post by PEB »

If I understand correctly what you are trying to do, this is the function you want to use: ReduceAlphaChannel()

zylesea
Posts: 212
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

Re: How to program a fast graphics filter operation

Post by zylesea »

PEB wrote:
Tue Jan 05, 2021 6:22 pm
If I understand correctly what you are trying to do, this is the function you want to use: ReduceAlphaChannel()
To my understanding ReduceAlphaChannel() works globally on the aplha channel, but I want to modify it pixelwise. i.e. pixel a to 50% pixel B to 25%, pixel C to 10%, etc.

zylesea
Posts: 212
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

Re: How to program a fast graphics filter operation

Post by zylesea »

jPV wrote:
Tue Jan 05, 2021 4:02 pm
How about putting the plotting between DisableLineHook() and EnableLineHook()? It should improve performance in this kind of situations at least. Didn't think better yet, but just a quick suggestion ;)
Thanks jPV. i just started to reply that this would probably not affect the issue as I work within the alphachannel without showing the brush. But since i use the plot function to change the alpha channel intensity i just tested the linehook and - tada- disabling linehook speeds it up quite a bit.
But it's still very slow. The pixelwise calculation is quite soem effort. Here's a test of writing an AlphaChannel with values according to their blue share (no elaborated code, just testing).

Code: Select all

SelectAlphaChannel(1)
        DisableLineHook
        For k=0 To 600
            For i=0 To 600
           Local pixi= ReadBrushPixel(1,k,i)
               pixi=(1+Red(pixi)+Green(pixi))/(1+Blue(pixi)*2)   ;100% Blau=255
               If pixi>1 Then pixi=1
               pixi=pixi*255
               If pixi<0 Then pixi=0
               ;DebugPrint (pixi)
               SetAlphaIntensity(pixi)   ;255= no transparency
              Plot(k,i)
              Next
            Next
            EnableLineHook
        EndSelect      
The linehook was a very good hint though.

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

Re: How to program a fast graphics filter operation

Post by airsoftsoftwair »

Another optimization is to use local for loops because they are faster than non-local for loops, i.e. use

Code: Select all

For Local k = 0 To 600
instead of

Code: Select all

For k = 0 To 600
Then you might want to avoid function calls like Red(), Green(), Blue() and substitute them with bitwise operations, e.g.

Code: Select all

color = $123456
r = color >> 16
g = (color >> 8) & $ff
b = color & $ff
Instead of calling ReadBrushPixel() for every pixel you could also try to use BrushToRGBArray() instead and then access the pixels from the table returned by BrushToRGBArray().

Of course, all these things probably won't give you a massive speed boost but they could make it faster.

Ultimately, Hollywod isn't the optimal choice when it comes to operations which involve mathematical operations for millions of pixels. Such things are better implemented in native code as a Hollywood plugin...

zylesea
Posts: 212
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

Re: How to program a fast graphics filter operation

Post by zylesea »

Hi Andreas, thank you for your suggestions. I was vaguely thinking about something like bitwise operators. Now I got a clue. Also the local loops are a good suggestion. I think I will also speed it up by working on a (tiled) preview.

And regarding a plugin - I am curious since a long time about that. Looking into the how to of a plug in is on my to do list since quite some time already.. Maybe it's ime to actually go into that.

Post Reply