Main Page   Data Structures   File List   Data Fields   Globals  

mosaic_disk2index.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 #include        "mosaic.h"
00003 
00004 /*-Copyright Information------------------------------------------------------*/
00005 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This function reads a mosaic index from disk into main memory.            */
00009 /*                                                                            */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void MOSAIC_DISK2INDEX(
00013 unsigned char  *name,    /*  I   String, containing the name of the disk file.         */
00014 MOSAIC_INDEX **out    /*  O   Address of a pointer to the mosaic index.                    */
00015 )
00016 /*----------------------------------------------------------------------------*/
00017 {   
00018     int i;
00019     static char array[2] = { 0x00, 0x01 };
00020     char msg[SLEN];
00021     int  nlin, npix, height_max, hstart, hend;
00022     short nframe;
00023     int value;
00024     FILE *fp=NULL;
00025 
00026 
00027     /* if (TIMES) TIMING(T_DISK2IMG); */
00028 
00029 
00030     /* open image file */
00031     if (!(fp=fopen(name,"r"))) {
00032         sprintf(msg," Can't open file %s.",name);
00033         MESSAGE('E',msg);
00034         goto the_end;
00035     }
00036 
00037 
00038 
00039     /* read index size parameters from file */
00040     if (fread(&height_max,sizeof(height_max),1,fp) != 1) {
00041         sprintf(msg," Can't read number of uncompressed lines from file %s.",name);
00042         MESSAGE('E',msg);
00043         goto the_end;
00044     }
00045 
00046     if (fread(&nlin,sizeof(nlin),1,fp) != 1) {
00047         sprintf(msg," Can't read number of compressed lines from file %s.",name);
00048         MESSAGE('E',msg);
00049         goto the_end;
00050     }
00051 
00052     if (fread(&npix,sizeof(npix),1,fp) != 1) {
00053         sprintf(msg," Can't read number of pixels from file %s.",name);
00054         MESSAGE('E',msg);
00055         goto the_end;
00056     }
00057 
00058     if (fread(&nframe,sizeof(nframe),1,fp) != 1) {
00059         sprintf(msg," Can't read number of frames from file %s.",name);
00060         MESSAGE('E',msg);
00061         goto the_end;
00062     }
00063 
00064     if (fread(&hstart,sizeof(hstart),1,fp) != 1) {
00065         sprintf(msg," Can't read X-coord of left extreme point in ROI from file %s.",name);
00066         MESSAGE('E',msg);
00067         goto the_end;
00068     }
00069 
00070     if (fread(&hend,sizeof(hend),1,fp) != 1) {
00071         sprintf(msg," Can't read X-coord of right extreme point in ROI from file %s.",name);
00072         MESSAGE('E',msg);
00073         goto the_end;
00074     }
00075 
00076     /* swap bytes, if necessary */
00077     if (*(short *)array != 1) {
00078         /*printf("DISK2IMG: Swapping bytes...\n");*/
00079     
00080         height_max = SWAP((unsigned char *)&height_max);
00081         npix = SWAP((unsigned char *)&npix);
00082         nlin = SWAP((unsigned char *)&nlin);
00083         nframe = SWAP((unsigned char *)&nframe);
00084         hstart = SWAP((unsigned char *)&hstart);
00085         hend = SWAP((unsigned char *)&hend);
00086     } 
00087     /*
00088     else {
00089         printf("DISK2IMG: No need to swap bytes...\n");
00090     }
00091     */
00092     
00093     printf("nlin = %d, npix = %d, nframe = %d\n",nlin,npix,nframe);
00094 
00095 
00096     /* create index of appropriate size */
00097     if (!CHECKIMG_MOSAIC_INDEX(*out)) GETMEM_MOSAIC_INDEX(nlin,npix,nframe,out);
00098     if (!CHECKIMG_MOSAIC_INDEX(*out)) {
00099         sprintf(msg," Can't allocate memory for index.");
00100         MESSAGE('E',msg);
00101         goto the_end;
00102     }
00103 
00104 
00105     (*out)->height_max = height_max;
00106     (*out)->npix = npix;
00107     (*out)->nlin = nlin;
00108     (*out)->nframe = nframe;
00109     (*out)->hstart = hstart;
00110     (*out)->hend = hend;
00111     
00112     if (*(short *)array != 1) {
00113         for (i=0; i<npix; i++) {
00114             if (fread(&value,sizeof(value),1,fp) != 1) {
00115                 sprintf(msg," Can't read data from file %s.",name);
00116                 MESSAGE('E',msg);
00117                 goto the_end;
00118             }
00119             value = SWAP((unsigned char *)&value);
00120             (*out)->voffset[i] = value;
00121         }
00122         for (i=0; i<npix; i++) {
00123             if (fread(&value,sizeof(value),1,fp) != 1) {
00124                 sprintf(msg," Can't read data from file %s.",name);
00125                 MESSAGE('E',msg);
00126                 goto the_end;
00127             }
00128             value = SWAP((unsigned char *)&value);
00129             (*out)->vheight[i] = value;
00130         }
00131         for (i=0; i<npix; i++) {
00132             if (fread(&value,sizeof(value),1,fp) != 1) {
00133                 sprintf(msg," Can't read data from file %s.",name);
00134                 MESSAGE('E',msg);
00135                 goto the_end;
00136             }
00137             value = SWAP((unsigned char *)&value);
00138             (*out)->vstart[i] = value;
00139         }
00140         for (i=0; i<npix; i++) {
00141             if (fread(&value,sizeof(value),1,fp) != 1) {
00142                 sprintf(msg," Can't read data from file %s.",name);
00143                 MESSAGE('E',msg);
00144                 goto the_end;
00145             }
00146             value = SWAP((unsigned char *)&value);
00147             (*out)->vend[i] = value;
00148         }
00149         for (i=0; i<nframe; i++) {
00150             if (fread(&value,sizeof(value),1,fp) != 1) {
00151                 sprintf(msg," Can't read data from file %s.",name);
00152                 MESSAGE('E',msg);
00153                 goto the_end;
00154             }
00155             value = SWAP((unsigned char *)&value);
00156             (*out)->frame[i].startx = value;
00157 
00158             if (fread(&value,sizeof(value),1,fp) != 1) {
00159                 sprintf(msg," Can't read data from file %s.",name);
00160                 MESSAGE('E',msg);
00161                 goto the_end;
00162             }
00163             value = SWAP((unsigned char *)&value);
00164             (*out)->frame[i].endx = value;
00165 
00166             if (fread(&value,sizeof(value),1,fp) != 1) {
00167                 sprintf(msg," Can't read data from file %s.",name);
00168                 MESSAGE('E',msg);
00169                 goto the_end;
00170             }
00171             value = SWAP((unsigned char *)&value);
00172             (*out)->frame[i].starty = value;
00173 
00174             if (fread(&value,sizeof(value),1,fp) != 1) {
00175                 sprintf(msg," Can't read data from file %s.",name);
00176                 MESSAGE('E',msg);
00177                 goto the_end;
00178             }
00179             value = SWAP((unsigned char *)&value);
00180             (*out)->frame[i].endy = value;
00181         }
00182 
00183         for(i = 0; i < 2; i++) {
00184             if (fread(&value,sizeof(value),1,fp) != 1) {
00185                 sprintf(msg," Can't read data from file %s.",name);
00186                 MESSAGE('E',msg);
00187                 goto the_end;
00188             }
00189             value = SWAP((unsigned char *)&value);
00190             (*out)->roi->top[i] = value;
00191 
00192             if (fread(&value,sizeof(value),1,fp) != 1) {
00193                 sprintf(msg," Can't read data from file %s.",name);
00194                 MESSAGE('E',msg);
00195                 goto the_end;
00196             }
00197             value = SWAP((unsigned char *)&value);
00198             (*out)->roi->bottom[i] = value;
00199 
00200             if (fread(&value,sizeof(value),1,fp) != 1) {
00201                 sprintf(msg," Can't read data from file %s.",name);
00202                 MESSAGE('E',msg);
00203                 goto the_end;
00204             }
00205             value = SWAP((unsigned char *)&value);
00206             (*out)->roi->left[i] = value;
00207 
00208             if (fread(&value,sizeof(value),1,fp) != 1) {
00209                 sprintf(msg," Can't read data from file %s.",name);
00210                 MESSAGE('E',msg);
00211                 goto the_end;
00212             }
00213             value = SWAP((unsigned char *)&value);
00214             (*out)->roi->right[i] = value;
00215         }
00216 
00217     } else {
00218         for (i=0; i<npix; i++) {
00219             if (fread(&value,sizeof(value),1,fp) != 1) {
00220                 sprintf(msg," Can't read data from file %s.",name);
00221                 MESSAGE('E',msg);
00222                 goto the_end;
00223             }
00224             
00225             (*out)->voffset[i] = value;
00226         }
00227         for (i=0; i<npix; i++) {
00228             if (fread(&value,sizeof(value),1,fp) != 1) {
00229                 sprintf(msg," Can't read data from file %s.",name);
00230                 MESSAGE('E',msg);
00231                 goto the_end;
00232             }
00233             
00234             (*out)->vheight[i] = value;
00235         }
00236         for (i=0; i<npix; i++) {
00237             if (fread(&value,sizeof(value),1,fp) != 1) {
00238                 sprintf(msg," Can't read data from file %s.",name);
00239                 MESSAGE('E',msg);
00240                 goto the_end;
00241             }
00242             
00243             (*out)->vstart[i] = value;
00244         }
00245         for (i=0; i<npix; i++) {
00246             if (fread(&value,sizeof(value),1,fp) != 1) {
00247                 sprintf(msg," Can't read data from file %s.",name);
00248                 MESSAGE('E',msg);
00249                 goto the_end;
00250             }
00251             
00252             (*out)->vend[i] = value;
00253         }
00254         for (i=0; i<nframe; i++) {
00255             if (fread(&value,sizeof(value),1,fp) != 1) {
00256                 sprintf(msg," Can't read data from file %s.",name);
00257                 MESSAGE('E',msg);
00258                 goto the_end;
00259             }
00260             (*out)->frame[i].startx = value;
00261 
00262             if (fread(&value,sizeof(value),1,fp) != 1) {
00263                 sprintf(msg," Can't read data from file %s.",name);
00264                 MESSAGE('E',msg);
00265                 goto the_end;
00266             }
00267             (*out)->frame[i].endx = value;
00268 
00269             if (fread(&value,sizeof(value),1,fp) != 1) {
00270                 sprintf(msg," Can't read data from file %s.",name);
00271                 MESSAGE('E',msg);
00272                 goto the_end;
00273             }
00274             (*out)->frame[i].starty = value;
00275 
00276             if (fread(&value,sizeof(value),1,fp) != 1) {
00277                 sprintf(msg," Can't read data from file %s.",name);
00278                 MESSAGE('E',msg);
00279                 goto the_end;
00280             }
00281             (*out)->frame[i].endy = value;
00282         }
00283         for(i = 0; i < 2; i++) {
00284             if (fread(&value,sizeof(value),1,fp) != 1) {
00285                 sprintf(msg," Can't read data from file %s.",name);
00286                 MESSAGE('E',msg);
00287                 goto the_end;
00288             }
00289             (*out)->roi->top[i] = value;
00290 
00291             if (fread(&value,sizeof(value),1,fp) != 1) {
00292                 sprintf(msg," Can't read data from file %s.",name);
00293                 MESSAGE('E',msg);
00294                 goto the_end;
00295             }
00296             (*out)->roi->bottom[i] = value;
00297 
00298             if (fread(&value,sizeof(value),1,fp) != 1) {
00299                 sprintf(msg," Can't read data from file %s.",name);
00300                 MESSAGE('E',msg);
00301                 goto the_end;
00302             }
00303             (*out)->roi->left[i] = value;
00304 
00305             if (fread(&value,sizeof(value),1,fp) != 1) {
00306                 sprintf(msg," Can't read data from file %s.",name);
00307                 MESSAGE('E',msg);
00308                 goto the_end;
00309             }
00310             (*out)->roi->right[i] = value;
00311         }
00312     }
00313 
00314 
00315     if (NAMES) {
00316         MESSAGE('I',"");
00317         MESSAGE('I',"MOSAIC_DISK2INDEX");
00318         MESSAGE('I',"");
00319         sprintf(msg," Input file:                                 %s",name);
00320         MESSAGE('I',msg); 
00321         sprintf(msg," Number of pixels:             %d",(*out)->npix);
00322         MESSAGE('I',msg);
00323         sprintf(msg," Number of frames:             %d",(*out)->nframe);
00324         MESSAGE('I',msg);
00325         MESSAGE('I'," ...............");
00326     }
00327 
00328     /* close image file */
00329 
00330     the_end:
00331     if (fp) {
00332         if (fclose(fp)) {
00333             sprintf(msg," Can't close file %s.",name);
00334             MESSAGE('W',msg);
00335         }
00336     }
00337 
00338     /* if (TIMES) TIMING(T_EXIT); */
00339 
00340 }

Generated on Wed Apr 9 08:56:09 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002