Hi All,
I am developing a Photoshop cs2 plugin for powerpc mac. My plugin does some processing when the user tries to duplicate channel. I handle by capturing 'eventDuplicate' in my plugin.
My problem is 'eventDuplicate' is also trigged when user tries to save a selection from the SELECT-%26gt;SAVE SELECTION menu. I dont want to handle this trigger of 'eventDuplicate'. Is there a way out to find out that this event is coming from the 'SAVE SELECTION' operation?
TIA,
-Anish
Thursday, April 1, 2010
Programming filters with Xcode +...
Hi,
I've figured out how to make a working PC Photoshop plugin and am now figuring out the Mac side. What is a reasonable method for creating/altering the GUI... e.g. altering the Dissolve filter example's GUI or creating my GUI from scratch?
I looked through the Dissolve filter example and it's not clear how to alter the GUI... the documentation talks about the example being a Xcode project but the .r file doesn't open in interface builder. Perhaps one is to use Metrowerks Codewarrior...? (But I don't have that program and it doesn't look available.) So basically I am thinking I have to figure out how to get the filter working with Xcode/interface builder/carbon. It would be helpful if there was example code for that.
2- I am on the Mactel platform (Macbook Pro).
Any help would be greatly appreciated! Thanks.
Programming filters with Xcode +...
Ok so I've figured out part of the puzzle. You can make Carbon windows normally, with the complication of the plugin finding the NIB properly.%26lt;br /%26gt;%26lt;br /%26gt;I needed to add the following two lines to info.plist (choose whatever identifier you want)%26lt;br /%26gt;%26lt;br /%26gt; %26lt;key%26gt;CFBundleIdentifier%26lt;/key%26gt;%26lt;br /%26gt; %26lt;string%26gt;Whatever identifier you want goes here%26lt;/string%26gt;%26lt;br /%26gt;%26lt;br /%26gt;And then in your DissolveMacUI.cpp you might do something like:%26lt;br /%26gt;%26lt;br /%26gt; IBNibRef theNib;%26lt;br /%26gt; CFBundleRef bundleRef;%26lt;br /%26gt; bundleRef = CFBundleGetBundleWithIdentifier (CFSTR (''Whatever identifier you want goes here''));%26lt;br /%26gt; %26lt;br /%26gt; err = CreateNibReferenceWithCFBundle(bundleRef, CFSTR(''Name of your NIB file here''), %26amp;theNib);%26lt;br /%26gt;%26lt;br /%26gt;I'm trying to figure out how to display a proxy in the resulting window. Does anyone have any insights here?Programming filters with Xcode +...
%26gt; I'm trying to figure out how to display a proxy in the resulting
%26gt; window. Does anyone have any insights here?
Use the Channel Ports suite to get your pixel data out of Photoshop; use the DisplayPixels callback (either from the UI Hooks suite, or from the filter record) to write pixel data to your dialog.
Hi Matthew,
Thanks for the reply. Right now I'm trying to figure out how the DisplayPixels callback works and how to integrate that into my GUI. I thought that you can just use the example code and cast the WindowRefs to DialogRefs (and other Window equivalents to their Dialog equivalent), but this is a dead end path (the WindowRefs need to be made with Dialog manager for that to work it seems).
So it looks like I need to figure out how to use Quickdraw (not Quartz) with Windows, not Dialogs.
Could you point me towards the right documentation to read to figure this out?
Hmm there is an example in ''Handling Carbon Windows and Controls''--%26gt; Control Implementation Examples (in the documentation that comes with Xcode). I think that might be what I was looking for.
Since i'm also developing a Plugin with a fairly complicated user interface, i would like to know if You've made any progress with the NIB based dialog. Thank You.
It's working for me. You need to use Quickdraw and you need to set the ports correctly.
Make sure you:
//Set the graphics port before calling displayPixels
GrafPtr oldPort;
GetPort(%26amp;oldPort);
SetPortWindowPort(theWindow);
//[...]
/* Display the data. */
if (gFilterRecord-%26gt;displayPixels != NULL)
{
OSErr err;
err = (*(gFilterRecord-%26gt;displayPixels)) (%26amp;outMap, %26amp;srcRect, dstRow, dstCol, gFilterRecord-%26gt;platformData);
}
//Set the port back.
SetPort(oldPort);
//Make the watch stop spinning
OSErr err;
err = PISetWatchSuspension(999); //%26lt;--not sure about this line, but do something like that.
InitCursor(); //This seems to fix a bug where the watch cursor needs to be refreshed.
Just to make sure i understand (because this is my first Mac OS project ever):
You've written a Plugin for Photoshop in XCode, using Carbon and Interface Builder and You display pixel data from the current photoshop document in the Window created by IB ? Because that's exactly what i need to do :-)
Thank You.
Yes.
I think there may have been some other gotchas that I forgot about... because I did not use Dialog Manager (Interface Builder won't do it, but the example code uses it). It's something like that; my memory is hazy. So I used the Window manager, and you sometimes need to create the equivalent functions to what the Dialog Manager is doing. And you can't convert Windows into Dialogs. You need to convert from Dialog Manager to Window manager.
Ok, now my dialog (by IB) is displaying and is handling events and i can draw into it. Next problem: I need the pixels from the current photoshop document for a preview. Where do You get the ''gFilterRecord-%26gt;displayPixels'' from ?
Did you take a look at the Dissolve example code? I would start from there and convert that code into Window manager.
My last message was assuming you were working off of the Dissolve sample code.
Christof: I have code for previewing. See http://www.telegraphics.com.au/svn/filterfoundry/trunk/preview.c (GPL).
Hi
Can u please send me the code for how to work with POP UP and buttons and how to handle events on varios events like when u select something from pop up and when u click on button.
and how to open a new window when user clicks on the buttons.
I've found that it's a hell of a lot easier to just do a Carbon NIB-based user interface than to try to deal with all of that antiquated crap that's in the sample code. I have quite a sophisticated UI working now in my filter, including a preview control, and it didn't take me any more effort than it would have if I were coding it in an application. Even the debugger works, as well as Xcode/GDB ever works (which isn't saying much).
The only trick is that you have to load the NIB file manually. Here's the code to put up your dialog:
IBNibRef dialogNibRef = NULL;
WindowRef windowRef = NULL;
CFBundleRef bundle = CFBundleGetBundleWithIdentifier(kMyBundleIdentifier);
CreateNibReferenceWithCFBundle(bundle, kMyNIBName, %26amp;dialogNibRef);
CreateWindowFromNib(dialogNibRef, kMyWindowName, %26amp;windowRef);
DisposeNibReference(dialogNibRef);
Having done this, you can show the window using RunAppModalLoopForWindow.
Hope this helps,
Aaron
Hello,
I currently have several Photoshop plugins available under Windows which are created using Visual Studios 2005 and I am trying to find an example plugin in the Photoshop CS4 SDK environment which I could practice on. My goal is to edit the dialogs/UI of the plugin and finally just add connect existing functionality.
The ultimate goal is to implement existing PC Photoshop plugins under Mac OS Systems using the Adoble Dialog Manager and API architecture. A cross platform solution for both PC and Mac is desired.
Could someone please direct me to a simple example in the Photoshop CS4 SDK environment or a good tutorial, as I am a working student with little C++ programming knowledge.
Thank you in advance,
Andreas
ADM has long been deprecated. Some developers are using Qt for x-platform UI, see other recent threads.
%26gt;The only trick is that you have to load the NIB file manually. Here's the code to put up your %26gt;dialog:
%26gt;
%26gt;IBNibRef dialogNibRef = NULL;
%26gt;WindowRef windowRef = NULL;
%26gt;CFBundleRef bundle = CFBundleGetBundleWithIdentifier(kMyBundleIdentifier);
%26gt;CreateNibReferenceWithCFBundle(bundle, kMyNIBName, %26amp;dialogNibRef);
%26gt;CreateWindowFromNib(dialogNibRef, kMyWindowName, %26amp;windowRef);
%26gt;DisposeNibReference(dialogNibRef);
%26gt;
%26gt;Having done this, you can show the window using RunAppModalLoopForWindow.
Could you please explain these steps more in detail Aaron. I've setup a UI using the Interface Builder and have put the above mentioned code into DissolveUIMac.cpp but i am getting the following errors:
error: 'kMyBundleIdentifier' was not declared in this scope
error: expected constructor, destructor, or type conversion before '(' token
error: expected constructor, destructor, or type conversion before '(' token
error: expected constructor, destructor, or type conversion before '(' token
I've figured out how to make a working PC Photoshop plugin and am now figuring out the Mac side. What is a reasonable method for creating/altering the GUI... e.g. altering the Dissolve filter example's GUI or creating my GUI from scratch?
I looked through the Dissolve filter example and it's not clear how to alter the GUI... the documentation talks about the example being a Xcode project but the .r file doesn't open in interface builder. Perhaps one is to use Metrowerks Codewarrior...? (But I don't have that program and it doesn't look available.) So basically I am thinking I have to figure out how to get the filter working with Xcode/interface builder/carbon. It would be helpful if there was example code for that.
2- I am on the Mactel platform (Macbook Pro).
Any help would be greatly appreciated! Thanks.
Programming filters with Xcode +...
Ok so I've figured out part of the puzzle. You can make Carbon windows normally, with the complication of the plugin finding the NIB properly.%26lt;br /%26gt;%26lt;br /%26gt;I needed to add the following two lines to info.plist (choose whatever identifier you want)%26lt;br /%26gt;%26lt;br /%26gt; %26lt;key%26gt;CFBundleIdentifier%26lt;/key%26gt;%26lt;br /%26gt; %26lt;string%26gt;Whatever identifier you want goes here%26lt;/string%26gt;%26lt;br /%26gt;%26lt;br /%26gt;And then in your DissolveMacUI.cpp you might do something like:%26lt;br /%26gt;%26lt;br /%26gt; IBNibRef theNib;%26lt;br /%26gt; CFBundleRef bundleRef;%26lt;br /%26gt; bundleRef = CFBundleGetBundleWithIdentifier (CFSTR (''Whatever identifier you want goes here''));%26lt;br /%26gt; %26lt;br /%26gt; err = CreateNibReferenceWithCFBundle(bundleRef, CFSTR(''Name of your NIB file here''), %26amp;theNib);%26lt;br /%26gt;%26lt;br /%26gt;I'm trying to figure out how to display a proxy in the resulting window. Does anyone have any insights here?Programming filters with Xcode +...
%26gt; I'm trying to figure out how to display a proxy in the resulting
%26gt; window. Does anyone have any insights here?
Use the Channel Ports suite to get your pixel data out of Photoshop; use the DisplayPixels callback (either from the UI Hooks suite, or from the filter record) to write pixel data to your dialog.
Hi Matthew,
Thanks for the reply. Right now I'm trying to figure out how the DisplayPixels callback works and how to integrate that into my GUI. I thought that you can just use the example code and cast the WindowRefs to DialogRefs (and other Window equivalents to their Dialog equivalent), but this is a dead end path (the WindowRefs need to be made with Dialog manager for that to work it seems).
So it looks like I need to figure out how to use Quickdraw (not Quartz) with Windows, not Dialogs.
Could you point me towards the right documentation to read to figure this out?
Hmm there is an example in ''Handling Carbon Windows and Controls''--%26gt; Control Implementation Examples (in the documentation that comes with Xcode). I think that might be what I was looking for.
Since i'm also developing a Plugin with a fairly complicated user interface, i would like to know if You've made any progress with the NIB based dialog. Thank You.
It's working for me. You need to use Quickdraw and you need to set the ports correctly.
Make sure you:
//Set the graphics port before calling displayPixels
GrafPtr oldPort;
GetPort(%26amp;oldPort);
SetPortWindowPort(theWindow);
//[...]
/* Display the data. */
if (gFilterRecord-%26gt;displayPixels != NULL)
{
OSErr err;
err = (*(gFilterRecord-%26gt;displayPixels)) (%26amp;outMap, %26amp;srcRect, dstRow, dstCol, gFilterRecord-%26gt;platformData);
}
//Set the port back.
SetPort(oldPort);
//Make the watch stop spinning
OSErr err;
err = PISetWatchSuspension(999); //%26lt;--not sure about this line, but do something like that.
InitCursor(); //This seems to fix a bug where the watch cursor needs to be refreshed.
Just to make sure i understand (because this is my first Mac OS project ever):
You've written a Plugin for Photoshop in XCode, using Carbon and Interface Builder and You display pixel data from the current photoshop document in the Window created by IB ? Because that's exactly what i need to do :-)
Thank You.
Yes.
I think there may have been some other gotchas that I forgot about... because I did not use Dialog Manager (Interface Builder won't do it, but the example code uses it). It's something like that; my memory is hazy. So I used the Window manager, and you sometimes need to create the equivalent functions to what the Dialog Manager is doing. And you can't convert Windows into Dialogs. You need to convert from Dialog Manager to Window manager.
Ok, now my dialog (by IB) is displaying and is handling events and i can draw into it. Next problem: I need the pixels from the current photoshop document for a preview. Where do You get the ''gFilterRecord-%26gt;displayPixels'' from ?
Did you take a look at the Dissolve example code? I would start from there and convert that code into Window manager.
My last message was assuming you were working off of the Dissolve sample code.
Christof: I have code for previewing. See http://www.telegraphics.com.au/svn/filterfoundry/trunk/preview.c (GPL).
Hi
Can u please send me the code for how to work with POP UP and buttons and how to handle events on varios events like when u select something from pop up and when u click on button.
and how to open a new window when user clicks on the buttons.
I've found that it's a hell of a lot easier to just do a Carbon NIB-based user interface than to try to deal with all of that antiquated crap that's in the sample code. I have quite a sophisticated UI working now in my filter, including a preview control, and it didn't take me any more effort than it would have if I were coding it in an application. Even the debugger works, as well as Xcode/GDB ever works (which isn't saying much).
The only trick is that you have to load the NIB file manually. Here's the code to put up your dialog:
IBNibRef dialogNibRef = NULL;
WindowRef windowRef = NULL;
CFBundleRef bundle = CFBundleGetBundleWithIdentifier(kMyBundleIdentifier);
CreateNibReferenceWithCFBundle(bundle, kMyNIBName, %26amp;dialogNibRef);
CreateWindowFromNib(dialogNibRef, kMyWindowName, %26amp;windowRef);
DisposeNibReference(dialogNibRef);
Having done this, you can show the window using RunAppModalLoopForWindow.
Hope this helps,
Aaron
Hello,
I currently have several Photoshop plugins available under Windows which are created using Visual Studios 2005 and I am trying to find an example plugin in the Photoshop CS4 SDK environment which I could practice on. My goal is to edit the dialogs/UI of the plugin and finally just add connect existing functionality.
The ultimate goal is to implement existing PC Photoshop plugins under Mac OS Systems using the Adoble Dialog Manager and API architecture. A cross platform solution for both PC and Mac is desired.
Could someone please direct me to a simple example in the Photoshop CS4 SDK environment or a good tutorial, as I am a working student with little C++ programming knowledge.
Thank you in advance,
Andreas
ADM has long been deprecated. Some developers are using Qt for x-platform UI, see other recent threads.
%26gt;The only trick is that you have to load the NIB file manually. Here's the code to put up your %26gt;dialog:
%26gt;
%26gt;IBNibRef dialogNibRef = NULL;
%26gt;WindowRef windowRef = NULL;
%26gt;CFBundleRef bundle = CFBundleGetBundleWithIdentifier(kMyBundleIdentifier);
%26gt;CreateNibReferenceWithCFBundle(bundle, kMyNIBName, %26amp;dialogNibRef);
%26gt;CreateWindowFromNib(dialogNibRef, kMyWindowName, %26amp;windowRef);
%26gt;DisposeNibReference(dialogNibRef);
%26gt;
%26gt;Having done this, you can show the window using RunAppModalLoopForWindow.
Could you please explain these steps more in detail Aaron. I've setup a UI using the Interface Builder and have put the above mentioned code into DissolveUIMac.cpp but i am getting the following errors:
error: 'kMyBundleIdentifier' was not declared in this scope
error: expected constructor, destructor, or type conversion before '(' token
error: expected constructor, destructor, or type conversion before '(' token
error: expected constructor, destructor, or type conversion before '(' token
November Quarterly Update Registration...
We've just opened up registration for the November 15th Quarterly developer update. Look for it at http://www.adobe.com/cfusion/event/index.cfm?event=detail%26amp;id=883099%26amp;loc=en_us
This is a presentation tailored to developers for Adobe Creative Suite products. This session will include presentations on Kuler, Flash, Dreamweaver, InDesign/InCopy, InDesign Server, Photoshop, Version Cue, Scripting, Illustrator and Bridge.
Details about past presentations can be found at http://blogs.adobe.com/notesfrommnr/quarterly_update/
MNR
mask making
This is a presentation tailored to developers for Adobe Creative Suite products. This session will include presentations on Kuler, Flash, Dreamweaver, InDesign/InCopy, InDesign Server, Photoshop, Version Cue, Scripting, Illustrator and Bridge.
Details about past presentations can be found at http://blogs.adobe.com/notesfrommnr/quarterly_update/
MNR
Preview in opened window with image
I am developing a filter plugin and I want to make a preview directly in the opened image in Photoshop rather than in some small frame in the setup dialog. But I didn't find any advice about it in the documentation (SDK ver. 6). Can anyone help, please?
With many thanks
Jirka (George)
Preview in opened window with image
From the FAQ.txt in the SDK:
======================
4.1 How do I preview my effect in the original document window?
You cannot. The built-in filters in the filter menu that show the preview on the
original document window are not plug-ins. They are not ''built-in plug-ins''
either. That makes no sense and makes us all here at Adobe giggle when you call
them that.
======================
With many thanks
Jirka (George)
Preview in opened window with image
From the FAQ.txt in the SDK:
======================
4.1 How do I preview my effect in the original document window?
You cannot. The built-in filters in the filter menu that show the preview on the
original document window are not plug-ins. They are not ''built-in plug-ins''
either. That makes no sense and makes us all here at Adobe giggle when you call
them that.
======================
Scripting to Record Brush Strokes?
Question: Is it technically feasible to write script that will act as a ''macro recorder'' to capture brush strokes for application to a ''nearly identical'' image?
Using STL collections in Photoshop...
Hello!%26lt;br /%26gt;%26lt;br /%26gt;Would you explain one moment. I need use a lot of STL collections in my Photoshop plug-in.%26lt;br /%26gt;%26lt;br /%26gt;First, I try to write something like%26lt;br /%26gt;---------------------------------------------------------------------%26lt;br /%26gt;#include %26lt;map%26gt;%26lt;br /%26gt;#include %26lt;string%26gt;%26lt;br /%26gt;%26lt;br /%26gt;...%26lt;br /%26gt;%26lt;br /%26gt; map%26lt;int,string%26gt; foo; // BANG!%26lt;br /%26gt;---------------------------------------------------------------------%26lt;br /%26gt;%26lt;br /%26gt;Next, I try to use Photoshop Basic Suite:%26lt;br /%26gt;%26lt;br /%26gt;---------------------------------------------------------------------%26lt;br /%26gt;#include %26lt;algorithm%26gt;%26lt;br /%26gt;%26lt;br /%26gt;namespace std {}%26lt;br /%26gt;using namespace std;%26lt;br /%26gt;%26lt;br /%26gt;#include %26lt;PIFormat.h%26gt;%26lt;br /%26gt;%26lt;br /%26gt;extern SPBasicSuite *g_sSPBasic;%26lt;br /%26gt;%26lt;br /%26gt;inline void * operator new ( const size_t size )%26lt;br /%26gt;{%26lt;br /%26gt; void *result = 0;%26lt;br /%26gt;%26lt;br /%26gt; if( 0 != g_sSPBasic )%26lt;br /%26gt; {%26lt;br /%26gt; void %26amp; nbsp; *temp;%26lt;br /%26gt;%26lt;br /%26gt; if( g_sSPBasic-%26gt;AllocateBlock( size, %26amp;result ) )%26lt;br /%26gt; {%26lt;br /%26gt; %26amp;nbsp ; result = 0;%26lt;br /%26gt; }%26lt;br /%26gt; else%26lt;br /%26gt; {%26lt;br /%26gt;#ifdef DEBUG%26lt;br /%26gt; %26amp;nbsp ; char *tmp = static_cast%26lt;char*%26gt;( result );%26lt;br /%26gt; %26amp;nbsp ; fill( tmp, tmp + size, 0xEB );%26lt;br /%26gt;#endif%26lt;br /%26gt; }%26lt;br /%26gt; }%26lt;br /%26gt;%26lt;br /%26gt; return result;%26lt;br /%26gt;}%26lt;br /%26gt;%26lt;br /%26gt;inline void operator delete ( void * ptr )%26lt;br /%26gt;{%26lt;br /%26gt; if( 0 != g_sSPBasic )%26lt;br /%26gt; {%26lt;br /%26gt; g_sSPBasic-%26gt;FreeB lock( ptr );%26lt;br /%26gt; }%26lt;br /%26gt;}%26lt;br /%26gt;%26lt;br /%26gt;// the same for operator new[] and operator delete[]%26lt;br /%26gt;---------------------------------------------------------------------%26lt;br /%26gt;%26lt;br /%26gt;Now simple STL collections can be created.%26lt;br /%26gt;%26lt;br /%26gt;Is there more laconic way to create STL collections?%26lt;br /%26gt;%26lt;br /%26gt;Moreover. This code is very dirty. For example, I even don't sure that Simple Suite address is constant between calls of plug-in entry point. So I think this is an awful dangerous code (just imagine the effect of two copies of of Adobe Photoshop using plug-in using this operators simultaneously).%26lt;br /%26gt;%26lt;br /%26gt;Do you have some ideas how to make it clean and working?Using STL collections in Photoshop...
Are you using PINew.h(cpp)? I would not use them and not override operator new and delete. You are probably having a mismatch of when the new and delete operators are getting executed.
Using STL collections in Photoshop...
1. don't create global objects!
2. standard operator new() can't return 0. throw std::bad_alloc instead
2 Pavel: welcome to developer[dog]akvis.com
2 Tom Ruark
Thanks for your support.
%26gt; Are you using PINew.h(cpp)?
What is PINew.h(cpp)? Yeah, I can guess that it's what I need.
I use Adobe Photoshop CS2 SDK. There are no files PINew*.*
To be more precise where can I find these files?
2 all
On dynamic C++ memory management in Adobe Photoshop plug-in
As there are some people interested in the question I'll try to explain a technique I use at present.
I have two memory allocators:
a) based on Adobe's Basic Suite for small blocks (under 2Kbytes)
b) based on Adobe's Handle Suite for large blocks (above 2Kbytes)
operator new and operator new[] allocate 4 additional bytes for every allocation, store in the first 4 bytes handle to memory allocator used for this new or new[] call, and return pointer after this handle.
operator delete and operator delete[] takes memory allocator handle from the pre-pointer 4 bytes, and dellocate memory using correct memory allocator.
This strategy works well.
Does anybody know a better dynamic memory management technique to use with Adobe SDK for Adobe Photoshop plug-ins?
If Photoshop Handle/Buffer suite unavailable, use malloc() instead, and store INVALID_HANDLE_VALUE in pre-pointer 4 bytes.
operator delete must compare stored handle with INVALID_HANDLE_VALUE and call Photoshop callbacks or free()
%26gt; If Photoshop Handle/Buffer suite unavailable, use malloc() instead
But malloc() always returns NULL in my tests. So I throw std::bad_alloc if Adobe's suites is unavailable.
class Foo
{
public:
Foo() : ptr( new int[100] ) {}
~Foo() { delete [] ptr; }
private:
int * ptr;
};
Foo foo;
void PLUGIN_ENTRY_POINT(...
During DLL run-time startup, Foo::Foo called, and you don't have pointers to PS funcs at this point.
Result: Unhandled exception.
Many third-party libs have hidden global objects (managers, caches etc).
if you don't have suites, call malloc(). If malloc() return NULL, throw std::bad_alloc. And don't forgot to implement no-throw operator new.
2 Ivan Kharin
%26gt; Result: Unhandled exception.
You got the point!
The thing is I prefer to get an error diagnostic exactly at the time the problem occurs. As you know it grants us developers (and possibly our QA teams) more chances to efficiently work around the issue.
The another not least important reason is that unhandled exception at program startup is much-much-better then one after two and half hours of hard work.
%26gt; And don't forgot to implement no-throw operator new.
When I need it I will certanly do it.
Great thanks for your feedback.
mask making
Are you using PINew.h(cpp)? I would not use them and not override operator new and delete. You are probably having a mismatch of when the new and delete operators are getting executed.
Using STL collections in Photoshop...
1. don't create global objects!
2. standard operator new() can't return 0. throw std::bad_alloc instead
2 Pavel: welcome to developer[dog]akvis.com
2 Tom Ruark
Thanks for your support.
%26gt; Are you using PINew.h(cpp)?
What is PINew.h(cpp)? Yeah, I can guess that it's what I need.
I use Adobe Photoshop CS2 SDK. There are no files PINew*.*
To be more precise where can I find these files?
2 all
On dynamic C++ memory management in Adobe Photoshop plug-in
As there are some people interested in the question I'll try to explain a technique I use at present.
I have two memory allocators:
a) based on Adobe's Basic Suite for small blocks (under 2Kbytes)
b) based on Adobe's Handle Suite for large blocks (above 2Kbytes)
operator new and operator new[] allocate 4 additional bytes for every allocation, store in the first 4 bytes handle to memory allocator used for this new or new[] call, and return pointer after this handle.
operator delete and operator delete[] takes memory allocator handle from the pre-pointer 4 bytes, and dellocate memory using correct memory allocator.
This strategy works well.
Does anybody know a better dynamic memory management technique to use with Adobe SDK for Adobe Photoshop plug-ins?
If Photoshop Handle/Buffer suite unavailable, use malloc() instead, and store INVALID_HANDLE_VALUE in pre-pointer 4 bytes.
operator delete must compare stored handle with INVALID_HANDLE_VALUE and call Photoshop callbacks or free()
%26gt; If Photoshop Handle/Buffer suite unavailable, use malloc() instead
But malloc() always returns NULL in my tests. So I throw std::bad_alloc if Adobe's suites is unavailable.
class Foo
{
public:
Foo() : ptr( new int[100] ) {}
~Foo() { delete [] ptr; }
private:
int * ptr;
};
Foo foo;
void PLUGIN_ENTRY_POINT(...
During DLL run-time startup, Foo::Foo called, and you don't have pointers to PS funcs at this point.
Result: Unhandled exception.
Many third-party libs have hidden global objects (managers, caches etc).
if you don't have suites, call malloc(). If malloc() return NULL, throw std::bad_alloc. And don't forgot to implement no-throw operator new.
2 Ivan Kharin
%26gt; Result: Unhandled exception.
You got the point!
The thing is I prefer to get an error diagnostic exactly at the time the problem occurs. As you know it grants us developers (and possibly our QA teams) more chances to efficiently work around the issue.
The another not least important reason is that unhandled exception at program startup is much-much-better then one after two and half hours of hard work.
%26gt; And don't forgot to implement no-throw operator new.
When I need it I will certanly do it.
Great thanks for your feedback.
Subscribe to:
Posts
(Atom)