; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; Copy multi layer image script for GIMP 1.2 ; Copyright (C) 2001 Iccii ; ; -------------------------------------------------------------------- ; version 0.1 2001/09/29 Iccii ; - Initial relase ; - Added Copy Layers option ; version 0.2 2001/09/30 Iccii ; - Added Copy Channels option ; version 0.3 2001/09/30 Iccii ; - Added Copy Paths option ; ; -------------------------------------------------------------------- ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ; ; <仕様という名のバグ? いや、仕様です!> ; ; - インデックス画像もグレースケール画像も RGB 画像になっちゃう ; - 背景レイヤーは結合後はアルファチャンネルのあるレイヤーになっちゃう ; - レイヤーをコピーしない時は新しい画像にレイヤーは無いよ ;; 二つの画像の全てのレイヤーを一つの画像にまとめるスクリプト (define (script-fu-copy-multi-layer img1 ;; 対象画像 drawable ;; 対象ドロアブル (unused) img2 ;; 対象画像2 copy-layer ;; レイヤーもコピーするか? copy-channel ;; チャンネルもコピーするか? copy-path ;; パスもコピーするか? ) ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; レイヤーのコピー ;;;;;;;;;;;;;;;;;;;; ;; local function to copy all layers in old image into new image (define (copy-all-layers-into-image image new-image number) (set! count 0) ;; count++ しなからレイヤーの枚数だけ繰り返す (while (< count number) ;; 下から count 番目のレイヤーを取り出す (let* ((layer (aref (cadr (gimp-image-get-layers image)) (- number count 1))) (linked (car (gimp-layer-get-linked layer))) (name (car (gimp-layer-get-name layer))) (opacity (car (gimp-layer-get-opacity layer))) (mode (car (gimp-layer-get-mode layer))) (mask (car (gimp-layer-mask layer))) (visible (car (gimp-layer-get-visible layer))) (p-trans (car (gimp-layer-get-preserve-trans layer))) (tmp-width (car (gimp-drawable-width layer))) (tmp-height (car (gimp-drawable-height layer))) (tmp-layer (car (gimp-layer-new new-image tmp-width tmp-height RGBA-IMAGE name opacity mode)))) ;; 取り出したレイヤーを画像に追加する (gimp-image-add-layer new-image tmp-layer -1) (gimp-edit-copy layer) (gimp-floating-sel-anchor (car (gimp-edit-paste tmp-layer FALSE))) ;; レイヤーマスクが存在する場合はマスクも一緒に追加する (if (< 0 mask) (let* ((tmp-mask (car (gimp-layer-create-mask tmp-layer WHITE-MASK)))) (gimp-image-add-layer-mask new-image tmp-layer tmp-mask) (gimp-edit-copy mask) (gimp-floating-sel-anchor (car (gimp-edit-paste tmp-mask FALSE))))) ;; 元レイヤーの状態も反映させる (gimp-layer-set-preserve-trans tmp-layer p-trans) (gimp-layer-set-visible tmp-layer visible) (gimp-layer-set-linked tmp-layer linked) ) ; end of let* (set! count (+ count 1)) ) ; end of while ) ; end of define (local function) ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; チャンネルのコピー ;;;;;;;;;;;;;;;;;;;; ;; local function to copy all channels in old image into new image (define (copy-all-channels-into-image image new-image number) (set! count 0) ;; count++ しなからチャンネルの枚数だけ繰り返す (while (< count number) ;; 下から count 番目のチャンネルを取り出す (let* ((channel (aref (cadr (gimp-image-get-channels image)) (- number count 1))) (name (car (gimp-channel-get-name channel))) (color (car (gimp-channel-get-color channel))) (opacity (car (gimp-channel-get-opacity channel))) (masked (car (gimp-channel-get-show-masked channel))) (tmp-width (car (gimp-drawable-width channel))) (tmp-height (car (gimp-drawable-height channel))) (tmp-channel (car (gimp-channel-new new-image tmp-width tmp-height name opacity color)))) ;; 取り出したチャンネルを画像に追加する (gimp-image-add-channel new-image tmp-channel -1) (gimp-edit-copy channel) (gimp-floating-sel-anchor (car (gimp-edit-paste tmp-channel FALSE))) (gimp-channel-set-show-masked tmp-channel masked) ; why gimp-channel-new sets incorrect opacity? (gimp-channel-set-opacity tmp-channel opacity) ) ; end of let* (set! count (+ count 1)) ) ; end of while ) ; end of define (local function) ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; パスのコピー ;;;;;;;;;;;;;;;;;;;; ;; local function to copy all paths in old image into new image (define (copy-all-paths-into-image image new-image number) (set! count 0) (define (list-ref l n) (nth n l)) ;; count++ しなからパスタイルの枚数だけ繰り返す (while (< count number) ;; 下から count 番目のパスを取り出す (let* ((pathname (list-ref (cadr (gimp-path-list image)) (- number count 1))) (path-data (gimp-path-get-points image pathname)) (locked (car (gimp-path-get-locked image pathname)))) ;; 取り出したパスを画像に追加する (gimp-path-set-points new-image pathname (list-ref path-data 0) (list-ref path-data 2) (list-ref path-data 3)) (gimp-path-set-locked new-image pathname locked) ) ; end of let* (set! count (+ count 1)) ) ; end of while ) ; end of define (local function) ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; メイン部分 ;;;;;;;;;;;;;;;;;;;; ;; コピーする新しい画像の作成 (let* ( (width (car (gimp-image-width img1))) (height (car (gimp-image-height img1))) (new-img (car (gimp-image-new width height RGB))) ) ; end variable definition ;; 本体 (gimp-image-undo-disable new-img) (if (eqv? copy-layer TRUE) (let* ((number1 (car (gimp-image-get-layers img1))) (number2 (car (gimp-image-get-layers img2)))) (copy-all-layers-into-image img1 new-img number1) (copy-all-layers-into-image img2 new-img number2) ) ; end of let* ) (if (eqv? copy-channel TRUE) (let* ((number1 (car (gimp-image-get-channels img1))) (number2 (car (gimp-image-get-channels img2)))) (copy-all-channels-into-image img1 new-img number1) (copy-all-channels-into-image img2 new-img number2) ) ; end of let* ) ;; 後処理 (gimp-image-undo-enable new-img) (if (or (eqv? copy-layer TRUE) (eqv? copy-channel TRUE) (eqv? copy-path TRUE)) (gimp-display-new new-img) (gimp-image-delete new-img)) (gimp-displays-flush) ) ) (script-fu-register "script-fu-copy-multi-layer" "/Script-Fu/Utils/Copy Multi Layer..." "Copy multi layers/channels/paths image into new image" "Iccii " "Iccii" "2001, Sep" "RGB* GRAY* INDEXED*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-IMAGE "Image" 0 SF-TOGGLE "Copy Layers" TRUE SF-TOGGLE "Copy Channels" FALSE SF-TOGGLE "Copy Paths" FALSE )