Example #1
0
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);
		
}
static SPErr Execute(PIActionParameters *actionParams) {
	SPErr error = kSPNoError;
	
	Initialize(); 
	
	PIDialogPlayOptions playInfo = actionParams->playInfo;
	if(playInfo == plugInDialogDisplay) error = DoUI();
	
	return error;
}
Example #3
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;
}	
Example #4
0
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);

	}
Example #5
0
//-------------------------------------------------------------------------------
//
// DoStart
//
// The main filtering routine for this plug in. See if we have any registry
// parameters from the last time we ran. Determine if the UI needs to be
// displayed by reading the script parameters. Save the last dialog parameters
// in case something goes wrong or the user cancels.
//
//-------------------------------------------------------------------------------
void DoStart(void)
{
	LockHandles();

	// see if we have any information in the Photoshop registry
	ReadRegistryParameters();

	// save parameters
	int16 lastDisposition = gParams->disposition;
	int16 lastPercent = gParams->percent;
	Boolean lastIgnoreSelection = gParams->ignoreSelection;

	// does the user want a dialog
	Boolean isOK = true;
	Boolean displayDialog;
	OSErr err = ReadScriptParameters(&displayDialog);
	err; // turn off compiler warning for now

	// run the dialog on the specific OS
	if (!err && displayDialog)
		isOK = DoUI();

	// we know we have enough information to run without next time
	gData->queryForParameters = false;

	if (isOK)
	{
		// the main processing routine
		DoFilter();
	}
	else
	{
		// restore if the user hit cancel
		gParams->disposition = lastDisposition;
		gParams->percent = lastPercent;
		gParams->ignoreSelection = lastIgnoreSelection;
		*gResult = userCanceledErr;
	}
}
Example #6
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);

}
Example #7
0
static void Run()
{
	CImg Source, SourceMask;
	InitSourceImage(gFilterRecord, Source, SourceMask);

	Parameters params;
	params.Init();

	ReadRegistryParameters(params);
	ReadScriptParameters(params);

	/* Run the UI if we've been told to. */
	bool bApplyToImage = true;
	if(!gFilterRecord->descriptorParameters || gFilterRecord->descriptorParameters->playInfo == plugInDialogDisplay)
	{
		PreviewRenderer pr;
		pr.Source.Hold(Source);
		pr.SourceMask.Hold(SourceMask);
		pr.FilterSettings = params.FilterSettings;
		pr.FilterOptions = params.FilterOptions;
		SetFromImage(gFilterRecord, pr.Source, pr.Image.PreviewImage);

		UIResult ret = DoUI(&pr);
		pr.m_pAlgorithm->Abort();
		pr.Image.PreviewImage.Free();

		if(ret == UI_CANCEL)
		{
			/* The user cancelled. */
			throw PhotoshopErrorException(userCanceledErr);
		}
		if(ret == UI_SAVE_ONLY)
			bApplyToImage = false;

		params.FilterSettings = pr.FilterSettings;
		params.FilterOptions = pr.FilterOptions;

		WriteRegistryParameters(params);
	}

	WriteScriptParameters(params);

	if(!bApplyToImage)
		return;

	/* Run the main filter. */
	auto_ptr<Algorithm> pAlgo(new Algorithm);
	pAlgo->SetTarget(Source);
	pAlgo->SetMask(SourceMask);

	pAlgo->GetSettings() = params.FilterSettings;
	pAlgo->GetOptions() = params.FilterOptions;
	if(Source.m_iBytesPerChannel == 2)
		pAlgo->GetSettings().m_fInputScale = 255.0f / 32768.0f;
	else
		pAlgo->GetSettings().m_fInputScale = 1.0f;

	pAlgo->Run();

	if(!ShowProgressDialog(pAlgo.get()))
		throw PhotoshopErrorException(userCanceledErr);

	string sError;
	if(pAlgo->GetError(sError))
		throw Exception(sError);
}
Example #8
0
void CMFCPlugInApp::Start(void)
{
	DoUI();
}