toon_root.c: fix handling of XGetWindowProperty
[xpenguins.git] / lay-out-frames.scm
blob8460a01dfbe5dec7fcc680c72ab51c521f5186fe
1 ; lay-out-frames - lay out frames of animated gif to make xpenguins theme
2 ; Copyright (C) 2001 Robin Hogan
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 2 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, write to the Free Software
16 ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 (define (script-fu-lay-out-frames img
19                                   drawable
20                                   reversed
21                                   swap
22                                   flatten
23                                   index)
24   (let* ((frameWidth (car (gimp-image-width img)))
25          (frameHeight (car (gimp-image-height img)))
26          (layers (gimp-image-get-layers img))
27          (nFrames (car layers))
28          (frameList (cadr layers))
29          (width (* frameWidth nFrames))
30          (height frameHeight)
31          (frame 0)
32          (normalYoffset 0)
33          (reversedYoffset frameHeight)
34          (flattenedFrame #f))
35     
36     (gimp-image-undo-disable img)
37     (if (= reversed TRUE)
38         (begin
39           (set! height (* frameHeight 2))
40           (if (= swap TRUE)
41               (begin
42                 (set! normalYoffset frameHeight)
43                 (set! reversedYoffset 0)))))
45     (gimp-image-resize img width height 0 0)
47     (while (< frame nFrames)
48            (let* ((currentFrame (aref frameList (- (- nFrames 1) frame)))
49                   (offsets (gimp-drawable-offsets currentFrame))
50                   (xoffset (car offsets))
51                   (yoffset (cadr offsets))
52                   (newFrame #f))
53              (gimp-layer-resize currentFrame
54                                 frameWidth
55                                 frameHeight
56                                 xoffset
57                                 yoffset)
58              (gimp-layer-set-offsets currentFrame
59                                      (* frame frameWidth)
60                                      normalYoffset)
61              (if (= reversed TRUE)
62                  (begin
63                    (set! newFrame (car (gimp-layer-copy currentFrame TRUE)))
64                    (gimp-image-add-layer img newFrame -1)
65                    (gimp-layer-set-offsets newFrame
66                                            (* frame frameWidth)
67                                            reversedYoffset)
68                    (gimp-flip newFrame 0)
69                  ))
70              (set! frame (+ frame 1))))
72     (if (= flatten TRUE)
73         (gimp-image-merge-visible-layers img 0))
74     (if (= index TRUE)
75         (gimp-convert-indexed img 2 0 63 0 1 ""))
76     (gimp-image-undo-enable img)
77     (gimp-displays-flush)))
79 (script-fu-register "script-fu-lay-out-frames"
80                     _"<Image>/Script-Fu/Utils/Lay out frames..."
81                     "Lay out the frames of an animation side by side. This is useful for creating themes for the XPenguins program."
82                     "Robin Hogan <R.J.Hogan@reading.ac.uk>"
83                     "Robin Hogan"
84                     "April 2001"
85                     ""
86                     SF-IMAGE "Image" 0
87                     SF-DRAWABLE "Drawable" 0
88                     SF-TOGGLE _"Include reversed frames" FALSE
89                     SF-TOGGLE _"Swap normal & reversed frames" FALSE
90                     SF-TOGGLE _"Merge down frames" FALSE
91                     SF-TOGGLE _"Convert to an indexed image" FALSE)