//=============================PluginMain Start====================== DLLExport MACPASCAL void PluginMain (const short selector, PISelectionParams *selectionParamBlock, long *data,short *result) { //显示About对话框 if (selector == selectionSelectorAbout) { DoAbout((AboutRecordPtr)selectionParamBlock); } else { static const FProc routineForSelector [] = { /* selectionSelectorAbout DoAbout, */ /* selectionSelectorExecute */DoExecute }; Ptr globalPtr = NULL;// Pointer for global structure GPtr globals = NULL; // actual globals //包装selectionParamBlock到globals中,真正有用的还是globals->selectionParamBlock globalPtr = AllocateGlobals ((uint32)result, (uint32)selectionParamBlock, selectionParamBlock->handleProcs, sizeof(Globals), data, InitGlobals); if (globalPtr == NULL) { *result = memFullErr;return; } globals = (GPtr)globalPtr; //调用 DoExecute 函数 if (selector > selectionSelectorAbout && selector <= selectionSelectorExecute) (routineForSelector[selector-1])(globals); else gResult = selectionBadParameters; if ((Handle)*data != NULL) PIUnlockHandle((Handle)*data); } // about selector special } //=============================PluginMain End================================= //=============================DoExecute Start================================= void DoExecute (GPtr globals) { //一些变量声明,省略... //... // //从剪贴板中读取自己定义格式的选区信息,保存到全局变量中,我加的 //省略部分内容 gQueryForParameters = ReadScriptParams (globals); gStuff->treatment = 0;//KeyToEnum(EnumToKey(gCreate,typeMyCreate),typeMyPISel); //忽略原程序的UI参数处理 //获取读取端口 gResult = ReadFromWritePort(&selectionRead, selection->port); //省略部分内容 //分配内存 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; sData = LockBuffer (sBuffer, false); dData = LockBuffer (dBuffer, false); rData = LockBuffer (rBuffer, false); //省略部分内容 //统计要处理的通道 curChannel = composite; while (curChannel != NULL) { if (DoTarget curChannel->target : curChannel->shown) total += AccountChannel (curChannel, transparency, selection); curChannel = curChannel->next; } //进行实际的处理工作 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; } //善后工作... } //=========DoExecute End=========== //========ApplyChannel Start======== static void ApplyChannel (GPtr globals, ReadChannelDesc *source, PixelMemoryDesc *sDesc, ReadChannelDesc *mask, PixelMemoryDesc *mDesc, WriteChannelDesc *dest, ChannelReadPort destRead, PixelMemoryDesc *dDesc, PixelMemoryDesc *rDesc, int32 *done,int32 total) { //声明变量,参数检查,省略 //内层循环中,每次读取64×64的块处理 //#define kBlockRows 64 for (row = limit.top; row < limit.bottom; row += kBlockRows) for (col = limit.left; col < limit.right; col += kBlockCols) { //省略部分内容 gResult = ReadPixels (destRead, &scaling, &area, dDesc, &wrote); //省略部分内容 gResult = ReadPixels (source->port, &scaling, &area, sDesc, &wrote); s = (unsigned8 *) sDesc->data;//这里是原图象数据 d = (unsigned8 *) dDesc->data;//这里保存处理结果 //逐个象素处理64×64的块 for (row2 = 0; row2 < kBlockRows; ++row2) { int y = row + row2; for (col2 = 0; col2 < kBlockCols; ++col2) { int x = col + col2; int nRc = 0; bool bFound = false; while(nRc < g_rcCount)//g_rcCount是一共要显示的区域数,通过剪贴板传递计算 { if(PtInRect(&g_rcArr[nRc],x,y))//g_rcArr存放所有要显示的区域 { *d = 255;//这个象素处于选区内 bFound = true; break; } ++nRc; } //if(!bFound) *d = 0; ++s; ++d; ++r; } } //处理完毕一小块,写回 gResult = WritePixels (dest->port, &area, dDesc); //省略部分内容 } } //========ApplyChannel End===== |