home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / image-structure.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2000-12-27  |  7.4 KB  |  160 lines

  1. ;;; image-structure.scm -*-scheme-*-
  2. ;;; Time-stamp: <1998/03/28 02:46:26 narazaki@InetQ.or.jp>
  3. ;;; Author: Shuji Narazaki <narazaki@InetQ.or.jp>
  4. ;;; Version 0.7
  5. ; ************************************************************************
  6. ; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
  7. ; For use with GIMP 1.1.
  8. ; All calls to gimp-text-* have been converted to use the *-fontname form.
  9. ; The corresponding parameters have been replaced by an SF-FONT parameter.
  10. ; ************************************************************************
  11. ;;; Code:
  12.  
  13. (if (not (symbol-bound? 'script-fu-show-image-structure-new-image?
  14.             (the-environment)))
  15.     (define script-fu-show-image-structure-new-image? TRUE))
  16. (if (not (symbol-bound? 'script-fu-show-image-structure-space 
  17.             (the-environment)))
  18.     (define script-fu-show-image-structure-space 50))
  19. (if (not (symbol-bound? 'script-fu-show-image-structure-shear-length
  20.             (the-environment)))
  21.     (define script-fu-show-image-structure-shear-length 50))
  22. (if (not (symbol-bound? 'script-fu-show-image-structure-border
  23.             (the-environment)))
  24.     (define script-fu-show-image-structure-border 10))
  25. (if (not (symbol-bound? 'script-fu-show-image-structure-apply-layer-mask?
  26.             (the-environment)))
  27.     (define script-fu-show-image-structure-apply-layer-mask? TRUE))
  28. (if (not (symbol-bound? 'script-fu-show-image-structure-with-layer-name?
  29.             (the-environment)))
  30.     (define script-fu-show-image-structure-with-layer-name? TRUE))
  31. (if (not (symbol-bound? 'script-fu-show-image-structure-with-pad?
  32.             (the-environment)))
  33.     (define script-fu-show-image-structure-with-pad? TRUE))
  34. (if (not (symbol-bound? 'script-fu-show-image-structure-padding-color
  35.             (the-environment)))
  36.     (define script-fu-show-image-structure-padding-color '(255 255 255)))
  37. (if (not (symbol-bound? 'script-fu-show-image-structure-padding-opacity
  38.             (the-environment)))
  39.     (define script-fu-show-image-structure-padding-opacity 25))
  40. (if (not (symbol-bound? 'script-fu-show-image-structure-with-background?
  41.             (the-environment)))
  42.     (define script-fu-show-image-structure-with-background? TRUE))
  43. (if (not (symbol-bound? 'script-fu-show-image-structure-background-color
  44.             (the-environment)))
  45.     (define script-fu-show-image-structure-background-color '(0 0 0)))
  46.  
  47. (define (script-fu-show-image-structure img drawable new-image? space
  48.                     shear-length border apply-layer-mask?
  49.                     with-layer-name? with-pad? padding-color
  50.                     padding-opacity with-background?
  51.                     background-color)
  52.   (if (eq? new-image? TRUE)
  53.       (begin (set! img (car (gimp-channel-ops-duplicate img)))
  54.          (gimp-display-new img)))
  55.   (let* ((layers (gimp-image-get-layers img))
  56.      (num-of-layers (car layers))
  57.      (old-width (car (gimp-image-width img)))
  58.      (old-height (car (gimp-image-height img)))
  59.      (new-width (+ (* 2 border) (+ old-width (* 2 shear-length))))
  60.      (new-height (+ (* 2 border) (+ old-height (* space (- num-of-layers 1)))))
  61.      (new-bg #f)
  62.      (old-foreground (car (gimp-palette-get-foreground)))
  63.      (old-background (car (gimp-palette-get-background)))
  64.      (layer-names '())
  65.      (layer #f)
  66.      (index 0))
  67.     (gimp-image-resize img new-width new-height 0 0)
  68.     (set! layers (cadr layers))
  69.     (gimp-selection-none img)
  70.     (while (< index num-of-layers)
  71.       (set! layer (aref layers index))
  72.       (if (equal? "Background" (car (gimp-layer-get-name layer)))
  73.       (begin
  74.         (gimp-layer-add-alpha layer)
  75.         (gimp-layer-set-name layer "Original Background")))
  76.       (set! layer-names (cons (car (gimp-layer-get-name layer)) layer-names))
  77.       (if (not (= -1 (car (gimp-layer-mask layer))))
  78.       (gimp-image-remove-layer-mask img layer
  79.                     (if (= TRUE apply-layer-mask?)
  80.                         APPLY
  81.                         DISCARD)))
  82.       (if (= TRUE with-pad?)
  83.       (begin
  84.         (gimp-selection-layer-alpha layer)
  85.         (gimp-selection-invert img)
  86.         (gimp-layer-set-preserve-trans layer FALSE)
  87.         (gimp-palette-set-foreground padding-color)
  88.         (gimp-bucket-fill layer FG-BUCKET-FILL NORMAL
  89.                   padding-opacity 0 0 0 0)
  90.         (gimp-selection-none img)))
  91.       
  92.       (gimp-layer-translate layer
  93.                 (+ border shear-length) (+ border (* space index)))
  94.       (gimp-shear layer TRUE 0 (* (/ (car (gimp-drawable-height layer))
  95.                      old-height)
  96.                       (* -2 shear-length)))
  97.       (set! index (+ index 1)))
  98.     (set! new-bg (- num-of-layers 1))
  99.     (if (= TRUE with-background?)
  100.     (begin
  101.       (set! new-bg (car (gimp-layer-new img new-width new-height RGBA_IMAGE
  102.                         "New Background" 100 NORMAL)))
  103.       (gimp-image-add-layer img new-bg num-of-layers)
  104.       (gimp-palette-set-background background-color)
  105.       (gimp-edit-fill new-bg BG-IMAGE-FILL)))
  106.     (gimp-image-set-active-layer img (aref layers 0))
  107.     (if (= TRUE with-layer-name?)
  108.     (let ((text-layer #f))
  109.       (gimp-palette-set-foreground '(255 255 255))
  110.       (set! index 0)
  111.       (set! layer-names (nreverse layer-names))
  112.       (while (< index num-of-layers)
  113.         (set! text-layer (car (gimp-text-fontname img -1 (/ border 2)
  114.                          (+ (* space index) old-height)
  115.                          (car layer-names)
  116.                          0 TRUE 14 PIXELS "-*-helvetica-*-r-*-*-14-*-*-*-p-*-*-*")))
  117.         (gimp-layer-set-mode text-layer NORMAL)
  118.         (set! index (+ index 1))
  119.         (set! layer-names (cdr layer-names)))))
  120.     (gimp-image-set-active-layer img new-bg)
  121.     (gimp-palette-set-background old-background)
  122.     (gimp-palette-set-foreground old-foreground)
  123.     (set! script-fu-show-image-structure-new-image? new-image?)
  124.     (set! script-fu-show-image-structure-space space)
  125.     (set! script-fu-show-image-structure-shear-length shear-length)
  126.     (set! script-fu-show-image-structure-border border)
  127.     (set! script-fu-show-image-structure-apply-layer-mask? apply-layer-mask?)
  128.     (set! script-fu-show-image-structure-with-layer-name? with-layer-name?)
  129.     (set! script-fu-show-image-structure-with-pad? with-pad?)
  130.     (set! script-fu-show-image-structure-padding-color padding-color)
  131.     (set! script-fu-show-image-structure-padding-opacity padding-opacity)
  132.     (set! script-fu-show-image-structure-with-background? with-background?)
  133.     (set! script-fu-show-image-structure-background-color background-color)
  134.     (gimp-displays-flush)))
  135.  
  136. (script-fu-register
  137.  "script-fu-show-image-structure"
  138.  _"<Image>/Script-Fu/Utils/Show Image Structure..."
  139.  "Show the layer structure of the image"
  140.  "Shuji Narazaki <narazaki@InetQ.or.jp>"
  141.  "Shuji Narazaki"
  142.  "1997"
  143.  "RGB*, GRAY*"
  144.  SF-IMAGE "image" 0
  145.  SF-DRAWABLE "Drawable (unused)" 0
  146.  SF-TOGGLE _"Create New Image" script-fu-show-image-structure-new-image?
  147.  SF-ADJUSTMENT _"Space Between Layers" (cons script-fu-show-image-structure-space '(0 1000 1 10 0 1))
  148.  SF-ADJUSTMENT _"Shear Length" (cons script-fu-show-image-structure-shear-length '(1 1000 1 10 0 1))
  149.  SF-ADJUSTMENT _"Outer Border" (cons script-fu-show-image-structure-border '(0 250 1 10 0 1))
  150.  SF-TOGGLE _"Apply Layer Mask (or discard)" script-fu-show-image-structure-apply-layer-mask?
  151.  SF-TOGGLE _"Insert Layer Names" script-fu-show-image-structure-with-layer-name?
  152.  SF-TOGGLE _"Padding for Transparent Regions" script-fu-show-image-structure-with-pad?
  153.  SF-COLOR  _"Pad Color" script-fu-show-image-structure-padding-color
  154.  SF-ADJUSTMENT _"Pad Opacity" (cons script-fu-show-image-structure-padding-opacity '(0 100 1 10 1 0))
  155.  SF-TOGGLE _"Make New Background" script-fu-show-image-structure-with-background?
  156.  SF-COLOR  _"Background Color" script-fu-show-image-structure-background-color
  157. )
  158.  
  159. ;;; image-structure.scm ends here
  160.