[bb] OIL painting by PantsOn [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:39

Previous topic - Next topic

BlitzBot

Title : OIL painting
Author : PantsOn
Posted : 1+ years ago

Description : v3. used banks instead of image. less error checking
3x quicker than v2
[img]www.pantson.com/examples/temp.html">
usage
new_img = OILimage(orig_img)
new_img = OILimage(orig_img,11)

the higher the brush_detail the larger the brush and more time it takes. defaults to 5 [/i]

Code :
Code (blitzbasic) Select
Dim OILcol(1,0)
; OILimage - Rich Hanson (PantsOn Software)
;            v3
Function OILimage(image_img,brush_detail=5)
; set variables
iw = ImageWidth(image_img)
ih = ImageHeight(image_img)
output_img = CreateImage(iw,ih)
ib = ImageBuffer(image_img)
ob = ImageBuffer(output_img)
scan = brush_detail / 2
brush_detail2 = brush_detail*brush_detail

; create temp bank for pic data
; bank is larger than needed so no need to error check later
LockBuffer ib
tmp_bnk = CreateBank(4*(iw+brush_detail)*(ih+brush_detail))
For x = 0 To iw - 1
For y = 0 To ih - 1
PokeInt tmp_bnk,(x+scan)*4 + (y+scan)*(iw+brush_detail)*4, ReadPixelFast(x,y,ib) And %00000000111111001111110011111100
Next
Next
UnlockBuffer ib

; convert pic data
LockBuffer ob
For x = 0 To iw - 1
For y = 0 To ih - 1

Dim OILcol(1,brush_detail2)
count = 0

; scan around pixel. No more error checking
For x1 = -scan To scan
For y1 = -scan To scan
; read values from bank rather than screen
c = PeekInt(tmp_bnk,(x+x1+scan)*4 + (y+y1+scan)*(iw+brush_detail)*4)
; stpre populatiry of colour (needs opt)
For i = 0 To count
If OILcol(0,i) = c
OILcol(1,i) = OILcol(1,i) + 1
i = brush_detail2 + 2
EndIf
Next
If i = count + 1
OILcol(0,count) = c
OILcol(1,count) = 1
count = count + 1
EndIf
Next
Next

; find highest most common colour (needs opt)
high = 0
For a = 0 To brush_detail2
If OILcol(1,a) > high
OILcolour = OILcol(0,a)
high = OILcol(1,a)
EndIf
Next

WritePixelFast x,y,OILcolour,ob

Dim OILcol(0,0)
Next
Next
UnlockBuffer ob

; free temp stuff
FreeBank tmp_bnk
Dim OILcol(0,0)

; return new piccy
Return output_img
End Function


Comments :


PsychicParrot(Posted 1+ years ago)

 Nice effect, Rich ... now if I can get it running 3d AND oil painting ;)


PantsOn(Posted 1+ years ago)

 I've been thinking about a 3d filter with the above effect..Getting some strange effects, but getting there.. (don't know how fast it'll be though)


RoofPig(Posted 1+ years ago)

 That's really cool. I always wanted to do something like that but was never sure how. I tried your code in my game so it applies the filter to every frame of the 3d scene in realtime and was only able to get around 4fps at 640x480x16. If I shrank the viewport to 320x240 it averaged about 10fps. I'm on a laptop with a P4 2.6ghz GeForce4 Go, 512mb. With the effect off, the framerate is usually > 100 at 1024x768x32.


PantsOn(Posted 1+ years ago)

 I'm rewriting the algorithm for 3D.. won't be as good quality.. some interesting results so far..


RifRaf(Posted 1+ years ago)

 hows the 3d version comming ?


Doggie(Posted 1+ years ago)

 I just now after all these years noticed your company name.So, did it ever get off the ground????;)