home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 August / ENTER.ISO / files / gimp-2.0.5-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / selection-round.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2004-09-26  |  3.8 KB  |  132 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; This program is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2 of the License, or
  6. ; (at your option) any later version.  
  7. ; This program is distributed in the hope that it will be useful,
  8. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. ; GNU General Public License for more details.
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program; if not, write to the Free Software
  13. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ;
  15. ;
  16. ; selection-round.scm   version 1.02   1998/02/06
  17. ;
  18. ; CHANGE-LOG:
  19. ; 1.00 - initial release
  20. ; 1.01 - some code cleanup, no real changes
  21. ; 1.02 - made script undoable
  22. ;
  23. ; Copyright (C) 1997, 1998 Sven Neumann <sven@gimp.org>
  24. ;  
  25. ; Rounds the current selection by cutting of rectangles from the edges and 
  26. ; adding circles. The relative radius describes the radius of this cricles
  27. ; in relation to the selections width or height (depends on which of these 
  28. ; is smaller) 
  29.  
  30. (define (script-fu-selection-round image
  31.                         drawable
  32.                                    radius)
  33.  
  34.   (let* ((radius (min radius 1.0))
  35.      (radius (max radius 0.0))
  36.      (select-bounds (gimp-selection-bounds image))
  37.      (has-selection (car select-bounds))
  38.      (select-x1 (cadr select-bounds))
  39.      (select-y1 (caddr select-bounds))
  40.      (select-x2 (cadr (cddr select-bounds)))
  41.      (select-y2 (caddr (cddr select-bounds)))
  42.      (select-width (- select-x2 select-x1))
  43.      (select-height (- select-y2 select-y1))
  44.      (cut-radius 0)
  45.      (ellipse-radius 0))
  46.  
  47.   (gimp-image-undo-group-start image)
  48.  
  49.   (if (> select-width select-height)
  50.       (set! cut-radius (trunc (+ 1 (* radius (/ select-height 2)))))
  51.       (set! cut-radius (trunc (+ 1 (* radius (/ select-width 2))))))
  52.   (set! ellipse-radius (* cut-radius 2))
  53.   (gimp-rect-select image
  54.             select-x1
  55.             select-y1
  56.             (+ cut-radius 1)
  57.             (+ cut-radius 1)
  58.             CHANNEL-OP-SUBTRACT
  59.             FALSE 0)
  60.   (gimp-rect-select image
  61.             select-x1
  62.             (- select-y2 cut-radius)
  63.             (+ cut-radius 1)
  64.             (+ cut-radius 1)
  65.             CHANNEL-OP-SUBTRACT
  66.             FALSE 0)
  67.   (gimp-rect-select image
  68.             (- select-x2 cut-radius)
  69.             select-y1
  70.             (+ cut-radius 1)
  71.             (+ cut-radius 1)
  72.             CHANNEL-OP-SUBTRACT
  73.             FALSE 0)
  74.   (gimp-rect-select image
  75.             (- select-x2 cut-radius)
  76.             (- select-y2 cut-radius)
  77.             (+ cut-radius 1)
  78.             (+ cut-radius 1)
  79.             CHANNEL-OP-SUBTRACT
  80.             FALSE 0)
  81.   (gimp-ellipse-select image
  82.                select-x1
  83.                select-y1
  84.                ellipse-radius
  85.                ellipse-radius
  86.                CHANNEL-OP-ADD
  87.                TRUE
  88.                FALSE 0)
  89.   (gimp-ellipse-select image
  90.                select-x1
  91.                (- select-y2 ellipse-radius)
  92.                ellipse-radius
  93.                ellipse-radius
  94.                CHANNEL-OP-ADD
  95.                TRUE
  96.                FALSE 0)
  97.   (gimp-ellipse-select image
  98.                (- select-x2 ellipse-radius)
  99.                select-y1
  100.                ellipse-radius
  101.                ellipse-radius
  102.                CHANNEL-OP-ADD
  103.                TRUE
  104.                FALSE 0)
  105.   (gimp-ellipse-select image
  106.                (- select-x2 ellipse-radius)
  107.                (- select-y2 ellipse-radius)
  108.                ellipse-radius
  109.                ellipse-radius
  110.                CHANNEL-OP-ADD
  111.                TRUE
  112.                FALSE 0)
  113.  
  114.   (gimp-image-undo-group-end image)
  115.   (gimp-displays-flush)))
  116.  
  117.  
  118. (script-fu-register "script-fu-selection-round"
  119.             _"<Image>/Script-Fu/Selection/_Round..."
  120.             "Rounds the active selection. The selection should be rectangular."
  121.             "Sven Neumann <sven@gimp.org>"
  122.             "Sven Neumann"
  123.             "1998/02/06"
  124.             "*"
  125.             SF-IMAGE "Image" 0
  126.             SF-DRAWABLE "Drawable" 0
  127.             SF-ADJUSTMENT _"Relative Radius" '(1 0 128 .1 1 1 1))
  128.