Boolean ReadScriptParams (GPtr globals)
{
	PIReadDescriptor			token = NULL;
	DescriptorKeyID				key = NULLID;
	DescriptorTypeID			type = NULLID;
	double						percent = 0;
	const double				minValue = kPercentMin, maxValue = kPercentMax;
	DescriptorUnitID			percentUnitPass = unitPercent;
	OSType						x = typeNull;
	DescriptorKeyIDArray		array = { keyMyShape, keyMyChannels, keyMyCreate, NULLID };
	int32						flags = 0;
	OSErr						stickyError = noErr;
	Boolean						returnValue = true;
	
	if (DescriptorAvailable(NULL))
	{ /* playing back.  Do our thing. */
		token = OpenReader(array);
		if (token)
		{
			while (PIGetKey(token, &key, &type, &flags))
			{
				switch (key)
				{
					case keyMyArea:
						PIGetEnum(token, &x);
						gWhatArea = KeyToEnum(x, typeMySelect);
						break;
					case keyMyAmount: // optional
						PIGetPinUnitFloat(token, &minValue, &maxValue, &percentUnitPass, &percent);
						gPercent = (short)percent;
						break;
					case keyMyChannels:
						PIGetEnum(token, &x);
						gWhatChannels = KeyToEnum(x, typeMyComposite);
						break;
					case keyMyCreate:
						PIGetEnum(token, &x);
						gCreate = KeyToEnum(x, typeMyCreate);
						break;
				}
			}

			stickyError = CloseReader(&token); // closes & disposes.
				
			if (stickyError)
			{
				if (stickyError == errMissingParameter) // missedParamErr == -1715
					;
					/* (descriptorKeyIDArray != NULL)
					   missing parameter somewhere.  Walk IDarray to find which one. */
				else
					gResult = stickyError;
			}
		}		
		returnValue = PlayDialog();
		/* return TRUE if want to show our Dialog */
	}
	return returnValue;
}
示例#2
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);

}