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?
How to program a fast graphics filter operation
Re: How to program a fast graphics filter operation
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
Re: How to program a fast graphics filter operation
If I understand correctly what you are trying to do, this is the function you want to use: ReduceAlphaChannel()
Re: How to program a fast graphics filter operation
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.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()
Re: How to program a fast graphics filter operation
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.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
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
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: How to program a fast graphics filter operation
Another optimization is to use local for loops because they are faster than non-local for loops, i.e. use
instead of
Then you might want to avoid function calls like Red(), Green(), Blue() and substitute them with bitwise operations, e.g.
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...
Code: Select all
For Local k = 0 To 600
Code: Select all
For k = 0 To 600
Code: Select all
color = $123456
r = color >> 16
g = (color >> 8) & $ff
b = color & $ff
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...
Re: How to program a fast graphics filter operation
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.
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.