Rev 484 | Rev 486 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
484 | daniel-mar | 1 | /* |
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 |
||
4 | Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft |
||
5 | |||
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 |
||
8 | the Free Software Foundation; either version 2 of the License, or |
||
9 | (at your option) any later version. |
||
10 | |||
11 | This program is distributed in the hope that it will be useful, |
||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | GNU General Public License for more details. |
||
15 | |||
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 |
||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
19 | */ |
||
20 | |||
21 | #include "ff.h" |
||
22 | |||
485 | daniel-mar | 23 | #include "PIBufferSuite.h" |
24 | |||
25 | // TODO: Also implement the handleSuite like this |
||
26 | |||
27 | FFBuffer newBuffer(size_t nBytes) { |
||
28 | PSBufferSuite1* pSBufferSuite32 = NULL; |
||
29 | PSBufferSuite2* pSBufferSuite64 = NULL; |
||
30 | |||
31 | FFBuffer ret; |
||
32 | |||
33 | if ((gpb->sSPBasic != 0) && |
||
34 | (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) && |
||
35 | (pSBufferSuite64 != NULL) && |
||
36 | (pSBufferSuite64 != (PSBufferSuite2*)gpb->bufferProcs /*Implementation mistake in old Photoshop versions! (see note below)*/) |
||
37 | ) |
||
38 | { |
||
39 | // PICA Buffer Suite 2.0 (64 bit) |
||
40 | // |
||
41 | // Note: Windows Photoshop 7 and CS 2 (Other Photoshop versions were not tested) accept |
||
42 | // kPSBufferSuiteVersion2, but dont't correctly implement it: |
||
43 | // Instead of returning a pointer to a PSBufferSuite2 structure, |
||
44 | // they return the pointer RecordPtr->bufferProcs (structure BufferProcs)! |
||
45 | // |
||
46 | // 64-bit support for Windows was established in Photoshop CS 4, |
||
47 | // and PSBufferSuite2 was first documented in SDK CS 6. |
||
48 | // |
||
49 | // So, kPSBufferSuiteVersion2 probably was partially implemented as hidden "Work in progress" version |
||
50 | // before it was publicly documented. |
||
51 | // Side note: pb->bufferSpace64/pb->maxSpace64 was documented in SDK CC 2017. |
||
52 | // pb->bufferProcs->allocateProc64/spaceProc64 was documented in SDK CS 6. |
||
53 | unsigned32 siz = nBytes; |
||
54 | ret.signature = BUFVERSION_SUITE64; |
||
55 | ret.suite64 = (Ptr)pSBufferSuite64->New(&siz, siz); |
||
56 | if (siz < nBytes) { |
||
57 | ret.signature = BUFVERSION_NULL; |
||
58 | ret.suite64 = NULL; |
||
59 | } |
||
60 | gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2); |
||
484 | daniel-mar | 61 | } |
485 | daniel-mar | 62 | else if ((gpb->sSPBasic != 0) && |
63 | (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) && |
||
64 | (pSBufferSuite32 != NULL)) |
||
65 | { |
||
66 | // PICA Buffer Suite 1.0 (32 bit) |
||
67 | unsigned32 siz = nBytes; |
||
68 | ret.signature = BUFVERSION_SUITE32; |
||
69 | ret.suite32 = (Ptr)pSBufferSuite32->New(&siz, siz); |
||
70 | if (siz < nBytes) { |
||
71 | ret.signature = BUFVERSION_NULL; |
||
72 | ret.suite32 = NULL; |
||
73 | } |
||
74 | gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1); |
||
484 | daniel-mar | 75 | } |
485 | daniel-mar | 76 | else if (gpb->bufferProcs->numBufferProcs >= 8) |
77 | { |
||
78 | // Standard Buffer Suite 64 bit (deprecated) |
||
79 | ret.signature = BUFVERSION_STD64; |
||
80 | if ((/* *result = */ gpb->bufferProcs->allocateProc64(nBytes, &ret.standard))) { |
||
81 | ret.signature = BUFVERSION_NULL; |
||
82 | ret.standard = NULL; |
||
83 | } |
||
84 | } |
||
85 | else |
||
86 | { |
||
87 | // Standard Buffer Suite 32 bit (deprecated) |
||
88 | ret.signature = BUFVERSION_STD32; |
||
89 | if ((/* *result = */ gpb->bufferProcs->allocateProc(nBytes, &ret.standard))) { |
||
90 | ret.signature = BUFVERSION_NULL; |
||
91 | ret.standard = NULL; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | return ret; |
||
484 | daniel-mar | 96 | } |
97 | |||
485 | daniel-mar | 98 | Ptr lockBuffer(FFBuffer bid) { |
99 | if (bid.signature == BUFVERSION_SUITE64) { |
||
100 | return bid.suite64; |
||
101 | } |
||
102 | else if (bid.signature == BUFVERSION_SUITE32) { |
||
103 | return bid.suite32; |
||
104 | } |
||
105 | else if (bid.signature == BUFVERSION_STD64) { |
||
106 | return gpb->bufferProcs->lockProc(bid.standard, true); |
||
107 | } |
||
108 | else if (bid.signature == BUFVERSION_STD32) { |
||
109 | return gpb->bufferProcs->lockProc(bid.standard, true); |
||
110 | } |
||
111 | else { |
||
112 | return NULL; |
||
113 | } |
||
484 | daniel-mar | 114 | } |
115 | |||
485 | daniel-mar | 116 | void unlockBuffer(FFBuffer bid) { |
117 | if (bid.signature == BUFVERSION_STD64) { |
||
118 | gpb->bufferProcs->unlockProc(bid.standard); |
||
119 | } |
||
120 | else if (bid.signature == BUFVERSION_STD32) { |
||
121 | gpb->bufferProcs->unlockProc(bid.standard); |
||
122 | } |
||
484 | daniel-mar | 123 | } |
124 | |||
485 | daniel-mar | 125 | void disposeBuffer(FFBuffer* bid) { |
126 | if ((*bid).signature == BUFVERSION_SUITE64) { |
||
127 | PSBufferSuite2* pSBufferSuite64 = NULL; |
||
128 | if ((gpb->sSPBasic != 0) && |
||
129 | (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion2, (const void**)&pSBufferSuite64) == noErr) && |
||
130 | (pSBufferSuite64 != NULL)) |
||
131 | { |
||
132 | // PICA Buffer Suite 2.0 (64 bit) |
||
133 | pSBufferSuite64->Dispose(&((*bid).suite64)); |
||
134 | gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion2); |
||
135 | } |
||
136 | } |
||
137 | else if ((*bid).signature == BUFVERSION_SUITE32) { |
||
138 | PSBufferSuite1* pSBufferSuite32 = NULL; |
||
139 | if ((gpb->sSPBasic != 0) && |
||
140 | (gpb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&pSBufferSuite32) == noErr) && |
||
141 | (pSBufferSuite32 != NULL)) |
||
142 | { |
||
143 | // PICA Buffer Suite 1.0 (32 bit) |
||
144 | pSBufferSuite32->Dispose(&((*bid).suite32)); |
||
145 | gpb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1); |
||
146 | } |
||
147 | } |
||
148 | else if ((*bid).signature == BUFVERSION_STD64) { |
||
149 | gpb->bufferProcs->freeProc((*bid).standard); |
||
150 | } |
||
151 | else if ((*bid).signature == BUFVERSION_STD32) { |
||
152 | gpb->bufferProcs->freeProc((*bid).standard); |
||
153 | } |
||
154 | (*bid).signature = BUFVERSION_NULL; |
||
484 | daniel-mar | 155 | } |