Rev 483 | Rev 491 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 483 | Rev 486 | ||
---|---|---|---|
Line 137... | Line 137... | ||
137 | 137 | ||
138 | simplealert((TCHAR*)TEXT("You tried to execute this DLL with RunDLL32. This is a Photoshop plugin!")); |
138 | simplealert((TCHAR*)TEXT("You tried to execute this DLL with RunDLL32. This is a Photoshop plugin!")); |
139 | return; |
139 | return; |
140 | } |
140 | } |
141 | 141 | ||
142 | // this method is currently not used. We keep it in the code in case it is useful for someone... |
- | |
143 | Ptr NewPtrClearUsingBufferSuite(size_t nBytes) { |
- | |
144 | PSBufferSuite1* pSBufferSuite32 = NULL; |
- | |
145 | PSBufferSuite2* pSBufferSuite64 = NULL; |
- | |
146 | void* data; |
- | |
147 | - | ||
148 | if ((gpb->sSPBasic != 0) && |
- | |
149 | (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) && |
- | |
150 | (pSBufferSuite64 != NULL) && |
- | |
151 | (pSBufferSuite64 != (PSBufferSuite2*)gpb->bufferProcs /*Implementation mistake in old Photoshop versions! (see note below)*/) |
- | |
152 | ) |
- | |
153 | { |
- | |
154 | // PICA Buffer Suite 2.0 (64 bit) |
- | |
155 | // |
- | |
156 | // Note: Windows Photoshop 7 and CS 2 (Other Photoshop versions were not tested) accept |
- | |
157 | // kPSBufferSuiteVersion2, but dont't correctly implement it: |
- | |
158 | // Instead of returning a pointer to a PSBufferSuite2 structure, |
- | |
159 | // they return the pointer RecordPtr->bufferProcs (structure BufferProcs)! |
- | |
160 | // |
- | |
161 | // 64-bit support for Windows was established in Photoshop CS 4, |
- | |
162 | // and PSBufferSuite2 was first documented in SDK CS 6. |
- | |
163 | // |
- | |
164 | // So, kPSBufferSuiteVersion2 probably was partially implemented as hidden "Work in progress" version |
- | |
165 | // before it was publicly documented. |
- | |
166 | // Side note: pb->bufferSpace64/pb->maxSpace64 was documented in SDK CC 2017. |
- | |
167 | // pb->bufferProcs->allocateProc64/spaceProc64 was documented in SDK CS 6. |
- | |
168 | unsigned32 siz = nBytes; |
- | |
169 | data = (void*)pSBufferSuite64->New(&siz, siz); |
- | |
170 | if (siz < nBytes) data = NULL; |
- | |
171 | gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2); |
- | |
172 | } |
- | |
173 | else if ((gpb->sSPBasic != 0) && |
- | |
174 | (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) && |
- | |
175 | (pSBufferSuite32 != NULL)) |
- | |
176 | { |
- | |
177 | // PICA Buffer Suite 1.0 (32 bit) |
- | |
178 | unsigned32 siz = nBytes; |
- | |
179 | data = (void*)pSBufferSuite32->New(&siz, siz); |
- | |
180 | if (siz < nBytes) data = NULL; |
- | |
181 | gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1); |
- | |
182 | } |
- | |
183 | else |
- | |
184 | { |
- | |
185 | // Standard Buffer Suite (deprecated) |
- | |
186 | BufferID tempId; |
- | |
187 | if ((/* *result = */ gpb->bufferProcs->allocateProc(nBytes, &tempId))) { |
- | |
188 | data = NULL; |
- | |
189 | return (Ptr)data; |
- | |
190 | } |
- | |
191 | data = (void*)gpb->bufferProcs->lockProc(tempId, true); |
- | |
192 | } |
- | |
193 | - | ||
194 | if (data) memset(data, 0, nBytes); |
- | |
195 | return (Ptr)data; |
- | |
196 | } |
- | |
197 | - | ||
198 | void CreateDataPointer(intptr_t* data) { |
142 | void CreateDataPointer(intptr_t* data) { |
199 | // Register "gdata" that contains the PARM information and other things which need to be persistant |
143 | // Register "gdata" that contains the PARM information and other things which need to be persistant |
200 | // and preserve them in *data |
144 | // and preserve them in *data |
201 | // This memory allocation is never freed, because the filter can always be invoked again. |
145 | // This memory allocation is never freed, because the filter can always be invoked again. |
202 | // The memory allocation will be kept for the lifetime of the Photoshop process and |
146 | // The memory allocation will be kept for the lifetime of the Photoshop process and |
Line 204... | Line 148... | ||
204 | 148 | ||
205 | // We have at least 5 options to allocate memory: |
149 | // We have at least 5 options to allocate memory: |
206 | 150 | ||
207 | // (Method 1) |
151 | // (Method 1) |
208 | // 1. The deprecated Standard Buffer Suite (pb->bufferProcs) - works fine! |
152 | // 1. The deprecated Standard Buffer Suite (pb->bufferProcs) - works fine! |
- | 153 | /* |
|
209 | //BufferID tempId; |
154 | BufferID tempId; |
210 | //if ((/* *result = */ gpb->bufferProcs->allocateProc(sizeof(globals_t), &tempId))) { |
155 | if (gpb->bufferProcs->allocateProc(sizeof(globals_t), &tempId) != noErr) { |
211 | // *data = NULL; |
156 | *data = NULL; |
212 | // return *data; |
- | |
213 | //} |
157 | } |
- | 158 | else { |
|
214 | //*data = (void*)gpb->bufferProcs->lockProc(tempId, true); |
159 | *data = (void*)gpb->bufferProcs->lockProc(tempId, true); |
- | 160 | if (*data) memset((void*)*data, 0, sizeof(globals_t)); |
|
- | 161 | } |
|
- | 162 | */ |
|
215 | 163 | ||
216 | // (Method 2) *DOES NOT WORK* |
164 | // (Method 2) *DOES NOT WORK* |
217 | // 2. The recommended buffer suite (kPSBufferSuite), |
165 | // 2. The recommended buffer suite (kPSBufferSuite), |
218 | // It does not work, since it causes memory corruption when the filter is invoked a second time. |
166 | // It does not work, since it causes memory corruption when the filter is invoked a second time. |
219 | // Probably the BufferSuite cannot be used to share data between filter invocations? |
167 | // Probably the BufferSuite cannot be used to share data between filter invocations? |
220 | // Also, the buffer suite is only available in a Adobe Photoshop host. |
168 | // Also, the buffer suite is only available in a Adobe Photoshop host. |
- | 169 | /* |
|
- | 170 | FFBuffer buf; |
|
- | 171 | newBuffer(&buf, sizeof(globals_t)); |
|
- | 172 | *data = (intptr_t)lockBuffer(&buf); |
|
221 | //*data = (intptr_t)NewPtrClearUsingBufferSuite(sizeof(globals_t)); |
173 | if (*data) memset((void*)*data, 0, sizeof(globals_t)); |
- | 174 | */ |
|
222 | 175 | ||
223 | // (Method 3) |
176 | // (Method 3) |
224 | // 3. Using malloc(), which works also fine and is more independent from the host. It is also easier. |
177 | // 3. Using malloc(), which works also fine and is more independent from the host. It is also easier. |
225 | // However, we do not know how malloc() is implemented, and it might cause problems if the |
178 | // However, we do not know how malloc() is implemented, and it might cause problems if the |
226 | // DLL is unloaded between invocations. |
179 | // DLL is unloaded between invocations. |
- | 180 | /* |
|
227 | //*data = (intptr_t)malloc(sizeof(globals_t)); |
181 | *data = (intptr_t)malloc(sizeof(globals_t)); |
228 | //if (*data) memset(*data, 0, sizeof(globals_t)); |
182 | if (*data) memset((void*)*data, 0, sizeof(globals_t)); |
- | 183 | */ |
|
229 | 184 | ||
230 | // (Method 4) |
185 | // (Method 4) |
231 | // 4. Using PLUGIN.DLL:NewPtr(). This does FilterFactory 3.0.4, but requires an Adobe host. |
186 | // 4. Using PLUGIN.DLL:NewPtr(). This does FilterFactory 3.0.4, but requires an Adobe host. |
232 | // In Plugin.dll, the function NewPtr() and NewPtrClear() are implemented as GlobalAlloc/GlobalLock. |
187 | // In Plugin.dll, the function NewPtr() and NewPtrClear() are implemented as GlobalAlloc/GlobalLock. |
233 | // Nothing special. |
188 | // Nothing special. |