Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /main.cpp [68cdf8] .. [ed05d7] Maximize Restore

  Switch to unified view

a/main.cpp b/main.cpp
1
2
// PTLens, Copyright (C) 2004, Thomas Niemann
3
// email: thomasn@epaperpress.com, subject=ptlens
4
// 
5
// This program is free software; you can redistribute 
1
// This program is free software; you can redistribute 
6
// it and/or modify it under the terms of the GNU
2
// it and/or modify it under the terms of the GNU
7
// General Public License as published by the Free 
3
// General Public License as published by the Free 
8
// Software Foundation; either version 2 of the 
4
// Software Foundation; either version 2 of the 
9
// License, or (at your option) any later version. 
5
// License, or (at your option) any later version. 
...
...
17
// You should have received a copy of the GNU General 
13
// You should have received a copy of the GNU General 
18
// Public License along with this program; if not, 
14
// Public License along with this program; if not, 
19
// write to the Free Software Foundation, Inc., 675 
15
// write to the Free Software Foundation, Inc., 675 
20
// Mass Ave, Cambridge, MA 02139, USA.
16
// Mass Ave, Cambridge, MA 02139, USA.
21
17
18
/**
19
* @file main.cpp
20
* This file is included in all four plug-ins (PTAdjust, PTCorrect, PTPerspect, and PTRemap)
21
* Includes the main entry point for the plug-ins
22
* @date January 2007
23
*/
24
22
#include "main.h"
25
#include "main.h"
23
26
24
SPBasicSuite * sSPBasic = NULL;
27
SPBasicSuite   *sSPBasic  = NULL;
25
StaticData *gData = NULL;
28
StaticData     *gData     = NULL;
26
ParamData *gParam = NULL;
29
ParamData      *gParam    = NULL;
27
FilterRecord *gFr = NULL;
30
FilterRecord   *gFr       = NULL;
28
int16 *gResult;
31
int16          *gResult   = NULL;
29
32
33
34
/**
35
* Display a message box
36
* @param[in] fmt formatted string to display
37
* @param[in] ... additional items to add to string
38
* @return 1
39
* @todo error check for memory overflow on buf
40
**/
30
int display(const char *fmt, ...) {
41
int display(const char *fmt, ...)
42
{
43
  int  BuffSize = 0;
31
  char buf[100];
44
  char buf[400];
32
  va_list ap;
45
  va_list ap;
33
46
34
  va_start(ap, fmt);
47
  va_start(ap, fmt);
48
  BuffSize = sizeof(buf)/sizeof(char);
49
#if _MSC_VER >= 1400
50
  vsprintf_s(buf, BuffSize, fmt, ap);
51
#else
35
  vsprintf(buf, fmt, ap);
52
  vsprintf(buf, fmt, ap);
53
#endif
36
  MessageBox(NULL, buf, "Info", MB_OK);
54
  MessageBox(NULL, buf, "Info", MB_OK);
37
  va_end(ap);
55
  va_end(ap);
38
  return 1;
56
  return 1;
39
}
57
}
40
58
59
/**
60
* Init Parameters
61
* @return none
62
**/
41
static void initParameters() {}
63
static void initParameters()
64
{
65
}
42
66
67
/**
68
* Init Data
69
* @return none
70
**/
43
static void initData() {
71
static void initData()
72
{
44
  memset(gData, 0, sizeof(StaticData));
73
  memset(gData, 0, sizeof(StaticData));
45
  memInit(memStatic);
74
  memInit(memStatic);
46
  memInit(memDynamic);
75
  memInit(memDynamic);
47
  DLL.initDLL = false;
76
  DLL.initDLL = false;
48
}
77
}
49
78
50
79
80
/**
81
* Lock Data
82
* @param[in] data pointer to the data to lock
83
* @return none
84
**/
51
static void lockData(int32 *data) {
85
static void lockData(int32 *data)
86
{
52
  bool init = false;
87
  bool init = false;
53
  BufferProcs *bufferProcs = gFr->bufferProcs;
88
  BufferProcs *bufferProcs = gFr->bufferProcs;
54
89
55
  if (*data == NULL) {
90
  if (*data == NULL)
56
91
  {
57
      // create handle
92
    // create handle
58
      BufferID h;
93
    BufferID h;
59
      if (bufferProcs->allocateProc(sizeof(StaticData), &h)) {
94
    if (bufferProcs->allocateProc(sizeof(StaticData), &h))
95
    {
60
          *gResult = memFullErr;
96
      *gResult = memFullErr;
61
          return;
97
      display("lockData: allocateProc");
62
      }
98
      return;
99
    }
63
100
64
      *data = (int32)h;
101
    *data = (int32)h;
65
          init = true;
102
    init = true;
66
  }
103
  }
67
104
68
  gData = (StaticData *)bufferProcs->lockProc((BufferID)(*data), true);
105
  gData = (StaticData *)bufferProcs->lockProc((BufferID)(*data), true);
69
  if (gData == NULL) {
106
  if (gData == NULL)
107
  {
70
      *gResult = memFullErr;
108
    *gResult = memFullErr;
71
      return;
109
    display("lockData: lockProc");
72
  }
110
    return;
111
  }
73
112
74
  if (init) initData();
113
  if (init)
75
  
114
  {
115
    initData();
116
  }
117
  
76
  return;
118
  return;
77
}
119
}
78
120
121
/**
122
* Unlock Data
123
* @param[in] data pointer to the data to unlock
124
* @return none
125
**/
79
static void unlockData(int32 *data) {
126
static void unlockData(int32 *data)
127
{
80
  if (*data != NULL)
128
  if (*data != NULL)
129
  {
81
      gFr->bufferProcs->unlockProc((BufferID)(*data));
130
    gFr->bufferProcs->unlockProc((BufferID)(*data));
131
  }
82
}
132
}
83
133
134
/**
135
* Lock the Parameters
136
* @return none
137
**/
84
static void lockParameters() {
138
static void lockParameters()
139
{
85
  bool init = false;
140
  bool init = false;
86
  BufferProcs *bufferProcs = gFr->bufferProcs;
141
  BufferProcs *bufferProcs = gFr->bufferProcs;
87
142
88
  if (gFr->parameters == NULL) {
143
  if (gFr->parameters == NULL)
89
144
  {
90
      // create handle
145
    // create handle
91
      BufferID h;
146
    BufferID h;
92
      if (bufferProcs->allocateProc(sizeof(ParamData), &h)) {
147
    if (bufferProcs->allocateProc(sizeof(ParamData), &h))
148
    {
93
          *gResult = memFullErr;
149
      *gResult = memFullErr;
94
          return;
150
      display("lockParameters: allocateProc");
95
      }
151
      return;
152
    }
96
153
97
      gFr->parameters = (Handle)h;
154
    gFr->parameters = (Handle)h;
98
      init = true;
155
    init = true;
99
  }
156
  }
100
157
101
  // lock handle
158
  // lock handle
102
  gParam = (ParamData *)bufferProcs->lockProc((BufferID)(gFr->parameters), true);
159
  gParam = (ParamData *)bufferProcs->lockProc((BufferID)(gFr->parameters), true);
103
  if (gParam == NULL) {
160
  if (gParam == NULL)
161
  {
104
      *gResult = memFullErr;
162
    *gResult = memFullErr;
105
      return;
163
    display("lockParameters: lockProc");
164
    return;
165
  }
166
  
167
  if (init)
168
  {
169
    initParameters();
170
  }
106
  }
171
}
107
  
108
  if (init) initParameters();
109
}
110
172
173
/**
174
* Unlock the Parameters
175
* @return none
176
**/
111
static void unlockParameters() {
177
static void unlockParameters()
178
{
112
  if (gFr->parameters != NULL)
179
  if (gFr->parameters != NULL)
180
  {
113
      gFr->bufferProcs->unlockProc((BufferID)(gFr->parameters));
181
    gFr->bufferProcs->unlockProc((BufferID)(gFr->parameters));
182
  }
114
}
183
}
115
184
185
/**
186
* Lock Data, Parameters, memStatic, and memDynamic
187
* @param[in] data pointer to the handle to lock
188
* @return none
189
**/
116
static void lockHandles(int32 *data) {
190
static void lockHandles(int32 *data)
191
{
117
  lockData(data);
192
  lockData(data);
118
  lockParameters();
193
  lockParameters();
119
  memLockHandles(memStatic);
194
  memLockHandles(memStatic);
120
  memLockHandles(memDynamic);
195
  memLockHandles(memDynamic);
121
}
196
}
122
197
198
/**
199
* Unlock Data, Parameters, memStatic, and memDynamic
200
* @param[in] data pointer to the handle to unlock
201
* @return none
202
**/
123
static void unlockHandles(int32 *data) {
203
static void unlockHandles(int32 *data)
204
{
124
  memUnlockHandles(memDynamic);
205
  memUnlockHandles(memDynamic);
125
  memFreeAll(memDynamic);
206
  memFreeAll(memDynamic);
126
  memUnlockHandles(memStatic);
207
  memUnlockHandles(memStatic);
127
  unlockParameters();
208
  unlockParameters();
128
  unlockData(data);
209
  unlockData(data);
129
}
210
}
130
211
212
/**
213
* Do Continue
214
* @return none
215
**/
131
static void DoContinue(void) {
216
static void DoContinue(void)
217
{
132
  gFr->inRect.top = 0;
218
  gFr->inRect.top = 0;
133
  gFr->inRect.bottom = 0;
219
  gFr->inRect.bottom = 0;
134
  gFr->inRect.left = 0;
220
  gFr->inRect.left = 0;
135
  gFr->inRect.right = 0;
221
  gFr->inRect.right = 0;
136
  gFr->outRect.top = 0;
222
  gFr->outRect.top = 0;
137
  gFr->outRect.bottom = 0;
223
  gFr->outRect.bottom = 0;
138
  gFr->outRect.left = 0;
224
  gFr->outRect.left = 0;
139
  gFr->outRect.right = 0;
225
  gFr->outRect.right = 0;
140
  gFr->maskRect.top = 0;
226
  gFr->maskRect.top = 0;
141
  gFr->maskRect.bottom = 0;
227
  gFr->maskRect.bottom = 0;
142
  gFr->maskRect.left = 0;
228
  gFr->maskRect.left = 0;
143
  gFr->maskRect.right = 0;
229
  gFr->maskRect.right = 0;
144
}
230
}
145
231
232
/**
233
* Do Finish
234
* @return 0
235
**/
146
static int DoFinish(void) {
236
static int DoFinish(void)
237
{
147
  return 0;
238
  return 0;
148
}
239
}
149
240
241
/**
242
* Check Prefs
243
* @return none
244
**/
150
static void checkPrefs() {
245
static void checkPrefs()
151
246
{
152
  // force dialog box if requested by script
247
  // force dialog box if requested by script
153
  PIDescriptorParameters* descParams = gFr->descriptorParameters;
248
  PIDescriptorParameters *descParams = gFr->descriptorParameters;
154
  if (!descParams) return;
249
  if (!descParams)
250
  {
251
    return;
252
  }
155
  ReadDescriptorProcs* readProcs = gFr->descriptorParameters->readDescriptorProcs;
253
  ReadDescriptorProcs *readProcs = gFr->descriptorParameters->readDescriptorProcs;
156
  if (!readProcs) return;
254
  if ( !readProcs 
157
  if (!descParams->descriptor) return;
255
    || !descParams->descriptor
158
  if (descParams->playInfo != plugInDialogDisplay) return;
256
    || descParams->playInfo != plugInDialogDisplay )
257
  {
258
    return;
259
  }
159
260
160
  PAN.initPrefs = false;
261
  PAN.initPrefs = false;
161
}
262
}
162
263
264
/**
265
* Determine if displaying dialog box
266
* @return 1 if displaying dialog, 0 if not
267
**/
163
static int DoStart(void) {
268
static int DoStart(void)
164
  
269
{
165
  // if scripting, check to see if user wants dialog box
270
  // if scripting, check to see if user wants dialog box
166
    if (PAN.initPrefs) checkPrefs();
271
  if (PAN.initPrefs)
167
  if (panTools()) return 1;
272
  {
273
    checkPrefs();
274
  }
275
  if (panTools())
276
  {
277
    return 1;
278
  }
279
168
  return 0;
280
  return 0;
169
}
281
}
170
282
283
/**
284
* Do Prepare
285
* @return none 
286
**/
171
static void DoPrepare(void) {
287
static void DoPrepare(void)
288
{
172
  // we'll allocate our own space
289
  // we'll allocate our own space
173
  gFr->bufferSpace = 0;
290
  gFr->bufferSpace = 0;
174
  gFr->maxSpace = 0;
291
  gFr->maxSpace = 0;
175
}
292
}
176
293
294
/**
295
* Do Parameters
296
* @return none 
297
**/
177
static void DoParameters(void) {
298
static void DoParameters(void)
299
{
178
  PAN.initPrefs = false;
300
  PAN.initPrefs = false;
179
}
301
}
180
302
303
/**
304
* the main entry point for the plugin
305
* @param[in] selector
306
* @param[in,out] filterParamBlock
307
* @param[in,out] data
308
* @param[out] result 
309
* @return none 
310
**/
181
DLLExport MACPASCAL void PluginMain(const int16 selector,
311
DLLExport MACPASCAL void PluginMain(const int16 selector,
182
                                  FilterRecord *filterParamBlock,
312
                    FilterRecord *filterParamBlock,
183
                                  int32 *data,
313
                    int32 *data,
184
                                  int16 *result)
314
                    int16 *result)
185
{
315
{
186
      // update our global parameters
316
    // update our global parameters
187
  gFr = filterParamBlock;
317
  gFr = filterParamBlock;
188
  gResult = result;
318
  gResult = result;
189
  *gResult = noErr;
319
  *gResult = noErr;
190
320
191
  // handle About dialog
321
  // handle About dialog
192
  if (selector == filterSelectorAbout) {
322
  if (selector == filterSelectorAbout)
323
  {
193
      sSPBasic = ((AboutRecordPtr)filterParamBlock)->sSPBasic;
324
    sSPBasic = ((AboutRecordPtr)filterParamBlock)->sSPBasic;
194
      dlgAbout((AboutRecordPtr)filterParamBlock);
325
    dlgAbout((AboutRecordPtr)filterParamBlock);
195
      return;
326
    return;
196
  }
327
  }
197
  sSPBasic = filterParamBlock->sSPBasic;
328
  sSPBasic = filterParamBlock->sSPBasic;
198
329
199
  lockHandles(data);
330
  lockHandles(data);
200
331
201
  if (*gResult != noErr) return;
332
  if (*gResult != noErr)
333
  {
334
    return;
335
  }
202
336
203
  // do the command according to the selector
337
  // do the command according to the selector
204
  switch (selector) {
338
  switch (selector)
339
  {
205
  case filterSelectorParameters:
340
  case filterSelectorParameters:
206
      DoParameters();
341
    DoParameters();
207
      break;
342
    break;
208
  case filterSelectorPrepare:
343
  case filterSelectorPrepare:
209
      DoPrepare();
344
    DoPrepare();
210
      break;
345
    break;
211
  case filterSelectorStart:
346
  case filterSelectorStart:
212
      DoStart();
347
    DoStart();
213
      break;
348
    break;
214
  case filterSelectorContinue:
349
  case filterSelectorContinue:
215
      DoContinue();
350
    DoContinue();
216
      break;
351
    break;
217
  case filterSelectorFinish:
352
  case filterSelectorFinish:
218
      DoFinish();
353
    DoFinish();
219
      break;
354
    break;
220
  }
355
  }
221
356
222
  unlockHandles(data);
357
  unlockHandles(data);
223
}
358
}