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 / copy-visible.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2004-09-26  |  3.2 KB  |  89 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. ; "Copy Visible"  version 0.11 01/24/98
  16. ;     by Adrian Likins <adrian@gimp.org>
  17. ;   _heavily_ based on:
  18. ;        cyn-merge.scm   version 0.02   10/10/97
  19. ;        Copyright (C) 1997 Sven Neumann (neumanns@uni-duesseldorf.de)
  20.  
  21. (define (script-fu-copy-visible image
  22.                  drawable)
  23.   (let* ((layers (gimp-image-get-layers image))
  24.      (num-layers (car layers))
  25.      (num-visi-layers 0)
  26.      (curlayer (car (gimp-image-get-active-layer image)))
  27.      (layer-array (cadr layers)))
  28.   
  29.   (if (= curlayer -1)
  30.       (set! curlayer (car (gimp-image-get-active-channel image))))
  31.   
  32.   (gimp-image-undo-group-start image)
  33.     
  34.   ; copy all visible layers and make them invisible
  35.   (set! layer-count 1)
  36.   (set! visi-array (cons-array num-layers))
  37.   (while (<= layer-count num-layers)
  38.      (set! layer (aref layer-array (- num-layers layer-count)))
  39.      (aset visi-array (- num-layers layer-count)
  40.                       (car (gimp-drawable-get-visible layer)))
  41.      (if (= TRUE (car (gimp-drawable-get-visible layer)))
  42.          (begin
  43.            (set! copy (car (gimp-layer-copy layer TRUE)))
  44.            (gimp-image-add-layer image copy -1)
  45.            (gimp-drawable-set-visible copy TRUE)
  46.            (gimp-drawable-set-visible layer FALSE)
  47.            (set! num-visi-layers (+ num-visi-layers 1))))
  48.      (set! layer-count (+ layer-count 1)))
  49.   
  50.   ; merge all visible layers
  51.   (if (> num-visi-layers 1)
  52.       (set! merged-layer (car (gimp-image-merge-visible-layers image
  53.                                                                EXPAND-AS-NECESSARY)))
  54.       (if (> num-visi-layers 0)
  55.       (set! merged-layer copy)))
  56.  
  57.   (if (> num-visi-layers 0)
  58.       (begin
  59.     (gimp-edit-copy merged-layer)
  60.     (gimp-image-remove-layer image merged-layer)))
  61.  
  62.   ; restore the layers visibilty
  63.   (set! layer-count 0)
  64.   (while (< layer-count num-layers)
  65.      (set! layer (aref layer-array layer-count))
  66.      (gimp-drawable-set-visible layer (aref visi-array layer-count))
  67.      (set! layer-count (+ layer-count 1)))
  68.   
  69.   (if (= (car (gimp-drawable-is-layer curlayer)) 1)
  70.       (gimp-image-set-active-layer image curlayer)
  71.       (gimp-image-set-active-channel image curlayer))
  72.  
  73.   (gimp-image-undo-group-end image)
  74.   (gimp-displays-flush)))
  75.  
  76. (script-fu-register "script-fu-copy-visible"
  77.             _"<Image>/Edit/Copy _Visible"
  78.             "Copy the visible selection"
  79.             "Sven Neumann <sven@gimp.org>, Adrian Likins <adrian@gimp.org>"
  80.             "Sven Neumann, Adrian Likins"
  81.             "01/24/1998"
  82.             "RGB* INDEXED* GRAY*"
  83.             SF-IMAGE    "Image"    0
  84.             SF-DRAWABLE "Drawable" 0)
  85.