Page 1 of 1

How can improve speed?

Posted: Sun Sep 29, 2024 12:16 pm
by minimy
Hello im trying to copy window (or canvas, image) content to another window,, how can improve speed?
Thanks for help!

Code: Select all

Procedure   copyThis(w1,w2)
  Protected   img
  StartDrawing(WindowOutput(w1))
    img= GrabDrawingImage(#PB_Any,0,0,OutputWidth(),OutputHeight())
  StopDrawing()
  StartDrawing(WindowOutput(w2))
    DrawImage(ImageID(img),0,0,OutputWidth(),OutputHeight())
  StopDrawing()
  FreeImage(img)
EndProcedure  

Procedure   draw(w1)
  Static x=-100
  StartDrawing(WindowOutput(c))
  For p= 0 To 100
    Box(0,0,OutputWidth(),OutputHeight(),$ffffff)
    Circle(x,150,100,$0000ff)
    x+1:If x>OutputWidth():x=-100:EndIf
    DrawText(10,10,Str(x),$0,$ffffff)
  Next p
  StopDrawing()
EndProcedure

OpenWindow(0,0,0,400,300,"W1",#PB_Window_SystemMenu)
OpenWindow(1,500,0,400,300,"W2",#PB_Window_SystemMenu)

t= ElapsedMilliseconds()
For p= 1 To 100
; Repeat
  event= WindowEvent()
  If event= #PB_Event_CloseWindow
    Break
  EndIf
  draw(0)
  copyThis(0,1)
;   Delay(1)
; ForEver
Next p
MessageRequester("Time", Str(ElapsedMilliseconds()-t) +" ms")

Re: How can improve speed?

Posted: Sun Sep 29, 2024 8:41 pm
by SMaag
Why you want to speed up and what you want to speed up?

Your Code context look like you want to speed up the CopyThis()

I tested what is slow:
and it is not the CopyThis()

My timing:
With CopyThis 1130ms
without CopyThis 940ms

CopyThis needs 190ms only!

So the draw() Procedure is the bottleneck!

DrawText(10,10,Str(x),$0,$ffffff) ; 200ms
Circle(x,150,100,$0000ff) ; 650ms

Re: How can improve speed?

Posted: Mon Sep 30, 2024 7:07 am
by Psychophanta
One of the fastests ways to manage bitmaps in windows is to treat it as "device independent bitmap (DIB)".
So please take a look at my source in:
viewtopic.php?p=200273#p200273
And take a look at the webpage I'm referring to there. :wink:

Re: How can improve speed?

Posted: Tue Oct 01, 2024 11:13 pm
by minimy
Thanks to both for comments and help.
is true, the speed is not bad :lol: