void DoStart (GPtr globals) { ValidateParameters (globals); /* if stuff hasn't been initialized that we need, do it, then go check if we've got scripting commands to override our settings */ // update our parameters with the scripting parameters, if available ReadScriptParams (globals); // always reset the global document descriptor for safety gDocDesc = gDocInfo; if (gQueryForParameters) { DoUI (globals); // Show the UI gQueryForParameters = FALSE; } // Delete the memory we used for the Proxy view ReleaseProxyMemory(globals); if (gResult != noErr) return; // Do the actual filtering operation on the original image DoEffect(globals); }
int main( int argc, char* argv[] ) { clock_t t0 = StartTiming(); /* ------------------ */ /* Parse command line */ /* ------------------ */ gArgs.SetCmdLine( argc, argv ); TS.SetLogFile( flog ); if( !ReadScriptParams( scr, gArgs.script, flog ) ) goto exit; inv_scl = 1.0 / scr.crossscale; /* ---------------- */ /* Read source data */ /* ---------------- */ if( gArgs.zb >= 0 && gArgs.za < 0 ) gArgs.za = gArgs.zb; TS.FillFromRgns( gArgs.srcmons, gArgs.idb, gArgs.zb, gArgs.za ); fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); if( !TS.vtil.size() ) goto exit; TS.SetTileDimsFromImageFile(); TS.GetTileDims( gW, gH ); t0 = StopTiming( flog, "ReadFile", t0 ); /* ------------- */ /* Sort by layer */ /* ------------- */ TS.SortAll_z(); /* ----- */ /* Stuff */ /* ----- */ ScapeStuff(); /* ---- */ /* Done */ /* ---- */ exit: fprintf( flog, "\n" ); VMStats( flog ); fclose( flog ); return 0; }
//------------------------------------------------------------------------------- // // Execute // // Main routine. // //------------------------------------------------------------------------------- SPErr Execute(PIActionParameters* actionParams) { SPErr error = kSPNoError; // Default parameters for all globals. Initialize(); // Override globals with new descriptor info. ReadScriptParams(actionParams); // Determine if we need to pop our dialog: PIDialogPlayOptions playInfo = actionParams->playInfo; // Others = plugInDialogDontDisplay / plugInDialogSilent if (playInfo == plugInDialogDisplay) { // Go ahead and display a dialog: error = DoUI(); if (error != kSPNoError) { // delete the globals created by the UI // I should remove this global crap if (gActionSet != NULL) { delete gActionSet; gActionSet = NULL; } if (gActionName != NULL) { delete gActionName; gActionName = NULL; } } } // register for this event if (error == kSPNoError) error = DoRegister(); // write our script parameters to the scripting system if (error == kSPNoError) WriteScriptParams(actionParams); return error; }
void DoStart (GPtr globals) { if (!WarnAdvanceStateAvailable ()) { gResult = userCanceledErr; // exit gracefully goto done; } if (!WarnColorServicesAvailable()) { gResult = userCanceledErr; // exit gracefully goto done; } ValidateParameters (globals); /* if stuff hasn't been initialized that we need, do it, then go check if we've got scripting commands to override our settings */ gQueryForParameters = ReadScriptParams (globals); // update our parameters with the scripting parameters, if available if (gQueryForParameters) { gQueryForParameters = FALSE; if (!DoUI (globals)) goto done; // canceled } if (gResult != noErr) goto done; done: // if one screws with the outData with a proxy, reset that here PISetRect (&gStuff->inRect, 0, 0, 0, 0); PISetRect (&gStuff->outRect, 0, 0, 0, 0); PISetRect (&gStuff->maskRect, 0, 0, 0, 0); }
void DoExecute (GPtr globals) { size_t total = 0; size_t done = 0; Boolean doThis = true; BufferID sBuffer = 0; Ptr sData = NULL; BufferID dBuffer = 0; Ptr dData = NULL; BufferID mBuffer = 0; Ptr mData = NULL; BufferID rBuffer = 0; Ptr rData = NULL; PixelMemoryDesc sDesc, dDesc, mDesc, rDesc; ReadImageDocumentDesc *doc = gStuff->documentInfo; WriteChannelDesc *selection = gStuff->newSelection; ChannelReadPort selectionRead; ReadChannelDesc *composite; ReadChannelDesc *transparency; ReadChannelDesc *curChannel; /* Access the port procs. */ if (!WarnChannelPortAvailable ()) { gResult = errPlugInHostInsufficient; goto CleanUp; } gQueryForParameters = ReadScriptParams (globals); if ( gQueryForParameters ) doThis = DoUI (globals); if ( !doThis ) goto CleanUp; // user cancelled, etc. /* look in gStuff->supportedTreatments for support for this next thang */ if (gCreate == iCreateMaskpath) { // can't do that! Handle h = PIGetResource (StringResource, errCantCreatePath, &total); if (h != NULL) { Str255 errString = ""; // The handle, since it's a string, is automagically fetched as a // pascal string. If we use PIHandle2PString, we'll get two // length bytes. This way, the length byte (which is already byte // 0 of the handle) is preserved as the very first byte of the // string: PIHandle2CString(h, (char*)errString, 255); // handle, string, maxlength PIDisposeHandle(h); h = NULL; // reset gResult = PIReportError(errString); } else gStuff->treatment = KeyToEnum(EnumToKey(gCreate,typeMyCreate),typeMyPISel); // otherwise Pshop will catch it automatically goto CleanUp; // don't do any of this gunk } else gStuff->treatment = KeyToEnum(EnumToKey(gCreate,typeMyCreate),typeMyPISel); // Set the treatment then move on /* We will need a read port for the selection. */ gResult = ReadFromWritePort(&selectionRead, selection->port); if (gResult != noErr) goto CleanUp; /* Figure out which composite data to use. */ if (DoTarget) { composite = doc->targetCompositeChannels; transparency = doc->targetTransparency; if (composite == NULL) { composite = doc->mergedCompositeChannels; transparency = doc->mergedTransparency; } } else { composite = doc->mergedCompositeChannels; transparency = doc->mergedTransparency; } /* Allocate the buffers. */ if (!WarnBufferProcsAvailable ()) { gResult = +1; goto CleanUp; } #define kBufferSize kBlockRows * (long) kBlockCols gResult = AllocateBuffer (kBufferSize, &sBuffer); if (gResult != noErr) goto CleanUp; gResult = AllocateBuffer (kBufferSize, &dBuffer); if (gResult != noErr) goto CleanUp; gResult = AllocateBuffer (kBufferSize, &rBuffer); if (gResult != noErr) goto CleanUp; if (transparency != NULL) { gResult = AllocateBuffer (kBufferSize, &mBuffer); if (gResult != noErr) goto CleanUp; } /* Lock the buffers down. */ sData = LockBuffer (sBuffer, false); dData = LockBuffer (dBuffer, false); rData = LockBuffer (rBuffer, false); if (mBuffer != 0) mData = LockBuffer (mBuffer, false); /* Set up the pixel memory descriptors. */ sDesc.data = sData; sDesc.rowBits = kBlockCols * 8; sDesc.colBits = 8; sDesc.bitOffset = 0; sDesc.depth = 8; dDesc = sDesc; dDesc.data = dData; rDesc = sDesc; rDesc.data = rData; mDesc = sDesc; mDesc.data = mData; rData[0] = kInitRandom; // flag for uninitialized random buffer /* Count the channels to process. */ if (doc->selection != NULL) total += AccountChannel (doc->selection, NULL, selection); curChannel = composite; while (curChannel != NULL) { if (DoTarget ? curChannel->target : curChannel->shown) total += AccountChannel (curChannel, transparency, selection); curChannel = curChannel->next; } if (doc->targetLayerMask != NULL && (DoTarget ? doc->targetLayerMask->target : doc->targetLayerMask->shown)) total += AccountChannel (doc->targetLayerMask, NULL, selection); curChannel = doc->alphaChannels; while (curChannel != NULL) { if (DoTarget ? curChannel->target : curChannel->shown) total += AccountChannel (curChannel, NULL, selection); curChannel = curChannel->next; } /* Apply any existing selection. */ if (doc->selection != NULL) { ApplyChannel (globals, doc->selection, &sDesc, NULL, &mDesc, selection, selectionRead, &dDesc, &rDesc, &done, total); if (gResult != noErr) goto CleanUp; } /* Apply each of the channels. This isn't the most efficient approach since it reads the data back out of the selection repeatedly, but it provides a good work out for the code. */ curChannel = composite; while (curChannel != NULL) { if (DoTarget ? curChannel->target : curChannel->shown) { ApplyChannel (globals, curChannel, &sDesc, transparency, &mDesc, selection, selectionRead, &dDesc, &rDesc, &done, total); if (gResult != noErr) goto CleanUp; } curChannel = curChannel->next; } /* Apply the layer mask. */ if (doc->targetLayerMask != NULL && (DoTarget ? doc->targetLayerMask->target : doc->targetLayerMask->shown)) { ApplyChannel (globals, doc->targetLayerMask, &sDesc, NULL, &mDesc, selection, selectionRead, &dDesc, &rDesc, &done, total); if (gResult != noErr) goto CleanUp; } /* Process the alpha channels. */ curChannel = doc->alphaChannels; while (curChannel != NULL) { if (DoTarget ? curChannel->target : curChannel->shown) { ApplyChannel (globals, curChannel, &sDesc, NULL, &mDesc, selection, selectionRead, &dDesc, &rDesc, &done, total); if (gResult != noErr) goto CleanUp; } curChannel = curChannel->next; } CleanUp: if (sData != NULL) UnlockBuffer (sBuffer); if (dData != NULL) UnlockBuffer (dBuffer); if (mData != NULL) UnlockBuffer (mBuffer); if (rData != NULL) UnlockBuffer (rBuffer); if (sBuffer != 0) FreeBuffer (sBuffer); if (dBuffer != 0) FreeBuffer (dBuffer); if (mBuffer != 0) FreeBuffer (mBuffer); if (rBuffer != 0) FreeBuffer (rBuffer); WriteScriptParams(globals); }