
I've implemented a square radius blurring algorithm (I just made that up, but that is what it's doing

I'm fairly certain that it'll have to be shifted into pure memory management, but I'm not certain how to go about that from PB images - hints please!
Code: Select all
DisableDebugger
Procedure.i Blur(pImageIn.i, pRadius.i)
Protected rv.i = CreateImage(#PB_Any, ImageWidth(pImageIn), ImageHeight(pImageIn))
Average = Pow( ( pRadius * 2 ) + 1, 2)
Dim out.i(ImageWidth(rv) - 1, ImageHeight(rv) - 1)
Protected r.i, g.i, b.i
StartDrawing(ImageOutput(pImageIn))
For ImageOutX = 0 To ImageWidth(rv) - 1
For ImageOutY = 0 To ImageHeight(rv) - 1
r = 0
g = 0
b = 0
colour = 0
For ImageInX = ImageOutX - pRadius To ImageOutX + pRadius
For ImageInY = ImageOutY - pRadius To ImageOutY + pRadius
x = ImageInX
If x < 0
x = 0
EndIf
If x > ImageWidth(rv) - 1
x = ImageWidth(rv) - 1
EndIf
y = ImageInY
If y < 0
y = 0
EndIf
If y > ImageHeight(rv) - 1
y = ImageHeight(rv) - 1
EndIf
colour = Point(x, y)
r + Red(colour)
g + Green(colour)
b + Blue(colour)
Next
Next
out(ImageOutX, ImageOutY) = RGB(r / Average, g / Average, b / Average)
Next
Next
StopDrawing()
StartDrawing(ImageOutput(rv))
For ImageOutX = 0 To ImageWidth(rv) - 1
For ImageOutY = 0 To ImageHeight(rv) - 1
Plot(ImageOutX, ImageOutY, out(ImageOutX, ImageOutY))
Next
Next
StopDrawing()
ProcedureReturn rv
EndProcedure
Procedure.i CaptureScreen(left.l, top.l, Width.l, Height.l, Blur)
#CAPTUREBLT = $40000000
dm.DEVMODE ;structure for CreateDC()
srcDC.l
trgDC.l
BMPHandle.l
srcDC = CreateDC_ ( "DISPLAY" , "" , "" , dm)
trgDC = CreateCompatibleDC_ (srcDC)
BMPHandle = CreateCompatibleBitmap_ (srcDC, Width, Height)
SelectObject_ ( trgDC, BMPHandle)
BitBlt_ ( trgDC, 0, 0, Width, Height, srcDC, left , top, #SRCCOPY|#CAPTUREBLT )
RawImage.i = CreateImage ( #PB_Any ,Width,Height)
StartDrawing ( ImageOutput ( RawImage ))
DrawImage (BMPHandle,0,0)
StopDrawing ()
DeleteDC_ ( trgDC)
ReleaseDC_ ( BMPHandle, srcDC)
rv = Blur(RawImage, Blur)
FreeImage(RawImage)
ProcedureReturn rv
EndProcedure
FormWidth = 0
FormHeight = 0
DesktopCount = ExamineDesktops()
For i = 0 To DesktopCount-1
If FormWidth < DesktopX(i) + DesktopWidth(i)
FormWidth = DesktopX(i) + DesktopWidth(i)
EndIf
If FormHeight < DesktopY(i) + DesktopHeight(i)
FormHeight = DesktopY(i) + DesktopHeight(i)
EndIf
Next
t = ElapsedMilliseconds()
img = CaptureScreen(0, 0, FormWidth, FormHeight, 2) ; blurriness radius of 2
t = ElapsedMilliseconds() - t
OpenWindow(0, 0, 0, FormWidth, FormHeight, "...", #PB_Window_BorderLess )
StickyWindow(0, 1)
CanvasGadget(0, 0, 0, FormWidth, FormHeight)
SetGadgetAttribute(0, #PB_Canvas_Image, ImageID(img))
StartDrawing(CanvasOutput(0))
DrawText(10, 10, Str(t))
StopDrawing()
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_LeftClick
Break
EndSelect
EndSelect
ForEver