Example #1
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 #2
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);
}