I just did an outline function for someone else. It could probably be optimized somehow, but it needed to be clear to the receiver what was going on and it gets the job done. Example usage is included in code.
SuperStrict
Graphics 640,480
' create a pixmap
Local tmpPix:TPixmap = CreatePixmap(64,64,PF_RGBA8888)
' clear the pixmap
ClearPixels(tmpPix)
' draw a square and X into pixmap
Local color:Int = $FF88FF00
For Local i:Int = 0 To 55
WritePixel(tmpPix,4+i,4,color)
WritePixel(tmpPix,4+i,59,color)
WritePixel(tmpPix,4,4+i,color)
WritePixel(tmpPix,59,4+i,color)
WritePixel(tmpPix,4+i,4+i,color)
WritePixel(tmpPix,59-i,4+i,color)
Next
' convert pixmap to an image
Local tmpImg:TImage = LoadImage(tmpPix,0)
' create a new image with outlines
Local tmpImg2:TImage = outline(tmpImg,2,128)
' clear the screen
Cls
' draw the images
DrawImage(tmpImg,256,256)
DrawImage(tmpImg2,256+64,256)
' show the screen
Flip
' wait for a keypress
WaitKey
' end
End
Function outline:TImage(img:TImage,thickness:Int=1,dilute:Int=0)
' create pixmap from image
Local scrPix:TPixmap = LockImage(img,0)
' get pointer to pixmap pixels
Local scrPtr:Byte Ptr = PixmapPixelPtr(scrPix,0,0)
' copy pixmap to temp pixmap
Local tmpPix:TPixmap = CopyPixmap(scrPix)
' get pointer to temp pixmap pixels
Local tmpPtr:Byte Ptr = PixmapPixelPtr(tmpPix,0,0)
' get widht and height of pixmap
Local w:Int = tmpPix.width
Local h:Int = tmpPix.height
' define local variables
Local r:Int,g:Int,b:Int
Local dx:Int,dy:Int,x:Int,y:Int
Local thick:Int
' draw outlines
For thick = thickness To 1 Step -1
For dy = -thick To thick
For dx = -thick To thick
For y = 0 To h-1
' first bounds check
If y+dy > -1 And y+dy < h Then
For x = 0 To w-1
' second bounds check
If x+dx > -1 And x+dx < w Then
r = scrPtr[x*4+y*4*w]-dilute
g = scrPtr[x*4+y*4*w+1]-dilute
b = scrPtr[x*4+y*4*w+2]-dilute
If r < 0 Then r = 0
If g < 0 Then g = 0
If b < 0 Then b = 0
' check to see if there are pixels
If r+g+b <> $00000000 Then
tmpPtr[(x+dx)*4+(y+dy)*4*w] = r
tmpPtr[(x+dx)*4+(y+dy)*4*w+1] = g
tmpPtr[(x+dx)*4+(y+dy)*4*w+2] = b
tmpPtr[(x+dx)*4+(y+dy)*4*w+3] = $FF
End If
End If
Next
End If
Next
Next
Next
dilute :/ 2
Next
' draw original ontop of outlines
For y = 0 To h-1
For x = 0 To w-1
r = scrPtr[x*4+y*4*w]
g = scrPtr[x*4+y*4*w+1]
b = scrPtr[x*4+y*4*w+2]
If r+g+b <> $00000000 Then
tmpPtr[x*4+y*4*w] = r
tmpPtr[x*4+y*4*w+1] = g
tmpPtr[x*4+y*4*w+2] = b
tmpPtr[x*4+y*4*w+3] = $FF
End If
Next
Next
' return pixmap converted to image
Return LoadImage(tmpPix,0)
EndFunction