Subversion Repositories filter_foundry

Rev

Rev 488 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 488 Rev 505
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-2022 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.
10
 
10
 
11
        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,
12
        but WITHOUT ANY WARRANTY; without even the implied warranty of
12
        but WITHOUT ANY WARRANTY; without even the implied warranty of
13
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
        GNU General Public License for more details.
14
        GNU General Public License for more details.
15
 
15
 
16
        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
17
        along with this program; if not, write to the Free Software
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
18
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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
#include "PIHandleSuite.h"
25
 
25
 
26
void newHandle(FFHandle* hdl, size_t nBytes) {
26
void newHandle(FFHandle* hdl, size_t nBytes) {
27
        PSHandleSuite1* pSHandleSuite1 = NULL;
27
        PSHandleSuite1* pSHandleSuite1 = NULL;
28
        PSHandleSuite2* pSHandleSuite2 = NULL;
28
        PSHandleSuite2* pSHandleSuite2 = NULL;
29
 
29
 
30
        if ((gpb->sSPBasic != 0) &&
30
        if ((gpb->sSPBasic != 0) &&
31
                (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
31
                (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
32
                (pSHandleSuite2 != NULL) &&
32
                (pSHandleSuite2 != NULL) &&
33
                (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
33
                (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
34
                )
34
                )
35
        {
35
        {
36
                // PICA Handle Suite 2.0
36
                // PICA Handle Suite 2.0
37
                hdl->signature = HDLVERSION_SUITE2;
37
                hdl->signature = HDLVERSION_SUITE2;
38
                if (gdata) gdata->lastKnownHandleVersion = hdl->signature;
38
                if (gdata) gdata->lastKnownHandleVersion = hdl->signature;
39
                hdl->handle = pSHandleSuite2->New(nBytes);
39
                hdl->handle = pSHandleSuite2->New((int32)nBytes);
40
                gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
40
                gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
41
        }
41
        }
42
        else if ((gpb->sSPBasic != 0) &&
42
        else if ((gpb->sSPBasic != 0) &&
43
                (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
43
                (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
44
                (pSHandleSuite1 != NULL) &&
44
                (pSHandleSuite1 != NULL) &&
45
                (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
45
                (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
46
                )
46
                )
47
        {
47
        {
48
                // PICA Handle Suite 1.0
48
                // PICA Handle Suite 1.0
49
                hdl->signature = HDLVERSION_SUITE1;
49
                hdl->signature = HDLVERSION_SUITE1;
50
                if (gdata) gdata->lastKnownHandleVersion = hdl->signature;
50
                if (gdata) gdata->lastKnownHandleVersion = hdl->signature;
51
                hdl->handle = pSHandleSuite1->New(nBytes);
51
                hdl->handle = pSHandleSuite1->New((int32)nBytes);
52
                gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
52
                gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
53
        }
53
        }
54
        else {
54
        else {
55
                // Standard Handle Suite (deprecated)
55
                // Standard Handle Suite (deprecated)
56
                hdl->signature = HDLVERSION_STANDARD;
56
                hdl->signature = HDLVERSION_STANDARD;
57
                if (gdata) gdata->lastKnownHandleVersion = hdl->signature;
57
                if (gdata) gdata->lastKnownHandleVersion = hdl->signature;
58
                hdl->handle = gpb->handleProcs->newProc(nBytes);
58
                hdl->handle = gpb->handleProcs->newProc((int32)nBytes);
59
        }
59
        }
60
}
60
}
61
 
61
 
62
void disposeHandle(FFHandle* hdl) {
62
void disposeHandle(FFHandle* hdl) {
63
        if (hdl->signature == HDLVERSION_SUITE2) {
63
        if (hdl->signature == HDLVERSION_SUITE2) {
64
                PSHandleSuite2* pSHandleSuite2 = NULL;
64
                PSHandleSuite2* pSHandleSuite2 = NULL;
65
                if ((gpb->sSPBasic != 0) &&
65
                if ((gpb->sSPBasic != 0) &&
66
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
66
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
67
                        (pSHandleSuite2 != NULL) &&
67
                        (pSHandleSuite2 != NULL) &&
68
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
68
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
69
                        )
69
                        )
70
                {
70
                {
71
                        // PICA Handle Suite 2.0
71
                        // PICA Handle Suite 2.0
72
                        pSHandleSuite2->Dispose(hdl->handle);
72
                        pSHandleSuite2->Dispose(hdl->handle);
73
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
73
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
74
                }
74
                }
75
        }
75
        }
76
        else if (hdl->signature == HDLVERSION_SUITE1) {
76
        else if (hdl->signature == HDLVERSION_SUITE1) {
77
                PSHandleSuite1* pSHandleSuite1 = NULL;
77
                PSHandleSuite1* pSHandleSuite1 = NULL;
78
                if ((gpb->sSPBasic != 0) &&
78
                if ((gpb->sSPBasic != 0) &&
79
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
79
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
80
                        (pSHandleSuite1 != NULL) &&
80
                        (pSHandleSuite1 != NULL) &&
81
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
81
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
82
                        )
82
                        )
83
                {
83
                {
84
                        // PICA Handle Suite 1.0
84
                        // PICA Handle Suite 1.0
85
                        pSHandleSuite1->Dispose(hdl->handle);
85
                        pSHandleSuite1->Dispose(hdl->handle);
86
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
86
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
87
                }
87
                }
88
        }
88
        }
89
        else if (hdl->signature == HDLVERSION_STANDARD) {
89
        else if (hdl->signature == HDLVERSION_STANDARD) {
90
                // Standard Handle Suite (deprecated)
90
                // Standard Handle Suite (deprecated)
91
                gpb->handleProcs->disposeProc(hdl->handle);
91
                gpb->handleProcs->disposeProc(hdl->handle);
92
        }
92
        }
93
        hdl->signature = HDLVERSION_NULL;
93
        hdl->signature = HDLVERSION_NULL;
94
}
94
}
95
 
95
 
96
size_t getHandleSize(FFHandle* hdl) {
96
size_t getHandleSize(FFHandle* hdl) {
97
        if (hdl->signature == HDLVERSION_SUITE2) {
97
        if (hdl->signature == HDLVERSION_SUITE2) {
98
                PSHandleSuite2* pSHandleSuite2 = NULL;
98
                PSHandleSuite2* pSHandleSuite2 = NULL;
99
                if ((gpb->sSPBasic != 0) &&
99
                if ((gpb->sSPBasic != 0) &&
100
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
100
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
101
                        (pSHandleSuite2 != NULL) &&
101
                        (pSHandleSuite2 != NULL) &&
102
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
102
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
103
                        )
103
                        )
104
                {
104
                {
105
                        // PICA Handle Suite 2.0
105
                        // PICA Handle Suite 2.0
106
                        int32 size = pSHandleSuite2->GetSize(hdl->handle);
106
                        int32 size = pSHandleSuite2->GetSize(hdl->handle);
107
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
107
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
108
                        return (size_t)size;
108
                        return (size_t)size;
109
                }
109
                }
110
        }
110
        }
111
        else if (hdl->signature == HDLVERSION_SUITE1) {
111
        else if (hdl->signature == HDLVERSION_SUITE1) {
112
                PSHandleSuite1* pSHandleSuite1 = NULL;
112
                PSHandleSuite1* pSHandleSuite1 = NULL;
113
                if ((gpb->sSPBasic != 0) &&
113
                if ((gpb->sSPBasic != 0) &&
114
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
114
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
115
                        (pSHandleSuite1 != NULL) &&
115
                        (pSHandleSuite1 != NULL) &&
116
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
116
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
117
                        )
117
                        )
118
                {
118
                {
119
                        // PICA Handle Suite 1.0
119
                        // PICA Handle Suite 1.0
120
                        int32 size = pSHandleSuite1->GetSize(hdl->handle);
120
                        int32 size = pSHandleSuite1->GetSize(hdl->handle);
121
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
121
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
122
                        return (size_t)size;
122
                        return (size_t)size;
123
                }
123
                }
124
        }
124
        }
125
        else if (hdl->signature == HDLVERSION_STANDARD) {
125
        else if (hdl->signature == HDLVERSION_STANDARD) {
126
                // Standard Handle Suite (deprecated)
126
                // Standard Handle Suite (deprecated)
127
                return gpb->handleProcs->getSizeProc(hdl->handle);
127
                return gpb->handleProcs->getSizeProc(hdl->handle);
128
        }
128
        }
129
        return 0;
129
        return 0;
130
}
130
}
131
 
131
 
132
OSErr setHandleSize(FFHandle* hdl, size_t nBytes) {
132
OSErr setHandleSize(FFHandle* hdl, size_t nBytes) {
133
        if (hdl->signature == HDLVERSION_SUITE2) {
133
        if (hdl->signature == HDLVERSION_SUITE2) {
134
                PSHandleSuite2* pSHandleSuite2 = NULL;
134
                PSHandleSuite2* pSHandleSuite2 = NULL;
135
                if ((gpb->sSPBasic != 0) &&
135
                if ((gpb->sSPBasic != 0) &&
136
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
136
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
137
                        (pSHandleSuite2 != NULL) &&
137
                        (pSHandleSuite2 != NULL) &&
138
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
138
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
139
                        )
139
                        )
140
                {
140
                {
141
                        // PICA Handle Suite 2.0
141
                        // PICA Handle Suite 2.0
142
                        OSErr ret = pSHandleSuite2->SetSize(hdl->handle, nBytes);
142
                        OSErr ret = pSHandleSuite2->SetSize(hdl->handle, (int32)nBytes);
143
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
143
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
144
                        return ret;
144
                        return ret;
145
                }
145
                }
146
        }
146
        }
147
        else if (hdl->signature == HDLVERSION_SUITE1) {
147
        else if (hdl->signature == HDLVERSION_SUITE1) {
148
                PSHandleSuite1* pSHandleSuite1 = NULL;
148
                PSHandleSuite1* pSHandleSuite1 = NULL;
149
                if ((gpb->sSPBasic != 0) &&
149
                if ((gpb->sSPBasic != 0) &&
150
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
150
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
151
                        (pSHandleSuite1 != NULL) &&
151
                        (pSHandleSuite1 != NULL) &&
152
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
152
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
153
                        )
153
                        )
154
                {
154
                {
155
                        // PICA Handle Suite 1.0
155
                        // PICA Handle Suite 1.0
156
                        OSErr ret = pSHandleSuite1->SetSize(hdl->handle, nBytes);
156
                        OSErr ret = pSHandleSuite1->SetSize(hdl->handle, (int32)nBytes);
157
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
157
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
158
                        return ret;
158
                        return ret;
159
                }
159
                }
160
        }
160
        }
161
        else if (hdl->signature == HDLVERSION_STANDARD) {
161
        else if (hdl->signature == HDLVERSION_STANDARD) {
162
                // Standard Handle Suite (deprecated)
162
                // Standard Handle Suite (deprecated)
163
                return gpb->handleProcs->setSizeProc(hdl->handle, nBytes);
163
                return gpb->handleProcs->setSizeProc(hdl->handle, (int32)nBytes);
164
        }
164
        }
165
        return errMissingParameter;
165
        return errMissingParameter;
166
}
166
}
167
 
167
 
168
Ptr lockHandle(FFHandle* hdl) {
168
Ptr lockHandle(FFHandle* hdl) {
169
        if (hdl->signature == HDLVERSION_SUITE2) {
169
        if (hdl->signature == HDLVERSION_SUITE2) {
170
                PSHandleSuite2* pSHandleSuite2 = NULL;
170
                PSHandleSuite2* pSHandleSuite2 = NULL;
171
                if ((gpb->sSPBasic != 0) &&
171
                if ((gpb->sSPBasic != 0) &&
172
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
172
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
173
                        (pSHandleSuite2 != NULL) &&
173
                        (pSHandleSuite2 != NULL) &&
174
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
174
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
175
                        )
175
                        )
176
                {
176
                {
177
                        // PICA Handle Suite 2.0
177
                        // PICA Handle Suite 2.0
178
                        Ptr address;
178
                        Ptr address;
179
                        Boolean oldLock;
179
                        Boolean oldLock;
180
                        pSHandleSuite2->SetLock(hdl->handle, true, &address, &oldLock);
180
                        pSHandleSuite2->SetLock(hdl->handle, true, &address, &oldLock);
181
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
181
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
182
                        return address;
182
                        return address;
183
                }
183
                }
184
        }
184
        }
185
        else if (hdl->signature == HDLVERSION_SUITE1) {
185
        else if (hdl->signature == HDLVERSION_SUITE1) {
186
                PSHandleSuite1* pSHandleSuite1 = NULL;
186
                PSHandleSuite1* pSHandleSuite1 = NULL;
187
                if ((gpb->sSPBasic != 0) &&
187
                if ((gpb->sSPBasic != 0) &&
188
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
188
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
189
                        (pSHandleSuite1 != NULL) &&
189
                        (pSHandleSuite1 != NULL) &&
190
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
190
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
191
                        )
191
                        )
192
                {
192
                {
193
                        // PICA Handle Suite 1.0
193
                        // PICA Handle Suite 1.0
194
                        Ptr address;
194
                        Ptr address;
195
                        Boolean oldLock;
195
                        Boolean oldLock;
196
                        pSHandleSuite1->SetLock(hdl->handle, true, &address, &oldLock);
196
                        pSHandleSuite1->SetLock(hdl->handle, true, &address, &oldLock);
197
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
197
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
198
                        return address;
198
                        return address;
199
                }
199
                }
200
        }
200
        }
201
        else if (hdl->signature == HDLVERSION_STANDARD) {
201
        else if (hdl->signature == HDLVERSION_STANDARD) {
202
                // Standard Handle Suite (deprecated)
202
                // Standard Handle Suite (deprecated)
203
                return gpb->handleProcs->lockProc(hdl->handle, true);
203
                return gpb->handleProcs->lockProc(hdl->handle, true);
204
        }
204
        }
205
        return NULL;
205
        return NULL;
206
}
206
}
207
 
207
 
208
void unlockHandle(FFHandle* hdl) {
208
void unlockHandle(FFHandle* hdl) {
209
        if (hdl->signature == HDLVERSION_SUITE2) {
209
        if (hdl->signature == HDLVERSION_SUITE2) {
210
                PSHandleSuite2* pSHandleSuite2 = NULL;
210
                PSHandleSuite2* pSHandleSuite2 = NULL;
211
                if ((gpb->sSPBasic != 0) &&
211
                if ((gpb->sSPBasic != 0) &&
212
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
212
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion2, (const void**)&pSHandleSuite2) == noErr) &&
213
                        (pSHandleSuite2 != NULL) &&
213
                        (pSHandleSuite2 != NULL) &&
214
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
214
                        (pSHandleSuite2 != (PSHandleSuite2*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
215
                        )
215
                        )
216
                {
216
                {
217
                        // PICA Handle Suite 2.0
217
                        // PICA Handle Suite 2.0
218
                        Ptr address;
218
                        Ptr address;
219
                        Boolean oldLock;
219
                        Boolean oldLock;
220
                        pSHandleSuite2->SetLock(hdl->handle, false, &address, &oldLock);
220
                        pSHandleSuite2->SetLock(hdl->handle, false, &address, &oldLock);
221
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
221
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion2);
222
                }
222
                }
223
        }
223
        }
224
        else if (hdl->signature == HDLVERSION_SUITE1) {
224
        else if (hdl->signature == HDLVERSION_SUITE1) {
225
                PSHandleSuite1* pSHandleSuite1 = NULL;
225
                PSHandleSuite1* pSHandleSuite1 = NULL;
226
                if ((gpb->sSPBasic != 0) &&
226
                if ((gpb->sSPBasic != 0) &&
227
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
227
                        (gpb->sSPBasic->AcquireSuite(kPIHandleSuite, kPSHandleSuiteVersion1, (const void**)&pSHandleSuite1) == noErr) &&
228
                        (pSHandleSuite1 != NULL) &&
228
                        (pSHandleSuite1 != NULL) &&
229
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
229
                        (pSHandleSuite1 != (PSHandleSuite1*)gpb->handleProcs /* Just to be sure (although no bug is known) */)
230
                        )
230
                        )
231
                {
231
                {
232
                        // PICA Handle Suite 1.0
232
                        // PICA Handle Suite 1.0
233
                        Ptr address;
233
                        Ptr address;
234
                        Boolean oldLock;
234
                        Boolean oldLock;
235
                        pSHandleSuite1->SetLock(hdl->handle, false, &address, &oldLock);
235
                        pSHandleSuite1->SetLock(hdl->handle, false, &address, &oldLock);
236
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
236
                        gpb->sSPBasic->ReleaseSuite(kPIHandleSuite, kPSHandleSuiteVersion1);
237
                }
237
                }
238
        }
238
        }
239
        else if (hdl->signature == HDLVERSION_STANDARD) {
239
        else if (hdl->signature == HDLVERSION_STANDARD) {
240
                // Standard Handle Suite (deprecated)
240
                // Standard Handle Suite (deprecated)
241
                gpb->handleProcs->unlockProc(hdl->handle);
241
                gpb->handleProcs->unlockProc(hdl->handle);
242
        }
242
        }
243
}
243
}
244
 
244
 
245
// -----------------------------------------------------------------------------------
245
// -----------------------------------------------------------------------------------
246
// These functions are for code backwards compatibility:
246
// These functions are for code backwards compatibility:
247
 
247
 
248
Handle PINEWHANDLE(int32 size) {
248
Handle PINEWHANDLE(int32 size) {
249
        FFHandle fh;
249
        FFHandle fh;
250
        newHandle(&fh, size);
250
        newHandle(&fh, size);
251
        // Note: newHandle() set gdata->lastKnownHandleVersion, so that
251
        // Note: newHandle() set gdata->lastKnownHandleVersion, so that
252
        // the other functions like PILOCKHANDLE can use it. This is safe,
252
        // the other functions like PILOCKHANDLE can use it. This is safe,
253
        // as we can assume that the version is always the same for all handles from this host.
253
        // as we can assume that the version is always the same for all handles from this host.
254
        return fh.handle;
254
        return fh.handle;
255
}
255
}
256
 
256
 
257
void PIDISPOSEHANDLE(Handle h) {
257
void PIDISPOSEHANDLE(Handle h) {
258
        FFHandle fh;
258
        FFHandle fh;
259
        fh.signature = gdata->lastKnownHandleVersion;
259
        fh.signature = gdata->lastKnownHandleVersion;
260
        fh.handle = h;
260
        fh.handle = h;
261
        disposeHandle(&fh);
261
        disposeHandle(&fh);
262
}
262
}
263
 
263
 
264
int32 PIGETHANDLESIZE(Handle h) {
264
size_t PIGETHANDLESIZE(Handle h) {
265
        FFHandle fh;
265
        FFHandle fh;
266
        fh.signature = gdata->lastKnownHandleVersion;
266
        fh.signature = gdata->lastKnownHandleVersion;
267
        fh.handle = h;
267
        fh.handle = h;
268
        return getHandleSize(&fh);
268
        return getHandleSize(&fh);
269
}
269
}
270
 
270
 
271
OSErr PISETHANDLESIZE(Handle h, int32 newSize) {
271
OSErr PISETHANDLESIZE(Handle h, int32 newSize) {
272
        FFHandle fh;
272
        FFHandle fh;
273
        fh.signature = gdata->lastKnownHandleVersion;
273
        fh.signature = gdata->lastKnownHandleVersion;
274
        fh.handle = h;
274
        fh.handle = h;
275
        return setHandleSize(&fh, newSize);
275
        return setHandleSize(&fh, newSize);
276
}
276
}
277
 
277
 
278
Ptr PILOCKHANDLE(Handle h, Boolean moveHigh) {
278
Ptr PILOCKHANDLE(Handle h, Boolean moveHigh) {
279
        FFHandle fh;
279
        FFHandle fh;
280
        UNREFERENCED_PARAMETER(moveHigh);
280
        UNREFERENCED_PARAMETER(moveHigh);
281
        fh.signature = gdata->lastKnownHandleVersion;
281
        fh.signature = gdata->lastKnownHandleVersion;
282
        fh.handle = h;
282
        fh.handle = h;
283
        return lockHandle(&fh);
283
        return lockHandle(&fh);
284
}
284
}
285
 
285
 
286
void PIUNLOCKHANDLE(Handle h) {
286
void PIUNLOCKHANDLE(Handle h) {
287
        FFHandle fh;
287
        FFHandle fh;
288
        fh.signature = gdata->lastKnownHandleVersion;
288
        fh.signature = gdata->lastKnownHandleVersion;
289
        fh.handle = h;
289
        fh.handle = h;
290
        unlockHandle(&fh);
290
        unlockHandle(&fh);
291
}
291
}
292
 
292
 
293
// -----------------------------------------------------------------------------------
293
// -----------------------------------------------------------------------------------
294
 
294
 
295
void newBuffer(FFBuffer* buf, size_t nBytes) {
295
void newBuffer(FFBuffer* buf, size_t nBytes) {
296
        PSBufferSuite1* pSBufferSuite32 = NULL;
296
        PSBufferSuite1* pSBufferSuite32 = NULL;
297
        PSBufferSuite2* pSBufferSuite64 = NULL;
297
        PSBufferSuite2* pSBufferSuite64 = NULL;
298
 
298
 
299
        if ((gpb->sSPBasic != 0) &&
299
        if ((gpb->sSPBasic != 0) &&
300
                (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) &&
300
                (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) &&
301
                (pSBufferSuite64 != NULL) &&
301
                (pSBufferSuite64 != NULL) &&
302
                (pSBufferSuite64 != (PSBufferSuite2*)gpb->bufferProcs /*Implementation mistake in old Photoshop versions! (see note below)*/)
302
                (pSBufferSuite64 != (PSBufferSuite2*)gpb->bufferProcs /*Implementation mistake in old Photoshop versions! (see note below)*/)
303
                )
303
                )
304
        {
304
        {
305
                // PICA Buffer Suite 2.0 (64 bit)
305
                // PICA Buffer Suite 2.0 (64 bit)
306
                // 
306
                // 
307
                // Note: Windows Photoshop 7 and CS 2 (Other Photoshop versions were not tested) accept
307
                // Note: Windows Photoshop 7 and CS 2 (Other Photoshop versions were not tested) accept
308
                // kPSBufferSuiteVersion2, but dont't correctly implement it:
308
                // kPSBufferSuiteVersion2, but dont't correctly implement it:
309
                // Instead of returning a pointer to a PSBufferSuite2 structure,
309
                // Instead of returning a pointer to a PSBufferSuite2 structure,
310
                // they return the pointer RecordPtr->bufferProcs (structure BufferProcs)!
310
                // they return the pointer RecordPtr->bufferProcs (structure BufferProcs)!
311
                // 
311
                // 
312
                // Side note:  64-bit support for Windows was established in Photoshop CS 4,
312
                // Side note:  64-bit support for Windows was established in Photoshop CS 4,
313
                //             PSBufferSuite2 was first documented in SDK CS 6,
313
                //             PSBufferSuite2 was first documented in SDK CS 6,
314
                //             pb->bufferProcs->allocateProc64 and spaceProc64 were documented in SDK CS 6,
314
                //             pb->bufferProcs->allocateProc64 and spaceProc64 were documented in SDK CS 6,
315
                //             pb->bufferSpace64 and pb->maxSpace64 were documented in SDK CC 2017.
315
                //             pb->bufferSpace64 and pb->maxSpace64 were documented in SDK CC 2017.
316
                unsigned32 siz = nBytes;
316
                unsigned32 siz = (unsigned32)nBytes;
317
                buf->signature = BUFVERSION_SUITE64;
317
                buf->signature = BUFVERSION_SUITE64;
318
                if (gdata) gdata->lastKnownBufferVersion = buf->signature;
318
                if (gdata) gdata->lastKnownBufferVersion = buf->signature;
319
                buf->suite = (Ptr)pSBufferSuite64->New(&siz, siz);
319
                buf->suite = (Ptr)pSBufferSuite64->New(&siz, siz);
320
                if (siz < nBytes) {
320
                if (siz < nBytes) {
321
                        buf->signature = BUFVERSION_NULL;
321
                        buf->signature = BUFVERSION_NULL;
322
                        buf->suite = NULL;
322
                        buf->suite = NULL;
323
                }
323
                }
324
                gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2);
324
                gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2);
325
        }
325
        }
326
        else if ((gpb->sSPBasic != 0) &&
326
        else if ((gpb->sSPBasic != 0) &&
327
                (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) &&
327
                (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) &&
328
                (pSBufferSuite32 != NULL) &&
328
                (pSBufferSuite32 != NULL) &&
329
                (pSBufferSuite32 != (PSBufferSuite1*)gpb->bufferProcs /* Just to be sure (although no bug is known) */)
329
                (pSBufferSuite32 != (PSBufferSuite1*)gpb->bufferProcs /* Just to be sure (although no bug is known) */)
330
                )
330
                )
331
        {
331
        {
332
                // PICA Buffer Suite 1.0 (32 bit)
332
                // PICA Buffer Suite 1.0 (32 bit)
333
                unsigned32 siz = nBytes;
333
                unsigned32 siz = (unsigned32)nBytes;
334
                buf->signature = BUFVERSION_SUITE32;
334
                buf->signature = BUFVERSION_SUITE32;
335
                if (gdata) gdata->lastKnownBufferVersion = buf->signature;
335
                if (gdata) gdata->lastKnownBufferVersion = buf->signature;
336
                buf->suite = (Ptr)pSBufferSuite32->New(&siz, siz);
336
                buf->suite = (Ptr)pSBufferSuite32->New(&siz, siz);
337
                if (siz < nBytes) {
337
                if (siz < nBytes) {
338
                        buf->signature = BUFVERSION_NULL;
338
                        buf->signature = BUFVERSION_NULL;
339
                        buf->suite = NULL;
339
                        buf->suite = NULL;
340
                }
340
                }
341
                gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1);
341
                gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1);
342
        }
342
        }
343
        else if (gpb->bufferProcs->numBufferProcs >= 8)
343
        else if (gpb->bufferProcs->numBufferProcs >= 8)
344
        {
344
        {
345
                // Standard Buffer Suite 64 bit (deprecated)
345
                // Standard Buffer Suite 64 bit (deprecated)
346
                buf->signature = BUFVERSION_STD64;
346
                buf->signature = BUFVERSION_STD64;
347
                if (gdata) gdata->lastKnownBufferVersion = buf->signature;
347
                if (gdata) gdata->lastKnownBufferVersion = buf->signature;
348
                if (gpb->bufferProcs->allocateProc64(nBytes, &buf->standard) != noErr) {
348
                if (gpb->bufferProcs->allocateProc64(nBytes, &buf->standard) != noErr) {
349
                        buf->signature = BUFVERSION_NULL;
349
                        buf->signature = BUFVERSION_NULL;
350
                        buf->standard = NULL;
350
                        buf->standard = NULL;
351
                }
351
                }
352
        }
352
        }
353
        else
353
        else
354
        {
354
        {
355
                // Standard Buffer Suite 32 bit (deprecated)
355
                // Standard Buffer Suite 32 bit (deprecated)
356
                buf->signature = BUFVERSION_STD32;
356
                buf->signature = BUFVERSION_STD32;
357
                if (gdata) gdata->lastKnownBufferVersion = buf->signature;
357
                if (gdata) gdata->lastKnownBufferVersion = buf->signature;
358
                if (gpb->bufferProcs->allocateProc(nBytes, &buf->standard) != noErr) {
358
                if (gpb->bufferProcs->allocateProc((int32)nBytes, &buf->standard) != noErr) {
359
                        buf->signature = BUFVERSION_NULL;
359
                        buf->signature = BUFVERSION_NULL;
360
                        buf->standard = NULL;
360
                        buf->standard = NULL;
361
                }
361
                }
362
        }
362
        }
363
}
363
}
364
 
364
 
365
Ptr lockBuffer(FFBuffer* buf) {
365
Ptr lockBuffer(FFBuffer* buf) {
366
        const Boolean moveHigh = false; // Under the Mac OS, the moveHigh flag indicates whether you want the memory blocked moved
366
        const Boolean moveHigh = false; // Under the Mac OS, the moveHigh flag indicates whether you want the memory blocked moved
367
                                        // to the high end of memory to avoid fragmentation. The moveHigh flag has no effect with Windows
367
                                        // to the high end of memory to avoid fragmentation. The moveHigh flag has no effect with Windows
368
        if (buf->signature == BUFVERSION_SUITE64) {
368
        if (buf->signature == BUFVERSION_SUITE64) {
369
                return buf->suite;
369
                return buf->suite;
370
        }
370
        }
371
        else if (buf->signature == BUFVERSION_SUITE32) {
371
        else if (buf->signature == BUFVERSION_SUITE32) {
372
                return buf->suite;
372
                return buf->suite;
373
        }
373
        }
374
        else if (buf->signature == BUFVERSION_STD64) {
374
        else if (buf->signature == BUFVERSION_STD64) {
375
                return gpb->bufferProcs->lockProc(buf->standard, moveHigh);
375
                return gpb->bufferProcs->lockProc(buf->standard, moveHigh);
376
        }
376
        }
377
        else if (buf->signature == BUFVERSION_STD32) {
377
        else if (buf->signature == BUFVERSION_STD32) {
378
                return gpb->bufferProcs->lockProc(buf->standard, moveHigh);
378
                return gpb->bufferProcs->lockProc(buf->standard, moveHigh);
379
        }
379
        }
380
        else {
380
        else {
381
                return NULL;
381
                return NULL;
382
        }
382
        }
383
}
383
}
384
 
384
 
385
void unlockBuffer(FFBuffer* buf) {
385
void unlockBuffer(FFBuffer* buf) {
386
        if (buf->signature == BUFVERSION_STD64) {
386
        if (buf->signature == BUFVERSION_STD64) {
387
                gpb->bufferProcs->unlockProc(buf->standard);
387
                gpb->bufferProcs->unlockProc(buf->standard);
388
        }
388
        }
389
        else if (buf->signature == BUFVERSION_STD32) {
389
        else if (buf->signature == BUFVERSION_STD32) {
390
                gpb->bufferProcs->unlockProc(buf->standard);
390
                gpb->bufferProcs->unlockProc(buf->standard);
391
        }
391
        }
392
}
392
}
393
 
393
 
394
void disposeBuffer(FFBuffer* buf) {
394
void disposeBuffer(FFBuffer* buf) {
395
        if (buf->signature == BUFVERSION_SUITE64) {
395
        if (buf->signature == BUFVERSION_SUITE64) {
396
                PSBufferSuite2* pSBufferSuite64 = NULL;
396
                PSBufferSuite2* pSBufferSuite64 = NULL;
397
                if ((gpb->sSPBasic != 0) &&
397
                if ((gpb->sSPBasic != 0) &&
398
                        (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) &&
398
                        (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) &&
399
                        (pSBufferSuite64 != NULL) &&
399
                        (pSBufferSuite64 != NULL) &&
400
                        (pSBufferSuite64 != (PSBufferSuite2*)gpb->bufferProcs /*Implementation mistake in old Photoshop versions! (see note below)*/)
400
                        (pSBufferSuite64 != (PSBufferSuite2*)gpb->bufferProcs /*Implementation mistake in old Photoshop versions! (see note below)*/)
401
                        )
401
                        )
402
                {
402
                {
403
                        // PICA Buffer Suite 2.0 (64 bit)
403
                        // PICA Buffer Suite 2.0 (64 bit)
404
                        pSBufferSuite64->Dispose(&buf->suite);
404
                        pSBufferSuite64->Dispose(&buf->suite);
405
                        gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2);
405
                        gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2);
406
                }
406
                }
407
        }
407
        }
408
        else if (buf->signature == BUFVERSION_SUITE32) {
408
        else if (buf->signature == BUFVERSION_SUITE32) {
409
                PSBufferSuite1* pSBufferSuite32 = NULL;
409
                PSBufferSuite1* pSBufferSuite32 = NULL;
410
                if ((gpb->sSPBasic != 0) &&
410
                if ((gpb->sSPBasic != 0) &&
411
                        (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) &&
411
                        (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) &&
412
                        (pSBufferSuite32 != NULL))
412
                        (pSBufferSuite32 != NULL))
413
                {
413
                {
414
                        // PICA Buffer Suite 1.0 (32 bit)
414
                        // PICA Buffer Suite 1.0 (32 bit)
415
                        pSBufferSuite32->Dispose(&buf->suite);
415
                        pSBufferSuite32->Dispose(&buf->suite);
416
                        gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1);
416
                        gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1);
417
                }
417
                }
418
        }
418
        }
419
        else if (buf->signature == BUFVERSION_STD64) {
419
        else if (buf->signature == BUFVERSION_STD64) {
420
                gpb->bufferProcs->freeProc(buf->standard);
420
                gpb->bufferProcs->freeProc(buf->standard);
421
        }
421
        }
422
        else if (buf->signature == BUFVERSION_STD32) {
422
        else if (buf->signature == BUFVERSION_STD32) {
423
                gpb->bufferProcs->freeProc(buf->standard);
423
                gpb->bufferProcs->freeProc(buf->standard);
424
        }
424
        }
425
        buf->signature = BUFVERSION_NULL;
425
        buf->signature = BUFVERSION_NULL;
426
}
426
}
427
 
427