[Part I. GIMP基礎功]

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



30.5 程式old-photo.scm分三部份

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

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

程式old-photo.scm分三部份:
  • 1~26行:註解,功能說明與版權聲明。
  • 27~88行:定義函式
  • 89~110行:註冊函式

第1到第26行:註解說明1: ;
2: ; old-photo
3: ;
4: ;
5: ; Chris Gutteridge (cjg@ecs.soton.ac.uk)
6: ; At ECS Dept, University of Southampton, England.
7:
8: ; This program is free software; you can redistribute it and/or modify
9: ; it under the terms of the GNU General Public License as published by
10: ; the Free Software Foundation; either version 2 of the License, or
11: ; (at your option) any later version.
12: ;
13: ; This program is distributed in the hope that it will be useful,
14: ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15: ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: ; GNU General Public License for more details.
17: ;
18: ; You should have received a copy of the GNU General Public License
19: ; along with this program; if not, write to the Free Software
20: ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21: ;
22: ; Branko Collin <collin@xs4all.nl> added the possibility to change
23: ; the border size in October 2001.
24:
25: ; Define the function:
26:

第27到第88行:定義函式
27: (define (script-fu-old-photo inImage inLayer inDefocus inBorderSize inSepia inMottle inCopy)
28: (let (
29: (theImage 0)
30: (theLayer 0)
31: (theWidth 0)
32: (theHeight 0)
33: )
34: (gimp-image-undo-group-start inImage)
35: (gimp-selection-all inImage)
36: (set! theImage (if (= inCopy TRUE)
37: (car (gimp-image-duplicate inImage))
38: inImage)
39: )
40:
41: (set! theLayer (car (gimp-image-flatten theImage)))
42: (if (= inDefocus TRUE)
43: (plug-in-gauss-rle RUN-NONINTERACTIVE theImage theLayer 1.5 TRUE TRUE)
44: )
45: (if (> inBorderSize 0)
46: (script-fu-fuzzy-border theImage theLayer '(255 255 255)
47: inBorderSize TRUE 8 FALSE 100 FALSE TRUE )
48: )
49: (set! theLayer (car (gimp-image-flatten theImage)))
50:
51: (if (= inSepia TRUE)
52: (begin (gimp-desaturate theLayer)
53: (gimp-brightness-contrast theLayer -20 -40)
54: (gimp-color-balance theLayer 0 TRUE 30 0 -30)
55: )
56: )
57: (set! theWidth (car (gimp-image-width theImage)))
58: (set! theHeight (car (gimp-image-height theImage)))
59: (if (= inMottle TRUE)
60: (let (
61: (mLayer (car (gimp-layer-new theImage theWidth theHeight
62: RGBA-IMAGE "Mottle"
63: 100 DARKEN-ONLY-MODE)))
64: )
65:
66: (gimp-image-add-layer theImage mLayer 0)
67: (gimp-selection-all theImage)
68: (gimp-edit-clear mLayer)
69: (gimp-selection-none theImage)
70: (plug-in-noisify RUN-NONINTERACTIVE theImage mLayer TRUE 0 0 0 0.5)
71: (plug-in-gauss-rle RUN-NONINTERACTIVE theImage mLayer 5 TRUE TRUE)
72: (set! theLayer (car (gimp-image-flatten theImage)))
73: )
74: )
75:
76:
77:
78: (if (= inCopy TRUE)
79: (begin (gimp-image-clean-all theImage)
80: (gimp-display-new theImage)
81: )
82: )
83: (gimp-selection-none inImage)
84: (gimp-image-undo-group-end inImage)
85: (gimp-displays-flush theImage)
86: )
87: )
88:

第89到第110行:註冊函式
89: (script-fu-register "script-fu-old-photo"
90: _"_Old Photo..."
91: _"Make an image look like an old photo"
92: "Chris Gutteridge"
93: "1998, Chris Gutteridge / ECS dept, University of Southampton, England."
94: "16th April 1998"
95: "RGB* GRAY*"
96: SF-IMAGE "The image" 0
97: SF-DRAWABLE "The layer" 0
98: SF-TOGGLE _"Defocus" TRUE
99: SF-ADJUSTMENT _"Border size" '(20 0 300 1 10 0 1)
100: ; since this plug-in uses the fuzzy-border plug-in, I used the
101: ; values of the latter, with the exception of the initial value
102: ; and the 'minimum' value.
103: SF-TOGGLE _"Sepia" TRUE
104: SF-TOGGLE _"Mottle" FALSE
105: SF-TOGGLE _"Work on copy" TRUE
106: )
107:
108: (script-fu-menu-register "script-fu-old-photo"
109: "<Image>/Filters/Decor")
110: