Here's what I tested about ilbarbax's situation:
Code: Select all
w, h = 2560, 1920
CreateBrush(1, w, h, $FF0000)
StartTimer(1)
DisableLineHook()
t = BrushToRGBArray(1)
For Local i = 0 To ListItems(t) - 1
t[i] = RGB(Green(t[i]), Red(t[i]), Blue(t[i]))
Next
RGBArrayToBrush(1, t, w, h)
t = Nil
EnableLineHook()
DebugPrint(GetTimer(1)/1000) ; 16 secs on Mac mini G4
DisplayBrush(1, 0, 0)
StartTimer(1)
DisableLineHook()
For Local y = 0 To h - 1
For Local x = 0 To w - 1
Local c = ReadBrushPixel(1, x, y)
WriteBrushPixel(1, x, y, RGB(Green(c), Red(c), Blue(c)))
Next
Next
EnableLineHook()
DebugPrint(GetTimer(1)/1000) ; 19 secs on Mac mini G4
DisplayBrush(1, 0, 0)
WaitLeftMouse()
So two different solutions, but the BrushToRGBArray seems to be faster.
In any case I would put the main For loop between
DisableLineHook() and
EnableLineHook(), they make a big difference in these kinds of situations.
I also noticed that using table values directly instead of placing them in variables is a bit faster solution.
Notes about ilbarbax's code:
1) Local variables are always faster, so do "For Local k=0 To ListItems(t)-1"
2) Again do "Local RR=Red(t[k])" rather than global variables inside a loop
3) Although according to my test it would better not use RR, BB, and GG as variables at all, but do "t[k]=RGB(Blue(t[k]), Green(t[k]), Red(t[k]))". Or "Local c=t[k]" and "t[k]=RGB(Blue(c), Green(c), Red(c))" could be theoreticaly faster.
4) Use ElseIf:s instead of calling If three times, because if the first If does it, it useless to check the rest.
5) Actually, don't check these C1 and C2 at all inside the very big loop, it's useless to waste time on them. So forget 4) and figure out some another solution. Even three separate loop code blocks would be better.
6) And remember to disable that line hook for heavy loops as told few lines ago
These might sound small things, but when looping millions of times, they do affect to the total time used. Although you never get this one that quick.. it's only "minimizing the damage".
Here's an untested suggestion for the looping part:
Code: Select all
DisableLineHook()
If C1="R" And C2="B"
For Local k=0 To ListItems(t)-1
t[k]=RGB(Blue(t[k]),Green(t[k]),Red(t[k]))
Next
ElseIf C1="R" And C2="G"
For Local k=0 To ListItems(t)-1
t[k]=RGB(Green(t[k]),Red(t[k]),Blue(t[k]))
Next
ElseIf C1="B" And C2="G"
For Local k=0 To ListItems(t)-1
t[k]=RGB(Red(t[k]),Blue(t[k]),Green(t[k]))
Next
EndIf
EnableLineHook()
So, have as little code inside a long loop as possible to avoid unnecessary work for the machine.