Tuesday, March 23, 2010
Format Plugin Help Requested
I'm trying to get my feet wet by creating a REALLY simple file format plug-in but I just cannot get my image data into photoshop. I've modeled my simple plug-in after the TextFormat example code that came with the Advanced SDK. I found this one much easier to follow then the SimpleFormat example, though I've spent a lot of time studying that project too. I've also read through chapters 1, 2, 3, 9 and 11 of the documentation several times, but still cannot figure out what I'm doing wrong. If anyone can point me in the right direction, I would be very grateful.%26lt;br /%26gt;%26lt;br /%26gt;Pretty much all the relevant code is below in my ReadStart() function. It's long but relatively simple. It just sets relevant formatRecord components, allocates memory for the 256x256x8Bit RGB image and paints some data into the buffer. It then points formatRecord-%26gt;data at the image data and calls formatRecord-%26gt;advanceState(). My problem is that that function always returns formatBadParameters (-30500). I'm at a complete loss at what I could be doing wrong. Thank you for any help or suggestions you can provide.%26lt;br /%26gt;%26lt;br /%26gt;Rob%26lt;br /%26gt;%26lt;br /%26gt;PS - I'm running my plugin in Photoshop Elements 5.0 using which is running on Windows XP.%26lt;br /%26gt;%26lt;br /%26gt;%26lt;code%26gt;%26lt;br /%26gt;void TrivialFormatPlugin::ReadStart(void)%26lt;br /%26gt;{%26lt;br /%26gt; static const unsigned int imSizeX = 256;%26lt;br /%26gt; static const unsigned int imSizeY = 256;%26lt;br /%26gt; static const unsigned int imSizeC = 3;%26lt;br /%26gt; formatRecord-%26gt;imageMode = plugInModeRGBColor;%26lt;br /%26gt; formatRecord-%26gt;depth = 8;%26lt;br /%26gt;%26lt;br /%26gt; formatRecord-%26gt;imageHRes = static_cast%26lt;Fixed%26gt;( 72 );%26lt;br /%26gt; formatRecord-%26gt;imageVRes = static_cast%26lt;Fixed%26gt;( 72 );%26lt;br /%26gt;%26lt;br /%26gt; //really only relevant for 16 bit data (depth = 16)%26lt;br /%26gt; formatRecord-%26gt;maxValue = 256;%26lt;br /%26gt;%26lt;br /%26gt; formatRecord-%26gt;imageSize.h = static_cast%26lt;short%26gt;( imSizeX );%26lt;br /%26gt; formatRecord-%26gt;imageSize.v = static_cast%26lt;short%26gt;( imSizeY );%26lt;br /%26gt; formatRecord-%26gt;planes = static_cast%26lt;int16%26gt;( imSizeC );%26lt;br /%26gt; formatRecord-%26gt;colBytes = static_cast%26lt;int16%26gt;( imSizeC );%26lt;br /%26gt; formatRecord-%26gt;rowBytes = static_cast%26lt;int32%26gt;( imSizeC * imSizeX );%26lt;br /%26gt; formatRecord-%26gt;planeBytes = static_cast%26lt;int32%26gt;( 1 );%26lt;br /%26gt;%26lt;br /%26gt; formatRecord-%26gt;theRect.left = static_cast%26lt;short%26gt;( 0 );%26lt;br /%26gt; formatRecord-%26gt;theRect.bottom = static_cast%26lt;short%26gt;( 0 );%26lt;br /%26gt; formatRecord-%26gt;loPlane = static_cast%26lt;int16%26gt;( 0 );%26lt;br /%26gt; formatRecord-%26gt;theRect.right = static_cast%26lt;short%26gt;( imSizeX-1 );%26lt;br /%26gt; formatRecord-%26gt;theRect.top = static_cast%26lt;short%26gt;( imSizeY-1 );%26lt;br /%26gt; formatRecord-%26gt;hiPlane = static_cast%26lt;int16%26gt;( imSizeC-1 );%26lt;br /%26gt;%26lt;br /%26gt; //32 bit equivalents%26lt;br /%26gt; formatRecord-%26gt;PluginUsing32BitCoordinates = true;%26lt;br /%26gt; formatRecord-%26gt;theRect32.left = static_cast%26lt;int32%26gt;( 0 );%26lt;br /%26gt; formatRecord-%26gt;theRect32.bottom = static_cast%26lt;int32%26gt;( 0 );%26lt;br /%26gt; formatRecord-%26gt;theRect32.right = static_cast%26lt;int32%26gt;( imSizeX-1 );%26lt;br /%26gt; formatRecord-%26gt;theRect32.top = static_cast%26lt;int32%26gt;( imSizeY-1 );%26lt;br /%26gt; formatRecord-%26gt;imageSize32.h = static_cast%26lt;int32%26gt;( imSizeX );%26lt;br /%26gt; formatRecord-%26gt;imageSize32.v = static_cast%26lt;int32%26gt;( imSizeY );%26lt;br /%26gt;%26lt;br /%26gt; if( formatRecord-%26gt;openForPreview || formatRecord-%26gt;extractQuickThumbnail ) {%26lt;br /%26gt; //read whole image in at once%26lt;br /%26gt; uint32 bufferSize = static_cast%26lt;uint32%26gt;( imSizeX*imSizeY*imSizeC*formatRecord-%26gt;depth );%26lt;br /%26gt;%26lt;br /%26gt; BufferID bufferId;%26lt;br /%26gt; OSErr allocationStatus = formatRecord-%26gt;bufferProcs-%26gt;allocateProc( bufferSize, %26amp;bufferId );%26lt;br /%26gt; if( allocationStatus == noErr ) {%26lt;br /%26gt; Ptr dataBuffer = formatRecord-%26gt;bufferProcs-%26gt;lockProc( bufferId, false );%26lt;br /%26gt; for( unsigned int j = 0 ; j %26lt; imSizeY ; j++ ) {%26lt;br /%26gt; for( unsigned int i = 0 ; i %26lt; imSizeX ; i++ ) {%26lt;br /%26gt; for( unsigned int c = 0 ; c %26lt; imSizeC ; c++ ) {%26lt;br /%26gt; unsigned char value = ( i + j + c ) % 256;%26lt;br /%26gt; unsigned int index = c + i*imSizeC + j*imSizeC*imSizeX;%26lt;br /%26gt; dataBuffer[index] = value;%26lt;br /%26gt; }%26lt;br /%26gt; }%26lt;br /%26gt; formatRecord-%26gt;progressProc(j, 256);%26lt;br /%26gt; }%26lt;br /%26gt; //send data to host%26lt;br /%26gt; formatRecord-%26gt;data = dataBuffer;%26lt;br /%26gt; OSErr hostErr = formatRecord-%26gt;advanceState();%26lt;br /%26gt; if( hostErr != noErr ) {%26lt;br /%26gt; LOG_DEBUG %26lt;%26lt; ''Error returned from advanceState() call:'' %26lt;%26lt; hostErr %26lt;%26lt; '' quitting.\n'';%26lt;br /%26gt; LOG_DEBUG %26lt;%26lt; ''Format Record:\n'' %26lt;%26lt; *formatRecord
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment