developing a plugin

Comments and discussions about 8bf plugins which can be use in various applications like Photoshop, Paint Shop Pro or Photo-Paint
Post Reply
SlimTimmy
Plugin Novice
Plugin Novice
Posts: 2
Joined: Tue Apr 29, 2003 4:24 pm

developing a plugin

Post by SlimTimmy »

hi,

i want to develop a plugin for AdobePhotoshop 6.0 .
I have the SDK and now i want to change the code from the SimpleFormat-Example. But I don't know what these lines do:

Code: Select all

int16 resourceCount = CountPIResources(histResource);

	while (resourceCount)
		{
		Handle resourceHandle = GetPIResource(histResource,resourceCount--);
		Ptr resourcePtr = PILockHandle(resourceHandle, FALSE);
		PIUnlockHandle(resourceHandle);
		}
And what are resources??

toby
Plugin Master
Plugin Master
Posts: 35
Joined: Sun Nov 10, 2002 11:42 am
Location: Toronto, Canada
Contact:

resources

Post by toby »

Hi SlimTimmy,

Resources, or "image resources", are blocks of data which Photoshop maintains for image documents. They are read in when the document is opened, can be accessed and changed by Photoshop or plugins, and are stored in saved files. Image resources describe things such as paths, metadata, etc. Each resource has a type, ID, name, and contents - see chapter 2 of Photoshop File Formats for details. The routines in the "pseudo-resource callback suite" are used to manipulate them.

The Photoshop API Guide (chapter 3) calls them "pseudo-resources" to distinguish them from platform resources, which accompany a Macintosh or Windows executable and are typically used to store things like user interface elements and text strings. (Platform resources are manipulated by Resource Manager or Win32 routines respectively.)

The code you quote simply enumerates all image resources of type histResource. It makes calls to read them in decreasing order of index, locking each data block in memory and finding its start address (resourcePtr), but it does nothing with the data, so I'm not even sure why it's there other than as an example of an enumeration loop. You can safely remove those lines.

Let me know if you need more information.

Toby

SlimTimmy
Plugin Novice
Plugin Novice
Posts: 2
Joined: Tue Apr 29, 2003 4:24 pm

Post by SlimTimmy »

thanks!
(i thought this, too)

I wrote a Plugin for Adobe Photoshop, which should write RGB-images+Alpha-Channel!
Now, i can write RGB-images, but I have some problems with the Alpha-Channel! I created an image in Photoshop and assigned the color 172 to the Alpha-Channel. When I saved this image with my own plugin, i got the color 170 instead of 172!
(I don't know, why!)
Here is the code for writing an image:

Code: Select all

static void DoWriteStart (GPtr globals)
{
	FileHeader header;

    if (gResult != noErr) return;
	
	if (!TSC ((Boolean)(!CheckForServices (globals)))) return;
	
	gResult = SetFPos (gStuff->dataFork, fsFromStart, 0);
	
	header.Width=gStuff->imageSize.h;
	header.Height=gStuff->imageSize.v;
	header.Identification=1331;

	if(gStuff->imageMode==plugInModeRGBColor && gStuff->planes==3)
		header.BitCount=24;
	else if(gStuff->imageMode==plugInModeRGBColor && gStuff->planes==4)
		header.BitCount=32;
	else
	{
		gResult=formatCannotRead;
		return;
	}

	WriteSome (globals, sizeof (FileHeader), &header);
	
	if (gResult != noErr) return;

	BufferID buffer;

	gPixelBuffer = 0;
	AllocateBuffer((header.Width*header.BitCount/8), &buffer);
	gPixelBuffer = buffer;
	gPixelData = LockBuffer (gPixelBuffer, FALSE);

	gStuff->data=gPixelData;
	gStuff->depth=8;

	if(header.BitCount==24)
	{
		gStuff->loPlane=0;
		gStuff->hiPlane=2;
		gStuff->colBytes=3;
		gStuff->rowBytes=3*header.Width;
		gStuff->planeBytes=1;
		
		for(int y=0;y<header.Height;y++)
		{
			gStuff->theRect.top = y;
			gStuff->theRect.left = 0;
			gStuff->theRect.bottom = y+1;
			gStuff->theRect.right = header.Width;
			gResult=AdvanceState ();
			if(gResult!=noErr)
				return;
	
			WriteSome (globals,header.Width*header.BitCount/8,gPixelData);
			if(gResult!=noErr)
				return;	
		}

		if (gPixelBuffer != 0)
		{	
			FreeBuffer (gPixelBuffer);
			gPixelBuffer = 0;
			gPixelData = 0;	
		}
	}
	else if(header.BitCount==32)
	{
		gStuff->loPlane=0;
		gStuff->hiPlane=3;
		gStuff->colBytes=4;
		gStuff->rowBytes=4*header.Width;
		gStuff->planeBytes=1;

		for(int y=0;y<header.Height;y++)
		{
			gStuff->theRect.top = y;
			gStuff->theRect.left = 0;
			gStuff->theRect.bottom = y+1;
			gStuff->theRect.right = header.Width;
			gResult=AdvanceState();
			if(gResult!=noErr)
				return;
			WriteSome (globals,(header.Width*header.BitCount/8),gPixelData);
			if(gResult!=noErr)
				return;	
		}

		if (gPixelBuffer != 0)
		{	
			FreeBuffer (gPixelBuffer);
			gPixelBuffer = 0;
			gPixelData = 0;	
		}
	}

	gStuff->data = NULL;
}

Post Reply