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

Linux Cross Reference
Tina6/tina-libs/tina/file/fileAni_io.c

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/file/fileAni_io.c,v $
 37  * Date    :  $Date: 2009/03/19 18:36:26 $
 38  * Version :  $Revision: 1.9 $
 39  * CVS Id  :  $Id: fileAni_io.c,v 1.9 2009/03/19 18:36:26 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes   :
 44  *
 45  *  Functions to read/write RAW image files
 46  *
 47  *********
 48 */
 49 
 50 #include "fileAni_io.h"
 51 #include "fileThirdParty_air.h"
 52 
 53 #if HAVE_CONFIG_H
 54 #include <config.h>
 55 #endif
 56 
 57 #include <stdio.h>
 58 /*
 59 #include <string.h>
 60 */
 61 #include <limits.h>
 62 #include <tina/sys/sysPro.h>
 63 #include <tina/sys/sysDef.h>
 64 #include <tina/image/imgPro.h>
 65 #include <tina/image/imgDef.h>
 66 #include <tina/math/mathDef.h>
 67 #include <tina/math/mathPro.h>
 68 #include <tina/file/file_AniDef.h>
 69 #include <tina/file/file_NemaPro.h>
 70 #include <tina/file/file_UtilPro.h>
 71 #include <tina/file/fileAni_read_header.h>
 72 
 73 
 74 static float x_s=1.0, y_s = 1.0, z_s=1.0;               /* static data! */
 75 static int  tina_ani_byte_reverse;                              /* static data! */
 76 
 77 int     get_tina_ani_byte_reverse()
 78 {
 79         return(tina_ani_byte_reverse);
 80 }
 81 
 82 void set_tina_ani_byte_reverse(int v)
 83 {
 84         tina_ani_byte_reverse = v;
 85 }
 86 
 87 
 88 /* Create an imrect and read an image file called 'pathname' into it.
 89  * Open file, read data and close file. On failure, give error message
 90  * and return NULL. */
 91 Imrect *ani_read_image(char *pathname, int slice)
 92 {
 93     Imrect *imrect = NULL;
 94     struct key_info         dimensions;
 95     FILE                    *fp_hdr=NULL;
 96     FILE                    *fp_img=NULL;
 97     int                     dummy[8];
 98     Vartype                 new_vtype;
 99     Sequence * seq = (Sequence *)seq_get_current(); 
100 
101     tina_ani_byte_reverse = 0;
102     ani_read_header(pathname, &fp_hdr, &fp_img, &dimensions, -1, dummy);
103     if(fp_hdr == NULL) return(NULL);
104     fclose(fp_hdr);
105     /*
106       format("bits/pixel=%i\n",dimensions.bits);
107     */
108     if (dimensions.bits==32) 
109     {
110         new_vtype = int_v;
111     }
112     else if (dimensions.bits==16) 
113     {
114         new_vtype = short_v;
115     }
116     else if (dimensions.bits==8) 
117     {
118         new_vtype = uchar_v;
119     }
120     else
121     {
122         format("Unsupported bits/pixel\n");
123         return NULL;
124     }
125 /*
126     format("x_dim=%i ",dimensions.x_dim);
127     format("y_dim=%i ",dimensions.y_dim);
128     format("z_dim=%i\n",dimensions.z_dim);
129     format("x_s=%e ",dimensions.x_size);
130     format("y_s=%e ",dimensions.y_size);
131     format("z_s=%e\n",dimensions.z_size);
132 */
133     x_s = dimensions.x_size;
134     y_s = dimensions.y_size;
135     z_s = dimensions.z_size;
136 
137     ani_read_header(pathname, &fp_hdr, &fp_img, &dimensions, slice, dummy);
138 
139     if (fp_img)
140     {
141         Imregion *imregion = NULL;
142 
143         imrect = im_alloc(dimensions.y_dim, dimensions.x_dim, imregion, (Vartype) new_vtype);
144         if (fread_imrect_data(imrect, fp_img, pathname)==false)
145         {
146             im_free(imrect);
147             imrect = NULL;
148         }
149         else
150         {
151         if (tina_ani_byte_reverse == 1)
152           im_endian_inplace(imrect);
153 
154         seq->dim[0] = dimensions.x_size;
155         seq->dim[1] = dimensions.y_size;
156         seq->dim[2] = dimensions.z_size;
157         
158         }
159         fclose_2(fp_img, pathname);
160     }
161     return imrect;
162 }
163 
164 /*
165  *   Altered following to improve lib / tool separation - GAB 19 Feb 2003
166  *   The original ani_write_image has become 3 functions -  to open a stream, 
167  *   write image data and close the stream.
168  */
169 FILE *ani_write_openfile(char *filename, struct key_info *dimensions, Imrect *current, 
170                            Sequence *seq) 
171 {
172     int         new_type;
173     Imregion   *region=NULL;
174     char        comment[80];
175     FILE       *stream;
176 
177     format("All Analyze volumes start at z=0\n");
178     sprintf(comment, "Tina generated processed file, some data fields may be missing");
179     error(comment, warning);
180 
181     region = current->region;
182     new_type = current->vtype;
183     if (new_type == int_v) dimensions->bits = 32;
184     else if (new_type == short_v) dimensions->bits = 16;
185     else if (new_type == ushort_v) dimensions->bits = 16;
186     else if (new_type == uchar_v) dimensions->bits = 8;
187     else 
188     {
189        sprintf(comment, " data type not supported for output ");
190        error(comment, warning);
191        return NULL;
192     }
193 
194     dimensions->x_dim = region->ux - region->lx; 
195     dimensions->y_dim = region->uy - region->ly;
196     dimensions->x_size = seq->dim[0];
197     dimensions->y_size = seq->dim[1];
198     dimensions->z_size = seq->dim[2];
199 
200     stream = fopen_2(filename, "wb");
201     
202     /* Tool/lib separation had led to a problem here: 
203     revision 1.7 of this file was broken PAB 11/2/2005*/
204     
205     return stream;
206 }
207 
208 void ani_write_imagedata(Imrect *current, FILE *stream, char *filename) 
209 {
210 /* 
211   maintain BIG_ENDIAN format when writing
212   swap - write - swap
213   a.lacey@man.ac.uk
214 */
215 #ifndef BIG_ENDIAN_ARCHITECTURE
216     im_endian_inplace(current);
217     fwrite_imrect_data(current, stream, filename); 
218     im_endian_inplace(current);
219 #else
220     fwrite_imrect_data(current, stream, filename); 
221 #endif
222 }
223 
224 
225 void ani_write_closefile(char *filename, FILE *stream) 
226 {
227     (void) fclose_2(stream,  filename); 
228 }
229 

~ [ 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.