#include <mil.h>
#define DIGITIZER_NUM 2
#define BUFFERING_SIZE_MAX 30
#define DRAW_ANNOTATION M_NO
MIL_INT MFTYPE ProcessingFunction(MIL_INT HookType, MIL_ID HookId, void* HookDataPtr);
typedef struct
{
MIL_ID MilImageDisp;
MIL_INT ProcessedImageCount;
} HookDataStruct;
int MosMain(void)
{
MIL_ID MilApplication;
MIL_ID MilSystem;
MIL_ID MilDigitizer[DIGITIZER_NUM];
MIL_ID MilDisplay[DIGITIZER_NUM];
MIL_ID MilImageDisp[DIGITIZER_NUM];
MIL_ID MilGrabBufferList[DIGITIZER_NUM][BUFFERING_SIZE_MAX];
MIL_INT n, m, BufferLocation = M_NULL;
MIL_INT LastAllocatedN = M_NULL;
MIL_INT LastAllocatedM = M_NULL;
MIL_INT MilGrabBufferListSize = M_NULL;
MIL_INT ProcessFrameCount;
double ProcessFrameRate;
MIL_INT BufferAllocationSuccess = 1;
HookDataStruct UserHookData[DIGITIZER_NUM];
MappAlloc(M_NULL, M_DEFAULT, &MilApplication);
MsysAlloc(M_DEFAULT, M_SYSTEM_DEFAULT, M_DEFAULT, M_DEFAULT, &MilSystem);
for(n=0; n<DIGITIZER_NUM; n++)
MdigAlloc(MilSystem, n, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDigitizer[n]);
for(n=0; n<DIGITIZER_NUM; n++)
MdispAlloc(MilSystem, M_DEV0, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDisplay[n]);
for(n=0; n<DIGITIZER_NUM; n++)
{
MbufAlloc2d(MilSystem,
MdigInquire(MilDigitizer[n], M_SIZE_X, M_NULL),
MdigInquire(MilDigitizer[n], M_SIZE_Y, M_NULL),
8+M_UNSIGNED, M_IMAGE+M_GRAB+M_PROC+M_DISP+BufferLocation,
&MilImageDisp[n]);
MbufClear(MilImageDisp[n], 0);
}
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
for(n = 0; n < DIGITIZER_NUM; n++)
for(m = 0; m < BUFFERING_SIZE_MAX; m++)
MilGrabBufferList[n][m] = M_NULL;
for(m = M_NULL; m < BUFFERING_SIZE_MAX; m++)
{
for(n = M_NULL; n < DIGITIZER_NUM; n++)
{
MbufAlloc2d(MilSystem,
MdigInquire(MilDigitizer[n], M_SIZE_X, M_NULL),
MdigInquire(MilDigitizer[n], M_SIZE_Y, M_NULL),
MdigInquire(MilDigitizer[n], M_TYPE, M_NULL),
M_IMAGE+M_GRAB+M_PROC+BufferLocation,
&MilGrabBufferList[n][m]);
if (MilGrabBufferList[n][m])
{
MbufClear(MilGrabBufferList[n][m], 0xFF);
LastAllocatedN = n;
LastAllocatedM = m;
}
else
{
BufferAllocationSuccess = 0;
break;
}
}
if(BufferAllocationSuccess)
MilGrabBufferListSize++;
else
break;
}
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
MbufFree(MilGrabBufferList[LastAllocatedN][LastAllocatedM]);
MilGrabBufferList[LastAllocatedN][LastAllocatedM] = M_NULL;
for(n = 0; n < DIGITIZER_NUM; n++)
{
if(MilGrabBufferList[n][LastAllocatedM])
{
MbufFree(MilGrabBufferList[n][LastAllocatedM]);
MilGrabBufferList[n][LastAllocatedM] = M_NULL;
}
}
MilGrabBufferListSize--;
for(n = 0; n < DIGITIZER_NUM; n++)
{
MdispSelect(MilDisplay[n], MilImageDisp[n]);
MdigGrabContinuous(MilDigitizer[n], MilImageDisp[n]);
MosPrintf(MIL_TEXT("\nPROCESSING #%ld: Multiple buffered processing (%d buffers).\n"),
n+1, MilGrabBufferListSize);
MosPrintf(MIL_TEXT("--------------------------------------------\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to start.\r"));
MosGetch();
MosPrintf(MIL_TEXT("Processing started... \n\n"));
MdigHalt(MilDigitizer[n]);
UserHookData[n].MilImageDisp = MilImageDisp[n];
UserHookData[n].ProcessedImageCount = 0;
MdigProcess(MilDigitizer[n], MilGrabBufferList[n], MilGrabBufferListSize,
M_START, M_DEFAULT, ProcessingFunction, &UserHookData[n]);
}
MosPrintf(MIL_TEXT("\nMAIN: Processing task(s) running...\n"));
MosPrintf(MIL_TEXT("-----------------------------------\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to stop.\n\n"));
MosGetch();
for(n=0; n<DIGITIZER_NUM; n++)
{
MdigProcess(MilDigitizer[n], MilGrabBufferList[n], MilGrabBufferListSize,
M_STOP, M_DEFAULT, ProcessingFunction, &UserHookData[n]);
MdigInquire(MilDigitizer[n], M_PROCESS_FRAME_COUNT, &ProcessFrameCount);
MdigInquire(MilDigitizer[n], M_PROCESS_FRAME_RATE, &ProcessFrameRate);
MosPrintf(MIL_TEXT("Processing #%ld: %ld frames grabbed at %.1f frames/sec ")
MIL_TEXT("(%.1f ms/frame).\n"), n+1, ProcessFrameCount, ProcessFrameRate,
1000.0/ProcessFrameRate);
}
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
for (n=0 ;n<DIGITIZER_NUM; n++)
{
for (m = 0; m < BUFFERING_SIZE_MAX; m++)
{
if(MilGrabBufferList[n][m])
{
MbufFree(MilGrabBufferList[n][m]);
MilGrabBufferList[n][m] = 0;
}
}
MbufFree(MilImageDisp[n]);
MdispFree(MilDisplay[n]);
MdigFree(MilDigitizer[n]);
}
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
MosPrintf(MIL_TEXT("\nPress <Enter> to end.\n\n"));
MosGetch();
MsysFree(MilSystem);
MappFree(MilApplication);
return 0;
}
#define STRING_LENGTH_MAX 20
#define STRING_POS_X 20
#define STRING_POS_Y 20
MIL_INT MFTYPE ProcessingFunction(MIL_INT HookType, MIL_ID HookId, void* HookDataPtr)
{
HookDataStruct *UserHookDataPtr = (HookDataStruct *)HookDataPtr;
MIL_ID ModifiedBufferId;
MIL_TEXT_CHAR Text[STRING_LENGTH_MAX]= {MIL_TEXT('\0'),};
MdigGetHookInfo(HookId, M_MODIFIED_BUFFER+M_BUFFER_ID, &ModifiedBufferId);
UserHookDataPtr->ProcessedImageCount++;
if (DRAW_ANNOTATION)
{
MosSprintf(Text, STRING_LENGTH_MAX, MIL_TEXT("%ld"),
UserHookDataPtr->ProcessedImageCount);
MgraText(M_DEFAULT, ModifiedBufferId, STRING_POS_X, STRING_POS_Y, Text);
}
MimArith(ModifiedBufferId, M_NULL, UserHookDataPtr->MilImageDisp, M_NOT);
return 0;
}