/************************** graba_imagen_campo **************************** Función para efectuar la grabación en disco de una imagen del campo. "nombre" es el nombre del archivo a almacenar. "buffer" es el buffer que quiero copiar a disco. Se espera que este buffer este en 8 o 16 bits reales (dependiendo de la profundidad de la camara) nBits - profundidad en bits en que se grabará la imagen (8,12,16) ****************************************************************************/ int graba_imagen_campo_bits(parametros& param, char *nombre, MIL_ID buffer, int nBits, double dEscala) { int res = 0; if (param.Cam.profundidad == 16 && (nBits == 8 || nBits == 12)) { MIL_ID M_buf16; long altoImagen,anchoImagen; MbufInquire(buffer, M_SIZE_X, &anchoImagen); MbufInquire(buffer, M_SIZE_Y, &altoImagen); MbufAlloc2d(M_sistema, anchoImagen, altoImagen, 16+M_UNSIGNED, M_IMAGE+M_DISP+M_PROC, &M_buf16 ); if (nBits == 8) { MIL_ID M_buf8; MbufAlloc2d(M_sistema, anchoImagen, altoImagen, 8+M_UNSIGNED, M_IMAGE+M_DISP+M_PROC, &M_buf8 ); MimShift(buffer,M_buf16,-8);//conversion a 8 bit MbufCopy(M_buf16, M_buf8); // MimShift(buffer,buffer,4);//conversion a 12 bit. Para que luego los histogramas funcionen correctamente res = graba_imagen_campo(nombre,M_buf8, nBits, dEscala); MbufFree(M_buf8); } else //nBits==12 { MimShift(buffer,M_buf16,-4);//conversion a 12 bit res = graba_imagen_campo(nombre,M_buf16, nBits, dEscala); } MbufFree(M_buf16); } else //Grabar tal cual (imagen origen esta en 8 bit o esta en 16 bit y se quiere dejar en 16 bit) { res = graba_imagen_campo(nombre,buffer, nBits, dEscala); } return res; }
/************************** calcula_valores_linea ************************* Calcula los valores de nivel de gris de una determinada línea. (horizontal o vertical). *****************************************************************************/ int calcula_valores_linea(MIL_ID M_fb, int posX, int posY, int linea) { BYTE val_pixel_h[MAX_ANCHO_IMAGEN], val_pixel_v[MAX_ALTO_IMAGEN]; int altoImagen, anchoImagen; MbufCopy(M_fb, M_imagen6); /* Compruebo que los valores a calcular no están fuera de los límites definidos por el buffer. */ anchoImagen = MbufInquire(M_imagen6, M_SIZE_X, M_NULL); altoImagen = MbufInquire(M_imagen6, M_SIZE_Y, M_NULL); posX = (posX < 0)? 0 : posX; posX = (posX > anchoImagen)? anchoImagen : posX; posY = (posY < 0)? 0 : posY; posY = (posY > altoImagen)? altoImagen : posY; // Línea horizontal. if (linea == L_HORIZ) { MbufGetLine(M_imagen6, 0, posY, anchoImagen-1, posY, M_DEFAULT, M_NULL, &val_pixel_h); dibuja_analisis_linea(val_pixel_h, linea, altoImagen, anchoImagen); } // Línea vertical. else if (linea == L_VERT) { MbufGetLine(M_imagen6, posX, 0, posX, altoImagen-1, M_DEFAULT, M_NULL, &val_pixel_v); dibuja_analisis_linea(val_pixel_v, linea, altoImagen, anchoImagen); } else { error_leve("calcula_valores_linea", "no se puede mostrar el análisis de la línea"); return -1; } return 0; }
/************************** carga_imagen_campo **************************** Función para efectuar la carga desde disco de una imagen del campo. Se le pasan a esta función los siguientes argumentos: nombre: nombre del fichero que quiero cargar. buffer: le paso el buffer donde quiero almacenar la imagen a cargar. Esto define el tamaño del mismo. nProfundidad: profundidad (bits) del buffer (8,12,16) Esta función únicamente carga la imagen en el buffer seleccionado, no la muestra en el display. LEE LA PROFUNDIDAD GUARDADA, EL BUFFER ESTA EN nProfundidad ****************************************************************************/ int carga_imagen_campo_bits(char *nombre, MIL_ID buffer, int nProfundidad) { // Leer informacion TIF (escala reflectancia y profundidad) int nProfundidadFichero = -1; double dEscalaFichero; try { CString csNombreImagen; INTERFAZ_LIBTIF::LeerTags(nombre,nProfundidadFichero,dEscalaFichero); //Leemos de la imagen la profundidad en bits y la escala reflectancia-gris if (nProfundidadFichero < 0 ) nProfundidadFichero = 8; // por defecto las imagenes estan en 8 bit } catch(...) { nProfundidadFichero = 8; } if (nProfundidad != nProfundidadFichero) { // Buffer auxiliar de 16 es necesario para poder operar (M_PROC) MIL_ID M_buf16; long altoImagen,anchoImagen; MbufInquire(buffer, M_SIZE_X, &anchoImagen); MbufInquire(buffer, M_SIZE_Y, &altoImagen); MbufAlloc2d(M_DEFAULT_HOST, anchoImagen, altoImagen, 16+M_UNSIGNED, M_IMAGE+M_DISP+M_PROC, &M_buf16 ); if (nProfundidad >= 12 && nProfundidadFichero >= 12) { if (carga_imagen_campo(nombre,M_buf16)) return 1;//ERROR MimShift(M_buf16,buffer,nProfundidad - nProfundidadFichero);//conversion de 12 a 16 bit } else if (nProfundidadFichero == 8) //nProfundidad>8 { MIL_ID M_buf8; MbufAlloc2d(M_DEFAULT_HOST, anchoImagen, altoImagen, 8+M_UNSIGNED, M_IMAGE+M_DISP+M_PROC, &M_buf8 ); if (carga_imagen_campo(nombre,M_buf8)) //ERROR return 1; MbufCopy(M_buf8, M_buf16); MbufFree(M_buf8); MimShift(M_buf16,buffer,nProfundidad - nProfundidadFichero);//conversion de 8 a 12 bit } else //(nProfundidad == 8 && nProfundidadFichero > 8 { if (carga_imagen_campo(nombre,M_buf16)) //ERROR return 1; MimShift(M_buf16,buffer,nProfundidad - nProfundidadFichero);//conversion de 8 a 12 bit } MbufFree(M_buf16); } else { if (carga_imagen_campo(nombre,buffer)) //ERROR return 1; } return 0; }
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); }