Subversion Repositories filter_foundry

Rev

Rev 485 | Rev 487 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 485 Rev 486
Line 1... Line 1...
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-2009 Toby Thain, toby@telegraphics.com.au
3
        Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
4
    Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft
4
        Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft
5
 
5
 
6
    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
7
    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
8
    the Free Software Foundation; either version 2 of the License, or
8
        the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
9
        (at your option) any later version.
Line 19... Line 19...
19
*/
19
*/
20
 
20
 
21
#include "ff.h"
21
#include "ff.h"
22
 
22
 
23
#include "PIBufferSuite.h"
23
#include "PIBufferSuite.h"
-
 
24
#include "PIHandleSuite.h"
24
 
25
 
-
 
26
void newHandle(FFHandle* hdl, size_t nBytes) {
-
 
27
        PSHandleSuite1* pSHandleSuite1 = NULL;
25
// TODO: Also implement the handleSuite like this
28
        PSHandleSuite2* pSHandleSuite2 = NULL;
26
 
29
 
-
 
30
        if ((gpb->sSPBasic != 0) &&
-
 
31
                (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
-
 
32
                (pSHandleSuite2 != NULL) &&
-
 
33
                (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /*PS7 doesn't have the bug like in BufferSuite2, but we just want to be sure...*/)
-
 
34
                )
-
 
35
        {
-
 
36
                // PICA Handle Suite 2.0
-
 
37
                hdl->signature = HDLVERSION_SUITE2;
-
 
38
                gdata->lastKnownHandleVersion = hdl->signature;
-
 
39
                hdl->handle = pSHandleSuite2->New(nBytes);
-
 
40
                gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
-
 
41
        }
-
 
42
        else if ((gpb->sSPBasic != 0) &&
-
 
43
                (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
-
 
44
                (pSHandleSuite1 != NULL)
-
 
45
                )
-
 
46
        {
-
 
47
                // PICA Handle Suite 1.0
-
 
48
                hdl->signature = HDLVERSION_SUITE1;
-
 
49
                gdata->lastKnownHandleVersion = hdl->signature;
-
 
50
                hdl->handle = pSHandleSuite1->New(nBytes);
-
 
51
                gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
-
 
52
        }
-
 
53
        else {
-
 
54
                // Standard Handle Suite (deprecated)
-
 
55
                hdl->signature = HDLVERSION_STANDARD;
-
 
56
                gdata->lastKnownHandleVersion = hdl->signature;
-
 
57
                hdl->handle = gpb->handleProcs->newProc(nBytes);
-
 
58
        }
-
 
59
}
-
 
60
 
-
 
61
void disposeHandle(FFHandle* hdl) {
-
 
62
        if (hdl->signature == HDLVERSION_SUITE2) {
-
 
63
                PSHandleSuite2* pSHandleSuite2 = NULL;
-
 
64
                if ((gpb->sSPBasic != 0) &&
-
 
65
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
-
 
66
                        (pSHandleSuite2 != NULL) &&
-
 
67
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /*PS7 doesn't have the bug like in BufferSuite2, but we just want to be sure...*/)
-
 
68
                        )
-
 
69
                {
-
 
70
                        // PICA Handle Suite 2.0
-
 
71
                        pSHandleSuite2->Dispose(hdl->handle);
-
 
72
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
-
 
73
                }
-
 
74
        }
-
 
75
        else if (hdl->signature == HDLVERSION_SUITE1) {
-
 
76
                PSHandleSuite1* pSHandleSuite1 = NULL;
-
 
77
                if ((gpb->sSPBasic != 0) &&
-
 
78
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
-
 
79
                        (pSHandleSuite1 != NULL)
-
 
80
                        )
-
 
81
                {
-
 
82
                        // PICA Handle Suite 1.0
-
 
83
                        pSHandleSuite1->Dispose(hdl->handle);
-
 
84
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
-
 
85
                }
-
 
86
        }
-
 
87
        else if (hdl->signature == HDLVERSION_STANDARD) {
-
 
88
                // Standard Handle Suite (deprecated)
-
 
89
                gpb->handleProcs->disposeProc(hdl->handle);
-
 
90
        }
-
 
91
        hdl->signature = HDLVERSION_NULL;
-
 
92
}
-
 
93
 
-
 
94
size_t getHandleSize(FFHandle* hdl) {
-
 
95
        if (hdl->signature == HDLVERSION_SUITE2) {
-
 
96
                PSHandleSuite2* pSHandleSuite2 = NULL;
-
 
97
                if ((gpb->sSPBasic != 0) &&
-
 
98
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
-
 
99
                        (pSHandleSuite2 != NULL) &&
-
 
100
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /*PS7 doesn't have the bug like in BufferSuite2, but we just want to be sure...*/)
-
 
101
                        )
-
 
102
                {
-
 
103
                        // PICA Handle Suite 2.0
-
 
104
                        int32 size = pSHandleSuite2->GetSize(hdl->handle);
-
 
105
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
-
 
106
                        return (size_t)size;
-
 
107
                }
-
 
108
        }
-
 
109
        else if (hdl->signature == HDLVERSION_SUITE1) {
-
 
110
                PSHandleSuite1* pSHandleSuite1 = NULL;
-
 
111
                if ((gpb->sSPBasic != 0) &&
-
 
112
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
-
 
113
                        (pSHandleSuite1 != NULL)
-
 
114
                        )
-
 
115
                {
-
 
116
                        // PICA Handle Suite 1.0
-
 
117
                        int32 size = pSHandleSuite1->GetSize(hdl->handle);
-
 
118
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
-
 
119
                        return (size_t)size;
-
 
120
                }
-
 
121
        }
-
 
122
        else if (hdl->signature == HDLVERSION_STANDARD) {
-
 
123
                // Standard Handle Suite (deprecated)
-
 
124
                return gpb->handleProcs->getSizeProc(hdl->handle);
-
 
125
        }
-
 
126
        return 0;
-
 
127
}
-
 
128
 
-
 
129
OSErr setHandleSize(FFHandle* hdl, size_t nBytes) {
-
 
130
        if (hdl->signature == HDLVERSION_SUITE2) {
-
 
131
                PSHandleSuite2* pSHandleSuite2 = NULL;
-
 
132
                if ((gpb->sSPBasic != 0) &&
-
 
133
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
-
 
134
                        (pSHandleSuite2 != NULL) &&
-
 
135
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /*PS7 doesn't have the bug like in BufferSuite2, but we just want to be sure...*/)
-
 
136
                        )
-
 
137
                {
-
 
138
                        // PICA Handle Suite 2.0
-
 
139
                        OSErr ret = pSHandleSuite2->SetSize(hdl->handle, nBytes);
-
 
140
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
-
 
141
                        return ret;
-
 
142
                }
-
 
143
        }
-
 
144
        else if (hdl->signature == HDLVERSION_SUITE1) {
-
 
145
                PSHandleSuite1* pSHandleSuite1 = NULL;
-
 
146
                if ((gpb->sSPBasic != 0) &&
-
 
147
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
-
 
148
                        (pSHandleSuite1 != NULL)
-
 
149
                        )
-
 
150
                {
-
 
151
                        // PICA Handle Suite 1.0
-
 
152
                        OSErr ret = pSHandleSuite1->SetSize(hdl->handle, nBytes);
-
 
153
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
-
 
154
                        return ret;
-
 
155
                }
-
 
156
        }
-
 
157
        else if (hdl->signature == HDLVERSION_STANDARD) {
-
 
158
                // Standard Handle Suite (deprecated)
-
 
159
                return gpb->handleProcs->setSizeProc(hdl->handle, nBytes);
-
 
160
        }
-
 
161
        return errMissingParameter;
-
 
162
}
-
 
163
 
-
 
164
Ptr lockHandle(FFHandle* hdl) {
-
 
165
        if (hdl->signature == HDLVERSION_SUITE2) {
-
 
166
                PSHandleSuite2* pSHandleSuite2 = NULL;
-
 
167
                if ((gpb->sSPBasic != 0) &&
-
 
168
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
-
 
169
                        (pSHandleSuite2 != NULL) &&
-
 
170
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /*PS7 doesn't have the bug like in BufferSuite2, but we just want to be sure...*/)
-
 
171
                        )
-
 
172
                {
-
 
173
                        // PICA Handle Suite 2.0
-
 
174
                        Ptr address;
-
 
175
                        Boolean oldLock;
-
 
176
                        pSHandleSuite2->SetLock(hdl->handle, true, &address, &oldLock);
-
 
177
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
-
 
178
                        return address;
-
 
179
                }
-
 
180
        }
-
 
181
        else if (hdl->signature == HDLVERSION_SUITE1) {
-
 
182
                PSHandleSuite1* pSHandleSuite1 = NULL;
-
 
183
                if ((gpb->sSPBasic != 0) &&
-
 
184
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
-
 
185
                        (pSHandleSuite1 != NULL)
-
 
186
                        )
-
 
187
                {
-
 
188
                        // PICA Handle Suite 1.0
-
 
189
                        Ptr address;
-
 
190
                        Boolean oldLock;
-
 
191
                        pSHandleSuite1->SetLock(hdl->handle, true, &address, &oldLock);
-
 
192
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
-
 
193
                        return address;
-
 
194
                }
-
 
195
        }
-
 
196
        else if (hdl->signature == HDLVERSION_STANDARD) {
-
 
197
                // Standard Handle Suite (deprecated)
-
 
198
                return gpb->handleProcs->lockProc(hdl->handle, true);
-
 
199
        }
-
 
200
        return NULL;
-
 
201
}
-
 
202
 
-
 
203
void unlockHandle(FFHandle* hdl) {
-
 
204
        if (hdl->signature == HDLVERSION_SUITE2) {
-
 
205
                PSHandleSuite2* pSHandleSuite2 = NULL;
-
 
206
                if ((gpb->sSPBasic != 0) &&
-
 
207
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
-
 
208
                        (pSHandleSuite2 != NULL) &&
-
 
209
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /*PS7 doesn't have the bug like in BufferSuite2, but we just want to be sure...*/)
-
 
210
                        )
-
 
211
                {
-
 
212
                        // PICA Handle Suite 2.0
-
 
213
                        Ptr address;
-
 
214
                        Boolean oldLock;
-
 
215
                        pSHandleSuite2->SetLock(hdl->handle, false, &address, &oldLock);
-
 
216
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
-
 
217
                }
-
 
218
        }
-
 
219
        else if (hdl->signature == HDLVERSION_SUITE1) {
-
 
220
                PSHandleSuite1* pSHandleSuite1 = NULL;
-
 
221
                if ((gpb->sSPBasic != 0) &&
-
 
222
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
-
 
223
                        (pSHandleSuite1 != NULL)
-
 
224
                        )
-
 
225
                {
-
 
226
                        // PICA Handle Suite 1.0
-
 
227
                        Ptr address;
-
 
228
                        Boolean oldLock;
-
 
229
                        pSHandleSuite1->SetLock(hdl->handle, false, &address, &oldLock);
-
 
230
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
-
 
231
                }
-
 
232
        }
-
 
233
        else if (hdl->signature == HDLVERSION_STANDARD) {
-
 
234
                // Standard Handle Suite (deprecated)
-
 
235
                gpb->handleProcs->unlockProc(hdl->handle);
-
 
236
        }
-
 
237
}
-
 
238
 
-
 
239
// -----------------------------------------------------------------------------------
-
 
240
// These functions are for code backwards compatibility:
-
 
241
 
-
 
242
Handle PINEWHANDLE(int32 size) {
-
 
243
        FFHandle fh;
-
 
244
        newHandle(&fh, size);
-
 
245
        // Note: newHandle() set gdata->lastKnownHandleVersion, so that
-
 
246
        // the other functions like PILOCKHANDLE can use it. This is safe,
-
 
247
        // as we can assume that the version is always the same for all handles from this host.
-
 
248
        return fh.handle;
-
 
249
}
-
 
250
 
-
 
251
void PIDISPOSEHANDLE(Handle h) {
-
 
252
        FFHandle fh;
-
 
253
        fh.signature = gdata->lastKnownHandleVersion;
-
 
254
        fh.handle = h;
-
 
255
        disposeHandle(&fh);
-
 
256
}
-
 
257
 
-
 
258
int32 PIGETHANDLESIZE(Handle h) {
-
 
259
        FFHandle fh;
-
 
260
        fh.signature = gdata->lastKnownHandleVersion;
-
 
261
        fh.handle = h;
-
 
262
        return getHandleSize(&fh);
-
 
263
}
-
 
264
 
-
 
265
OSErr PISETHANDLESIZE(Handle h, int32 newSize) {
-
 
266
        FFHandle fh;
-
 
267
        fh.signature = gdata->lastKnownHandleVersion;
-
 
268
        fh.handle = h;
-
 
269
        return setHandleSize(&fh, newSize);
-
 
270
}
-
 
271
 
-
 
272
Ptr PILOCKHANDLE(Handle h, Boolean moveHigh) {
-
 
273
        FFHandle fh;
-
 
274
        fh.signature = gdata->lastKnownHandleVersion;
-
 
275
        fh.handle = h;
-
 
276
        return lockHandle(&fh);
-
 
277
}
-
 
278
 
-
 
279
void PIUNLOCKHANDLE(Handle h) {
-
 
280
        FFHandle fh;
-
 
281
        fh.signature = gdata->lastKnownHandleVersion;
-
 
282
        fh.handle = h;
-
 
283
        unlockHandle(&fh);
-
 
284
}
-
 
285
 
-
 
286
// -----------------------------------------------------------------------------------
-
 
287
 
27
FFBuffer newBuffer(size_t nBytes) {
288
void newBuffer(FFBuffer* buf, size_t nBytes) {
28
        PSBufferSuite1* pSBufferSuite32 = NULL;
289
        PSBufferSuite1* pSBufferSuite32 = NULL;
29
        PSBufferSuite2* pSBufferSuite64 = NULL;
290
        PSBufferSuite2* pSBufferSuite64 = NULL;
30
 
291
 
31
        FFBuffer ret;
-
 
32
 
-
 
33
        if ((gpb->sSPBasic != 0) &&
292
        if ((gpb->sSPBasic != 0) &&
34
                (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) &&
293
                (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) &&
35
                (pSBufferSuite64 != NULL) &&
294
                (pSBufferSuite64 != NULL) &&
36
                (pSBufferSuite64 != (PSBufferSuite2*)gpb->bufferProcs /*Implementation mistake in old Photoshop versions! (see note below)*/)
295
                (pSBufferSuite64 != (PSBufferSuite2*)gpb->bufferProcs /*Implementation mistake in old Photoshop versions! (see note below)*/)
37
                )
296
                )
Line 49... Line 308...
49
                // So, kPSBufferSuiteVersion2 probably was partially implemented as hidden "Work in progress" version
308
                // So, kPSBufferSuiteVersion2 probably was partially implemented as hidden "Work in progress" version
50
                // before it was publicly documented.
309
                // before it was publicly documented.
51
                // Side note:  pb->bufferSpace64/pb->maxSpace64 was documented in SDK CC 2017.
310
                // Side note:  pb->bufferSpace64/pb->maxSpace64 was documented in SDK CC 2017.
52
                //             pb->bufferProcs->allocateProc64/spaceProc64 was documented in SDK CS 6.
311
                //             pb->bufferProcs->allocateProc64/spaceProc64 was documented in SDK CS 6.
53
                unsigned32 siz = nBytes;
312
                unsigned32 siz = nBytes;
54
                ret.signature = BUFVERSION_SUITE64;
313
                buf->signature = BUFVERSION_SUITE64;
-
 
314
                gdata->lastKnownBufferVersion = buf->signature;
55
                ret.suite64 = (Ptr)pSBufferSuite64->New(&siz, siz);
315
                buf->suite = (Ptr)pSBufferSuite64->New(&siz, siz);
56
                if (siz < nBytes) {
316
                if (siz < nBytes) {
57
                        ret.signature = BUFVERSION_NULL;
317
                        buf->signature = BUFVERSION_NULL;
58
                        ret.suite64 = NULL;
318
                        buf->suite = NULL;
59
                }
319
                }
60
                gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2);
320
                gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2);
61
        }
321
        }
62
        else if ((gpb->sSPBasic != 0) &&
322
        else if ((gpb->sSPBasic != 0) &&
63
                (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) &&
323
                (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) &&
64
                (pSBufferSuite32 != NULL))
324
                (pSBufferSuite32 != NULL))
65
        {
325
        {
66
                // PICA Buffer Suite 1.0 (32 bit)
326
                // PICA Buffer Suite 1.0 (32 bit)
67
                unsigned32 siz = nBytes;
327
                unsigned32 siz = nBytes;
68
                ret.signature = BUFVERSION_SUITE32;
328
                buf->signature = BUFVERSION_SUITE32;
-
 
329
                gdata->lastKnownBufferVersion = buf->signature;
69
                ret.suite32 = (Ptr)pSBufferSuite32->New(&siz, siz);
330
                buf->suite = (Ptr)pSBufferSuite32->New(&siz, siz);
70
                if (siz < nBytes) {
331
                if (siz < nBytes) {
71
                        ret.signature = BUFVERSION_NULL;
332
                        buf->signature = BUFVERSION_NULL;
72
                        ret.suite32 = NULL;
333
                        buf->suite = NULL;
73
                }
334
                }
74
                gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1);
335
                gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1);
75
        }
336
        }
76
        else if (gpb->bufferProcs->numBufferProcs >= 8)
337
        else if (gpb->bufferProcs->numBufferProcs >= 8)
77
        {
338
        {
78
                // Standard Buffer Suite 64 bit (deprecated)
339
                // Standard Buffer Suite 64 bit (deprecated)
79
                ret.signature = BUFVERSION_STD64;
340
                buf->signature = BUFVERSION_STD64;
-
 
341
                gdata->lastKnownBufferVersion = buf->signature;
80
                if ((/* *result = */ gpb->bufferProcs->allocateProc64(nBytes, &ret.standard))) {
342
                if (gpb->bufferProcs->allocateProc64(nBytes, &buf->standard) != noErr) {
81
                        ret.signature = BUFVERSION_NULL;
343
                        buf->signature = BUFVERSION_NULL;
82
                        ret.standard = NULL;
344
                        buf->standard = NULL;
83
                }
345
                }
84
        }
346
        }
85
        else
347
        else
86
        {
348
        {
87
                // Standard Buffer Suite 32 bit (deprecated)
349
                // Standard Buffer Suite 32 bit (deprecated)
88
                ret.signature = BUFVERSION_STD32;
350
                buf->signature = BUFVERSION_STD32;
-
 
351
                gdata->lastKnownBufferVersion = buf->signature;
89
                if ((/* *result = */ gpb->bufferProcs->allocateProc(nBytes, &ret.standard))) {
352
                if (gpb->bufferProcs->allocateProc(nBytes, &buf->standard) != noErr) {
90
                        ret.signature = BUFVERSION_NULL;
353
                        buf->signature = BUFVERSION_NULL;
91
                        ret.standard = NULL;
354
                        buf->standard = NULL;
92
                }
355
                }
93
        }
356
        }
94
 
-
 
95
        return ret;
-
 
96
}
357
}
97
 
358
 
98
Ptr lockBuffer(FFBuffer bid) {
359
Ptr lockBuffer(FFBuffer* buf) {
99
        if (bid.signature == BUFVERSION_SUITE64) {
360
        if (buf->signature == BUFVERSION_SUITE64) {
100
                return bid.suite64;
361
                return buf->suite;
101
        }
362
        }
102
        else if (bid.signature == BUFVERSION_SUITE32) {
363
        else if (buf->signature == BUFVERSION_SUITE32) {
103
                return bid.suite32;
364
                return buf->suite;
104
        }
365
        }
105
        else if (bid.signature == BUFVERSION_STD64) {
366
        else if (buf->signature == BUFVERSION_STD64) {
106
                return gpb->bufferProcs->lockProc(bid.standard, true);
367
                return gpb->bufferProcs->lockProc(buf->standard, true);
107
        }
368
        }
108
        else if (bid.signature == BUFVERSION_STD32) {
369
        else if (buf->signature == BUFVERSION_STD32) {
109
                return gpb->bufferProcs->lockProc(bid.standard, true);
370
                return gpb->bufferProcs->lockProc(buf->standard, true);
110
        }
371
        }
111
        else {
372
        else {
112
                return NULL;
373
                return NULL;
113
        }
374
        }
114
}
375
}
115
 
376
 
116
void unlockBuffer(FFBuffer bid) {
377
void unlockBuffer(FFBuffer* buf) {
117
        if (bid.signature == BUFVERSION_STD64) {
378
        if (buf->signature == BUFVERSION_STD64) {
118
                gpb->bufferProcs->unlockProc(bid.standard);
379
                gpb->bufferProcs->unlockProc(buf->standard);
119
        }
380
        }
120
        else if (bid.signature == BUFVERSION_STD32) {
381
        else if (buf->signature == BUFVERSION_STD32) {
121
                gpb->bufferProcs->unlockProc(bid.standard);
382
                gpb->bufferProcs->unlockProc(buf->standard);
122
        }
383
        }
123
}
384
}
124
 
385
 
125
void disposeBuffer(FFBuffer* bid) {
386
void disposeBuffer(FFBuffer* buf) {
126
        if ((*bid).signature == BUFVERSION_SUITE64) {
387
        if (buf->signature == BUFVERSION_SUITE64) {
127
                PSBufferSuite2* pSBufferSuite64 = NULL;
388
                PSBufferSuite2* pSBufferSuite64 = NULL;
128
                if ((gpb->sSPBasic != 0) &&
389
                if ((gpb->sSPBasic != 0) &&
129
                        (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) &&
390
                        (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) &&
130
                        (pSBufferSuite64 != NULL))
391
                        (pSBufferSuite64 != NULL) &&
-
 
392
                        (pSBufferSuite64 != (PSBufferSuite2*)gpb->bufferProcs /*Implementation mistake in old Photoshop versions! (see note below)*/)
-
 
393
                        )
131
                {
394
                {
132
                        // PICA Buffer Suite 2.0 (64 bit)
395
                        // PICA Buffer Suite 2.0 (64 bit)
133
                        pSBufferSuite64->Dispose(&((*bid).suite64));
396
                        pSBufferSuite64->Dispose(&buf->suite);
134
                        gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2);
397
                        gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2);
135
                }
398
                }
136
        }
399
        }
137
        else if ((*bid).signature == BUFVERSION_SUITE32) {
400
        else if (buf->signature == BUFVERSION_SUITE32) {
138
                PSBufferSuite1* pSBufferSuite32 = NULL;
401
                PSBufferSuite1* pSBufferSuite32 = NULL;
139
                if ((gpb->sSPBasic != 0) &&
402
                if ((gpb->sSPBasic != 0) &&
140
                        (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) &&
403
                        (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) &&
141
                        (pSBufferSuite32 != NULL))
404
                        (pSBufferSuite32 != NULL))
142
                {
405
                {
143
                        // PICA Buffer Suite 1.0 (32 bit)
406
                        // PICA Buffer Suite 1.0 (32 bit)
144
                        pSBufferSuite32->Dispose(&((*bid).suite32));
407
                        pSBufferSuite32->Dispose(&buf->suite);
145
                        gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1);
408
                        gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1);
146
                }
409
                }
147
        }
410
        }
148
        else if ((*bid).signature == BUFVERSION_STD64) {
411
        else if (buf->signature == BUFVERSION_STD64) {
149
                gpb->bufferProcs->freeProc((*bid).standard);
412
                gpb->bufferProcs->freeProc(buf->standard);
150
        }
413
        }
151
        else if ((*bid).signature == BUFVERSION_STD32) {
414
        else if (buf->signature == BUFVERSION_STD32) {
152
                gpb->bufferProcs->freeProc((*bid).standard);
415
                gpb->bufferProcs->freeProc(buf->standard);
153
        }
416
        }
154
        (*bid).signature = BUFVERSION_NULL;
417
        buf->signature = BUFVERSION_NULL;
155
}
418
}