"Fossies" - the Fresh Open Source Software Archive

Member "gimp-2.10.28/plug-ins/script-fu/scripts/addborder.scm" (14 Sep 2021, 6008 Bytes) of package /linux/misc/gimp-2.10.28.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "addborder.scm": 2.99.4_vs_2.99.6.

    1 ; GIMP - The GNU Image Manipulation Program
    2 ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
    3 ;
    4 ; This program is free software: you can redistribute it and/or modify
    5 ; it under the terms of the GNU General Public License as published by
    6 ; the Free Software Foundation; either version 3 of the License, or
    7 ; (at your option) any later version.
    8 ;
    9 ; This program is distributed in the hope that it will be useful,
   10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
   11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12 ; GNU General Public License for more details.
   13 ;
   14 ; You should have received a copy of the GNU General Public License
   15 ; along with this program.  If not, see <https://www.gnu.org/licenses/>.
   16 ;
   17 ; Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
   18 ;
   19 ; Version 0.2 10.6.97 Changed to new script-fu interface in 0.99.10
   20 
   21 ; Delta the color by the given amount. Check for boundary conditions
   22 ; If < 0 set to zero
   23 ; If > 255 set to 255
   24 ; Return the new value
   25 
   26 (define (script-fu-addborder aimg adraw xsize ysize color dvalue)
   27 
   28   (define (deltacolor col delta)
   29     (let* ((newcol (+ col delta)))
   30       (if (< newcol 0) (set! newcol 0))
   31       (if (> newcol 255) (set! newcol 255))
   32       newcol
   33     )
   34   )
   35 
   36   (define (adjcolor col delta)
   37     (mapcar (lambda (x) (deltacolor x delta)) col)
   38   )
   39 
   40   (define (gen_top_array xsize ysize owidth oheight width height)
   41     (let* ((n_array (cons-array 10 'double)))
   42       (aset n_array 0 0 )
   43       (aset n_array 1 0 )
   44       (aset n_array 2 xsize)
   45       (aset n_array 3 ysize)
   46       (aset n_array 4 (+ xsize owidth))
   47       (aset n_array 5 ysize)
   48       (aset n_array 6 width)
   49       (aset n_array 7 0 )
   50       (aset n_array 8 0 )
   51       (aset n_array 9 0 )
   52       n_array)
   53   )
   54 
   55   (define (gen_left_array xsize ysize owidth oheight width height)
   56     (let* ((n_array (cons-array 10 'double)))
   57       (aset n_array 0 0 )
   58       (aset n_array 1 0 )
   59       (aset n_array 2 xsize)
   60       (aset n_array 3 ysize)
   61       (aset n_array 4 xsize)
   62       (aset n_array 5 (+ ysize oheight))
   63       (aset n_array 6 0 )
   64       (aset n_array 7 height )
   65       (aset n_array 8 0 )
   66       (aset n_array 9 0 )
   67       n_array)
   68   )
   69 
   70   (define (gen_right_array xsize ysize owidth oheight width height)
   71     (let* ((n_array (cons-array 10 'double)))
   72       (aset n_array 0 width )
   73       (aset n_array 1 0 )
   74       (aset n_array 2 (+ xsize owidth))
   75       (aset n_array 3 ysize)
   76       (aset n_array 4 (+ xsize owidth))
   77       (aset n_array 5 (+ ysize oheight))
   78       (aset n_array 6 width)
   79       (aset n_array 7 height)
   80       (aset n_array 8 width )
   81       (aset n_array 9 0 )
   82       n_array)
   83   )
   84 
   85   (define (gen_bottom_array xsize ysize owidth oheight width height)
   86     (let* ((n_array (cons-array 10 'double)))
   87       (aset n_array 0 0 )
   88       (aset n_array 1 height)
   89       (aset n_array 2 xsize)
   90       (aset n_array 3 (+ ysize oheight))
   91       (aset n_array 4 (+ xsize owidth))
   92       (aset n_array 5 (+ ysize oheight))
   93       (aset n_array 6 width)
   94       (aset n_array 7 height)
   95       (aset n_array 8 0 )
   96       (aset n_array 9 height)
   97       n_array)
   98   )
   99 
  100   (let* ((img (car (gimp-item-get-image adraw)))
  101          (owidth (car (gimp-image-width img)))
  102          (oheight (car (gimp-image-height img)))
  103          (width (+ owidth (* 2 xsize)))
  104          (height (+ oheight (* 2 ysize)))
  105          (layer (car (gimp-layer-new img
  106                                      width height
  107                                      (car (gimp-drawable-type-with-alpha adraw))
  108                                      _"Border Layer" 100 LAYER-MODE-NORMAL))))
  109 
  110     (gimp-context-push)
  111     (gimp-context-set-paint-mode LAYER-MODE-NORMAL)
  112     (gimp-context-set-opacity 100.0)
  113     (gimp-context-set-antialias FALSE)
  114     (gimp-context-set-feather FALSE)
  115 
  116     (gimp-image-undo-group-start img)
  117 
  118     (gimp-image-resize img
  119                        width
  120                        height
  121                        xsize
  122                        ysize)
  123 
  124     (gimp-image-insert-layer img layer 0 0)
  125     (gimp-drawable-fill layer FILL-TRANSPARENT)
  126 
  127     (gimp-context-set-background (adjcolor color dvalue))
  128     (gimp-image-select-polygon img
  129                                CHANNEL-OP-REPLACE
  130                                10
  131                                (gen_top_array xsize ysize owidth oheight width height))
  132     (gimp-drawable-edit-fill layer FILL-BACKGROUND)
  133     (gimp-context-set-background (adjcolor color (/ dvalue 2)))
  134     (gimp-image-select-polygon img
  135                                CHANNEL-OP-REPLACE
  136                                10
  137                                (gen_left_array xsize ysize owidth oheight width height))
  138     (gimp-drawable-edit-fill layer FILL-BACKGROUND)
  139     (gimp-context-set-background (adjcolor color (- 0 (/ dvalue 2))))
  140     (gimp-image-select-polygon img
  141                                CHANNEL-OP-REPLACE
  142                                10
  143                                (gen_right_array xsize ysize owidth oheight width height))
  144 
  145     (gimp-drawable-edit-fill layer FILL-BACKGROUND)
  146     (gimp-context-set-background (adjcolor color (- 0 dvalue)))
  147     (gimp-image-select-polygon img
  148                                CHANNEL-OP-REPLACE
  149                                10
  150                                (gen_bottom_array xsize ysize owidth oheight width height))
  151 
  152     (gimp-drawable-edit-fill layer FILL-BACKGROUND)
  153     (gimp-selection-none img)
  154     (gimp-image-undo-group-end img)
  155     (gimp-displays-flush)
  156 
  157     (gimp-context-pop)
  158     )
  159 )
  160 
  161 (script-fu-register "script-fu-addborder"
  162   _"Add _Border..."
  163   _"Add a border around an image"
  164   "Andy Thomas <alt@picnic.demon.co.uk>"
  165   "Andy Thomas"
  166   "6/10/97"
  167   "*"
  168   SF-IMAGE       "Input image" 0
  169   SF-DRAWABLE    "Input drawable" 0
  170   SF-ADJUSTMENT _"Border X size" '(12 1 250 1 10 0 1)
  171   SF-ADJUSTMENT _"Border Y size" '(12 1 250 1 10 0 1)
  172   SF-COLOR      _"Border color" '(38 31 207)
  173   SF-ADJUSTMENT _"Delta value on color" '(25 1 255 1 10 0 1)
  174 )
  175 
  176 (script-fu-menu-register "script-fu-addborder"
  177                          "<Image>/Filters/Decor")