/**************************  ini_TomaPatrones  ******************************
	Reserva de memoria para tomar una serie de imagenes promediadas.
*****************************************************************************/
int ini_TomaPatrones(parametros *param)
{
	int i;

    //Acumuladores
	for (i=0; i < param->nBandas; i++)  {
	    MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, PROFUNDIDAD_ACUMULACION+M_UNSIGNED,
		    M_IMAGE+M_DISP+M_PROC, &M_banda_acum[i]);
	    MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, PROFUNDIDAD_ACUMULACION+M_UNSIGNED,
		    M_IMAGE+M_DISP+M_PROC, &M_banda_enmascarada_acum[i]);
	    MbufClear(M_banda_acum[i], 0);
	    MbufClear(M_banda_enmascarada_acum[i], 0);

        //Contador
	    MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, 8+M_UNSIGNED, //necesario 32+M_FLOAT para realizar operaciones en coma flotante
		    M_IMAGE+M_PROC, &M_cont_campos[i]);
	    MbufClear(M_cont_campos[i], 0);

	}

    //Buffers auxiliares
	MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, 8+M_UNSIGNED,
		M_IMAGE+M_PROC, &M_mascara_aux);
	MbufClear(M_mascara_aux, 0);

	MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, PROFUNDIDAD_ACUMULACION+M_UNSIGNED,
		M_IMAGE+M_PROC+M_GRAB, &M_acum_aux);
	MbufClear(M_acum_aux, 0);

	return 0;
}
Ejemplo n.º 2
0
// A partir de las imagenes guardadas en disco, genera la imagen mosaico
void GenerarMosaicos()
{
	char nombre_fich[512];
    MIL_ID M_aux;
    MIL_ID M_mosaico;
    long lSizeX, lSizeY; //dimensiones imagen


    // Leer tamaño de primera imagen
    sprintf(nombre_fich, "%s%s_%03d_%03d_%02d%s", g_csDirectorioBarrido, g_csMuestra, g_nFilaInicio, g_nColumnaInicio, g_arrFiltros[0]+1, ".tif");
    MbufDiskInquire(nombre_fich,M_SIZE_X, &lSizeX);
    MbufDiskInquire(nombre_fich,M_SIZE_Y, &lSizeY);

	MbufAlloc2d(M_DEFAULT_HOST, lSizeX, lSizeY, 8/*theApp.m_ParamIni.Cam.profundidad*/+M_UNSIGNED,
		M_IMAGE+M_PROC, &M_aux);
	MbufAlloc2d(M_DEFAULT_HOST, lSizeX * (g_nColumnaFin - g_nColumnaInicio + 1), lSizeY * (g_nFilaFin - g_nFilaInicio + 1), 8/*theApp.m_ParamIni.Cam.profundidad*/+M_UNSIGNED,
		M_IMAGE+M_PROC, &M_mosaico);
	for (int f=0; f < g_nBandas; f++)  
    {
        MbufClear(M_mosaico,0);
        for (int i=g_nFilaInicio;i<=g_nFilaFin;i++)
        {
            printf("\rComponiendo mosaico filtro %d  Fila %d ...    ", g_arrFiltros[f], i);
            for (int j=g_nColumnaInicio;j<=g_nColumnaFin;j++)
            {
		        sprintf(nombre_fich, "%s%s_%03d_%03d_%02d%s", g_csDirectorioBarrido, g_csMuestra, i, j, g_arrFiltros[f], ".tif");
		        //carga_imagen_campo8bit(nombre_fich, M_aux, theApp.m_ParamIni.Cam.profundidad); 
		        carga_imagen_campo_bits(nombre_fich, M_aux,8); 
                MbufCopyClip(M_aux,M_mosaico,(j-g_nColumnaInicio)*lSizeX,(i-g_nFilaInicio)*lSizeY);
            }
        }
        printf("\rSalvando mosaico filtro %d ...                      ", g_arrFiltros[f]);
        sprintf(nombre_fich, "%s%s_%02d%s", g_csDirectorioBarrido, g_csMuestra, g_arrFiltros[f], ".tif");
		graba_imagen_campo(nombre_fich, M_mosaico); 

    }
    printf("\r                                                         \n");

	MbufFree(M_aux);
	MbufFree(M_mosaico);
}
Ejemplo n.º 3
0
// Se reserva memoria, se carga y se presenta la imagen "nomFich"
// Se presupone que no hay otra imagen cargada con el mismo numero de filtro ("numFiltro")
//  m_control es el control al dialogo
//  bMostrar indica si debe de mostrarse la imagen en pantalla o solo cargar la imagen en memoria
// Se inicializa M_overlay_normal
// Se deja el zoom a 0.5
bool ControlImagenes::CargarImagen(char* nomFich, CStatic&	m_control, int numFiltro, bool bMostrar)
{

	// Comprobaciones
	struct stat stFileInfo;
	if (stat(nomFich,&stFileInfo) != 0)
		return false;
    if (m_Milimagen[numFiltro-1] != NULL)
        return false;

    long lSizeX, lSizeY;
    MbufDiskInquire(nomFich,M_SIZE_X, &lSizeX);
    MbufDiskInquire(nomFich,M_SIZE_Y, &lSizeY);
    MbufAlloc2d(M_DEFAULT_HOST, lSizeX,lSizeY, 16 + M_UNSIGNED, M_IMAGE + M_DISP + M_PROC, &m_Milimagen[numFiltro-1]);
    if (MbufImport(nomFich,M_TIFF,M_LOAD,M_NULL,&m_Milimagen[numFiltro-1]) == M_NULL)
//    if (MbufImport(nomFich,M_TIFF,M_RESTORE,M_DEFAULT_HOST,&m_Milimagen[numFiltro-1]) == M_NULL)
        return false;
    if (m_Milimagen[numFiltro-1] == NULL)
        return false;

    m_numImagenes++;

	if (bMostrar)
	{
		MdispSelectWindow(m_Mildisplay,m_Milimagen[numFiltro-1],m_control);
		// Inicializar Overlay la primera vez que se carga una imagen
		// Esto se hace aqui porque no funciona si no hay un buffer asociado con el display
		// ha de usarse la variable global M_overlay_normal para que funcionen las funciones graficas
		if (M_overlay_normal == M_NULL)
		{
			MdispInquire(m_Mildisplay, M_OVERLAY_ID, &M_overlay_normal);

			// Relleno el buffer overlay con el color TRANSPARENTE
//			MbufClear(M_overlay_normal, TRANSPARENTE );
		}
        // TRUCO para evitar que los rectangulos se pinten con un reborde negro. Pero la carga de imagenes es mas lenta
        // Se deja el zoom a 0.5
        // Los rectangulos se pintan con un reborde negro cuando el zoom esta entre 0.5 y 1 en MIL 8
        // por razones desconocidas. Este truco funciona, pero tampoco se sabe porque
//        MdispZoom(m_Mildisplay, 0.5, 0.5);
        //En la funcion llamante, se debe actualizar correctamente el zoom
	}
    // Solo una vez cada vez que se cargan todas las imagenes
    if (numFiltro == 2)
    {
        // Recuperamos las dimensiones de la imagen
        MbufInquire(m_Milimagen[1],M_SIZE_X,&m_nAnchoImagen);
        MbufInquire(m_Milimagen[1],M_SIZE_Y,&m_nAltoImagen);
	}

    return true;
}
/**************************  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;
}
/*************************** ini_control_digitalizador  *********************
	Función para reservar memoria para los diferentes formatos de
	digitalizadores que se utilizarán en la toma de imágenes.
	Previamente, se comprueba que los parámetros iniciales son válidos para
	el formato y tipo de digitalizador reservado.
	Seguidamente se reserva el display y los buffers que se utilizan en el
	proceso de adquisición de imágenes.
*****************************************************************************/
int ini_control_digitalizador(parametros *param)
{
	char	*fn = "ini_control_digitalizador - ";
	int		i;

	paramAux = param; //para usar en otras funciones

	//	SI DEFINO UN TAMAÑO DE DIGITALIZADOR DE ENFOQUE...	(DIGITALIZADOR)
	//	Reservo memoria para un nuevo display en el que se mostrarán los campos
	//	recorridos y los que se han podido enfocar. 
	if (param->Cam.formatoDig_e[0] != '\0' &&
		strcmp(param->Cam.formatoDig, param->Cam.formatoDig_e) )  
    {

		//	Configuro el digitalizador en formato enfoque
		if (M_digitalizador != M_NULL)
			libera_digitalizador();
		if ( MdigAlloc (M_sistema, M_DEV0, param->Cam.formatoDig_e, M_DEFAULT, &M_digitalizador)
			== M_NULL )  
        {
			error_fatal("ini_control_digitalizador", "Formato incorrecto", 0);
#if !defined (__BORLANDC__)
			putch('\a');
#endif
			return 1;
		}
		MdigInquire(M_digitalizador, M_SIZE_X, &limCam.anchoDig_e);
		if ( limCam.anchoDig_e > MAX_ANCHO_IMAGEN ||
				limCam.anchoDig_e < param->Cam.anchoImagen_e )  
        {
			error_fatal(fn, "Error en los parámetros iniciales", 0);
#if !defined (__BORLANDC__)
			putch('\a');
#endif
			return 1;
		}

		MdigInquire(M_digitalizador, M_SIZE_Y, &limCam.altoDig_e);
		if ( limCam.altoDig_e > MAX_ALTO_IMAGEN || 
                limCam.altoDig_e < param->Cam.altoImagen_e )  
        {
			error_fatal(fn, "Error en los parámetros iniciales", 0);
#if !defined (__BORLANDC__)
			putch('\a');
#endif
			return 1;
		}
	}


	//	Configuro el digitalizador en formato normal. 
	if (M_digitalizador != M_NULL)
		libera_digitalizador();

	if ( MdigAlloc (M_sistema, M_DEV0, param->Cam.formatoDig, M_DEFAULT, &M_digitalizador)
		== M_NULL )  {
		error_fatal("ini_control_proceso_imagenes", "Formato incorrecto", 0);
		return 1;
	}
	MdigInquire(M_digitalizador, M_SIZE_X, &limCam.anchoDig);
	if ( limCam.anchoDig > MAX_ANCHO_IMAGEN ||
			limCam.anchoDig < param->Cam.anchoImagen )  {
		error_fatal(fn, "Error en los parámetros iniciales", 0);
#if !defined (__BORLANDC__)
		putch('\a');
#endif
		return 1;
	}

	MdigInquire(M_digitalizador, M_SIZE_Y, &limCam.altoDig);
	if ( limCam.altoDig > MAX_ALTO_IMAGEN || 
            limCam.altoDig < param->Cam.altoImagen )  {
		error_fatal(fn, "Error en los parámetros iniciales", 0);
#if !defined (__BORLANDC__)
		putch('\a');
#endif
		return 1;
	}

	//	Si el formato del digitalizador de enfoque es el mismo que el de
	//	captura normal, copiamos las dimensiones porque no se leyeron. 
	if ( strcmp(param->Cam.formatoDig, param->Cam.formatoDig_e) == 0 )  {
		limCam.anchoDig_e = limCam.anchoDig;
		limCam.altoDig_e = limCam.altoDig;
	}

	//	Compruebo los valores iniciales de brillo, ganancia y exposición. 
	if ( info_digitalizador(M_digitalizador) )  {
		error_fatal(fn, "Error en los parámetros iniciales", 0);
		return 1;
	}

    // Se centra la camara en el caso de que se haya configurado un tamaño de toma diferente al maximo de la camara
	if ( configura_digitalizador(FORMATO_NORMAL) )  
        return 1;

	//	Buffer auxiliar de PROFUNDIDAD_ACUMULACION bits para acumular valores.
	MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, PROFUNDIDAD_ACUMULACION+M_UNSIGNED,
		M_IMAGE+M_DISP+M_PROC+M_GRAB, &M_imagen_acum);
	if ( M_imagen_acum == M_NULL )  {
		error_fatal(fn, "M_imagen_acum", 0);
		return 1;
	}

    // Obtenemos la profundidad de la camara
	MdigInquire(M_digitalizador, M_SIZE_BIT , &param->Cam.profundidad);

    if ( (BITS_CAMARA > 8 && param->Cam.profundidad <= 8) ||
         (BITS_CAMARA <= 8 && param->Cam.profundidad > 8) )
    {
		error_fatal(fn, "BITS_CAMARA (DEFINE en codigo) y profundidad camara no coherentes", 0);
		return 1;
	}

    //Si la profundidad no es de 8bit, hay que configurar el display.
    //El display siempre es de 8 bit
    if (param->Cam.profundidad == 16)
    {
        MdispControl(M_display_normal,M_VIEW_MODE,M_BIT_SHIFT);
        MdispControl(M_display_normal,M_VIEW_BIT_SHIFT,4); //despreciamos los 4 bits menos significativos
		MdispLut(M_display_normal, M_PSEUDO); //esto es necesario para que la intensidad no sea anormalmente elevada
    }

	//	Reservamos los buffers donde se almacenarán y procesarán las imágenes. 
	//	M_imagen1 será el buffer que normalmente estará asociado al display_normal.

	// En modo VGA no permite grabar datos en el buffer.
    long nSD_size;
    MsysInquire(M_sistema,M_SYSTEM_DESCRIPTOR_SIZE,&nSD_size);
    char* systemDescriptor = new char[nSD_size];
    MsysInquire(M_sistema,M_SYSTEM_DESCRIPTOR,systemDescriptor);
	if (systemDescriptor == M_SYSTEM_VGA)
		MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, param->Cam.profundidad+M_UNSIGNED,
			M_IMAGE+M_DISP+M_PROC, &M_imagen1 );
	else
		MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, param->Cam.profundidad+M_UNSIGNED,
			M_IMAGE+M_DISP+M_GRAB+M_PROC, &M_imagen1 );
    delete [ ] systemDescriptor;
	if ( M_imagen1 == M_NULL)  {
		error_fatal(fn, "M_imagen1", 0);
		return -1;
	}
	if ( M_imagen1 != M_NULL )  
    {
	//	Seleccionamos el display para imagen normal, asociando el overlay. 
#if !defined (__BORLANDC__)
	    configura_overlay(M_display_normal, M_imagen1, &M_overlay_normal, 1);
#else
	    configura_overlay(M_display_normal, M_imagen1, HWindow, &M_overlay_normal, 1);
        borra_buffer(M_imagen1, NEGRO, 0, 0, NULL, NULL);
#endif
/*
*/
	    if (param->Cam.anchoImagen != param->Cam.anchoImagen_e    || 
            param->Cam.altoImagen != param->Cam.altoImagen_e)  
        {
            // Reservo un child buffer de M_imagen1 con el tamaño de enfoque.
            MbufChild2d(M_imagen1, (param->Cam.anchoImagen - param->Cam.anchoImagen_e) /2,
                (param->Cam.altoImagen- param->Cam.altoImagen_e) /2,
                param->Cam.anchoImagen_e, param->Cam.altoImagen_e, &M_centro_imagen);
            if (M_centro_imagen == M_NULL)  
            {
                error_fatal(fn, "M_centro_imagen", 0);
                return -1;
		    }
        }
        else
            M_centro_imagen = M_imagen1;
	}

	MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, param->Cam.profundidad+M_UNSIGNED,
		M_IMAGE+M_DISP+M_PROC, &M_imagen2 );
	if ( M_imagen2 == M_NULL )  {
		error_fatal(fn, "M_imagen2", 0);
		return -1;
	}

	MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, param->Cam.profundidad+M_UNSIGNED,
		M_IMAGE+M_DISP+M_PROC, &M_imagen3);
	if ( M_imagen3 == M_NULL )  {
		error_fatal(fn, "M_imagen3", 0);
		return -1;
	}

	MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, param->Cam.profundidad+M_UNSIGNED,
		M_IMAGE+M_DISP+M_PROC, &M_imagen4);
	if ( M_imagen4 == M_NULL )  {
		error_fatal(fn, "M_imagen4", 0);
		return -1;
	}

	MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, param->Cam.profundidad+M_UNSIGNED,
		M_IMAGE+M_DISP+M_PROC, &M_imagen5);
	if ( M_imagen5 == M_NULL )  {
		error_fatal(fn, "M_imagen5", 0);
		return -1;
	}

	MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, param->Cam.profundidad+M_UNSIGNED,
		M_IMAGE+M_DISP+M_PROC, &M_imagen6);
	if ( M_imagen6 == M_NULL )  {
		error_fatal(fn, "M_imagen6", 0);
		return -1;
	}

	//	Reservo memoria para los buffers utilizados en la adquisición
	//	de las bandas y en la correccion de la iluminación.
	for (i=0; i < param->nBandas; i++) {
		MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, param->Cam.profundidad+M_UNSIGNED,
			M_IMAGE+M_DISP+M_PROC, &M_banda[i]);
		MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, 32+M_FLOAT,
			M_IMAGE+M_PROC, &M_correc_denom[i]);
		MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, 32+M_FLOAT,
			M_IMAGE+M_PROC, &M_correc_numer[i]);

		if ( M_banda[i] == M_NULL ||
				M_correc_numer[i] == M_NULL || M_correc_denom[i] == M_NULL )  {
			error_fatal(fn, "M_banda", 0);
			return 1;
		}
	}
    //El resto de filtros no usados a NULL
	for (; i < MAX_FILTROS_DTA; i++)
		M_banda[i] = M_correc_numer[i] = M_correc_denom[i] = M_NULL;

	MbufAlloc2d(M_sistema, param->Cam.anchoImagen, param->Cam.altoImagen, 32+M_FLOAT,
		M_IMAGE+M_PROC, &M_correc_aux);
	if ( M_correc_aux == M_NULL )  {
		error_fatal(fn, "M_correc_aux", 0);
		return 1;
	}

	//	SI DEFINO UN TAMAÑO DE DIGITALIZADOR DE ENFOQUE...	(BUFFERS)
    //	Reservo memoria para los buffers empleados durante el enfoque mediante la funcion determina_contraste2
	if ( param->Cam.formatoDig_e[0] != '\0' )  {
		MbufAlloc2d(M_sistema, param->Cam.anchoImagen_e, param->Cam.altoImagen_e, param->Cam.profundidad+M_UNSIGNED,
			M_IMAGE+M_DISP+M_GRAB+M_PROC, &M_enfoque);
		if ( M_enfoque == M_NULL )  {
			error_fatal(fn, "M_enfoque", 0);
			return 1;
		}
	}

	return 0;
}
Ejemplo n.º 6
0
/* Main function. */
int MosMain(void)
   {
   MIL_ID   MilApplication;
   MIL_ID   MilSystem;
   MIL_ID   MilDigitizer[2];
   MIL_ID   MilDisplay[2];
   MIL_ID   MilImageDisp[2];

   /* Allocations. */
   MappAlloc(M_DEFAULT, &MilApplication);
   MsysAlloc(MIL_TEXT("M_DEFAULT"), M_DEFAULT, M_DEFAULT, &MilSystem);
   MdigAlloc(MilSystem,  M_DEV0,    MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDigitizer[0]);
   MdigAlloc(MilSystem,  M_DEV1,    MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDigitizer[1]);
   MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDisplay[0]);
   MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDisplay[1]);

   /* Allocate 2 display buffers and clear them. */
   MbufAlloc2d(MilSystem,
               (MIL_INT)(MdigInquire(MilDigitizer[0], M_SIZE_X, M_NULL)*GRAB_SCALE),
               (MIL_INT)(MdigInquire(MilDigitizer[0], M_SIZE_Y, M_NULL)*GRAB_SCALE),
               8L+M_UNSIGNED,
               M_IMAGE+M_GRAB+M_PROC+M_DISP, &MilImageDisp[0]);
   MbufClear(MilImageDisp[0], 0x0);
   MbufAlloc2d(MilSystem,
               (MIL_INT)(MdigInquire(MilDigitizer[1], M_SIZE_X, M_NULL)*GRAB_SCALE),
               (MIL_INT)(MdigInquire(MilDigitizer[1], M_SIZE_Y, M_NULL)*GRAB_SCALE),
               8L+M_UNSIGNED,
               M_IMAGE+M_GRAB+M_PROC+M_DISP, &MilImageDisp[1]);
   MbufClear(MilImageDisp[1], 0x80);

   /* Display the buffers. */
   MdispSelect(MilDisplay[0], MilImageDisp[0]);
   MdispSelect(MilDisplay[1], MilImageDisp[1]);

   /* Grab continuously on displays at the specified scale. */
   MdigControl(MilDigitizer[0], M_GRAB_SCALE, GRAB_SCALE);
   MdigGrabContinuous(MilDigitizer[0],MilImageDisp[0]);
   MdigControl(MilDigitizer[1], M_GRAB_SCALE, GRAB_SCALE);
   MdigGrabContinuous(MilDigitizer[1],MilImageDisp[1]);

   /* Print a message. */
   MosPrintf(MIL_TEXT("Press <Enter> to stop continuous grab.\n"));
   MosGetch();

   /* Halt continuous grab. */
   MdigHalt(MilDigitizer[0]);
   MdigHalt(MilDigitizer[1]);

   /* Print a message. */
   MosPrintf(MIL_TEXT("Press <Enter> to end.\n"));
   MosGetch();

   /* Free allocations. */
   MbufFree(MilImageDisp[0]);
   MbufFree(MilImageDisp[1]);
   MdispFree(MilDisplay[0]);
   MdispFree(MilDisplay[1]);
   MdigFree(MilDigitizer[0]);
   MdigFree(MilDigitizer[1]);
   MsysFree(MilSystem);
   MappFree(MilApplication);

   return 0;
   }
Ejemplo n.º 7
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;
}