main.c
//Esta funcion almacena una imagen de intensidad en
//archivo en formato BMP
Esta funcion almacena una imagen de intensidad en
archivo en formato BMP
Esta funcion almacena una imagen de intensidad en archivo en formato BMP
int SaveIntensityImageIn_BMP_file(unsigned char *pintensity, char *filename)
    {
        int i, j, jj, ipos;
        int bytesPerLine;
        unsigned char *line;
        unsigned char *ptempImage;
        int height, width;
        height=pInputImage->height;
        width=pInputImage->width;
        FILE *file;
        struct BMPHeader bmph;
        bytesPerLine = (3 * (width + 1) / 4) * 4;
        strcpy(bmph.bfType, "BM");
        bmph.bfOffBits = 54;
        bmph.bfSize = bmph.bfOffBits + bytesPerLine * height;
        bmph.bfReserved = 0;
        bmph.biSize = 40;
        bmph.biWidth = width;
        bmph.biHeight = height;
        bmph.biPlanes = 1;
        bmph.biBitCount = 24;
        bmph.biCompression = 0;
        bmph.biSizeImage = bytesPerLine * height;
        bmph.biXPelsPerMeter = 0;
        bmph.biYPelsPerMeter = 0;
        bmph.biClrUsed = 0;
        bmph.biClrImportant = 0;
        file = fopen (filename, "wb");
        if (file == NULL) return(0);
        fwrite(&bmph.bfType, 2, 1, file);
        fwrite(&bmph.bfSize, 4, 1, file);
        fwrite(&bmph.bfReserved, 4, 1, file);
        fwrite(&bmph.bfOffBits, 4, 1, file);
        fwrite(&bmph.biSize, 4, 1, file);
        fwrite(&bmph.biWidth, 4, 1, file);
        fwrite(&bmph.biHeight, 4, 1, file);
        fwrite(&bmph.biPlanes, 2, 1, file);
        fwrite(&bmph.biBitCount, 2, 1, file);
        fwrite(&bmph.biCompression, 4, 1, file);
        fwrite(&bmph.biSizeImage, 4, 1, file);
        fwrite(&bmph.biXPelsPerMeter, 4, 1, file);
        fwrite(&bmph.biYPelsPerMeter, 4, 1, file);
        fwrite(&bmph.biClrUsed, 4, 1, file);
        fwrite(&bmph.biClrImportant, 4, 1, file);
        line = (unsigned char*) malloc(bytesPerLine);
        if (line == NULL)
        {
            fprintf(stderr, "Can't allocate memory for BMP file.\n");
            return(0);
        }
        ptempImage = (unsigned char *)malloc(sizeof(unsigned char)*width*height);
        for (i=0;i<width*height;i++) ptempImage[i]=0;
        jj=0;
        for (j=height-1;j>=0;j--) {
            for (i=0;i<width;i++) {
                ptempImage[jj*width+i]= pintensity[j*width+i];
            }
            jj++;
        }
        for (i = height - 1; i >= 0; i--)
        {
            for (j = 0; j < width; j++)
            {
                ipos = (width * i + j);
                line[3*j] = ptempImage[ipos];
                line[3*j+1] = ptempImage[ipos];
                line[3*j+2] = ptempImage[ipos];
            }
            fwrite(line, bytesPerLine, 1, file);
        }
        free(line);
        fclose(file);
        free(ptempImage);
        return(1);
    }
int SaveIntensityImageIn_BMP_file ( unsigned char * pintensity , char * filename ) { int i , j , jj , ipos ; int bytesPerLine ; unsigned char * line ; unsigned char * ptempImage ; int height , width ; height = pInputImage -> height ; width = pInputImage -> width ; FILE * file ; struct BMPHeader bmph ; bytesPerLine = ( 3 * ( width + 1 ) / 4 ) * 4 ; strcpy ( bmph . bfType , " " ) ; bmph . bfOffBits = 54 ; bmph . bfSize = bmph . bfOffBits + bytesPerLine * height ; bmph . bfReserved = 0 ; bmph . biSize = 40 ; bmph . biWidth = width ; bmph . biHeight = height ; bmph . biPlanes = 1 ; bmph . biBitCount = 24 ; bmph . biCompression = 0 ; bmph . biSizeImage = bytesPerLine * height ; bmph . biXPelsPerMeter = 0 ; bmph . biYPelsPerMeter = 0 ; bmph . biClrUsed = 0 ; bmph . biClrImportant = 0 ; file = fopen ( filename , " " ) ; if ( file == NULL ) return ( 0 ) ; fwrite ( & bmph . bfType , 2 , 1 , file ) ; fwrite ( & bmph . bfSize , 4 , 1 , file ) ; fwrite ( & bmph . bfReserved , 4 , 1 , file ) ; fwrite ( & bmph . bfOffBits , 4 , 1 , file ) ; fwrite ( & bmph . biSize , 4 , 1 , file ) ; fwrite ( & bmph . biWidth , 4 , 1 , file ) ; fwrite ( & bmph . biHeight , 4 , 1 , file ) ; fwrite ( & bmph . biPlanes , 2 , 1 , file ) ; fwrite ( & bmph . biBitCount , 2 , 1 , file ) ; fwrite ( & bmph . biCompression , 4 , 1 , file ) ; fwrite ( & bmph . biSizeImage , 4 , 1 , file ) ; fwrite ( & bmph . biXPelsPerMeter , 4 , 1 , file ) ; fwrite ( & bmph . biYPelsPerMeter , 4 , 1 , file ) ; fwrite ( & bmph . biClrUsed , 4 , 1 , file ) ; fwrite ( & bmph . biClrImportant , 4 , 1 , file ) ; line = ( unsigned char * ) malloc ( bytesPerLine ) ; if ( line == NULL ) { fprintf ( stderr , " \n " ) ; return ( 0 ) ; } ptempImage = ( unsigned char * ) malloc ( sizeof ( unsigned char ) * width * height ) ; for ( i = 0 ; i < width * height ; i ++ ) ptempImage [ i ] = 0 ; jj = 0 ; for ( j = height - 1 ; j >= 0 ; j -- ) { for ( i = 0 ; i < width ; i ++ ) { ptempImage [ jj * width + i ] = pintensity [ j * width + i ] ; } jj ++ ; } for ( i = height - 1 ; i >= 0 ; i -- ) { for ( j = 0 ; j < width ; j ++ ) { ipos = ( width * i + j ) ; line [ 3 * j ] = ptempImage [ ipos ] ; line [ 3 * j + 1 ] = ptempImage [ ipos ] ; line [ 3 * j + 2 ] = ptempImage [ ipos ] ; } fwrite ( line , bytesPerLine , 1 , file ) ; } free ( line ) ; fclose ( file ) ; free ( ptempImage ) ; return ( 1 ) ; }
Esta funcion almacena una imagen de intensidad en
archivo en formato BMP
Esta funcion almacena una imagen de intensidad en archivo en formato BMP
/* The length of each line must be a multiple of 4 bytes */ //Cambiando posición del sistema de coordenadas de la equina inferior //izquierda a la esquina superior izquierda.