<name="button" left="10" top="30" right="24" bottom="70"/>. |
void PluginMain (const short selector, PISelectionParams *selectionParamBlock,long *data,short *result); |
globals->selectionParamBlock |
//=============================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; //調(diào)用 DoExecute 函數(shù) 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) { //一些變量聲明,省略... //... // //從剪貼板中讀取自己定義格式的選區(qū)信息,保存到全局變量中,我加的 //省略部分內(nèi)容 gQueryForParameters = ReadScriptParams (globals); gStuff->treatment = 0;//KeyToEnum(EnumToKey(gCreate,typeMyCreate),typeMyPISel); //忽略原程序的UI參數(shù)處理 //獲取讀取端口 gResult = ReadFromWritePort(&selectionRead, selection->port); //省略部分內(nèi)容 //分配內(nèi)存 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); //省略部分內(nèi)容 //統(tǒng)計要處理的通道 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) { //聲明變量,參數(shù)檢查,省略 //內(nèi)層循環(huán)中,每次讀取64×64的塊處理 //#define kBlockRows 64 for (row = limit.top; row < limit.bottom; row += kBlockRows) for (col = limit.left; col < limit.right; col += kBlockCols) { //省略部分內(nèi)容 gResult = ReadPixels (destRead, &scaling, &area, dDesc, &wrote); //省略部分內(nèi)容 gResult = ReadPixels (source->port, &scaling, &area, sDesc, &wrote); s = (unsigned8 *) sDesc->data;//這里是原圖象數(shù)據(jù) 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是一共要顯示的區(qū)域數(shù),通過剪貼板傳遞計算 { if(PtInRect(&g_rcArr[nRc],x,y))//g_rcArr存放所有要顯示的區(qū)域 { *d = 255;//這個象素處于選區(qū)內(nèi) bFound = true; break; } ++nRc; } //if(!bFound) *d = 0; ++s; ++d; ++r; } } //處理完畢一小塊,寫回 gResult = WritePixels (dest->port, &area, dDesc); //省略部分內(nèi)容 } } //========ApplyChannel End===== |
新聞熱點
疑難解答