No worries mate.
Looking through and trying your original routine you posted, theres not anything wrong with it. It does the job nicely, and it ran pretty quick on my machine too with an 800x600 image.
But you will get faster per pixel effects in lower resolutions / smaller image sizes. I've not changed a busting lot from the way you were cleverly working out the blur and avoiding the blur fade effect; which I kept getting from my spin on things.
The following routine has 3 different sized images that you can toggle by press + / -, to change the blur rate use the right and left mouse. Using MouseZ was causing a few errors in your original, so I opted for mouse buttons instead. From this you'll be able to see the difference in blurring different sized images.
;
; Ever so slightly adapted Blur Example.
; By Clyde For Paul.
;
Const XRES=800
Const YRES=600
Graphics XRES,YRES,32,0
SetBuffer BackBuffer()
Const MAXIMAGES=3
Dim ImageData( XRES, YRES, MAXIMAGES )
Dim ImageW ( MAXIMAGES ), ImageH ( MAXIMAGES )
Dim CenterX ( MAXIMAGES ), CenterY ( MAXIMAGES )
Dim BlurredImage( MAXIMAGES )
Global BlurRate=0
Global ImageNum
;
; Prepare Images & Data.
;
LoadImages( "Media\a-800-600.jpg" )
LoadImages( "Media\a-800-600.jpg",1,640,480 )
LoadImages( "Media\a-800-600.jpg",2,320,240 )
For create=0 To MaxImages-1
BlurImage( 0,Create )
Next
While Not KeyHit(1)
Cls
If BlurRate<000 Then BlurRate=000
;
; Right Mouse Button.
;
If MouseHit(1) Then
BlurRate=BlurRate+1
BlurImage( BlurRate, ImageNum )
End If
;
; Left Mouse Button.
;
If MouseHit(2) Then
BlurRate=BlurRate+1
If BlurRate>100 Then BlurRate=100
BlurImage( BlurRate, ImageNum )
End If
;
; Minus Key.
;
If KeyHit(12) Then
ImageNum=ImageNum-1
If ImageNum<0 Then ImageNum=0
BlurImage( BlurRate, ImageNum )
End If
;
; Plus Key.
;
If KeyHit(13) Then
ImageNum=ImageNum+1
If ImageNum>MAXIMAGES-1 Then ImageNum=MAXIMAGES-1
BlurImage( BlurRate, ImageNum )
End If
;
; Draw The image with Blurring.
;
DrawImage BlurredImage( ImageNum ), CenterX( ImageNum ), CenterY( ImageNum )
;
; Display Blur Rating.
;
Color 0,0,0
Text CenterX( ImageNum )+1, CenterY( ImageNum )+1, "Blur Rate:"+BlurRate+" ImageNum:"+ImageNum
Flip
Wend
;
; Free Images From Memory.
;
For Free=0 To MAXIMAGES-1
FreeImage BlurredImage( Free )
Next
End
Function LoadImages( FileName$, Num=0, SizeX=XRES, SizeY=YRES )
Local Image
If FileType( FileName$ )=1
Image=LoadImage(FileName$)
ResizeImage Image,SizeX,SizeY
ImageW( Num )=ImageWidth ( Image )
ImageH( Num )=ImageHeight( Image )
CenterX( Num )=(( XRES/2 ) - ( ImageW( Num )/2))
CenterY( Num )=(( YRES/2 ) - ( ImageH( Num )/2))
BlurredImage( Num )=CreateImage( ImageW( Num ), ImageH( Num ))
LockBuffer ImageBuffer( Image )
For y=0 To ImageH( Num )-1
For x=0 To ImageW( Num )-1
ImageData(x,y,Num)=ReadPixelFast(x,y,ImageBuffer( Image )) And $FFFFFF
Next
Next
UnlockBuffer ImageBuffer( Image )
FreeImage Image
Else
RuntimeError("File: "+FileName$+" not present.")
End If
End Function
Function BlurImage( Rate=0, ImageNum=0 )
Local x,y,ux,uy,R,G,B,tmp,col
LockBuffer ImageBuffer( BlurredImage( ImageNum ))
For y=0 To ImageH( ImageNum )-1
For x=0 To ImageW( ImageNum )-1
R =0
G =0
B =0
tmp =0
For uy=y-Rate To y+Rate
For ux=x-Rate To x+Rate
If ux=>0 And ux=<ImageW( ImageNum )-1 And uy=>0 And uy=<ImageH( ImageNum )-1
R=R+(( ImageData( ux, uy, ImageNum ) Shr 16) And $FF)
G=G+(( ImageData( ux, uy, ImageNum ) Shr 8 ) And $FF)
B=B+(( ImageData( ux, uy, ImageNum ) Shr 0 ) And $FF)
tmp=tmp+1
EndIf
Next
Next
R=R/tmp
G=G/tmp
B=B/tmp
Col=(R Shl 16) Or (G Shl 8) Or B
If Col<>0 Then
WritePixelFast x, y, Col, ImageBuffer( BlurredImage( ImageNum ))
End If
Next
Next
UnlockBuffer ImageBuffer( BlurredImage( ImageNum ))
End Function
Also a good tip, with Blitz it has a plus side and can easily load in png's without the need for a huge amount of code / or external dlls, like Freebasic would need; so if you can save as them then I'd advise you to use them as they will make for much smaller media for when it comes to distributing later.
Also try out upx ( which there's a few posts about it here - try the search for them, if you cant find them then I'll take alook for them ) on your executables as they'll be greatly reduced.
Your doing great guns Paul dude, and I hope my slightly changed routine helps you with this and gives you some ideas for future stuff.
Cheers and all the very best,
Clyde.