/*************************** toma2_acumulada ********************************* Función para la adquisición de una imagen con menor ruido, mediante la acumulacion de un cierto número de tomas buf - buffer donde se devolvera la imagen acumulada nAcum - numero de veces a acumular La imagen acumulada es devuelta en M_imagen1 *****************************************************************************/ void toma2_acumulada(MIL_ID buf, int nAcum) { /* fin_toma(); // tomaContinua = false; if (nAcum == 1) //optimizado { MdigGrab (M_digitalizador, buf); } else { MbufClear(buf, nAcum / 2); // para conseguir que en la división final se produzca un redondeo. int n; for (n = 0; n < nAcum; ++n) { MdigGrab (M_digitalizador, M_imagen1); MimArith (M_imagen1, buf, buf, M_ADD); } } */ // para conseguir que en la división final se produzca un redondeo. if (nAcum != 1) MbufClear(buf, nAcum / 2); else MbufClear(buf, 0); fin_toma(); // tomaContinua = false; int n; for (n = 0; n < nAcum; ++n) { MdigGrab (M_digitalizador, M_imagen1); MimArith (M_imagen1, buf, buf, M_ADD); } }
/*************************** toma2_promediada ********************************* Función para la adquisición de una imagen con menor ruido, mediante la acumulacion de un cierto número de tomas Modo del digitalizador: enfoque. nAcum - numero de veces a acumular La imagen acumulada es promediada y devuelta en M_imagen1 *****************************************************************************/ void toma2_promediada(int nAcum) { toma2_acumulada(M_imagen_acum, nAcum); // Una vez realizada la acumulación de imágenes en el buffer auxiliar, // procedo a dividirlo por el número de imágenes tomadas. // La imagen corregida es devuelta y almacenada en M_imagen1. if (nAcum != 1) MimArith(M_imagen_acum, nAcum, M_imagen1, M_DIV_CONST); }
MIL_INT MFTYPE ProcessingFunction(MIL_INT HookType, MIL_ID EventId, void MPTYPE *CallBackDataPtr) { /* Get the grabbed buffer. */ ProcessingDataStruct *ProcessingDataPtr = (ProcessingDataStruct *)CallBackDataPtr; MIL_ID CurrentProcSrcBufId, CurrentProcDstBufId; MIL_ID GrabbedBufferId; MIL_INT GrabbedBufferIndex; MIL_TEXT_CHAR Text[BUFFER_MAX_STRING_LENGTH]; MIL_DOUBLE RectHalfSizeStep = 0.0; long RectStep = 0; long NbSystem = ProcessingDataPtr->NbSystem; long NbProcInitial = ProcessingDataPtr->NbProc; long NbBufferToProcess, n; /* Retrieve the buffer to process and it's index */ MdigGetHookInfo(EventId, M_MODIFIED_BUFFER+M_BUFFER_ID, &GrabbedBufferId); MdigGetHookInfo(EventId, M_MODIFIED_BUFFER+M_BUFFER_INDEX, &GrabbedBufferIndex); /* Reset the timer. */ if (ProcessingDataPtr->NbProc == 0) MappTimer(M_TIMER_RESET+M_SYNCHRONOUS,&ProcessingDataPtr->Time); /* If PROCESS_EACH_IMAGE_ON_ALL_SYSTEMS is set, each grabbed image is processed on all the systems. To have each frame processed only once by one system in round robin fashion, set the define to M_NO. */ if (ProcessingDataPtr->ProcessEachImageOnAllSystems) NbBufferToProcess = NbSystem; else NbBufferToProcess = 1; /* Dispatch the job to the target processing system(s) */ for(n=0; n<NbBufferToProcess; n++) { /* Calculate target processing buffer. */ CurrentProcSrcBufId = ProcessingDataPtr->SrcProcBufferListPtr[(ProcessingDataPtr->NbProc)%(NbSystem*BUFFER_PER_PROCESSOR)]; CurrentProcDstBufId = ProcessingDataPtr->DstProcBufferListPtr[(ProcessingDataPtr->NbProc)%(NbSystem*BUFFER_PER_PROCESSOR)]; /* Copy the grabbed buffer to a processing platform. */ MbufCopy(GrabbedBufferId, CurrentProcSrcBufId); /* Draw the buffer index in the source. */ MosSprintf(Text, BUFFER_MAX_STRING_LENGTH, MIL_TEXT("#%ld."), ProcessingDataPtr->NbProc); MgraText(M_DEFAULT, CurrentProcSrcBufId, 50, 50, Text); /* Process the buffer. */ #if (!M_MIL_LITE) { MimArith(CurrentProcSrcBufId, 0x10, CurrentProcDstBufId, M_SUB_CONST+M_SATURATION); MimArith(CurrentProcDstBufId, M_NULL, CurrentProcSrcBufId, M_NOT); MimRotate(CurrentProcSrcBufId, CurrentProcDstBufId, (ProcessingDataPtr->NbProc*10)%360, (MIL_DOUBLE) ProcessingDataPtr->SizeX/2, (MIL_DOUBLE) ProcessingDataPtr->SizeY/2, (MIL_DOUBLE) ProcessingDataPtr->SizeX/2, (MIL_DOUBLE) ProcessingDataPtr->SizeY/2, M_NEAREST_NEIGHBOR); } #else { RectStep = (ProcessingDataPtr->NbProc % BUFFER_DRAW_RECT_NUMBER); if(RectStep < BUFFER_DRAW_INWARD_STEP_NUMBER) RectHalfSizeStep = RectStep * BUFFER_DRAW_RECT_STEP; else RectHalfSizeStep = (BUFFER_DRAW_RECT_NUMBER - RectStep) * BUFFER_DRAW_RECT_STEP; MgraColor(M_DEFAULT, 0xff); MgraRectFill(M_DEFAULT, CurrentProcDstBufId, ProcessingDataPtr->SizeX/2 - RectHalfSizeStep, ProcessingDataPtr->SizeY/2 - RectHalfSizeStep, ProcessingDataPtr->SizeX/2 + RectHalfSizeStep, ProcessingDataPtr->SizeY/2 + RectHalfSizeStep); } #endif /* Count processed buffers. */ ProcessingDataPtr->NbProc++; MosPrintf(MIL_TEXT("Processing #%ld.\r"), ProcessingDataPtr->NbProc); } /* If required, copy back the result buffers from the processing system(s) for display. */ #if (DISPLAY_EACH_IMAGE_PROCESSED) { for(n=0; n<NbBufferToProcess; n++) { /* Calculate target buffer for display. */ CurrentProcDstBufId = ProcessingDataPtr->DstProcBufferListPtr[(NbProcInitial+n)%(NbSystem*BUFFER_PER_PROCESSOR)]; /* Copy result to display. */ MbufCopy(CurrentProcDstBufId, ProcessingDataPtr->DispBuffer); } } #endif /* Read the timer. */ MappTimer(M_TIMER_READ+M_SYNCHRONOUS, &ProcessingDataPtr->Time); #if M_MIL_USE_CE /* Give execution time to user interface when the digitizer processing queue is full. If necessary, the Sleep value can be increased to give more execution time to user interface. */ if(MdigInquire(ProcessingDataPtr->MilDigitizer, M_PROCESS_PENDING_GRAB_NUM, M_NULL) <= 1) { if ((ProcessingDataPtr->NbProc%10) == 0) Sleep(2); } #endif return(0); }