-
Notifications
You must be signed in to change notification settings - Fork 1
/
Franzis_Focus.py
146 lines (113 loc) · 4.37 KB
/
Franzis_Focus.py
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
#!/usr/bin/env python
'''
Dfine2.py
call Nik's Collection's Viveza 2 passing the active layer as a temp file.
Author:
Rob Antonishen
Modified by
Partha Bagchi
Modified by Martin Pohl
Version:
0.8 Made it specific to Nik Collection
0.7 fixed file save bug where all files were png regardless of extension
0.6 modified to allow for a returned layer that is a different size
than the saved layer for
0.5 file extension parameter in program list.
0.4 modified to support many optional programs.
this script is modelled after the mm extern LabCurves trace plugin
by Michael Munzert http://www.mm-log.com/lab-curves-gimp
and thanks to the folds at gimp-chat has grown a bit ;)
License:
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; version 3 of the License.
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.
The GNU Public License is available at
http://www.gnu.org/copyleft/gpl.html
'''
from gimpfu import *
import shlex
import subprocess
import os, sys
import tempfile
def gimp_log( text ):
pdb.gimp_message( text )
def plugin_main( image, drawable, visible ):
pdb.gimp_image_undo_group_start(image)
# Copy so the save operations doesn't affect the original
if visible == 0:
# Save in temporary. Note: empty user entered file name
temp = pdb.gimp_image_get_active_drawable(image)
else:
# Get the current visible
temp = pdb.gimp_layer_new_from_visible(image, image, "Franzis_Focus")
image.add_layer(temp, 0)
buffer = pdb.gimp_edit_named_copy(temp, "ShellOutTemp")
#save selection if one exists
hassel = pdb.gimp_selection_is_empty(image) == 0
if hassel:
savedsel = pdb.gimp_selection_save(image)
tempimage = pdb.gimp_edit_named_paste_as_new(buffer)
pdb.gimp_buffer_delete(buffer)
if not tempimage:
raise RuntimeError
pdb.gimp_image_undo_disable(tempimage)
tempdrawable = pdb.gimp_image_get_active_layer(tempimage)
tempfilename = os.path.join(tempfile.gettempdir(), "ShellOutTempFile.tiff" )
# !!! Note no run-mode first parameter, and user entered filename is empty string
pdb.gimp_progress_set_text ("Saving a copy")
pdb.gimp_file_save(tempimage, tempdrawable, tempfilename, tempfilename)
# Build command line call
command = "\"C:\\Program Files\\Franzis\\FOCUS projects 3 professional\\FOCUS projects 3 professional.exe\"" + " \"" + tempfilename + "\""
args = shlex.split(command)
# Invoke external command
pdb.gimp_progress_set_text ("calling Franzis Focus...")
pdb.gimp_progress_pulse()
child = subprocess.Popen(args, shell=False)
child.communicate()
# put it as a new layer in the opened image
try:
newlayer2 = pdb.gimp_file_load_layer(tempimage, tempfilename)
except:
RuntimeError
tempimage.add_layer(newlayer2,-1)
buffer = pdb.gimp_edit_named_copy(newlayer2, "ShellOutTemp")
if visible == 0:
drawable.resize(newlayer2.width,newlayer2.height,0,0)
sel = pdb.gimp_edit_named_paste(drawable, buffer, 1)
drawable.translate((tempdrawable.width-newlayer2.width)/2,(tempdrawable.height-newlayer2.height)/2)
else:
temp.resize(newlayer2.width,newlayer2.height,0,0)
sel = pdb.gimp_edit_named_paste(temp, buffer, 1)
temp.translate((tempdrawable.width-newlayer2.width)/2,(tempdrawable.height-newlayer2.height)/2)
pdb.gimp_buffer_delete(buffer)
pdb.gimp_edit_clear(temp)
pdb.gimp_floating_sel_anchor(sel)
#load up old selection
if hassel:
pdb.gimp_selection_load(savedsel)
image.remove_channel(savedsel)
# cleanup
os.remove(tempfilename) # delete the temporary file
gimp.delete(tempimage) # delete the temporary image
# Note the new image is dirty in Gimp and the user will be asked to save before closing.
pdb.gimp_image_undo_group_end(image)
gimp.displays_flush()
register(
"python_fu_FranzisFocus",
"Call Franzis Focus",
"Call Franzis Focus",
"Rob Antonishen",
"Copyright 2011 Rob Antonishen",
"2011",
"<Image>/Photography/Franzis Focus",
"RGB*, GRAY*",
[ (PF_RADIO, "visible", "Layer:", 1, (("new from visible", 1),("current layer",0))),
],
[],
plugin_main,
)
main()