home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 February / PCWorld_2001-02_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / copy-visible.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2000-12-27  |  2.9 KB  |  82 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.      (layer-array (cadr layers)))
  27.   
  28.   (gimp-undo-push-group-start image)
  29.     
  30.   ; copy all visible layers and make them invisible
  31.   (set! layer-count 1)
  32.   (set! visi-array (cons-array num-layers))
  33.   (while (<= layer-count num-layers)
  34.      (set! layer (aref layer-array (- num-layers layer-count)))
  35.      (aset visi-array (- num-layers layer-count)
  36.                       (car (gimp-layer-get-visible layer)))
  37.      (if (= TRUE (car (gimp-layer-get-visible layer)))
  38.          (begin
  39.            (set! copy (car (gimp-layer-copy layer TRUE)))
  40.            (gimp-image-add-layer image copy -1)
  41.            (gimp-layer-set-visible copy TRUE)
  42.            (gimp-layer-set-visible layer FALSE)
  43.            (set! num-visi-layers (+ num-visi-layers 1))))
  44.      (set! layer-count (+ layer-count 1)))
  45.   
  46.   ; merge all visible layers
  47.   (if (> num-visi-layers 1)
  48.       (set! merged-layer (car (gimp-image-merge-visible-layers image EXPAND-AS-NECESSARY)))
  49.       (if (> num-visi-layers 0)
  50.       (set! merged-layer copy)))
  51.  
  52.   (if (> num-visi-layers 0)
  53.       (begin
  54.     (gimp-edit-copy merged-layer)
  55.     (gimp-image-remove-layer image merged-layer)))
  56.  
  57.   ; restore the layers visibilty
  58.   (set! layer-count 0)
  59.   (while (< layer-count num-layers)
  60.      (set! layer (aref layer-array layer-count))
  61.      (gimp-layer-set-visible layer (aref visi-array layer-count))
  62.      (set! layer-count (+ layer-count 1)))
  63.   
  64.   (gimp-image-set-active-layer image drawable)
  65.  
  66.   (gimp-undo-push-group-end image)
  67.   (gimp-displays-flush)))
  68.  
  69. (script-fu-register "script-fu-copy-visible"
  70.             _"<Image>/Edit/Copy Visible"
  71.             "Copy the visible selction"
  72.             "Sven Neumann <sven@gimp.org>, Adrian Likins <adrian@gimp.org>"
  73.             "Sven Neumann, Adrian Likins"
  74.             "01/24/1998"
  75.             "RGB* INDEXED* GRAY*"
  76.             SF-IMAGE "Image" 0
  77.             SF-DRAWABLE "Drawable" 0)
  78.