Subversion Repositories filter_foundry

Rev

Rev 91 | Rev 178 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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