March 01, 2021, 10:49:00 PM

Author Topic: [bb] OIL painting by PantsOn [ 1+ years ago ]  (Read 446 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] OIL painting by PantsOn [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
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
Code: [Select]
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
  1. Dim OILcol(1,0)
  2. ; OILimage - Rich Hanson (PantsOn Software)
  3. ;            v3
  4. Function OILimage(image_img,brush_detail=5)
  5.         ; set variables
  6.         iw = ImageWidth(image_img)
  7.         ih = ImageHeight(image_img)
  8.         output_img = CreateImage(iw,ih)
  9.         ib = ImageBuffer(image_img)
  10.         ob = ImageBuffer(output_img)
  11.         scan = brush_detail / 2
  12.         brush_detail2 = brush_detail*brush_detail
  13.        
  14.         ; create temp bank for pic data
  15.         ; bank is larger than needed so no need to error check later
  16.         LockBuffer ib
  17.         tmp_bnk = CreateBank(4*(iw+brush_detail)*(ih+brush_detail))
  18.         For x = 0 To iw - 1
  19.                 For y = 0 To ih - 1
  20.                         PokeInt tmp_bnk,(x+scan)*4 + (y+scan)*(iw+brush_detail)*4, ReadPixelFast(x,y,ib) And %00000000111111001111110011111100
  21.                 Next
  22.         Next
  23.         UnlockBuffer ib
  24.        
  25.         ; convert pic data
  26.         LockBuffer ob
  27.         For x = 0 To iw - 1
  28.                 For y = 0 To ih - 1
  29.                
  30.                         Dim OILcol(1,brush_detail2)
  31.                         count = 0
  32.                        
  33.                         ; scan around pixel. No more error checking
  34.                         For x1 = -scan To scan
  35.                                 For y1 = -scan To scan                                         
  36.                                         ; read values from bank rather than screen
  37.                                         c = PeekInt(tmp_bnk,(x+x1+scan)*4 + (y+y1+scan)*(iw+brush_detail)*4)
  38.                                         ; stpre populatiry of colour (needs opt)
  39.                                         For i = 0 To count
  40.                                                 If OILcol(0,i) = c
  41.                                                         OILcol(1,i) = OILcol(1,i) + 1
  42.                                                         i = brush_detail2 + 2
  43.                                                 EndIf
  44.                                         Next
  45.                                         If i = count + 1
  46.                                                 OILcol(0,count) = c
  47.                                                 OILcol(1,count) = 1
  48.                                                 count = count + 1
  49.                                         EndIf                  
  50.                                 Next
  51.                         Next
  52.                        
  53.                         ; find highest most common colour (needs opt)
  54.                         high = 0
  55.                         For a = 0 To brush_detail2
  56.                                 If OILcol(1,a) > high
  57.                                         OILcolour = OILcol(0,a)
  58.                                         high = OILcol(1,a)
  59.                                 EndIf
  60.                         Next
  61.                        
  62.                         WritePixelFast x,y,OILcolour,ob
  63.                        
  64.                         Dim OILcol(0,0)
  65.                 Next
  66.         Next
  67.         UnlockBuffer ob
  68.        
  69.         ; free temp stuff
  70.         FreeBank tmp_bnk
  71.         Dim OILcol(0,0)
  72.        
  73.         ; return new piccy
  74.         Return output_img
  75. 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????;)


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal