Fastest Resize Image?

BlitzMax Forums/BlitzMax Programming/Fastest Resize Image?

Grisu(Posted 2006) [#1]
Hi!

Is there a faster imageresize function than this?

Function ResizeImage:TImage(image:TImage,width,height)
	Local pix:TPixmap=LockImage(image)
	pix=ResizePixmap(pix,width,height)
	UnlockImage(image)	
	Return LoadImage(pix)
End Function


I just want to be sure there isn't as I need every millisecond.... :)

Grisu


TomToad(Posted 2006) [#2]
Every millisecond? That's a lot of resizing. I don't think any function could resize an image that fast. Or if it could resize one, I don't think it would be able to do two. Unless it was a very small image you were trying to resize.

Just tried an experiment using BMax120.png file. Resize at fastest was 2 milliseconds. Slowest was 15, probably during garbage collection. This is on a 2 Ghz system.

Any reason you couldn't use SetScale?


tonyg(Posted 2006) [#3]
Do you need the image physically resized?
Setscale is quicker than resizepixmap.


Drey(Posted 2006) [#4]
maybe he's looking out for ram.


tonyg(Posted 2006) [#5]
Blimey, how did TomToad get in front of me by 9 mins? I am sure there wasn't a response when I responded.
Anyway, think Grisu is saying that every ms is precious rather than wants to resize every ms.


Grisu(Posted 2006) [#6]
My problem is I'm writing a fully resizeable windows gui app.
In this app I have a native 340x340 pixel image displayed in a canvas.
As soon as I resize the window you can see how each element is changed in shape. This looks a bit ugly. So I'm searching for a way to speed this up.

' Done on EVENT_WINDOWSIZE
ClientW=ClientWidth(MyWindow)  
ClientH=ClientHeight(MyWindow)
CanW=(ClientW-800)/2  
CanH=(ClientH-401)/2
' ^^these vars are used more than one time, so I store them in vars

CoverIMG=ResizeImage:TImage(CoverIMG,(340+CanW),(340+CanH))   
SetGadgetShape(MyCanvas:TGadget,ClientW-345-CanW,5,(340+CanW),(340+CanH))
(...setting other shapes...) 


I have uploaded an alpha app, so you can see for yourself.
I'm not that good at explaining.

http://grisu.roxr.com/dfa.zip (2.4 MB)


If it is possible to use setscale for this I'm not sure how to calculate the new image scalefactor so that it fits the canvas size.


ImaginaryHuman(Posted 2006) [#7]
If you don't need it to be bigger than the backbuffer once resized, you can just use DrawImage using SetScale and then GrabImage, it might be faster than doing the pixmap resize.


tonyg(Posted 2006) [#8]
Aha, think I have it
Drawimagerect?
If you use the canvas sizes it should do the trick.


Grisu(Posted 2006) [#9]
Setscale... the problem is how do I calculate the percentage?

sx#=((100/340)*(340+CanW))/100
sy#=((100/340)*(340+CanH))/100

It seems to be faster though I can't calculate the values right. I don't need to grab and create a new image. I think its fast enough to simply scale it every frame.


Drawimagerect won't do. The original size is 340x340, so I could include bigger covers. But 1. that would bloat the exe and 2. the images wound't look any better as they are scaled up.


Yan(Posted 2006) [#10]
Tonyg is correct, you should use DrawImageRect() for this.

Bmax's DrawImageRect() works differently to the other BB versions. It scales the image up or down to fit into the defined rectangle.


Grisu(Posted 2006) [#11]
Ok, well, stupid me. I thought DrawImageRect was like it was in the "old days" with BP.

I simply changed one line of code and it now scales as smooth as silk.

THANKS A LOT EVERYONE!