~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/file/mipl/mip_io.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Functions to read/write RAW image files
  2 */
  3 
  4 #include <stdio.h>
  5 #include <string.h>
  6 #include <tina/file.h>
  7 #include <tina/sys.h>
  8 #include <tina/sys_types.h>
  9 #include <tina/sysfuncs.h>
 10 #include <tina/temporal.h>
 11 
 12 #define VOXELS    450
 13 #define DYNSTIME  451
 14 #define TE_DATA   453
 15 
 16 
 17 extern Bool fclose_2(FILE * stream, const char *pathname);
 18 extern FILE *fopen_2(const char *pathname, const char *mode);
 19 extern Bool fread_imrect_data(const Imrect * imrect, FILE * stream, const char *pathname);
 20 extern Bool fwrite_imrect_data(const Imrect * imrect, FILE * stream, const char *pathname);
 21 
 22 /* Create an imrect and read an image file called 'pathname' into it.
 23  * Open file, read data and close file. On failure, give error message
 24  * and return NULL. */
 25 
 26 
 27 void checkMiplHeader(FILE *fp_img, int row[], int col[], int nslc[], 
 28                      double pixl[], double thck[])
 29 {
 30         int      i;
 31   char name[80];
 32   char dummystring[80];
 33   char mipl_header[80];
 34         char thickness[80];
 35         char no_row[80];
 36         char no_col[80];
 37         char pixelsize[80];
 38         char noslices[80];
 39 
 40 
 41   for (i=0; i<31; i++){
 42                 fgets(mipl_header, 64, fp_img);  
 43     /*          printf("mipl_header(%d):  %s \n", i, mipl_header);      
 44      */
 45 
 46   }
 47 
 48 
 49   fgets(mipl_header, 64, fp_img);
 50         strcpy(thickness, mipl_header);
 51         printf("thickness : %s \n", thickness); 
 52 
 53 
 54   for (i=32; i<122; i++){
 55                 fgets(mipl_header, 64, fp_img);  
 56   }
 57 
 58         fgets(mipl_header, 64, fp_img);
 59         strcpy(no_row, mipl_header);
 60         printf("no_row : %s \n", no_row);       
 61 
 62 
 63         fgets(mipl_header, 64, fp_img);
 64         strcpy(no_col, mipl_header);
 65         printf("no_col : %s \n", no_col);       
 66 
 67         fgets(mipl_header, 64, fp_img);
 68         strcpy(pixelsize, mipl_header);
 69         printf("pixelsize : %s \n", pixelsize); 
 70 
 71   for (i=1; i<27; i++){
 72                 fgets(mipl_header, 64, fp_img);  
 73     /*
 74       printf("mipl_header(%d):  %s \n", i, mipl_header);        
 75                 */
 76 
 77   }
 78 
 79         fgets(mipl_header, 64, fp_img);
 80         strcpy(noslices, mipl_header);
 81         printf("noslices : %s \n", noslices);   
 82 
 83         *row = atoi(no_row);  
 84         *col = atoi(no_col);  
 85         *nslc = atoi(noslices);
 86 
 87         *thck = atof(thickness);
 88 
 89         *pixl = atof(pixelsize);  
 90 
 91 }
 92 
 93 
 94 
 95 
 96 Imrect *mip_read_image(const char *pathname, int i)
 97 {
 98   Imrect *imrect = NULL;
 99   FILE                    *fp_img=fopen_2(pathname, "rb");
100   Vartype                 new_vtype;
101   short                   fvernum;
102   short                   svernum;
103   int                     fimtype;
104   short                   rvernum;
105   int                       rowlo;
106   int                       rowhi;
107   int                       collo;
108   int                       colhi;
109 
110         int      nslc;
111         double  pixl, thck;
112 
113         rowlo=0;
114         collo=0;
115 
116   if (fp_img==NULL) return(NULL);
117 
118   checkMiplHeader(fp_img, &rowhi,&colhi,&nslc,&pixl,&thck);
119 
120   /*
121         format("image_row : %d \n", rowhi);
122         format("image_col : %d \n", colhi);
123         format("no_slices : %d \n", nslc);
124 
125         format("pixel_size : %lf \n", pixl);
126         format("slice_thck : %lf \n", thck);
127         */
128 
129         new_vtype = short_v;
130 
131   if (fseek(fp_img,(long)i*2*rowhi*colhi,SEEK_CUR)==0)
132     {
133       Imregion imregion;
134       imregion.lx = collo;
135       imregion.ux = colhi;
136       imregion.ly = rowlo;
137       imregion.uy = rowhi;
138 
139             imrect = im_alloc(rowhi-rowlo, colhi-collo,
140                         &imregion, (Vartype) new_vtype);
141             if (!fread_imrect_data(imrect, fp_img, pathname))
142         {
143                 im_free(imrect);
144                 imrect = NULL;
145         }
146             fclose_2(fp_img, pathname);
147     }
148   return imrect;
149 }
150 
151 
152 Bool   mip_hdr_TE_extract(FILE *fp, Imrect *im)
153 {
154   float     *TE;
155   int        i;
156   char       temp[128];
157 
158   TE = (float *)ralloc(sizeof(float));
159   
160   for (i = 0; i < 33; i++)
161                 fgets(temp, 64, fp);
162   fgets(temp, 64, fp);  /*i=33 is te */
163   if (sscanf(temp, "%f", TE) == EOF)
164     return(false);
165 
166   im->props = proplist_rm(im->props, TE_DATA);
167   im->props = proplist_addifnp(im->props, (void *)TE, TE_DATA, rfree, false);
168  
169   return (true);
170 }
171 
172 
173 Bool      mip_hdr_dynstimes_extract(FILE *fp, Imrect *im)
174 {
175   float     *times;
176   int        i, total;
177   char       temp[128];
178 
179   for (i = 0; i < 151; i++)
180                 fgets(temp, 64, fp);
181 
182         fgets(temp, 64, fp); /* i=151 is noslices */
183   if (sscanf(temp, "%d", &total) == EOF)
184     return(false);
185 
186   rewind(fp); 
187   times = fvector_alloc(0, total);
188 
189   for (i = 0; i < 57; i++)
190                 fgets(temp, 64, fp);
191 
192   for (i = 0; i < total; i++)
193       fscanf(fp, "%f\\", &(times[i]));
194 
195   im->props = proplist_rm(im->props, DYNSTIME);
196   im->props = proplist_addifnp(im->props, (void *)times, DYNSTIME, rfree, false);
197  
198   return(true);
199 }
200 
201 
202 
203 Bool    mip_hdrinfo_extract(Sequence *seq, void (*hdrextract_func))
204 {
205   List  *store = (List *)get_start_el();
206   Bool     status = false, success = true ;
207   FILE    *fp = NULL;
208   int      i;
209 
210   if ((fp = fopen_2(seq->filename, "rb")) == NULL)
211     return(success);
212 
213   for(i = (seq->seq_end); i >= seq->seq_start; i--)
214     {
215       if ((store == NULL) || (store->to == NULL))
216         continue;
217       status = ((Bool (*) ())hdrextract_func)(fp, (Imrect *)(store->to));
218       if (!status)
219         success = status;
220       store = store->next;
221       rewind(fp);
222     }
223 
224   fclose_2(fp, seq->filename);
225   return(success);
226 }
227 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.