; Blur [deluxe] rel 0.02
; Created by Graechan
; Comments directed to http://gimpchat.com or http://gimpscripts.com
;
; License: GPLv3
;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;    (at your option) any later version.
;
;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;    GNU General Public License for more details.
;
;    To view a copy of the GNU General Public License
;    visit: http://www.gnu.org/licenses/gpl.html
;
;
; ------------
;| Change Log |
; ------------ 
; Rel 0.01 - Initial Release
; Rel 0.02 - Shortened menu to only show usible settings
;
(define (script-fu-blur-deluxe image layer type edge)

    (gimp-image-undo-group-start image)
	(gimp-context-push)

 (let* (
        (centre-amt 1)
		(outer-amt 1)
		(t0 outer-amt)
		(t1 (cond ((> type 0) outer-amt)
		          (else 0)))
		(t2 (cond ((> type 1) outer-amt)
		          (else 0)))
		(t3 (cond ((> type 2) outer-amt)
		          (else 0)))
		(matrix (cons-array 25 'long))
		(n (cond ((= type 0) 4)
		         ((= type 1) 8)
				 ((= type 2) 12)
				 ((= type 3) 24)))
		(divisor     (+ (* outer-amt n) centre-amt))
		)

	    
    (aset matrix 0 t3) (aset matrix 1 t3) (aset matrix 2 t2) (aset matrix 3 t3) (aset matrix 4 t3)        
    (aset matrix 5 t3) (aset matrix 6 t1) (aset matrix 7 t0) (aset matrix 8 t1) (aset matrix 9 t3)        
    (aset matrix 10 t2) (aset matrix 11 t0) (aset matrix 12 centre-amt) (aset matrix 13 t0) (aset matrix 14 t2)        
    (aset matrix 15 t3) (aset matrix 16 t1) (aset matrix 17 t0) (aset matrix 18 t1) (aset matrix 19 t3)
    (aset matrix 20 t3) (aset matrix 21 t3) (aset matrix 22 t2) (aset matrix 23 t3) (aset matrix 24 t3)	
	
	
	    (plug-in-convmatrix RUN-NONINTERACTIVE image 
	            layer 
	            25 ;argc-matrix [The number of elements in the following array. Should be always 25.]  
                matrix
                TRUE ;alpha-alg [Enable weighting by alpha channel]
                divisor
                0 ;offset
                5 ;argc-channels [The number of elements in following array. Should be always 5.]
                #(1 1 1 1 0) ;channels [gray? red? green? blue? alpha?]
                edge ;bmode ;[Mode for treating image borders] { EXTEND (0), WRAP (1), CLEAR (2) } 
                )
	
	(gimp-displays-flush)
	(gimp-image-undo-group-end image)
	(gimp-context-pop)
	
 )
)

(script-fu-register "script-fu-blur-deluxe"        		    
  "Blur [deluxe]"
  "Instructions"
  "Graechan"
  "Graechan - http://gimpchat.com"
  "2012"
  "*"
  SF-IMAGE      "image"      0
  SF-DRAWABLE   "drawable"   0
  SF-OPTION "Matrix Type" '("Small" "Medium1" "Medium2" "Large")
  SF-OPTION "Mode for treating image borders" '("EXTEND" "WRAP" "CLEAR")  
)

(script-fu-menu-register "script-fu-blur-deluxe" "<Image>/Filters/Blur")


