-
Notifications
You must be signed in to change notification settings - Fork 0
/
elsamuko-national-geographic-next-gen.scm
283 lines (257 loc) · 12.2 KB
/
elsamuko-national-geographic-next-gen.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
; The GIMP -- an image manipulation program
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
;
; 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 3 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.
; http://www.gnu.org/licenses/gpl-3.0.html
;
; Copyright (C) 2008 elsamuko <[email protected]>
; 2024 ott 11 fix for 2.99.19 vitforlinux
; Version 0.1 - Simulate a high quality photo like these from the National Geographic
; Thanks to Martin Egger <[email protected]> for the shadow revovery and the sharpen script
;
; This is the batch version of the NG script, run it with
; gimp -i -b '(elsamuko-national-geographic-next-gen-batch "picture.jpg" 60 1 60 25 0.4 1 0)' -b '(gimp-quit 0)'
; or for more than one picture
; gimp -i -b '(elsamuko-national-geographic-next-gen-batch "*.jpg" 60 1 60 25 0.4 1 0)' -b '(gimp-quit 0)'
; Fix code for gimp 2.99.6 working in 2.10
(cond ((not (defined? 'gimp-image-get-width)) (define gimp-image-get-width gimp-image-width)))
(cond ((not (defined? 'gimp-image-get-height)) (define gimp-image-get-height gimp-image-height)))
(define (elsamuko-national-geographic-next-gen aimg adraw shadowopacity
sharpness screenopacity
overlayopacity localcontrast
screenmask tint)
(let* ((img (car (gimp-item-get-image adraw)))
(owidth (car (gimp-image-get-width img)))
(oheight (car (gimp-image-get-height img)))
(overlaylayer 0)
(overlaylayer2 0)
(screenlayer 0)
(contrastlayer 0)
(tmplayer1 0)
(tmplayer2 0)
(floatingsel 0)
(ShadowLayer (car (gimp-layer-copy adraw TRUE)))
(MaskImage (car (gimp-image-duplicate aimg)))
(MaskLayer (cadr (gimp-image-get-layers MaskImage)))
(OrigLayer (cadr (gimp-image-get-layers aimg)))
;(HSVImage (car (plug-in-decompose TRUE aimg adraw "Value" TRUE)))
(HSVImage (if (= (string->number (substring (car(gimp-version)) 0 3)) 2.10)
(car (plug-in-decompose TRUE aimg adraw "RGB" TRUE))
(car (plug-in-decompose 1 aimg 1 (vector adraw) "rgb" TRUE FALSE)) ;2.99.19
))
(HSVLayer (cadr (gimp-image-get-layers HSVImage)))
(SharpenLayer (car (gimp-layer-copy adraw TRUE)))
)
;init
(gimp-context-push)
(gimp-image-undo-group-start img)
(if (= (car (gimp-drawable-is-gray adraw )) TRUE)
(gimp-image-convert-rgb img)
)
;(gimp-context-set-foreground '(0 0 0))
;(gimp-context-set-background '(255 255 255))
;shadow recovery from here: http://registry.gimp.org/node/112
(if(> shadowopacity 0)
(begin
(gimp-image-insert-layer img ShadowLayer 0 -1)
(gimp-drawable-desaturate ShadowLayer 2)
(gimp-drawable-invert ShadowLayer FALSE)
(let* ((ShadowMask (car (gimp-layer-create-mask ShadowLayer ADD-MASK-WHITE))))
(gimp-layer-add-mask ShadowLayer ShadowMask)
(gimp-selection-all img)
(if (= (string->number (substring (car(gimp-version)) 0 3)) 2.10)
(begin (gimp-edit-copy ShadowLayer)
(gimp-floating-sel-anchor (car (gimp-edit-paste ShadowMask TRUE))))
(begin (gimp-edit-copy 1 (vector ShadowLayer))
(let* (
(pasted (gimp-edit-paste ShadowMask FALSE))
(num-pasted (car pasted))
(floating-sel (aref (cadr pasted) (- num-pasted 1)))
)
(gimp-floating-sel-anchor floating-sel)
)))
;(gimp-floating-sel-anchor (car (gimp-edit-paste ShadowMask TRUE)))
)
(gimp-layer-set-mode ShadowLayer LAYER-MODE-OVERLAY-LEGACY)
(gimp-layer-set-opacity ShadowLayer shadowopacity)
(gimp-item-set-name ShadowLayer "Shadow Recovery")
)
)
;smart sharpen from here: http://registry.gimp.org/node/108
(if(> sharpness 0)
(begin
(gimp-image-insert-layer img SharpenLayer 0 -1)
(gimp-selection-all HSVImage)
(if (= (string->number (substring (car(gimp-version)) 0 3)) 2.10)
(begin(gimp-edit-copy (aref HSVLayer 0))
(gimp-floating-sel-anchor (car (gimp-edit-paste SharpenLayer FALSE))))
(gimp-edit-copy 1 (vector (aref HSVLayer 0)))
; Clipboard is copy of mask-drawable. Paste into mask, a channel, and anchor it.
(begin (let* (
(pasted (gimp-edit-paste SharpenLayer FALSE))
(num-pasted (car pasted))
(floating-sel (aref (cadr pasted) (- num-pasted 1)))
)
(gimp-floating-sel-anchor floating-sel)
)))
(gimp-image-delete HSVImage)
;(gimp-floating-sel-anchor (car (gimp-edit-paste SharpenLayer FALSE)))
(gimp-layer-set-mode SharpenLayer LAYER-MODE-HSV-VALUE-LEGACY)
(plug-in-edge TRUE MaskImage (aref MaskLayer 0) 6 1 0)
(gimp-drawable-levels-stretch (aref MaskLayer 0))
(gimp-image-convert-grayscale MaskImage)
(plug-in-gauss TRUE MaskImage (aref MaskLayer 0) 6 6 TRUE)
(let* ((SharpenChannel (car (gimp-layer-create-mask SharpenLayer ADD-MASK-WHITE)))
)
(gimp-layer-add-mask SharpenLayer SharpenChannel)
(gimp-selection-all MaskImage)
(if (= (string->number (substring (car(gimp-version)) 0 3)) 2.10)
(begin (gimp-edit-copy (aref MaskLayer 0))
(gimp-floating-sel-anchor (car (gimp-edit-paste SharpenChannel FALSE))))
(begin (gimp-edit-copy 1 (vector (aref MaskLayer 0)))
;(gimp-floating-sel-anchor (car (gimp-edit-paste SharpenChannel FALSE)))
(let* (
(pasted (gimp-edit-paste SharpenChannel FALSE))
(num-pasted (car pasted))
(floating-sel (aref (cadr pasted) (- num-pasted 1)))
)
(gimp-floating-sel-anchor floating-sel)
)))
(gimp-image-delete MaskImage)
(plug-in-unsharp-mask TRUE img SharpenLayer 1 sharpness 0)
(gimp-layer-set-opacity SharpenLayer 80)
(gimp-layer-set-edit-mask SharpenLayer FALSE)
)
(gimp-item-set-name SharpenLayer "Sharpen")
)
)
;enhance local contrast
(if(> localcontrast 0)
(begin
(gimp-edit-copy-visible img)
(set! tmplayer1 (car (gimp-layer-new-from-visible img img "Temp 1")))
(set! tmplayer2 (car (gimp-layer-new-from-visible img img "Temp 2")))
(gimp-image-insert-layer img tmplayer1 0 -1)
(gimp-image-insert-layer img tmplayer2 0 -1)
(plug-in-unsharp-mask 1 img tmplayer1 60 localcontrast 0)
(gimp-layer-set-mode tmplayer2 LAYER-MODE-GRAIN-EXTRACT-LEGACY)
(gimp-edit-copy-visible img)
(set! contrastlayer (car (gimp-layer-new-from-visible img img "Local Contrast")))
(gimp-image-insert-layer img contrastlayer 0 -1)
(gimp-layer-set-mode contrastlayer LAYER-MODE-GRAIN-MERGE-LEGACY)
(gimp-image-remove-layer img tmplayer1)
(gimp-image-remove-layer img tmplayer2)
)
)
;copy visible three times
(gimp-edit-copy-visible img)
(set! overlaylayer (car (gimp-layer-new-from-visible img img "Overlay")))
(set! overlaylayer2 (car (gimp-layer-new-from-visible img img "Overlay2")))
(set! screenlayer (car (gimp-layer-new-from-visible img img "Screen")))
;add screen- and overlay- layers
(gimp-image-insert-layer img screenlayer 0 -1)
(gimp-image-insert-layer img overlaylayer 0 -1)
(gimp-image-insert-layer img overlaylayer2 0 -1)
;desaturate layers
(gimp-drawable-desaturate screenlayer 2)
(gimp-drawable-desaturate overlaylayer 2)
(gimp-drawable-desaturate overlaylayer2 2)
;set modes
(gimp-layer-set-mode screenlayer LAYER-MODE-SCREEN-LEGACY)
(gimp-layer-set-mode overlaylayer LAYER-MODE-OVERLAY-LEGACY)
(gimp-layer-set-mode overlaylayer2 LAYER-MODE-OVERLAY-LEGACY)
(gimp-layer-set-opacity screenlayer screenopacity)
(gimp-layer-set-opacity overlaylayer overlayopacity)
(gimp-layer-set-opacity overlaylayer2 overlayopacity)
;layermask for the screen layer
(if(= screenmask TRUE)
(begin
(set! floatingsel (car (gimp-layer-create-mask screenlayer 5)))
(gimp-layer-add-mask screenlayer floatingsel)
(gimp-drawable-invert floatingsel FALSE)
)
)
;overlay tint
;red
(if(= tint 1)
(begin
(gimp-drawable-colorize-hsl screenlayer 0 25 0)
(gimp-drawable-colorize-hsl overlaylayer 0 25 0)
(gimp-drawable-colorize-hsl overlaylayer2 0 25 0)
)
)
;blue
(if(= tint 2)
(begin
(gimp-drawable-colorize-hsl screenlayer 225 25 0)
(gimp-drawable-colorize-hsl overlaylayer 225 25 0)
(gimp-drawable-colorize-hsl overlaylayer2 225 25 0)
)
)
; tidy up
(gimp-image-undo-group-end img)
(gimp-displays-flush)
(gimp-context-pop)
)
)
(define (elsamuko-national-geographic-next-gen-batch pattern shadowopacity
sharpness screenopacity
overlayopacity localcontrast
screenmask tint)
(gimp-message (string-append "Pattern: " pattern))
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(fileparts (strbreakup filename "."))
(img (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(adraw (car (gimp-image-get-active-drawable img)))
)
(gimp-message (string-append "Filename: " filename))
(gimp-message "Calling elsamuko-national-geographic-next-gen")
(elsamuko-national-geographic-next-gen img adraw shadowopacity
sharpness screenopacity
overlayopacity localcontrast
screenmask tint)
(gimp-image-merge-visible-layers img EXPAND-AS-NECESSARY)
(set! adraw (car (gimp-image-get-active-drawable img)))
(gimp-message "Saving")
(gimp-file-save RUN-NONINTERACTIVE img adraw filename filename)
(gimp-image-delete img)
(set! filelist (cdr filelist))
)
)
)
)
(script-fu-register "elsamuko-national-geographic-next-gen"
_"_National Geographic Next Gen"
"Simulating high quality photos.
Latest version can be downloaded from http://registry.gimp.org/node/9592"
"elsamuko <[email protected]>"
"elsamuko"
"22/09/08"
"*"
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0
SF-ADJUSTMENT _"Shadow Recover Opacity" '(60 0 100 1 5 0 0)
SF-ADJUSTMENT _"Sharpness" '(0.5 0 2 0.1 1 1 0)
SF-ADJUSTMENT _"Screen Layer Opacity" '(50 0 100 1 5 0 0)
SF-ADJUSTMENT _"Overlay Layer Opacity" '(50 0 100 1 5 0 0)
SF-ADJUSTMENT _"Local Contrast" '(0.4 0 2 0.1 1 1 0)
SF-TOGGLE _"Layer Mask for the Screen Layer" TRUE
SF-OPTION _"Overlay Tint" '("Neutral"
"Red"
"Blue")
)
(script-fu-menu-register "elsamuko-national-geographic-next-gen" _"<Image>/Filters/Generic")