ResizeImage() slow under Linux?

Linux specific forum
Hexagon
User
User
Posts: 26
Joined: Sun Mar 13, 2005 9:52 pm
Location: Norway

ResizeImage() slow under Linux?

Post by Hexagon »

I'm doing a program which should resize big pictures for on screen view, and keep the original picture in memory. My computer is equipped with AMD XP2100 cpu and 1,25GB ram ticking at 333MHz. I'm running PB 4.10 on Ubuntu 7.10. My code gives these results:
  • Copytime when initializing using CopyImage()
    0
    Rezise time when initializing:
    5091
    Copytime within Redraw() using GrabImage()
    0
    Rezise time within Redraw():
    6442
    Copytime within Redraw() using GrabImage()
    0
    Rezise time within Redraw():
    8048
    Copytime within Redraw() using GrabImage()
    0
    Rezise time within Redraw():
    7997
Insane results. 5-8 seconds on each resize. The windows greys out in Ubuntu before the picture is resized. On the very same machine running Windows XP and PB 4.10:
  • Copytime when initializing using CopyImage()
    235
    Rezise time when initializing:
    281
    Copytime within Redraw() using GrabImage()
    94
    Rezise time within Redraw():
    281
    Copytime within Redraw() using GrabImage()
    94
    Rezise time within Redraw():
    281
It's still slow, but very fast compared to Ubuntu. How come, and how can I speed it up?
I don't know why, but neither CopyImage nor GrabImage() use more than 1ms to execute in Ubuntu. Can this be correct?
The rezise time is not consistant on Ubuntu. It varies several seconds. After running the program, the window cannot be closed for the first 20-30 seconds, as the Redraw() procedure is always called 3 times when started. "Only" 2 times in WinXP. Can I avoid this?

Code: Select all

Procedure Redraw() 
If IsImage(1) 
  FreeImage(1) 
EndIf 
tt=ElapsedMilliseconds() 
GrabImage(0, 1, 0, 0, ImageWidth(0), ImageHeight(0)) 
tt-ElapsedMilliseconds() 
t=ElapsedMilliseconds() 
ResizeImage(1,WindowWidth(0),WindowHeight(0)) 
t-ElapsedMilliseconds() 
If SetGadgetState(0, ImageID(1)) =0 
  Debug "Couldn't set gadget image" 
  End 
EndIf 
Debug "Copytime within Redraw() using GrabImage()" 
Debug -tt 
Debug "Rezise time within Redraw():" 
Debug -t 
EndProcedure 
Procedure LoadImg() 
x = 2399 
y = 3349 
If CreateImage(0,x,y,32) = 0 
  Debug "Couldn't create image" 
  End 
EndIf 
If StartDrawing(ImageOutput(0))=0 
  Debug "Could'nt draw on image" 
  End 
EndIf 
Box(x*0.1,y*0.1, x*0.8,y*0.8,$440000) 
xc=1 
yc=1 
c=Round(x*0.199,0) 
xstep=Round(x/c,0) 
ystep=Round(y/c,0) 
For co=1 To c 
  LineXY(1,yc,xc,(y-1),$FFFFFF) 
  LineXY(xc,1,(x-1),yc,$FFFFFF) 
  xc=xc+xstep 
  yc=yc+ystep 
Next co 
StopDrawing() 
EndProcedure 
LoadImg() 
WinWidth = 500 
WinHeight = Round((ImageHeight(0)/ImageWidth(0))*winwidth,0) 
tt=ElapsedMilliseconds() 
CopyImage(0,1) 
tt-ElapsedMilliseconds() 
t=ElapsedMilliseconds() 
ResizeImage(1,WinWidth,WinHeight) 
t-ElapsedMilliseconds() 
Debug "Copytime when initializing using CopyImage()" 
Debug -tt 
Debug "Rezise time when initializing:" 
Debug -t 
If OpenWindow(0, 0, 0, WinWidth, WinHeight, "Window for picture output", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) = 0 
  Debug "Could'nt open window" 
End 
EndIf 

ImageGadget(0,0,0,100,100,ImageID(1)) 
Redraw() 

Repeat 
  Event = WaitWindowEvent() 
  If Event = #PB_Event_CloseWindow 
    End 
  Else 
    If event = #PB_Event_SizeWindow 
      Redraw() 
    EndIf 
  EndIf 
ForEver
Irene
Enthusiast
Enthusiast
Posts: 461
Joined: Thu Oct 04, 2007 12:41 pm

Post by Irene »

Hi!

First off I would like to note that testing the speed of a procedure or function should be done with the Debugger off; instead write all debugging information to a text file (for example).

Slight modifications in your code to make it write to a text file:

Code: Select all

DebugFilename$ = "/home/mirini/debug-log" ; Change file path to home folder or Desktop, etc..
Procedure DebugFile(Text$)
 WriteStringN(0, Text$)
 ; Not the very best example, but with the Debugger on all speed tests are inaccurate.
 ; This needs optimizing, but I did not bother ^_^
 ; Cheers, Irene
EndProcedure
Procedure Redraw()
If IsImage(1)
  FreeImage(1)
EndIf
tt=ElapsedMilliseconds()
GrabImage(0, 1, 0, 0, ImageWidth(0), ImageHeight(0))
tt-ElapsedMilliseconds()
t=ElapsedMilliseconds()
ResizeImage(1,WindowWidth(0),WindowHeight(0))
t-ElapsedMilliseconds()
If SetGadgetState(0, ImageID(1)) =0
  DebugFile("Couldn't set gadget image")
  End
EndIf
DebugFile("Copytime within Redraw() using GrabImage()")
DebugFile(Str(-tt))
DebugFile("Rezise time within Redraw():")
DebugFile(Str(-t))
EndProcedure
Procedure LoadImg()
x = 2399
y = 3349
If CreateImage(0,x,y,32) = 0
  DebugFile("Couldn't create image")
  End
EndIf
If StartDrawing(ImageOutput(0))=0
  DebugFile("Could'nt draw on image")
  End
EndIf
Box(x*0.1,y*0.1, x*0.8,y*0.8,$440000)
xc=1
yc=1
c=Round(x*0.199,0)
xstep=Round(x/c,0)
ystep=Round(y/c,0)
For co=1 To c
  LineXY(1,yc,xc,(y-1),$FFFFFF)
  LineXY(xc,1,(x-1),yc,$FFFFFF)
  xc=xc+xstep
  yc=yc+ystep
Next co
StopDrawing()
EndProcedure
If CreateFile(0, DebugFilename$)
 LoadImg()
 WinWidth = 500
 WinHeight = Round((ImageHeight(0)/ImageWidth(0))*winwidth,0)
 tt=ElapsedMilliseconds()
 CopyImage(0,1)
 tt-ElapsedMilliseconds()
 t=ElapsedMilliseconds()
 ResizeImage(1,WinWidth,WinHeight)
 t-ElapsedMilliseconds()
 DebugFile("Copytime when initializing using CopyImage()")
 DebugFile(Str(-tt))
 DebugFile("Rezise time when initializing:")
 DebugFile(Str(-t))
 If OpenWindow(0, 0, 0, WinWidth, WinHeight, "Window for picture output", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) = 0
   DebugFile("Could'nt open window")
 End
 EndIf

 ImageGadget(0,0,0,100,100,ImageID(1))
 Redraw()

 Repeat
   Event = WaitWindowEvent()
   If Event = #PB_Event_CloseWindow
     DebugFile("Stuff ended")
     CloseFile(0)
     End
   Else
     If event = #PB_Event_SizeWindow
       Redraw()
     EndIf
   EndIf
 ForEver
EndIf
Hmm but results are still not cool (PureBasic 4.10, Arch Linux):
Copytime when initializing using CopyImage()
0
Rezise time when initializing:
2037
Copytime within Redraw() using GrabImage()
0
Rezise time within Redraw():
1983
Stuff ended
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

Interesting:

Original on my AMD 650 / OSS10.3 (Slow machines are great to test such stuff ;)):
Copytime when initializing using CopyImage()
0
Rezise time when initializing:
14322
Copytime within Redraw() using GrabImage()
0
Rezise time within Redraw():
14981
Copytime within Redraw() using GrabImage()
0
Rezise time within Redraw():
17312
Stuff ended
Significant speedup once i set the Resolution
to my Desktopsize: 2048x1536 compared to 3349x2399
Copytime when initializing using CopyImage()
0
Rezise time when initializing:
5850
Copytime within Redraw() using GrabImage()
0
Rezise time within Redraw():
6385
Copytime within Redraw() using GrabImage()
0
Rezise time within Redraw():
4466
Stuff ended
Now interestingly using: 2048x2048:
Copytime when initializing using CopyImage()
0
Rezise time when initializing:
2998
Copytime within Redraw() using GrabImage()
1
Rezise time within Redraw():
3394
Stuff ended
so.. euh .. something is silly here. fr34k/fred, are the resizeing f8unctions under linux the same as on win or is under win GDI used ?

Thalius
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
Post Reply