; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; read/write a parasite script for GIMP 1.2 ; Copyright (C) 2001-2002 Iccii ; ; -------------------------------------------------------------------- ; ; First, I'll recommend you to use Parasite Editor written in Perl-Fu ; if you don't have Perl environment e.g. Windows Gimp user. ; ; 1) List up the current parasite name with No. in target object ; (Image or Drawable or Global). Check parasite number. ; ; 2) Read the parasite contents by entering parasite number. Then, ; you'll get current parasite informatin. ; ; 3) If you add new parasite, select "Create new" and enter new name. ; then, you'll have new parasite with no contents. ; ; 4) If you edit parasite contens, select "Overwrite" and select ; target parasite number and enter new contents (string). ; ; 5) Select "Remove" and select target parasite number if you want to ; remove parasite from parasite list ; ; For example, Image has "Created with The GIMP" in "gimp-comment" ; when you create new blank image. ; (No.) (name) (contents) ; 0 gimp-comment Created with The GIMP ; ; -------------------------------------------------------------------- ; version 0.0 by Iccii 2001/08/10 ; - Initial relase (not work yet!) ; version 0.1 by Iccii 2001/08/26 ; - Now, real initial relase ; - Script can show current parasite list ; version 0.2 by Iccii 2001/08/27 ; - Add Overwrite option ; version 0.3 by Iccii 2001/08/28 ; - Add Read option ; - Add helper function ; version 0.4 by Iccii 2001/08/29 ; - Add remove option ; version 0.5 by Iccii 2001/09/25 ; - Add Create new option ; - Bug fixed in reading a parasite ; version 0.6 by Iccii 2001/09/27 ; - Add Addtional write option ; version 0.7 by Iccii 2002/01/05 ; - Added Export to File 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. ; ; -- TODO -- ; ; \ がらみで、\n を書き込むのが \\n でできるようにする、とか ; パラサイトの書き込みが上書きではなく、追加も選べるようにする (完了) ; パラサイトの書き込みで、ターゲットパラサイトが存在しない場合は新規作成する ; ターゲットオブジェクト Global が何だか変? ; 全てを一つのダイアログで済ませるのではなく、目的別に分けようか? ; パラサイトリストの取得表示時に、各パラサイト情報も表示する ;; convert Integer into Chracter string (define (integer->char integer) (define (list-ref l n) (nth n l)) (let* ( ; 0 1 2 3 4 5 6 7 8 9 (character-code0 '("\N" "\1" "\2" "\3" "\d" "\5" "\6" "\7" "" "\t")) (character-code1 '("\n" "" "" "\r" "" "" "" "" "" "")) (character-code2 '( "" "" "" "" "" "" "" "" "" "")) (character-code3 '( "" "" " " "!" "\"" "#" "$" "%" "&" "'")) (character-code4 '( "(" ")" "*" "+" "," "-" "." "/" "0" "1")) (character-code5 '( "2" "3" "4" "5" "6" "7" "8" "9" ":" ";")) (character-code6 '( "<" "=" ">" "?" "@" "A" "B" "C" "D" "E")) (character-code7 '( "F" "G" "H" "I" "J" "K" "L" "M" "N" "O")) (character-code8 '( "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y")) (character-code9 '( "Z" "[" "\\" "]" "^" "_" "`" "a" "b" "c")) (character-code10 '( "d" "e" "f" "g" "h" "i" "j" "k" "l" "m")) (character-code11 '( "n" "o" "p" "q" "r" "s" "t" "u" "v" "w")) (character-code12 '( "x" "y" "z" "{" "|" "}" "~" "" "" "")) (character-code (append character-code0 character-code1 character-code2 character-code3 character-code4 character-code5 character-code6 character-code7 character-code8 character-code9 character-code10 character-code11 character-code12 )) (result (if (and (<= 0 integer) (<= integer 127)) ; always 0 <= number <= 127 (list-ref character-code integer) (number->string integer))) ; debug output ) ; end variable definition result ) ; end of let* ) ;; View current parasites, or Read or Write or Remove a parasite (define (script-fu-read-write-parasite img ;; target imgae drawable ;; target drawable method ;; show / read / overwrite / addtional write / ;; remove / create new / the parasite target-object ;; Image / Drawable / Global comment-number ;; target comment name to work string ;; parasite string to write (attacth) filename ;; export final result to file ) (define (list-ref l n) (nth n l)) (define (parasite-attach target parasite) (cond ((eqv? target-object 0) (gimp-image-parasite-attach target parasite)) ((eqv? target-object 1) (gimp-drawable-parasite-attach target parasite)) ((eqv? target-object 2) (gimp-parasite-attach parasite)))) (define (parasite-detach target name) (cond ((eqv? target-object 0) (gimp-image-parasite-detach target name)) ((eqv? target-object 1) (gimp-drawable-parasite-detach target name)) ((eqv? target-object 2) (gimp-parasite-detach name)))) (define (parasite-find target name) (cond ((eqv? target-object 0) (gimp-image-parasite-find target name)) ((eqv? target-object 1) (gimp-drawable-parasite-find target name)) ((eqv? target-object 2) (gimp-parasite-find name)))) (define (parasite-list target) (cond ((eqv? target-object 0) (gimp-image-parasite-list target)) ((eqv? target-object 1) (gimp-drawable-parasite-list target)) ((eqv? target-object 2) (gimp-parasite-list)))) (set! target-type (cond ((eqv? target-object 0) img) ((eqv? target-object 1) drawable) ((eqv? target-object 2) img))) ; what is global id? (set! type (cond ((eqv? target-object 0) "Image") ((eqv? target-object 1) "Drawable") ((eqv? target-object 2) "Global"))) ;;;;;;;;;;;;;;;;;;;; Output final result to File or Display (set! export? (if (< 0 (string-length filename)) TRUE FALSE)) (if (equal? export? TRUE) (set! outfile (fopen filename "w"))) (define (output-result message) (if (equal? export? TRUE) (fwrite message outfile) (gimp-message message))) ;;;;;;;;;;;;;;;;;;;; Start (cond ;;;;;;;;;;;;;;;;;;;; Show current parasite list ((= method 0) (let* ((parasite-number (- (car (parasite-list target-type)) 1)) (result-message (string-append " \n" " Object Type: " type "\n")) (count 0) ) (if (= parasite-number -1) (gimp-message "Found not parasite information. Abort!") (begin (while (<= count parasite-number) (set! result-message (string-append result-message "\n" "No." (number->string count) ": \"" (list-ref (cadr (parasite-list target-type)) count) "\"\n")) (set! count (+ count 1)) ) ; end of while (output-result result-message) ) ; end of begin ) ; end of if ) ; end of let* ) ;;;;;;;;;;;;;;;;;;;; Read a parasite ((= method 1) (let* ((parasite-number (- (car (parasite-list target-type)) 1)) (target-comment (if (and (and (<= 0 comment-number) (<= comment-number parasite-number)) (not (= parasite-number -1))) (list-ref (cadr (parasite-list target-type)) comment-number) "")) (count 0) ) ;; find the location of target parasite name (if (= parasite-number -1) (gimp-message "Found not parasite information. Abort!") (if (not (and (<= 0 comment-number) (<= comment-number parasite-number))) (gimp-message "Incorrect Target comment No. Abort!") (begin (while (and (< count parasite-number) (not (equal? target-comment (list-ref (cadr (parasite-list target-type)) count)))) (set! count (+ count 1)) ) ; end of while ;; extract the parasite contents (let* ((result-message (string-append "Current parasite of \"" target-comment "\" is\n")) (parasite-comment (car (cddar (parasite-find target-type target-comment)))) (parasite-comment-length (length parasite-comment)) (count2 0) ) (while (< count2 parasite-comment-length) (set! result-message (string-append result-message (integer->char (aref parasite-comment count2)))) (set! count2 (+ count2 1)) ) ; end of while (output-result result-message) ) ; end of let* ) ; end of begin ) ; end of if ) ; end of if (= parasite-number -1) ) ; end of let* ) ;;;;;;;;;;;;;;;;;;;; Overwrite a parasite ((= method 2) (let* ((flag 1) ; what means flag number? (1 = ?), (2 = ?), etc. (parasite-number (- (car (parasite-list target-type)) 1)) (parasite-message (bytes-append (hexstr->bytes (array->hexstr string)) "\0")) (target-comment (if (and (and (<= 0 comment-number) (<= comment-number parasite-number)) (not (= parasite-number -1))) (list-ref (cadr (parasite-list target-type)) comment-number) "")) (result-parasite (list target-comment flag parasite-message)) ) (if (= parasite-number -1) (gimp-message "Found not parasite information. Abort!") (if (not (and (<= 0 comment-number) (<= comment-number parasite-number))) (gimp-message "Incorrect Target comment No. Abort!") (begin (parasite-attach target-type result-parasite) (gimp-message (string-append "Successful!\n" "Overwrited the \"" string "\" at parasite named \"" target-comment "\" in " type)) ) ; end of begin ) ; end of if ) ; end of if (= parasite-number -1) ) ; end of let* ) ;;;;;;;;;;;;;;;;;;;; Addtional write a parasite ((= method 3) (let* ((flag 1) ; what means flag number? (1 = ?), (2 = ?), etc. (parasite-number (- (car (parasite-list target-type)) 1)) (parasite-message (bytes-append (hexstr->bytes (array->hexstr string)) "\0")) (target-comment (if (and (and (<= 0 comment-number) (<= comment-number parasite-number)) (not (= parasite-number -1))) (list-ref (cadr (parasite-list target-type)) comment-number) "")) ) (if (= parasite-number -1) (gimp-message "Found not parasite information. Abort!") (if (not (and (<= 0 comment-number) (<= comment-number parasite-number))) (gimp-message "Incorrect Target comment No. Abort!") (let* ((result-message "") (parasite-comment (car (cddar (parasite-find target-type target-comment)))) (result-message (bytes-append parasite-comment parasite-message)) (result-parasite (list target-comment flag result-message)) ) ; end of let* (parasite-attach target-type result-parasite) (gimp-message (string-append "Successful!\n" "Addtional writed the \"" string "\" at parasite named \"" target-comment "\" in " type)) ) ; end of let* ) ; end of if ) ; end of if (= parasite-number -1) ) ; end of let* ) ;;;;;;;;;;;;;;;;;;;; Remove a parasite ((= method 4) (let* ((parasite-number (- (car (parasite-list target-type)) 1)) (target-comment (if (and (and (<= 0 comment-number) (<= comment-number parasite-number)) (not (= parasite-number -1))) (list-ref (cadr (parasite-list target-type)) comment-number) "")) ) (if (= parasite-number -1) (gimp-message "Found not parasite information. Abort!") (if (not (and (<= 0 comment-number) (<= comment-number parasite-number))) (gimp-message "Incorrect Target comment No. Abort!") (begin (parasite-detach target-type target-comment) (gimp-message (string-append "Successful!\n" "Removed the comment named \"" target-comment "\" from parasite list in " type)) ) ; end of begin ) ; end of if ) ; end of if (= parasite-number -1) ) ; end of let* ) ;;;;;;;;;;;;;;;;;;;; Create new parasite ((= method 5) (let* ((flag 1) ; what means flag number? (1 = ?), (2 = ?), etc. (parasite-number (- (car (parasite-list target-type)) 1)) (parasite-message "") (target-comment string) (result-parasite (list target-comment flag parasite-message)) (flag FALSE) (count 0) ) (if (equal? string "") (gimp-message "New comment name is empty. Abort!") (begin (while (< count parasite-number) (if (equal? target-comment (list-ref (cadr (parasite-list target-type)) count)) (set! flag TRUE)) (set! count (+ count 1)) ) ; end of while (if (eqv? flag TRUE) (gimp-message "The same comment name is existing. Abort!") (begin (parasite-attach target-type result-parasite) (gimp-message (string-append "Successful!\n" "Create new comment named \"" string "\" at parasite list in " type)) ) ; end of begin ) ; end of if ) ; end of begin ) ; end of if ) ; end of let* ) ;;;;;;;;;;;;;;;;;;;; helper function (never used) ((= method 6) (define (array->list array) (let* ((array-size (- (length array) 1)) (mylist '())) (while (>= array-size 0) (set! local-array (aref array array-size)) (set! mylist (cons local-array mylist)) (set! array-size (- array-size 1)) ) mylist ) ) (let* ((listed-string (array->list (hexstr->bytes (array->hexstr string)))) (list-length (length listed-string)) (result-message (string-append "String \"" string "\" is represented in Interger: \n(")) (count 0) ) (while (< count list-length) (set! result-message (string-append result-message " " (number->string (list-ref listed-string count)))) (set! count (+ count 1)) ) ; end of while (set! result-message (string-append result-message " )")) (output-result result-message)) ) ;;;;;;;;;;;;;;;;;;;; end ) ; end of cond (if (equal? export? TRUE) (fclose outfile)) ) ; end of define (script-fu-register "script-fu-read-write-parasite" "/Script-Fu/Utils/Read or Write a Parasite..." "Read/Write a parasite" "Iccii " "Iccii" "2001, Sep" "RGB* GRAY* INDEXED*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-OPTION "Method" '("Show list" "Read" "Overwrite" "Addtional Write" "Remove" "Create New" ; "Convert into Integer" ;; don't use ) SF-OPTION "Target Object" '("Image" "Drawable" "Global") SF-ADJUSTMENT "Target comment No." '(0 0 127 1 10 0 1) SF-STRING "String" "Happy GIMPing!" SF-FILENAME "Export Result to File" "" )