Rev 484 | Rev 486 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 484 | Rev 485 | ||
---|---|---|---|
Line 18... | Line 18... | ||
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" |
|
- | 24 | ||
- | 25 | // TODO: Also implement the handleSuite like this |
|
- | 26 | ||
23 | BufferID newBuffer(size_t size) { |
27 | FFBuffer newBuffer(size_t nBytes) { |
- | 28 | PSBufferSuite1* pSBufferSuite32 = NULL; |
|
24 | // TODO: If available, use new Buffer Suite ? |
29 | PSBufferSuite2* pSBufferSuite64 = NULL; |
- | 30 | ||
25 | BufferID bid; |
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); |
|
- | 61 | } |
|
- | 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); |
|
- | 75 | } |
|
26 | if (gpb->bufferProcs->numBufferProcs >= 8) { |
76 | else if (gpb->bufferProcs->numBufferProcs >= 8) |
- | 77 | { |
|
- | 78 | // Standard Buffer Suite 64 bit (deprecated) |
|
- | 79 | ret.signature = BUFVERSION_STD64; |
|
27 | gpb->bufferProcs->allocateProc64(size, &bid); |
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; |
|
28 | } |
92 | } |
29 | else { |
- | |
30 | gpb->bufferProcs->allocateProc(size, &bid); |
- | |
31 | } |
93 | } |
- | 94 | ||
32 | return bid; |
95 | return ret; |
33 | } |
96 | } |
34 | 97 | ||
35 | Ptr lockBuffer(BufferID bid) { |
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 | } |
|
36 | // TODO: If available, use new Buffer Suite ? |
108 | else if (bid.signature == BUFVERSION_STD32) { |
37 | return gpb->bufferProcs->lockProc(bid, true); |
109 | return gpb->bufferProcs->lockProc(bid.standard, true); |
- | 110 | } |
|
- | 111 | else { |
|
- | 112 | return NULL; |
|
- | 113 | } |
|
38 | } |
114 | } |
39 | 115 | ||
40 | void unlockBuffer(BufferID bid) { |
116 | void unlockBuffer(FFBuffer bid) { |
- | 117 | if (bid.signature == BUFVERSION_STD64) { |
|
- | 118 | gpb->bufferProcs->unlockProc(bid.standard); |
|
- | 119 | } |
|
41 | // TODO: If available, use new Buffer Suite ? |
120 | else if (bid.signature == BUFVERSION_STD32) { |
42 | gpb->bufferProcs->unlockProc(bid); |
121 | gpb->bufferProcs->unlockProc(bid.standard); |
- | 122 | } |
|
43 | } |
123 | } |
44 | 124 | ||
45 | void disposeBuffer(BufferID bid) { |
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) { |
|
46 | // TODO: If available, use new Buffer Suite ? |
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) { |
|
47 | gpb->bufferProcs->freeProc(bid); |
152 | gpb->bufferProcs->freeProc((*bid).standard); |
- | 153 | } |
|
- | 154 | (*bid).signature = BUFVERSION_NULL; |
|
48 | } |
155 | } |