Ooops
March 01, 2021, 10:48:35 PM

Author Topic: [bb] Blur Function by xlsior [ 1+ years ago ]  (Read 417 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Blur Function by xlsior [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Blur Function
Author : xlsior
Posted : 1+ years ago

Description : Blurs an image either horizonally, vertically, or both

Code :
Code: BlitzBasic
  1. ;
  2. ; Blur -- Horizontal and Vertical Blur routines
  3. ; 11/23/2003, by Marc van den Dikkenberg / xlsior
  4. ;
  5. ; Usage: HorizontalBlur(perct#)
  6. ;        Verticalblur(perct#)
  7. ;        perct# is the level of the effect, and expects a value between 50 and 99.
  8. ;    
  9. ; The color value of a pixel is smeared onto its neighbours - the higher the
  10. ; value, the more it gets smeared.
  11. ;
  12. ; To get a bi-directional blur effect, simply call the horizontal and Vertical
  13. ; blur functions directly after each other, before performing a 'flip' operation.
  14. ;      
  15. ; Tidbit: These two functions were created entirely by accident. I was working
  16. ; on my Monochrome() function when I accidentally forgot to declare a set of
  17. ; placeholder variables, and color information accidentally got passed on to
  18. ; the next pixel. Oh, well - maybe someone can use them.
  19. ;
  20.  
  21. Graphics 640,480,16,2
  22. SetBuffer BackBuffer()
  23. img%=LoadImage("monkey4.jpg")
  24.  
  25. For t=50 To 100 Step 5
  26.    DrawImage img%,0,0
  27.    HorizontalBlur(t)
  28.    VerticalBlur(t)
  29.    Flip
  30.    If KeyDown(1) Then End
  31. Next
  32.  
  33. WaitKey()
  34. End
  35.  
  36.  
  37. Function HorizontalBlur(perct#)
  38.    desr=0:desg=0:desb=0
  39.    If perct#<50 Then perct#=50
  40.    If perct#>99 Then perct#=99
  41.    SetBuffer BackBuffer()
  42.    LockBuffer
  43.    For y=0 To 479
  44.       For x=0 To 639
  45.          temp1=ReadPixel(x,y)
  46.          orgb=(temp1 And $FF)
  47.          orgg=(temp1 And $FF00) Shr 8
  48.          orgr=(temp1 And $FF0000) Shr 16
  49.          desr=orgr*(1-(perct#/100))+desr*(perct#/100)
  50.          desg=orgg*(1-(perct#/100))+desg*(perct#/100)
  51.          desb=orgb*(1-(perct#/100))+desb*(perct#/100)
  52.          WritePixel x,y,desb+(desg Shl 8)+(desr Shl 16)
  53.       Next
  54.    Next
  55.    UnlockBuffer
  56. End Function
  57.  
  58. Function VerticalBlur(perct#)
  59.    desr=0:desg=0:desb=0
  60.    If perct#<50 Then perct#=50
  61.    If perct#>99 Then perct#=99
  62.    SetBuffer BackBuffer()
  63.    LockBuffer
  64.    For x=0 To 639
  65.       For y=0 To 479
  66.          temp1=ReadPixel(x,y)
  67.          orgb=(temp1 And $FF)
  68.          orgg=(temp1 And $FF00) Shr 8
  69.          orgr=(temp1 And $FF0000) Shr 16
  70.          desr=orgr*(1-(perct#/100))+desr*(perct#/100)
  71.          desg=orgg*(1-(perct#/100))+desg*(perct#/100)
  72.          desb=orgb*(1-(perct#/100))+desb*(perct#/100)
  73.          WritePixel x,y,desb+(desg Shl 8)+(desr Shl 16)
  74.       Next
  75.    Next
  76.    UnlockBuffer
  77. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal