Subversion Repositories filter_foundry

Rev

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