Hi fellow dudes,
I've been working on an Image Resize Routine in Freebasic with TinyPTC. But am having big troubles & problems with using floats / decimal sizes. And would love some help on fixing it please.
The code below, as you'll see works well with integer sizes. And as for the float method looks cack and gappy.
'
' Resize Image Routine in Freebasic and TinyPTC.
' By Clyde Sometime And In A Distant Land In January '07
'
Option Explicit
Option Static
#Include Once "tinyptc.bi"
#Include Once "windows.bi"
#Include Once "crt.bi"
Const XRES=640
Const YRES=480
Const XRES2=XRES/2
Const YRES2=YRES/2
Const ARES=XRES*YRES
Dim Shared ScreenBuffer(ARES)
Dim Shared ImageData(128,128)
Dim Shared ImageW
Dim Shared ImageH
Declare Sub DrawImageResized( ByVal PosX As Single, ByVal PosY As Single, ByVal SizeX As Single, ByVal SizeY As Single )
Declare Sub FeedPixels( Byval x As Integer, Byval y As Integer, Byval col As Integer)
Declare Sub InitializeExample()
Declare Sub RunExample()
Declare Function KeyHit( ByVal KeyChar As Integer ) As Integer
InitializeExample()
RunExample()
PTC_Close()
End
Sub DrawImageResized( ByVal PosX As Single, ByVal PosY As Single, ByVal SizeX As Single, ByVal SizeY As Single )
Dim col
Dim As Single x,y
Dim As Single xx,yy
For y=0 to ImageW-1
For x=0 to ImageH-1
Col=ImageData(x,y)
For yy=0 To SizeY-1
For xx=0 To SizeX-1
FeedPixels( (x*SizeX)+(PosX-xx),(y*SizeY)+(PosY-yy),Col)
Next
Next
Next
Next
End sub
Sub FeedPixels( Byval x As Integer, Byval y As Integer, Byval col As Integer)
If X>0 and X<XRES-1 and Y>0 and Y<YRES-1 Then
ScreenBuffer(Y * XRES + X) = col
End If
End Sub
Sub InitializeExample()
Dim x,y
If( ptc_open( "Image Resizer Example", XRES, YRES ) = 0 ) Then
End -1
End If
'
' Create test image.
'
ImageW=32 : ImageH=32
For y=0 To ImageH-1
For x=0 To ImageW-1
ImageData(x,y)=&HFF00FF
Next
Next
End Sub
Sub RunExample()
Dim As Integer SizeX1, SizeY1
Dim As Single SizeX2, SizeY2
While KeyHit(27)<>TRUE
SizeX1=2
SizeY1=3
SizeX2=2.25
SizeY2=3.75
DrawImageResized(050,050,SizeX1,SizeY1)
DrawImageResized(150,050,SizeX2,SizeY2)
PTC_Update @ScreenBuffer(0)
Erase ScreenBuffer
Wend
End Sub
Function KeyHit( ByVal KeyChar As Integer ) As Integer
If (GetAsyncKeyState(KeyChar) AND 32768) Then
Return True
Else
Return False
End if
End Function
Cheers and huge thanks for your help,
Clyde.