#include <mil.h>
#include <stdlib.h>
MIL_INT MFTYPE GrabStart(MIL_INT, MIL_ID, void*);
typedef struct
{
MIL_INT NbGrabStart;
} UserDataStruct;
#define STRING_LENGTH_MAX 20
int MosMain(void)
{
MIL_ID MilApplication;
MIL_ID MilSystem ;
MIL_ID MilDigitizer ;
MIL_ID MilDisplay ;
MIL_ID MilImage[2] ;
MIL_ID MilImageDisp ;
long NbProc = 0, n = 0;
MIL_DOUBLE Time = 0.0;
MIL_TEXT_CHAR Text[STRING_LENGTH_MAX] = MIL_TEXT("0");
UserDataStruct UserStruct;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay,
&MilDigitizer, &MilImageDisp);
for (n=0; n<2; n++)
MbufAlloc2d(MilSystem,
MdigInquire(MilDigitizer, M_SIZE_X, M_NULL),
MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL),
8L+M_UNSIGNED,
M_IMAGE+M_GRAB+M_PROC, &MilImage[n]);
UserStruct.NbGrabStart = 0;
MdigHookFunction(MilDigitizer, M_GRAB_START, GrabStart, (void *)(&UserStruct));
MosPrintf(MIL_TEXT("\nDOUBLE BUFFERING ACQUISITION AND PROCESSING:\n"));
MosPrintf(MIL_TEXT("--------------------------------------------\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to stop.\n\n"));
MdigControl(MilDigitizer, M_GRAB_MODE, M_ASYNCHRONOUS);
MdigGrab(MilDigitizer, MilImage[0]);
n=0;
do {
MdigGrab(MilDigitizer, MilImage[1-n]);
if (NbProc == 0)
MappTimer(M_DEFAULT, M_TIMER_RESET+M_SYNCHRONOUS, M_NULL);
MosSprintf(Text, STRING_LENGTH_MAX, MIL_TEXT("%ld"), NbProc+1);
MgraText(M_DEFAULT, MilImage[n], 32, 32, Text);
MimArith(MilImage[n], M_NULL, MilImageDisp, M_NOT);
NbProc++;
n = 1-n;
}
while(!MosKbhit());
MdigGrabWait(MilDigitizer, M_GRAB_END);
MappTimer(M_DEFAULT, M_TIMER_READ+M_SYNCHRONOUS, &Time);
MosGetch();
MosPrintf(MIL_TEXT("%ld frames processed, at a frame rate of %.2f frames/sec ")
MIL_TEXT("(%.2f ms/frame).\n"), NbProc, NbProc/Time, 1000.0*Time/NbProc);
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
MdigHookFunction(MilDigitizer, M_GRAB_START+M_UNHOOK, GrabStart, (void *)(&UserStruct));
for (n=0; n<2; n++)
MbufFree(MilImage[n]);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp);
return 0;
}
MIL_INT MFTYPE GrabStart(MIL_INT HookType, MIL_ID EventId, void* UserStructPtr)
{
UserDataStruct *UserPtr=(UserDataStruct*)UserStructPtr;
UserPtr->NbGrabStart++;
MosPrintf(MIL_TEXT("#%ld\r"), UserPtr->NbGrabStart);
return(0);
}