Exemple #1
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);
}
Exemple #2
0
//-------------------------------------------------------------------------------
//
// DoFinish
//
// Everything went as planned and the pixels have been modified. Now record
// scripting parameters and put our information in the Photoshop Registry for the
// next time we get called. The Registry saves us from keeping a preferences file.
//
//-------------------------------------------------------------------------------
void DoFinish(void)
{
	LockHandles();
	WriteScriptParameters();
	WriteRegistryParameters();
}