I'm writing an export plugin and I need to access transparency information. The example code uses the following to access the three RGB channels:
// in RGB mode, gStuff-%26gt;planes is set to 3
gStuff-%26gt;loPlane = 0;
gStuff-%26gt;hiPlane = gStuff-%26gt;planes - 1;
(*(gStuff-%26gt;advanceState))();
After this, gStuff-%26gt;data contains the RGB channels, but no transparency info. I tried setting the following in the PiPL file, but it seemed to have no effect:
ExportFlags
{
 expSupportsTransparency
}
How do I access the transparency information from the export plugin?
Transparency in Export Plugin
Nevermind, I figured it out. The Channel Ports suite does the trick nicely. The code I used to get the transparency is posted below, if anyone else is interested (this assumes you're starting with the samplecode\export\outbound example):
void DoStart (GPtr globals)
{
 // verify globals, etc.
 ReadChannelDesc * alphaDesc = gStuff-%26gt;documentInfo-%26gt;targetTransparency;
 unsigned char * alphaChannel = ReadChannel(globals, alphaDesc);
 // do something with alphaChannel here...
}
unsigned char * ReadChannel(GPtr globals, ReadChannelDesc * readDesc)
{
 if (!readDesc)
 return 0;
 uint width = gStuff-%26gt;imageSize.h;
 uint height = gStuff-%26gt;imageSize.v;
 uint bitDepth = readDesc-%26gt;depth;
 uint dataByteSize = width * height * (bitDepth / 8);
 
 PixelMemoryDesc pixelMemDesc;
 pixelMemDesc.data = new unsigned char[dataByteSize];
 pixelMemDesc.rowBits = width * bitDepth;
 pixelMemDesc.colBits = bitDepth;
 pixelMemDesc.bitOffset = 0;
 pixelMemDesc.depth = bitDepth;
 memset(pixelMemDesc.data, 0, dataByteSize);
 
 PSScaling scaling;
 scaling.sourceRect = scaling.destinationRect = readDesc-%26gt;bounds;
 VRect wroteRect;
 int16 result = 
 (*gStuff-%26gt;channelPortProcs-%26gt;readPixelsProc)(
 readDesc-%26gt;port, 
 %26amp;scaling, 
 %26amp;readDesc-%26gt;bounds, 
 %26amp;pixelMemDesc, 
 %26amp;wroteRect
 );
 if (result != noErr)
 {
 delete [] pixelMemDesc.data;
 return 0;
 }
 return (unsigned char *) pixelMemDesc.data;
}
Subscribe to:
Post Comments 
(Atom)
 
No comments:
Post a Comment