[Part I. GIMP基礎功]

[Part II. 一種效果的誕生]
[Part III. Script-Fu的秘密]



25.5 程式clothify.scm分三部份

若要徹底瞭解clothify.scm,可仿傚第23章的方式,單步執行,來分析每一行程式碼的作用。

若用PSPad開啟程式檔(或任何文字編輯器),看到的Script-Fu程式碼,變數會對得很整齊。HTML會把大量的空白省略,因此程式碼的排版變成了下面這樣子。我替Script-Fu程式碼加上行號乎,方便讀者閱讀。

程式clothify.scm分三部份:
  • 1~17行:註解,功能說明與版權聲明。
  • 18~49行:定義函式,在測試程式的過程中,可將它改為(define (script-fu-clothify2 … ))
  • 50~68行:註冊函式,可將它改為(script-fu-register "script-fu- clothify2 " …)


第1到第17行:註解說明1: ; CLOTHIFY version 1.02
2: ; Gives the current layer in the indicated image a cloth-like texture.
3: ; Process invented by Zach Beane (Xath@irc.gimp.net)
4: ;
5: ; Tim Newsome <drz@froody.bloke.com> 4/11/97
6:
7: (define (script-fu-clothify timg tdrawable bx by azimuth elevation depth)
8: (let* (
9: (width (car (gimp-drawable-width tdrawable)))
10: (height (car (gimp-drawable-height tdrawable)))
11: (img (car (gimp-image-new width height RGB)))
12: ; (layer-two (car (gimp-layer-new img width height RGB-IMAGE "Y Dots" 100 MULTIPLY-MODE)))
13: (layer-one (car (gimp-layer-new img width height RGB-IMAGE "X Dots" 100 NORMAL-MODE)))
14: (layer-two 0)
15: (bump-layer 0)
16: )
17:

第18到第49行:定義函式18: (gimp-context-push)
19:
20: (gimp-image-undo-disable img)
21:
22: (gimp-image-add-layer img layer-one 0)
23:
24: (gimp-context-set-background '(255 255 255))
25: (gimp-edit-fill layer-one BACKGROUND-FILL)
26:
27: (plug-in-noisify RUN-NONINTERACTIVE img layer-one FALSE 0.7 0.7 0.7 0.7)
28:
29: (set! layer-two (car (gimp-layer-copy layer-one 0)))
30: (gimp-layer-set-mode layer-two MULTIPLY-MODE)
31: (gimp-image-add-layer img layer-two 0)
32:
33: (plug-in-gauss-rle RUN-NONINTERACTIVE img layer-one bx TRUE FALSE)
34: (plug-in-gauss-rle RUN-NONINTERACTIVE img layer-two by FALSE TRUE)
35: (gimp-image-flatten img)
36: (set! bump-layer (car (gimp-image-get-active-layer img)))
37:
38: (plug-in-c-astretch RUN-NONINTERACTIVE img bump-layer)
39: (plug-in-noisify RUN-NONINTERACTIVE img bump-layer FALSE 0.2 0.2 0.2 0.2)
40:
41: (plug-in-bump-map RUN-NONINTERACTIVE img tdrawable bump-layer azimuth elevation depth 0 0 0 0 FALSE FALSE 0)
42: (gimp-image-delete img)
43: (gimp-displays-flush)
44:
45: (gimp-context-pop)
46: )
47: )
48:
49:

第50到第68行:註冊函式50: (script-fu-register "script-fu-clothify"
51: _"_Clothify..."
52: _"Add a cloth-like texture to the selected region (or alpha)"
53: "Tim Newsome <drz@froody.bloke.com>"
54: "Tim Newsome"
55: "4/11/97"
56: "RGB* GRAY*"
57: SF-IMAGE "Input image" 0
58: SF-DRAWABLE "Input drawable" 0
59: SF-ADJUSTMENT _"Blur X" '(9 3 100 1 10 0 1)
60: SF-ADJUSTMENT _"Blur Y" '(9 3 100 1 10 0 1)
61: SF-ADJUSTMENT _"Azimuth" '(135 0 360 1 10 1 0)
62: SF-ADJUSTMENT _"Elevation" '(45 0 90 1 10 1 0)
63: SF-ADJUSTMENT _"Depth" '(3 1 50 1 10 0 1)
64: )
65:
66: (script-fu-menu-register "script-fu-clothify"
67: "<Image>/Filters/Artistic")
68: