nifti1_io.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /** \file nifti1_io.h
  2. \brief Data structures for using nifti1_io API.
  3. - Written by Bob Cox, SSCC NIMH
  4. - Revisions by Rick Reynolds, SSCC NIMH
  5. */
  6. #ifndef _NIFTI_IO_HEADER_
  7. #define _NIFTI_IO_HEADER_
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <math.h>
  12. #include <ctype.h>
  13. #ifndef DONT_INCLUDE_ANALYZE_STRUCT
  14. #define DONT_INCLUDE_ANALYZE_STRUCT /*** not needed herein ***/
  15. #endif
  16. #include "nifti1.h" /*** NIFTI-1 header specification ***/
  17. #include <znzlib.h>
  18. /*=================*/
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /*=================*/
  23. /*****===================================================================*****/
  24. /***** File nifti1_io.h == Declarations for nifti1_io.c *****/
  25. /*****...................................................................*****/
  26. /***** This code is released to the public domain. *****/
  27. /*****...................................................................*****/
  28. /***** Author: Robert W Cox, SSCC/DIRP/NIMH/NIH/DHHS/USA/EARTH *****/
  29. /***** Date: August 2003 *****/
  30. /*****...................................................................*****/
  31. /***** Neither the National Institutes of Health (NIH), nor any of its *****/
  32. /***** employees imply any warranty of usefulness of this software for *****/
  33. /***** any purpose, and do not assume any liability for damages, *****/
  34. /***** incidental or otherwise, caused by any use of this document. *****/
  35. /*****===================================================================*****/
  36. /*
  37. Modified by: Mark Jenkinson (FMRIB Centre, University of Oxford, UK)
  38. Date: July/August 2004
  39. Mainly adding low-level IO and changing things to allow gzipped files
  40. to be read and written
  41. Full backwards compatability should have been maintained
  42. Modified by: Rick Reynolds (SSCC/DIRP/NIMH, National Institutes of Health)
  43. Date: December 2004
  44. Modified and added many routines for I/O.
  45. */
  46. /********************** Some sample data structures **************************/
  47. typedef struct { /** 4x4 matrix struct **/
  48. float m[4][4] ;
  49. } mat44 ;
  50. typedef struct { /** 3x3 matrix struct **/
  51. float m[3][3] ;
  52. } mat33 ;
  53. /*...........................................................................*/
  54. /*! \enum analyze_75_orient_code
  55. * \brief Old-style analyze75 orientation
  56. * codes.
  57. */
  58. typedef enum _analyze75_orient_code {
  59. a75_transverse_unflipped = 0,
  60. a75_coronal_unflipped = 1,
  61. a75_sagittal_unflipped = 2,
  62. a75_transverse_flipped = 3,
  63. a75_coronal_flipped = 4,
  64. a75_sagittal_flipped = 5,
  65. a75_orient_unknown = 6
  66. } analyze_75_orient_code;
  67. /*! \struct nifti_image
  68. \brief High level data structure for open nifti datasets in the
  69. nifti1_io API. Note that this structure is not part of the
  70. nifti1 format definition; it is used to implement one API
  71. for reading/writing formats in the nifti1 format.
  72. */
  73. typedef struct { /*!< Image storage struct **/
  74. int ndim ; /*!< last dimension greater than 1 (1..7) */
  75. int nx ; /*!< dimensions of grid array */
  76. int ny ; /*!< dimensions of grid array */
  77. int nz ; /*!< dimensions of grid array */
  78. int nt ; /*!< dimensions of grid array */
  79. int nu ; /*!< dimensions of grid array */
  80. int nv ; /*!< dimensions of grid array */
  81. int nw ; /*!< dimensions of grid array */
  82. int dim[8] ; /*!< dim[0]=ndim, dim[1]=nx, etc. */
  83. size_t nvox ; /*!< number of voxels = nx*ny*nz*...*nw */
  84. int nbyper ; /*!< bytes per voxel, matches datatype */
  85. int datatype ; /*!< type of data in voxels: DT_* code */
  86. float dx ; /*!< grid spacings */
  87. float dy ; /*!< grid spacings */
  88. float dz ; /*!< grid spacings */
  89. float dt ; /*!< grid spacings */
  90. float du ; /*!< grid spacings */
  91. float dv ; /*!< grid spacings */
  92. float dw ; /*!< grid spacings */
  93. float pixdim[8] ; /*!< pixdim[1]=dx, etc. */
  94. float scl_slope ; /*!< scaling parameter - slope */
  95. float scl_inter ; /*!< scaling parameter - intercept */
  96. float cal_min ; /*!< calibration parameter, minimum */
  97. float cal_max ; /*!< calibration parameter, maximum */
  98. int qform_code ; /*!< codes for (x,y,z) space meaning */
  99. int sform_code ; /*!< codes for (x,y,z) space meaning */
  100. int freq_dim ; /*!< indexes (1,2,3, or 0) for MRI */
  101. int phase_dim ; /*!< directions in dim[]/pixdim[] */
  102. int slice_dim ; /*!< directions in dim[]/pixdim[] */
  103. int slice_code ; /*!< code for slice timing pattern */
  104. int slice_start ; /*!< index for start of slices */
  105. int slice_end ; /*!< index for end of slices */
  106. float slice_duration ; /*!< time between individual slices */
  107. /*! quaternion transform parameters
  108. [when writing a dataset, these are used for qform, NOT qto_xyz] */
  109. float quatern_b , quatern_c , quatern_d ,
  110. qoffset_x , qoffset_y , qoffset_z ,
  111. qfac ;
  112. mat44 qto_xyz ; /*!< qform: transform (i,j,k) to (x,y,z) */
  113. mat44 qto_ijk ; /*!< qform: transform (x,y,z) to (i,j,k) */
  114. mat44 sto_xyz ; /*!< sform: transform (i,j,k) to (x,y,z) */
  115. mat44 sto_ijk ; /*!< sform: transform (x,y,z) to (i,j,k) */
  116. float toffset ; /*!< time coordinate offset */
  117. int xyz_units ; /*!< dx,dy,dz units: NIFTI_UNITS_* code */
  118. int time_units ; /*!< dt units: NIFTI_UNITS_* code */
  119. int nifti_type ; /*!< 0==ANALYZE, 1==NIFTI-1 (1 file),
  120. 2==NIFTI-1 (2 files),
  121. 3==NIFTI-ASCII (1 file) */
  122. int intent_code ; /*!< statistic type (or something) */
  123. float intent_p1 ; /*!< intent parameters */
  124. float intent_p2 ; /*!< intent parameters */
  125. float intent_p3 ; /*!< intent parameters */
  126. char intent_name[16] ; /*!< optional description of intent data */
  127. char descrip[80] ; /*!< optional text to describe dataset */
  128. char aux_file[24] ; /*!< auxiliary filename */
  129. char *fname ; /*!< header filename (.hdr or .nii) */
  130. char *iname ; /*!< image filename (.img or .nii) */
  131. int iname_offset ; /*!< offset into iname where data starts */
  132. int swapsize ; /*!< swap unit in image data (might be 0) */
  133. int byteorder ; /*!< byte order on disk (MSB_ or LSB_FIRST) */
  134. void *data ; /*!< pointer to data: nbyper*nvox bytes */
  135. int num_ext ; /*!< number of extensions in ext_list */
  136. nifti1_extension * ext_list ; /*!< array of extension structs (with data) */
  137. analyze_75_orient_code analyze75_orient; /*!< for old analyze files, orient */
  138. } nifti_image ;
  139. /* struct for return from nifti_image_read_bricks() */
  140. typedef struct {
  141. int nbricks; /* the number of allocated pointers in 'bricks' */
  142. size_t bsize; /* the length of each data block, in bytes */
  143. void ** bricks; /* array of pointers to data blocks */
  144. } nifti_brick_list;
  145. /*****************************************************************************/
  146. /*------------------ NIfTI version of ANALYZE 7.5 structure -----------------*/
  147. /* (based on fsliolib/dbh.h, but updated for version 7.5) */
  148. typedef struct {
  149. /* header info fields - describes the header overlap with NIfTI */
  150. /* ------------------ */
  151. int sizeof_hdr; /* 0 + 4 same */
  152. char data_type[10]; /* 4 + 10 same */
  153. char db_name[18]; /* 14 + 18 same */
  154. int extents; /* 32 + 4 same */
  155. short int session_error; /* 36 + 2 same */
  156. char regular; /* 38 + 1 same */
  157. char hkey_un0; /* 39 + 1 40 bytes */
  158. /* image dimension fields - describes image sizes */
  159. short int dim[8]; /* 0 + 16 same */
  160. short int unused8; /* 16 + 2 intent_p1... */
  161. short int unused9; /* 18 + 2 ... */
  162. short int unused10; /* 20 + 2 intent_p2... */
  163. short int unused11; /* 22 + 2 ... */
  164. short int unused12; /* 24 + 2 intent_p3... */
  165. short int unused13; /* 26 + 2 ... */
  166. short int unused14; /* 28 + 2 intent_code */
  167. short int datatype; /* 30 + 2 same */
  168. short int bitpix; /* 32 + 2 same */
  169. short int dim_un0; /* 34 + 2 slice_start */
  170. float pixdim[8]; /* 36 + 32 same */
  171. float vox_offset; /* 68 + 4 same */
  172. float funused1; /* 72 + 4 scl_slope */
  173. float funused2; /* 76 + 4 scl_inter */
  174. float funused3; /* 80 + 4 slice_end, */
  175. /* slice_code, */
  176. /* xyzt_units */
  177. float cal_max; /* 84 + 4 same */
  178. float cal_min; /* 88 + 4 same */
  179. float compressed; /* 92 + 4 slice_duration */
  180. float verified; /* 96 + 4 toffset */
  181. int glmax,glmin; /* 100 + 8 108 bytes */
  182. /* data history fields - optional */
  183. char descrip[80]; /* 0 + 80 same */
  184. char aux_file[24]; /* 80 + 24 same */
  185. char orient; /* 104 + 1 NO GOOD OVERLAP */
  186. char originator[10]; /* 105 + 10 FROM HERE DOWN... */
  187. char generated[10]; /* 115 + 10 */
  188. char scannum[10]; /* 125 + 10 */
  189. char patient_id[10]; /* 135 + 10 */
  190. char exp_date[10]; /* 145 + 10 */
  191. char exp_time[10]; /* 155 + 10 */
  192. char hist_un0[3]; /* 165 + 3 */
  193. int views; /* 168 + 4 */
  194. int vols_added; /* 172 + 4 */
  195. int start_field; /* 176 + 4 */
  196. int field_skip; /* 180 + 4 */
  197. int omax, omin; /* 184 + 8 */
  198. int smax, smin; /* 192 + 8 200 bytes */
  199. } nifti_analyze75; /* total: 348 bytes */
  200. /*****************************************************************************/
  201. /*--------------- Prototypes of functions defined in this file --------------*/
  202. char const * nifti_datatype_string ( int dt ) ;
  203. char const *nifti_units_string ( int uu ) ;
  204. char const *nifti_intent_string ( int ii ) ;
  205. char const *nifti_xform_string ( int xx ) ;
  206. char const *nifti_slice_string ( int ss ) ;
  207. char const *nifti_orientation_string( int ii ) ;
  208. int nifti_is_inttype( int dt ) ;
  209. mat44 nifti_mat44_inverse( mat44 R ) ;
  210. mat33 nifti_mat33_inverse( mat33 R ) ;
  211. mat33 nifti_mat33_polar ( mat33 A ) ;
  212. float nifti_mat33_rownorm( mat33 A ) ;
  213. float nifti_mat33_colnorm( mat33 A ) ;
  214. float nifti_mat33_determ ( mat33 R ) ;
  215. mat33 nifti_mat33_mul ( mat33 A , mat33 B ) ;
  216. void nifti_swap_2bytes ( size_t n , void *ar ) ;
  217. void nifti_swap_4bytes ( size_t n , void *ar ) ;
  218. void nifti_swap_8bytes ( size_t n , void *ar ) ;
  219. void nifti_swap_16bytes( size_t n , void *ar ) ;
  220. void nifti_swap_Nbytes ( size_t n , int siz , void *ar ) ;
  221. int nifti_datatype_is_valid (int dtype, int for_nifti);
  222. int nifti_datatype_from_string(const char * name);
  223. const char * nifti_datatype_to_string (int dtype);
  224. int nifti_get_filesize( const char *pathname ) ;
  225. void swap_nifti_header ( struct nifti_1_header *h , int is_nifti ) ;
  226. void old_swap_nifti_header( struct nifti_1_header *h , int is_nifti );
  227. int nifti_swap_as_analyze( nifti_analyze75 *h );
  228. /* main read/write routines */
  229. nifti_image *nifti_image_read_bricks(const char *hname , int nbricks,
  230. const int *blist, nifti_brick_list * NBL);
  231. int nifti_image_load_bricks(nifti_image *nim , int nbricks,
  232. const int *blist, nifti_brick_list * NBL);
  233. void nifti_free_NBL( nifti_brick_list * NBL );
  234. nifti_image *nifti_image_read ( const char *hname , int read_data ) ;
  235. int nifti_image_load ( nifti_image *nim ) ;
  236. void nifti_image_unload ( nifti_image *nim ) ;
  237. void nifti_image_free ( nifti_image *nim ) ;
  238. int nifti_read_collapsed_image( nifti_image * nim, const int dims [8],
  239. void ** data );
  240. int nifti_read_subregion_image( nifti_image * nim,
  241. const int *start_index, const int *region_size,
  242. void ** data );
  243. void nifti_image_write ( nifti_image * nim ) ;
  244. void nifti_image_write_bricks(nifti_image * nim,
  245. const nifti_brick_list * NBL);
  246. void nifti_image_infodump( const nifti_image * nim ) ;
  247. void nifti_disp_lib_hist( void ) ; /* to display library history */
  248. void nifti_disp_lib_version( void ) ; /* to display library version */
  249. int nifti_disp_matrix_orient( const char * mesg, mat44 mat );
  250. int nifti_disp_type_list( int which );
  251. char * nifti_image_to_ascii ( const nifti_image * nim ) ;
  252. nifti_image *nifti_image_from_ascii( const char * str, int * bytes_read ) ;
  253. size_t nifti_get_volsize(const nifti_image *nim) ;
  254. /* basic file operations */
  255. int nifti_set_filenames(nifti_image * nim, const char * prefix, int check,
  256. int set_byte_order);
  257. char * nifti_makehdrname (const char * prefix, int nifti_type, int check,
  258. int comp);
  259. char * nifti_makeimgname (const char * prefix, int nifti_type, int check,
  260. int comp);
  261. int is_nifti_file (const char *hname);
  262. char * nifti_find_file_extension(const char * name);
  263. int nifti_is_complete_filename(const char* fname);
  264. int nifti_validfilename(const char* fname);
  265. int disp_nifti_1_header(const char * info, const nifti_1_header * hp ) ;
  266. void nifti_set_debug_level( int level ) ;
  267. void nifti_set_skip_blank_ext( int skip ) ;
  268. void nifti_set_allow_upper_fext( int allow ) ;
  269. int valid_nifti_brick_list(nifti_image * nim , int nbricks,
  270. const int * blist, int disp_error);
  271. /* znzFile operations */
  272. znzFile nifti_image_open(const char * hname, const char * opts, nifti_image ** nim);
  273. znzFile nifti_image_write_hdr_img(nifti_image *nim, int write_data,
  274. const char* opts);
  275. znzFile nifti_image_write_hdr_img2( nifti_image *nim , int write_opts ,
  276. const char* opts, znzFile imgfile, const nifti_brick_list * NBL);
  277. size_t nifti_read_buffer(znzFile fp, void* dataptr, size_t ntot,
  278. nifti_image *nim);
  279. int nifti_write_all_data(znzFile fp, nifti_image * nim,
  280. const nifti_brick_list * NBL);
  281. size_t nifti_write_buffer(znzFile fp, const void * buffer, size_t numbytes);
  282. nifti_image *nifti_read_ascii_image(znzFile fp, char *fname, int flen,
  283. int read_data);
  284. znzFile nifti_write_ascii_image(nifti_image *nim, const nifti_brick_list * NBL,
  285. const char * opts, int write_data, int leave_open);
  286. void nifti_datatype_sizes( int datatype , int *nbyper, int *swapsize ) ;
  287. void nifti_mat44_to_quatern( mat44 R ,
  288. float *qb, float *qc, float *qd,
  289. float *qx, float *qy, float *qz,
  290. float *dx, float *dy, float *dz, float *qfac ) ;
  291. mat44 nifti_quatern_to_mat44( float qb, float qc, float qd,
  292. float qx, float qy, float qz,
  293. float dx, float dy, float dz, float qfac );
  294. mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 ,
  295. float r21, float r22, float r23 ,
  296. float r31, float r32, float r33 ) ;
  297. int nifti_short_order(void) ; /* CPU byte order */
  298. /* Orientation codes that might be returned from nifti_mat44_to_orientation().*/
  299. #define NIFTI_L2R 1 /* Left to Right */
  300. #define NIFTI_R2L 2 /* Right to Left */
  301. #define NIFTI_P2A 3 /* Posterior to Anterior */
  302. #define NIFTI_A2P 4 /* Anterior to Posterior */
  303. #define NIFTI_I2S 5 /* Inferior to Superior */
  304. #define NIFTI_S2I 6 /* Superior to Inferior */
  305. void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) ;
  306. /*--------------------- Low level IO routines ------------------------------*/
  307. char * nifti_findhdrname (const char* fname);
  308. char * nifti_findimgname (const char* fname , int nifti_type);
  309. int nifti_is_gzfile (const char* fname);
  310. char * nifti_makebasename(const char* fname);
  311. /* other routines */
  312. struct nifti_1_header nifti_convert_nim2nhdr(const nifti_image* nim);
  313. nifti_1_header * nifti_make_new_header(const int arg_dims[], int arg_dtype);
  314. nifti_1_header * nifti_read_header(const char *hname, int *swapped, int check);
  315. nifti_image * nifti_copy_nim_info(const nifti_image * src);
  316. nifti_image * nifti_make_new_nim(const int dims[], int datatype,
  317. int data_fill);
  318. nifti_image * nifti_simple_init_nim(void);
  319. nifti_image * nifti_convert_nhdr2nim(struct nifti_1_header nhdr,
  320. const char * fname);
  321. int nifti_hdr_looks_good (const nifti_1_header * hdr);
  322. int nifti_is_valid_datatype (int dtype);
  323. int nifti_is_valid_ecode (int ecode);
  324. int nifti_nim_is_valid (nifti_image * nim, int complain);
  325. int nifti_nim_has_valid_dims (nifti_image * nim, int complain);
  326. int is_valid_nifti_type (int nifti_type);
  327. int nifti_test_datatype_sizes (int verb);
  328. int nifti_type_and_names_match (nifti_image * nim, int show_warn);
  329. int nifti_update_dims_from_array(nifti_image * nim);
  330. void nifti_set_iname_offset (nifti_image *nim);
  331. int nifti_set_type_from_names (nifti_image * nim);
  332. int nifti_add_extension(nifti_image * nim, const char * data, int len,
  333. int ecode );
  334. int nifti_compiled_with_zlib (void);
  335. int nifti_copy_extensions (nifti_image *nim_dest,const nifti_image *nim_src);
  336. int nifti_free_extensions (nifti_image *nim);
  337. int * nifti_get_intlist (int nvals , const char *str);
  338. char * nifti_strdup (const char *str);
  339. int valid_nifti_extensions(const nifti_image *nim);
  340. /*-------------------- Some C convenience macros ----------------------------*/
  341. /* NIfTI-1.1 extension codes:
  342. see http://nifti.nimh.nih.gov/nifti-1/documentation/faq#Q21 */
  343. #define NIFTI_ECODE_IGNORE 0 /* changed from UNKNOWN, 29 June 2005 */
  344. #define NIFTI_ECODE_DICOM 2 /* intended for raw DICOM attributes */
  345. #define NIFTI_ECODE_AFNI 4 /* Robert W Cox: rwcox@nih.gov
  346. https://afni.nimh.nih.gov/afni */
  347. #define NIFTI_ECODE_COMMENT 6 /* plain ASCII text only */
  348. #define NIFTI_ECODE_XCEDE 8 /* David B Keator: dbkeator@uci.edu
  349. http://www.nbirn.net/Resources
  350. /Users/Applications/
  351. /xcede/index.htm */
  352. #define NIFTI_ECODE_JIMDIMINFO 10 /* Mark A Horsfield:
  353. mah5@leicester.ac.uk
  354. http://someplace/something */
  355. #define NIFTI_ECODE_WORKFLOW_FWDS 12 /* Kate Fissell: fissell@pitt.edu
  356. http://kraepelin.wpic.pitt.edu
  357. /~fissell/NIFTI_ECODE_WORKFLOW_FWDS
  358. /NIFTI_ECODE_WORKFLOW_FWDS.html */
  359. #define NIFTI_ECODE_FREESURFER 14 /* http://surfer.nmr.mgh.harvard.edu */
  360. #define NIFTI_ECODE_PYPICKLE 16 /* embedded Python objects
  361. http://niftilib.sourceforge.net
  362. /pynifti */
  363. /* LONI MiND codes: http://www.loni.ucla.edu/twiki/bin/view/Main/MiND */
  364. #define NIFTI_ECODE_MIND_IDENT 18 /* Vishal Patel: vishal.patel@ucla.edu*/
  365. #define NIFTI_ECODE_B_VALUE 20
  366. #define NIFTI_ECODE_SPHERICAL_DIRECTION 22
  367. #define NIFTI_ECODE_DT_COMPONENT 24
  368. #define NIFTI_ECODE_SHC_DEGREEORDER 26 /* end LONI MiND codes */
  369. #define NIFTI_ECODE_VOXBO 28 /* Dan Kimberg: www.voxbo.org */
  370. #define NIFTI_ECODE_CARET 30 /* John Harwell: john@brainvis.wustl.edu
  371. http://brainvis.wustl.edu/wiki
  372. /index.php/Caret:Documentation
  373. :CaretNiftiExtension */
  374. #define NIFTI_ECODE_CIFTI 32 /* CIFTI-2_Main_FINAL_1March2014.pdf */
  375. #define NIFTI_ECODE_VARIABLE_FRAME_TIMING 34
  376. /* 36 is currently unassigned, waiting on NIFTI_ECODE_AGILENT_PROCPAR */
  377. #define NIFTI_ECODE_EVAL 38 /* Munster University Hospital */
  378. /* http://www.mathworks.com/matlabcentral/fileexchange/42997-dicom-to-nifti-converter */
  379. #define NIFTI_ECODE_MATLAB 40 /* MATLAB extension */
  380. /* Quantiphyse extension
  381. https://quantiphyse.readthedocs.io/en/latest/advanced/nifti_extension.html*/
  382. #define NIFTI_ECODE_QUANTIPHYSE 42 /* Quantiphyse extension */
  383. /* Magnetic Resonance Spectroscopy (MRS)
  384. link to come... */
  385. #define NIFTI_ECODE_MRS 44 /* MRS extension */
  386. #define NIFTI_MAX_ECODE 44 /******* maximum extension code *******/
  387. /* nifti_type file codes */
  388. #define NIFTI_FTYPE_ANALYZE 0
  389. #define NIFTI_FTYPE_NIFTI1_1 1
  390. #define NIFTI_FTYPE_NIFTI1_2 2
  391. #define NIFTI_FTYPE_ASCII 3
  392. #define NIFTI_MAX_FTYPE 3 /* this should match the maximum code */
  393. /*------------------------------------------------------------------------*/
  394. /*-- the rest of these apply only to nifti1_io.c, check for _NIFTI1_IO_C_ */
  395. /* Feb 9, 2005 [rickr] */
  396. #ifdef _NIFTI1_IO_C_
  397. typedef struct {
  398. int debug; /*!< debug level for status reports */
  399. int skip_blank_ext; /*!< skip extender if no extensions */
  400. int allow_upper_fext; /*!< allow uppercase file extensions */
  401. } nifti_global_options;
  402. typedef struct {
  403. int type; /* should match the NIFTI_TYPE_ #define */
  404. int nbyper; /* bytes per value, matches nifti_image */
  405. int swapsize; /* bytes per swap piece, matches nifti_image */
  406. char const * const name; /* text string to match #define */
  407. } nifti_type_ele;
  408. #undef LNI_FERR /* local nifti file error, to be compact and repetative */
  409. #define LNI_FERR(func,msg,file) \
  410. fprintf(stderr,"** ERROR (%s): %s '%s'\n",func,msg,file)
  411. #undef swap_2
  412. #undef swap_4
  413. #define swap_2(s) nifti_swap_2bytes(1,&(s)) /* s: 2-byte short; swap in place */
  414. #define swap_4(v) nifti_swap_4bytes(1,&(v)) /* v: 4-byte value; swap in place */
  415. /***** isfinite() is a C99 macro, which is
  416. present in many C implementations already *****/
  417. #undef IS_GOOD_FLOAT
  418. #undef FIXED_FLOAT
  419. #ifdef isfinite /* use isfinite() to check floats/doubles for goodness */
  420. # define IS_GOOD_FLOAT(x) isfinite(x) /* check if x is a "good" float */
  421. # define FIXED_FLOAT(x) (isfinite(x) ? (x) : 0) /* fixed if bad */
  422. #else
  423. # define IS_GOOD_FLOAT(x) 1 /* don't check it */
  424. # define FIXED_FLOAT(x) (x) /* don't fix it */
  425. #endif
  426. #undef ASSIF /* assign v to *p, if possible */
  427. #define ASSIF(p,v) if( (p)!=NULL ) *(p) = (v)
  428. #undef MSB_FIRST
  429. #undef LSB_FIRST
  430. #undef REVERSE_ORDER
  431. #define LSB_FIRST 1
  432. #define MSB_FIRST 2
  433. #define REVERSE_ORDER(x) (3-(x)) /* convert MSB_FIRST <--> LSB_FIRST */
  434. #define LNI_MAX_NIA_EXT_LEN 100000 /* consider a longer extension invalid */
  435. #endif /* _NIFTI1_IO_C_ section */
  436. /*------------------------------------------------------------------------*/
  437. /*=================*/
  438. #ifdef __cplusplus
  439. }
  440. #endif
  441. /*=================*/
  442. #endif /* _NIFTI_IO_HEADER_ */