/* File name: MdigMultDestination.c * Synopsis: This example shows how to maintain a color continuous * grab in the display and at the same time grab in * a monochrome Host buffer for processing. * For further information, refer to the MdigAlloc() * section of the Matrox Orion Board-Specific manual. * * Note: This example is only supported on the Matrox Orion, * and the Matrox Orion for 4Sight-II. * Your display depth must be in 32bpp. */ /* Processing operation to perform. */ #define REVERSE_IMAGE 0 #define EDGE_DETECT_IMAGE 0 #define COPY_IMAGE 1 /* Image scale. */ #define IMAGE_SCALE 0.5 #include #include #include #include "mil.h" void main(void) { MIL_ID MilApplication; MIL_ID MilSystem; MIL_ID MilDisplay; MIL_ID MilDisplayContinuous; MIL_ID MilDigitizer; MIL_ID MilDigitizerContinuous; MIL_ID MilImage[2]; MIL_ID MilImageDisp; MIL_ID MilImageDispContinuous; long i=0, n=0, t=0; double Time = 0.0; /* System allocation. */ MappAlloc(M_DEFAULT, &MilApplication); MsysAlloc(M_SYSTEM_ORION, M_DEF_SYSTEM_NUM, M_SETUP, &MilSystem); /* Allocate 2 displays, one for each digitizer. */ MdispAlloc(MilSystem, M_DEFAULT, M_DEF_DISPLAY_FORMAT, M_DEFAULT, &MilDisplayContinuous); MdispAlloc(MilSystem, M_DEFAULT, M_DEF_DISPLAY_FORMAT, M_DEFAULT, &MilDisplay); MdispControl(MilDisplayContinuous, M_TITLE, M_PTR_TO_DOUBLE("Continuous grab on display.")); MdispControl(MilDisplay, M_TITLE, M_PTR_TO_DOUBLE("Grab monoshot on Host and update to display.")); /* Allocate 2 digitizers, one for the continuous grab to the display and one for monochrome monoshots on the Host. */ MdigAlloc(MilSystem, M_DEV0, M_DEF_DIGITIZER_FORMAT, M_DEFAULT, &MilDigitizerContinuous); MdigAlloc(MilSystem, M_DEV0, M_DEF_DIGITIZER_FORMAT, M_DEFAULT, &MilDigitizer); MdigControl(MilDigitizer, M_GRAB_SCALE, IMAGE_SCALE); MdigControl(MilDigitizer, M_GRAB_MODE, M_ASYNCHRONOUS); /* Monoshot grab buffers. */ MbufAllocColor(MilSystem, 1, (long)(MdigInquire(MilDigitizer, M_SIZE_X, M_NULL)*IMAGE_SCALE), (long)(MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL)*IMAGE_SCALE), 8L+M_UNSIGNED, M_IMAGE+M_GRAB+M_PROC, &MilImage[0]); MbufAllocColor(MilSystem, 1, (long)(MdigInquire(MilDigitizer, M_SIZE_X, M_NULL)*IMAGE_SCALE), (long)(MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL)*IMAGE_SCALE), 8L+M_UNSIGNED, M_IMAGE+M_GRAB+M_PROC, &MilImage[1]); MbufClear(MilImage[0],M_BLACK); MbufClear(MilImage[1],M_BLACK); /* Monochrome display buffer. */ /* Note that the display update speed can be increased and CPU usage decreased if the display buffer is allocated in the VGA memory. Simply add M_DDRAW+M_ON_BOARD to the display buffer attributes. */ MbufAllocColor(MilSystem, 1, (long)(MdigInquire(MilDigitizer, M_SIZE_X, M_NULL)*IMAGE_SCALE), (long)(MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL)*IMAGE_SCALE), 8L+M_UNSIGNED, M_IMAGE+M_PROC+M_DISP+M_GRAB, &MilImageDisp); MbufClear(MilImageDisp,M_BLACK); /* Continuous grab display buffer. */ MbufAllocColor(MilSystem, (long)(MdigInquire(MilDigitizerContinuous, M_SIZE_BAND, M_NULL)), (long)(MdigInquire(MilDigitizerContinuous, M_SIZE_X, M_NULL)), (long)(MdigInquire(MilDigitizerContinuous, M_SIZE_Y, M_NULL)), 8L+M_UNSIGNED, M_IMAGE+M_PROC+M_DISP+M_GRAB, &MilImageDispContinuous); MbufClear(MilImageDispContinuous, M_BLACK); MdispSelect(MilDisplay, MilImageDisp); MdispSelect(MilDisplayContinuous, MilImageDispContinuous); /* Start continuous grab on the display. */ MdigGrabContinuous(MilDigitizerContinuous, MilImageDispContinuous); printf("Continuous grab in progress.\n"); printf("Press to start monoshot grabs\n"); printf("on Host and update to display.\n"); getchar(); /* Reset the timer to compute the number of actual frames grabbed per second by monoshot digitizer. */ MappTimer(M_TIMER_RESET, &Time); /* While the continuous grab is running in the display we do monoshot grabs with the other digitizer and copy them on the second display. This is done using double-buffering techniques. Please refer to mdbproc.c example for further details about double-buffering. */ while(!kbhit()) { /* Grab a frame. */ MdigGrab(MilDigitizer, MilImage[i]); /* Toggle between the 2 grab buffers. */ i = 1-i; n++;t++; /* Print frame rate. */ if (n==30) { MappTimer(M_TIMER_READ, &Time); printf("\rGrabbing and processing on Host at %2.3f frames/sec. Total frames: %d ",n/Time,t); n=0; MappTimer(M_TIMER_RESET, &Time); } /* Process the first buffer already grabbed. Note: Real time only if PC is fast enough. */ #if REVERSE_IMAGE MimArith(MilImage[i], M_NULL, MilImageDisp, M_NOT); #endif #if EDGE_DETECT_IMAGE MimConvolve(MilImage[i], MilImageDisp, M_EDGE_DETECT); #endif #if COPY_IMAGE MbufCopy(MilImage[i], MilImageDisp); #endif } /* Wait for the last queued monoshot to finish. */ MdigGrabWait(MilDigitizer, M_GRAB_END); /* Stop the continuous grab. */ MdigHalt(MilDigitizerContinuous); /* Free allocations. */ MbufFree (MilImage[0]); MbufFree (MilImage[1]); MbufFree (MilImageDisp); MbufFree (MilImageDispContinuous); MdigFree (MilDigitizer); MdigFree (MilDigitizerContinuous); MdispFree(MilDisplay); MdispFree(MilDisplayContinuous); MsysFree (MilSystem); MappFree (MilApplication); }