Warning, /graphics/krita/plugins/python/highpass/high-pass.scm is written in an unsupported language. File is not indexed.

0001 ;high-pass.scm
0002 ; by Rob Antonishen
0003 ; http://ffaat.pointclark.net
0004 
0005 ; Version 1.2 (20120427)
0006 
0007 ; Description
0008 ;
0009 ; This implements a highpass filter using the blur and invert method
0010 ; parameters are blur radius, a preserve colour toggle, and whether to keep the original layer
0011 ;
0012 ; Changes:
0013 ; v1.1 fixes "bug" created by bug fix for gimp 2.6.9 in gimp-histogram
0014 ; v1.2 changed to a different layer blend mode (thanks Blacklemon67) that
0015 ;      has less histogram banding, by eliminating the need for the contrast boost.
0016 ;
0017 
0018 ; License:
0019 ;
0020 ; This program is free software; you can redistribute it and/or modify
0021 ; it under the terms of the GNU General Public License as published by
0022 ; the Free Software Foundation; either version 2 of the License, or
0023 ; (at your option) any later version. 
0024 ;
0025 ; This program is distributed in the hope that it will be useful,
0026 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
0027 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0028 ; GNU General Public License for more details.
0029 ;
0030 ; The GNU Public License is available at
0031 ; http://www.gnu.org/copyleft/gpl.html
0032 
0033 (define (high-pass img inLayer inRadius inMode inKeepOrig)
0034   (let*
0035     (
0036           (blur-layer 0)
0037           (blur-layer2 0)
0038           (working-layer 0)
0039           (colours-layer 0)
0040           (colours-layer2 0)
0041           (orig-name (car (gimp-drawable-get-name inLayer)))
0042     )
0043     ;  it begins here
0044     (gimp-context-push)
0045     (gimp-image-undo-group-start img)
0046         
0047         ;if keep original selected, make a working copy
0048         (if (= inKeepOrig TRUE)
0049       (begin
0050         (set! working-layer (car (gimp-layer-copy inLayer FALSE)))
0051             (gimp-image-add-layer img working-layer -1)
0052                 (gimp-drawable-set-name working-layer "working")
0053           )
0054           (set! working-layer inLayer)  ;else
0055         )   
0056 
0057         (gimp-image-set-active-layer img working-layer)
0058 
0059         ;if keeping colours
0060         (if (or (= inMode 1) (= inMode 3))
0061       (begin
0062         (set! colours-layer (car (gimp-layer-copy inLayer FALSE)))
0063             (gimp-image-add-layer img colours-layer -1)
0064             (gimp-image-lower-layer img colours-layer)  
0065                 (gimp-drawable-set-name colours-layer "colours")
0066                 (gimp-image-set-active-layer img working-layer)
0067           )
0068         )   
0069         
0070     ;if Greyscale, desaturate
0071         (if (or (= inMode 2) (= inMode 3))
0072           (gimp-desaturate working-layer)       
0073         )
0074         
0075         ;Duplicate on top and blur
0076     (set! blur-layer (car (gimp-layer-copy working-layer FALSE)))
0077     (gimp-image-add-layer img blur-layer -1)
0078         (gimp-drawable-set-name blur-layer "blur")
0079 
0080         ;blur
0081     (plug-in-gauss 1 img blur-layer inRadius inRadius 1)        
0082         
0083         (if (<= inMode 3)
0084           (begin
0085         ;v1.2 using grain extract...
0086         (gimp-layer-set-mode blur-layer GRAIN-EXTRACT-MODE)
0087             (set! working-layer (car (gimp-image-merge-down img blur-layer 0)))
0088                 
0089             ; if preserve chroma, change set the mode to value and merge down with the layer we kept earlier.
0090             (if (= inMode 3)
0091           (begin
0092             (gimp-layer-set-mode working-layer VALUE-MODE)
0093                     (set! working-layer (car (gimp-image-merge-down img working-layer 0)))
0094               )
0095             )   
0096 
0097             ; if preserve DC, change set the mode to overlay and merge down with the average colour of the layer we kept earlier.
0098             (if (= inMode 1)
0099           (begin        
0100                 (gimp-context-set-foreground (list 
0101                 (car (gimp-histogram colours-layer HISTOGRAM-RED 0 255)) 
0102                 (car (gimp-histogram colours-layer HISTOGRAM-GREEN 0 255)) 
0103                 (car (gimp-histogram colours-layer HISTOGRAM-BLUE 0 255)))
0104             )
0105                     (gimp-drawable-fill colours-layer FOREGROUND-FILL)
0106             (gimp-layer-set-mode working-layer OVERLAY-MODE)
0107                     (set! working-layer (car (gimp-image-merge-down img working-layer 0)))
0108               )
0109             )   
0110           )
0111           (begin  ;else 4=redrobes method
0112           
0113             (gimp-image-set-active-layer img blur-layer)  ;top layer
0114                 
0115                 ;get the average colour of the input layer
0116             (set! colours-layer (car (gimp-layer-copy inLayer FALSE)))
0117             (gimp-image-add-layer img colours-layer -1)
0118                 (gimp-drawable-set-name colours-layer "colours")
0119 
0120             (gimp-context-set-foreground (list 
0121             (car (gimp-histogram colours-layer HISTOGRAM-RED 0 255)) 
0122             (car (gimp-histogram colours-layer HISTOGRAM-GREEN 0 255)) 
0123             (car (gimp-histogram colours-layer HISTOGRAM-BLUE 0 255)))
0124         )
0125                 (gimp-drawable-fill colours-layer FOREGROUND-FILL)
0126             (gimp-image-set-active-layer img colours-layer)
0127 
0128         ;copy the solid colour layer
0129                 (set! colours-layer2 (car (gimp-layer-copy colours-layer FALSE)))
0130         (gimp-image-add-layer img colours-layer2 -1)            
0131         (gimp-layer-set-mode colours-layer SUBTRACT-MODE)
0132             (gimp-image-set-active-layer img colours-layer2)
0133 
0134                 ;copy the blurred layer
0135                 (set! blur-layer2 (car (gimp-layer-copy blur-layer FALSE)))
0136         (gimp-image-add-layer img blur-layer2 -1)               
0137         (gimp-layer-set-mode blur-layer2 SUBTRACT-MODE)
0138                 
0139                 (set! blur-layer (car (gimp-image-merge-down img colours-layer 0)))
0140                 (set! blur-layer2 (car (gimp-image-merge-down img blur-layer2 0)))
0141                 
0142         (gimp-layer-set-mode blur-layer SUBTRACT-MODE)
0143         (gimp-layer-set-mode blur-layer2 ADDITION-MODE)
0144                 
0145             (set! working-layer (car (gimp-image-merge-down img blur-layer 0)))
0146             (set! working-layer (car (gimp-image-merge-down img blur-layer2 0)))
0147         
0148           )
0149         )
0150         
0151         (if (= inKeepOrig TRUE)
0152       (gimp-drawable-set-name working-layer (string-append orig-name " high pass"))
0153       (gimp-drawable-set-name working-layer orig-name)
0154         )   
0155         
0156         ;done
0157         (gimp-progress-end)
0158         (gimp-image-undo-group-end img)
0159         (gimp-displays-flush)
0160         (gimp-context-pop)
0161   )
0162 )
0163 
0164 (script-fu-register "high-pass"
0165                             "<Image>/Filters/Generic/_High Pass Filter"
0166                     "Basic High Pass Filter."
0167                     "Rob Antonishen"
0168                     "Rob Antonishen"
0169                     "April 2012"
0170                     "RGB* GRAY*"
0171                     SF-IMAGE      "image"      0
0172                     SF-DRAWABLE   "drawable"   0
0173                     SF-ADJUSTMENT "Filter Radius" '(10 2 200 1 10 0 0)
0174                     SF-OPTION     "Mode" '("Colour" "Preserve DC" "Greyscale" "Greyscale, Apply Chroma" "Redrobes")
0175                                     SF-TOGGLE     "Keep Original Layer?" TRUE
0176 )