Rev 189 | Rev 194 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 189 | Rev 192 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
3 | Copyright (C) 2003-2019 Toby Thain, toby@telegraphics.com.au |
3 | Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au |
- | 4 | Copyright (C) 2018-2019 Daniel Marschall, ViaThinkSoft |
|
4 | 5 | ||
5 | This program is free software; you can redistribute it and/or modify |
6 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
7 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
9 | (at your option) any later version. |
9 | 10 | ||
10 | This program is distributed in the hope that it will be useful, |
11 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
14 | GNU General Public License for more details. |
14 | 15 | ||
15 | You should have received a copy of the GNU General Public License |
16 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
17 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
19 | */ |
19 | 20 | ||
20 | /* Portions Copyright 1996 - 1999 Adobe Systems Incorporated */ |
21 | /* Portions Copyright 1996 - 1999 Adobe Systems Incorporated */ |
21 | /* All Rights Reserved. */ |
22 | /* All Rights Reserved. */ |
22 | 23 | ||
23 | //#include <stdio.h> |
24 | //#include <stdio.h> |
24 | 25 | ||
25 | //#include "world.h" // must come before Photoshop includes |
26 | //#include "world.h" // must come before Photoshop includes |
26 | 27 | ||
27 | #include "ff.h" |
28 | #include "ff.h" |
28 | 29 | ||
29 | #include "scripting.h" |
30 | #include "scripting.h" |
30 | //#include "ui.h" |
31 | //#include "ui.h" |
31 | #include "dbg.h" |
32 | #include "dbg.h" |
32 | 33 | ||
33 | //extern FilterRecordPtr gpb; |
34 | //extern FilterRecordPtr gpb; |
34 | 35 | ||
35 | OSErr put_cstring(PIWriteDescriptor token,DescriptorKeyID key,char *s){ |
36 | OSErr put_cstring(PIWriteDescriptor token,DescriptorKeyID key,char *s){ |
36 | size_t n = strlen(s); |
37 | size_t n = strlen(s); |
37 | Ptr p; |
38 | Ptr p; |
38 | Handle h = PINEWHANDLE((int32)n); |
39 | Handle h = PINEWHANDLE((int32)n); |
39 | p = PILOCKHANDLE(h,false); |
40 | p = PILOCKHANDLE(h,false); |
40 | memcpy(p,s,n); |
41 | memcpy(p,s,n); |
41 | PIUNLOCKHANDLE(h); |
42 | PIUNLOCKHANDLE(h); |
42 | return PIPutText(token,key,h); |
43 | return PIPutText(token,key,h); |
43 | /* FIXME: not sure if we are supposed to dispose of handle */ |
44 | /* FIXME: not sure if we are supposed to dispose of handle */ |
44 | } |
45 | } |
45 | 46 | ||
46 | char *get_cstring(PIReadDescriptor token){ |
47 | char *get_cstring(PIReadDescriptor token){ |
47 | int n; |
48 | int n; |
48 | Ptr p; |
49 | Ptr p; |
49 | char *str = NULL; |
50 | char *str = NULL; |
50 | Handle h; |
51 | Handle h; |
51 | OSErr e = PIGetText(token,&h); |
52 | OSErr e = PIGetText(token,&h); |
52 | 53 | ||
53 | if(!e && h){ |
54 | if(!e && h){ |
54 | n = PIGETHANDLESIZE(h); |
55 | n = PIGETHANDLESIZE(h); |
55 | p = PILOCKHANDLE(h,false); |
56 | p = PILOCKHANDLE(h,false); |
56 | //sprintf(str,"get_cstring: token=%#x s=%#x h=%#x p=%#x n=%d",token,s,h,p,n); dbg(str); |
57 | //sprintf(str,"get_cstring: token=%#x s=%#x h=%#x p=%#x n=%d",token,s,h,p,n); dbg(str); |
57 | if( (str = malloc(n+1)) ){ |
58 | if( (str = malloc(n+1)) ){ |
58 | memcpy(str,p,n); |
59 | memcpy(str,p,n); |
59 | str[n] = 0; |
60 | str[n] = 0; |
60 | } |
61 | } |
61 | PIUNLOCKHANDLE(h); |
62 | PIUNLOCKHANDLE(h); |
62 | /* FIXME: not sure if we are supposed to dispose of handle */ |
63 | /* FIXME: not sure if we are supposed to dispose of handle */ |
63 | } |
64 | } |
64 | return str; |
65 | return str; |
65 | } |
66 | } |
66 | 67 | ||
67 | /* return true if dialog should be shown */ |
68 | /* return true if dialog should be shown */ |
68 | 69 | ||
69 | Boolean ReadScriptParamsOnRead(void) |
70 | Boolean ReadScriptParamsOnRead(void) |
70 | { |
71 | { |
71 | PIReadDescriptor token; |
72 | PIReadDescriptor token; |
72 | DescriptorKeyID key; |
73 | DescriptorKeyID key; |
73 | DescriptorTypeID type; |
74 | DescriptorTypeID type; |
74 | DescriptorKeyIDArray array = { NULLID }; |
75 | DescriptorKeyIDArray array = { NULLID }; |
75 | int32 flags; |
76 | int32 flags; |
76 | OSErr stickyError; |
77 | OSErr stickyError; |
77 | int32 v; |
78 | int32 v; |
78 | 79 | ||
79 | if (DescriptorAvailable(NULL)){ /* playing back. Do our thing. */ |
80 | if (DescriptorAvailable(NULL)){ /* playing back. Do our thing. */ |
80 | token = OpenReader(array); |
81 | token = OpenReader(array); |
81 | if (token){ |
82 | if (token){ |
82 | while (PIGetKey(token, &key, &type, &flags)){ |
83 | while (PIGetKey(token, &key, &type, &flags)){ |
83 | switch (key){ |
84 | switch (key){ |
84 | case PARAM_R_KEY: expr[0] = get_cstring(token); break; |
85 | case PARAM_R_KEY: expr[0] = get_cstring(token); break; |
85 | case PARAM_G_KEY: expr[1] = get_cstring(token); break; |
86 | case PARAM_G_KEY: expr[1] = get_cstring(token); break; |
86 | case PARAM_B_KEY: expr[2] = get_cstring(token); break; |
87 | case PARAM_B_KEY: expr[2] = get_cstring(token); break; |
87 | case PARAM_A_KEY: expr[3] = get_cstring(token); break; |
88 | case PARAM_A_KEY: expr[3] = get_cstring(token); break; |
88 | default: |
89 | default: |
89 | if(key >= PARAM_CTL0_KEY && key <= PARAM_CTL7_KEY){ |
90 | if(key >= PARAM_CTL0_KEY && key <= PARAM_CTL7_KEY){ |
90 | PIGetInt(token,&v); |
91 | PIGetInt(token,&v); |
91 | slider[key - PARAM_CTL0_KEY] = v; |
92 | slider[key - PARAM_CTL0_KEY] = v; |
92 | } |
93 | } |
93 | break; |
94 | break; |
94 | } |
95 | } |
95 | } |
96 | } |
96 | 97 | ||
97 | stickyError = CloseReader(&token); // closes & disposes. |
98 | stickyError = CloseReader(&token); // closes & disposes. |
98 | 99 | ||
99 | // all Filter Foundry parameters are optional, |
100 | // all Filter Foundry parameters are optional, |
100 | // so we needn't worry if any are missing |
101 | // so we needn't worry if any are missing |
101 | } |
102 | } |
102 | 103 | ||
103 | return gpb->descriptorParameters->playInfo == plugInDialogDisplay; /* TRUE if want to show our Dialog */ |
104 | return gpb->descriptorParameters->playInfo == plugInDialogDisplay; /* TRUE if want to show our Dialog */ |
104 | } |
105 | } |
105 | 106 | ||
106 | return false; |
107 | return false; |
107 | } |
108 | } |
108 | 109 | ||
109 | OSErr WriteScriptParamsOnRead(void) |
110 | OSErr WriteScriptParamsOnRead(void) |
110 | { |
111 | { |
111 | PIWriteDescriptor token; |
112 | PIWriteDescriptor token; |
112 | OSErr gotErr = noErr; |
113 | OSErr gotErr = noErr; |
113 | extern int ctls[],maps[],nplanes; |
114 | extern int ctls[],maps[],nplanes; |
114 | int i,allctls; |
115 | int i,allctls; |
115 | 116 | ||
116 | if (DescriptorAvailable(NULL)){ /* recording. Do our thing. */ |
117 | if (DescriptorAvailable(NULL)){ /* recording. Do our thing. */ |
117 | token = OpenWriter(); |
118 | token = OpenWriter(); |
118 | if (token){ |
119 | if (token){ |
119 | // write keys here |
120 | // write keys here |
120 | if(!gdata->standalone){ |
121 | if(!gdata->standalone){ |
121 | if (nplanes > 0) put_cstring(token, PARAM_R_KEY, expr[0]); |
122 | if (nplanes > 0) put_cstring(token, PARAM_R_KEY, expr[0]); |
122 | if (nplanes > 1) put_cstring(token, PARAM_G_KEY, expr[1]); |
123 | if (nplanes > 1) put_cstring(token, PARAM_G_KEY, expr[1]); |
123 | if (nplanes > 2) put_cstring(token, PARAM_B_KEY, expr[2]); |
124 | if (nplanes > 2) put_cstring(token, PARAM_B_KEY, expr[2]); |
124 | if (nplanes > 3) put_cstring(token, PARAM_A_KEY, expr[3]); |
125 | if (nplanes > 3) put_cstring(token, PARAM_A_KEY, expr[3]); |
125 | } |
126 | } |
126 | 127 | ||
127 | /* only write values for the sliders that are actually used! */ |
128 | /* only write values for the sliders that are actually used! */ |
128 | allctls = checksliders(4,ctls,maps); |
129 | allctls = checksliders(4,ctls,maps); |
129 | for(i = 0; i < 8; ++i) |
130 | for(i = 0; i < 8; ++i) |
130 | if(allctls || ctls[i]) |
131 | if(allctls || ctls[i]) |
131 | PIPutInt(token, PARAM_CTL0_KEY+i, slider[i]); |
132 | PIPutInt(token, PARAM_CTL0_KEY+i, slider[i]); |
132 | 133 | ||
133 | gotErr = CloseWriter(&token); /* closes and sets dialog optional */ |
134 | gotErr = CloseWriter(&token); /* closes and sets dialog optional */ |
134 | /* done. Now pass handle on to Photoshop */ |
135 | /* done. Now pass handle on to Photoshop */ |
135 | } |
136 | } |
136 | } |
137 | } |
137 | return gotErr; |
138 | return gotErr; |
138 | } |
139 | } |
139 | 140 | ||
140 | 141 | ||
141 | //------------------------------------------------------------------------------- |
142 | //------------------------------------------------------------------------------- |
142 | // |
143 | // |
143 | // HostDescriptorAvailable |
144 | // HostDescriptorAvailable |
144 | // |
145 | // |
145 | // Determines whether the PIDescriptorParameters callback is available. |
146 | // Determines whether the PIDescriptorParameters callback is available. |
146 | // |
147 | // |
147 | // Check for valid suite version, routine suite version, and routine count. |
148 | // Check for valid suite version, routine suite version, and routine count. |
148 | // Also check that the subset of routines we actually use is actually present. |
149 | // Also check that the subset of routines we actually use is actually present. |
149 | // |
150 | // |
150 | //------------------------------------------------------------------------------- |
151 | //------------------------------------------------------------------------------- |
151 | 152 | ||
152 | Boolean HostDescriptorAvailable (PIDescriptorParameters *procs, |
153 | Boolean HostDescriptorAvailable (PIDescriptorParameters *procs, |
153 | Boolean *outNewerVersion) |
154 | Boolean *outNewerVersion) |
154 | { |
155 | { |
155 | if(outNewerVersion) |
156 | if(outNewerVersion) |
156 | *outNewerVersion = procs->descriptorParametersVersion > kCurrentDescriptorParametersVersion |
157 | *outNewerVersion = procs->descriptorParametersVersion > kCurrentDescriptorParametersVersion |
157 | || procs->readDescriptorProcs->readDescriptorProcsVersion > kCurrentReadDescriptorProcsVersion |
158 | || procs->readDescriptorProcs->readDescriptorProcsVersion > kCurrentReadDescriptorProcsVersion |
158 | || procs->writeDescriptorProcs->writeDescriptorProcsVersion > kCurrentWriteDescriptorProcsVersion ; |
159 | || procs->writeDescriptorProcs->writeDescriptorProcsVersion > kCurrentWriteDescriptorProcsVersion ; |
159 | 160 | ||
160 | return procs != NULL |
161 | return procs != NULL |
161 | && procs->descriptorParametersVersion == kCurrentDescriptorParametersVersion |
162 | && procs->descriptorParametersVersion == kCurrentDescriptorParametersVersion |
162 | 163 | ||
163 | && procs->readDescriptorProcs != NULL |
164 | && procs->readDescriptorProcs != NULL |
164 | && procs->readDescriptorProcs->readDescriptorProcsVersion == kCurrentReadDescriptorProcsVersion |
165 | && procs->readDescriptorProcs->readDescriptorProcsVersion == kCurrentReadDescriptorProcsVersion |
165 | && procs->readDescriptorProcs->numReadDescriptorProcs >= kCurrentReadDescriptorProcsCount |
166 | && procs->readDescriptorProcs->numReadDescriptorProcs >= kCurrentReadDescriptorProcsCount |
166 | && procs->readDescriptorProcs->openReadDescriptorProc != NULL |
167 | && procs->readDescriptorProcs->openReadDescriptorProc != NULL |
167 | && procs->readDescriptorProcs->closeReadDescriptorProc != NULL |
168 | && procs->readDescriptorProcs->closeReadDescriptorProc != NULL |
168 | && procs->readDescriptorProcs->getKeyProc != NULL |
169 | && procs->readDescriptorProcs->getKeyProc != NULL |
169 | && procs->readDescriptorProcs->getTextProc != NULL |
170 | && procs->readDescriptorProcs->getTextProc != NULL |
170 | && procs->readDescriptorProcs->getIntegerProc != NULL |
171 | && procs->readDescriptorProcs->getIntegerProc != NULL |
171 | 172 | ||
172 | && procs->writeDescriptorProcs != NULL |
173 | && procs->writeDescriptorProcs != NULL |
173 | && procs->writeDescriptorProcs->writeDescriptorProcsVersion == kCurrentWriteDescriptorProcsVersion |
174 | && procs->writeDescriptorProcs->writeDescriptorProcsVersion == kCurrentWriteDescriptorProcsVersion |
174 | && procs->writeDescriptorProcs->numWriteDescriptorProcs >= kCurrentWriteDescriptorProcsCount |
175 | && procs->writeDescriptorProcs->numWriteDescriptorProcs >= kCurrentWriteDescriptorProcsCount |
175 | && procs->writeDescriptorProcs->openWriteDescriptorProc != NULL |
176 | && procs->writeDescriptorProcs->openWriteDescriptorProc != NULL |
176 | && procs->writeDescriptorProcs->closeWriteDescriptorProc != NULL |
177 | && procs->writeDescriptorProcs->closeWriteDescriptorProc != NULL |
177 | && procs->writeDescriptorProcs->putTextProc != NULL |
178 | && procs->writeDescriptorProcs->putTextProc != NULL |
178 | && procs->writeDescriptorProcs->putIntegerProc != NULL ; |
179 | && procs->writeDescriptorProcs->putIntegerProc != NULL ; |
179 | } |
180 | } |
180 | 181 | ||
181 | 182 | ||
182 | //------------------------------------------------------------------------------- |
183 | //------------------------------------------------------------------------------- |
183 | // |
184 | // |
184 | // HostCloseReader |
185 | // HostCloseReader |
185 | // |
186 | // |
186 | // Closes a read token, disposes its handle, sets the token to NULL, and |
187 | // Closes a read token, disposes its handle, sets the token to NULL, and |
187 | // sets the parameter blocks' descriptor to NULL. |
188 | // sets the parameter blocks' descriptor to NULL. |
188 | // |
189 | // |
189 | // The Descriptor Parameters suite are callbacks designed for |
190 | // The Descriptor Parameters suite are callbacks designed for |
190 | // scripting and automation. See PIActions.h. |
191 | // scripting and automation. See PIActions.h. |
191 | // |
192 | // |
192 | // Inputs: |
193 | // Inputs: |
193 | // PIDescriptorParameters *procs Pointer to Descriptor Parameters suite. |
194 | // PIDescriptorParameters *procs Pointer to Descriptor Parameters suite. |
194 | // |
195 | // |
195 | // HandleProcs *hProcs Pointer to HandleProcs callback. |
196 | // HandleProcs *hProcs Pointer to HandleProcs callback. |
196 | // |
197 | // |
197 | // PIReadDescriptor *token Pointer to token to close. |
198 | // PIReadDescriptor *token Pointer to token to close. |
198 | // |
199 | // |
199 | // procs->descriptor Pointer to original read handle. |
200 | // procs->descriptor Pointer to original read handle. |
200 | // |
201 | // |
201 | // Outputs: |
202 | // Outputs: |
202 | // PIReadDescriptor *token Set to NULL. |
203 | // PIReadDescriptor *token Set to NULL. |
203 | // |
204 | // |
204 | // procs->descriptor Disposed then set to NULL. |
205 | // procs->descriptor Disposed then set to NULL. |
205 | // |
206 | // |
206 | // returns OSErr noErr or error if one occurred. |
207 | // returns OSErr noErr or error if one occurred. |
207 | // |
208 | // |
208 | //------------------------------------------------------------------------------- |
209 | //------------------------------------------------------------------------------- |
209 | 210 | ||
210 | OSErr HostCloseReader (PIDescriptorParameters *procs, |
211 | OSErr HostCloseReader (PIDescriptorParameters *procs, |
211 | HandleProcs *hProcs, |
212 | HandleProcs *hProcs, |
212 | PIReadDescriptor *token) |
213 | PIReadDescriptor *token) |
213 | { |
214 | { |
214 | // Close token: |
215 | // Close token: |
215 | OSErr err = procs->readDescriptorProcs->closeReadDescriptorProc(*token); |
216 | OSErr err = procs->readDescriptorProcs->closeReadDescriptorProc(*token); |
216 | 217 | ||
217 | // Dispose the parameter block descriptor: |
218 | // Dispose the parameter block descriptor: |
218 | hProcs->disposeProc(procs->descriptor); |
219 | hProcs->disposeProc(procs->descriptor); |
219 | 220 | ||
220 | // Set the descriptor and the read token to NULL: |
221 | // Set the descriptor and the read token to NULL: |
221 | procs->descriptor = NULL; |
222 | procs->descriptor = NULL; |
222 | *token = NULL; |
223 | *token = NULL; |
223 | 224 | ||
224 | return err; |
225 | return err; |
225 | 226 | ||
226 | } // end HostCloseReader |
227 | } // end HostCloseReader |
227 | 228 | ||
228 | //------------------------------------------------------------------------------- |
229 | //------------------------------------------------------------------------------- |
229 | // |
230 | // |
230 | // HostCloseWriter |
231 | // HostCloseWriter |
231 | // |
232 | // |
232 | // Closes a write token, stores its handle in the global parameter block for |
233 | // Closes a write token, stores its handle in the global parameter block for |
233 | // the host to use, sets the token to NULL, and sets the recordInfo to |
234 | // the host to use, sets the token to NULL, and sets the recordInfo to |
234 | // plugInDialogOptional (the default). |
235 | // plugInDialogOptional (the default). |
235 | // |
236 | // |
236 | // The Descriptor Parameters suite are callbacks designed for |
237 | // The Descriptor Parameters suite are callbacks designed for |
237 | // scripting and automation. See PIActions.h. |
238 | // scripting and automation. See PIActions.h. |
238 | // |
239 | // |
239 | // Inputs: |
240 | // Inputs: |
240 | // PIDescriptorParameters *procs Pointer to Descriptor Parameters suite. |
241 | // PIDescriptorParameters *procs Pointer to Descriptor Parameters suite. |
241 | // |
242 | // |
242 | // HandleProcs *hProcs Pointer to HandleProcs callback. |
243 | // HandleProcs *hProcs Pointer to HandleProcs callback. |
243 | // |
244 | // |
244 | // PIWriteDescriptor *token Pointer to token to close and pass on. |
245 | // PIWriteDescriptor *token Pointer to token to close and pass on. |
245 | // |
246 | // |
246 | // procs->descriptor Should be NULL. If not, its contents |
247 | // procs->descriptor Should be NULL. If not, its contents |
247 | // will be disposed and replaced. |
248 | // will be disposed and replaced. |
248 | // |
249 | // |
249 | // Outputs: |
250 | // Outputs: |
250 | // PIWriteDescriptor *token Set to NULL. |
251 | // PIWriteDescriptor *token Set to NULL. |
251 | // |
252 | // |
252 | // procs->descriptor Set to descriptor handle. |
253 | // procs->descriptor Set to descriptor handle. |
253 | // |
254 | // |
254 | // returns OSErr noErr or error if one occurred. |
255 | // returns OSErr noErr or error if one occurred. |
255 | // |
256 | // |
256 | //------------------------------------------------------------------------------- |
257 | //------------------------------------------------------------------------------- |
257 | 258 | ||
258 | OSErr HostCloseWriter(PIDescriptorParameters *procs, |
259 | OSErr HostCloseWriter(PIDescriptorParameters *procs, |
259 | HandleProcs *hProcs, |
260 | HandleProcs *hProcs, |
260 | PIWriteDescriptor *token) |
261 | PIWriteDescriptor *token) |
261 | { |
262 | { |
262 | OSErr err = noErr; // assume no error |
263 | OSErr err = noErr; // assume no error |
263 | PIDescriptorHandle h = NULL; |
264 | PIDescriptorHandle h = NULL; |
264 | 265 | ||
265 | if (procs->descriptor != NULL) // don't need descriptor passed to us |
266 | if (procs->descriptor != NULL) // don't need descriptor passed to us |
266 | hProcs->disposeProc(procs->descriptor); // dispose. |
267 | hProcs->disposeProc(procs->descriptor); // dispose. |
267 | procs->writeDescriptorProcs->closeWriteDescriptorProc(*token, &h); |
268 | procs->writeDescriptorProcs->closeWriteDescriptorProc(*token, &h); |
268 | procs->descriptor = h; |
269 | procs->descriptor = h; |
269 | 270 | ||
270 | // Set recordInfo to default. Options are: plugInDialogOptional, |
271 | // Set recordInfo to default. Options are: plugInDialogOptional, |
271 | // plugInDialogRequire, plugInDialogNone: |
272 | // plugInDialogRequire, plugInDialogNone: |
272 | procs->recordInfo = plugInDialogOptional; |
273 | procs->recordInfo = plugInDialogOptional; |
273 | 274 | ||
274 | *token = NULL; |
275 | *token = NULL; |
275 | 276 | ||
276 | return err; |
277 | return err; |
277 | 278 | ||
278 | } // end HostCloseWriter |
279 | } // end HostCloseWriter |
279 | 280 |