diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0ad7fd88626..2a8aaa7c5fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -98,8 +98,10 @@ repos: entry: 'Utilities/Hooks/kw-commit-msg' language: system stages: [commit-msg] + exclude: "\\/ThirdParty\\/" - id: kw-pre-commit name: 'kw-pre-commit' entry: 'Utilities/Hooks/kw-pre-commit' language: system stages: [pre-commit] + exclude: "\\/ThirdParty\\/" diff --git a/Modules/ThirdParty/NIFTI/src/nifti/CMakeLists.txt b/Modules/ThirdParty/NIFTI/src/nifti/CMakeLists.txt index e1a38819411..cc62797caea 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/CMakeLists.txt +++ b/Modules/ThirdParty/NIFTI/src/nifti/CMakeLists.txt @@ -54,6 +54,28 @@ endif() # current build behavior option( BUILD_SHARED_LIBS "Toggle building shared libraries." OFF) +# Add options to mimic FSL features, Can manually specify -DFSLSTYLE:BOOL=ON for parity support with makefile +if(NOT FSLSTYLE) + # If FSL_STYLE is not defined, then + option( FSLSTYLE_NAME_CONFLICTS "FSL behavior for name conflicts (generate error if both img.nii and img.nii.gz exists)" OFF) + option( FSLSTYLE_PIGZ_SUPPORT "PIGZ: Use PIGZ parallel compression if environment includes AFNI_COMPRESSOR=PIGZ" OFF) + option( FSLSTYLE_REJECT_COMPLEX "REJECT_COMPLEX: Generate error if file is complex datatype." OFF) +else() + set(FSLSTYLE_NAME_CONFLICTS ON CACHE BOOL "FSL behavior for name conflicts (ambiguous files img.nii and img.nii.gz is an error)" FORCE) + set(FSLSTYLE_PIGZ_SUPPORT ON CACHE BOOL "PIGZ support" FORCE) + set(FSLSTYLE_REJECT_COMPLEX ON CACHE BOOL "Reject complex images." FORCE) +endif() + +if(FSLSTYLE_NAME_CONFLICTS) + ADD_DEFINITIONS(-DFSLSTYLE) +endif() +if(FSLSTYLE_PIGZ_SUPPORT) + ADD_DEFINITIONS(-DPIGZ) +endif() +if(FSLSTYLE_REJECT_COMPLEX) + ADD_DEFINITIONS(-DREJECT_COMPLEX) +endif() + # Include executables as part of the build option(NIFTI_BUILD_APPLICATIONS "Build various utility tools" ON) mark_as_advanced(NIFTI_BUILD_APPLICATIONS) @@ -79,6 +101,7 @@ set_if_not_defined(NIFTI_INSTALL_ARCHIVE_DIR ${NIFTI_INSTALL_LIBRARY_DIR}) set_if_not_defined(NIFTI_INSTALL_INCLUDE_DIR include/nifti) set_if_not_defined(NIFTI_INSTALL_MAN_DIR share/man/man1) set_if_not_defined(NIFTI_INSTALL_DOC_DIR share/doc/${PROJECT_NAME}) +set_if_not_defined(NIFTI_INSTALL_MODULE_DIR share/cmake/${PACKAGE_NAME}) set_if_not_defined(NIFTI_ZLIB_LIBRARIES "") set_if_not_defined(ZNZ_COMPILE_DEF "") if(NOT NIFTI_ZLIB_LIBRARIES) # If using a custom zlib library, skip the find package @@ -141,9 +164,11 @@ if (NIFTI_BUILD_TESTING ) include(FetchContent) # fetch data a configure time to simplify tests # If new or changed data is needed, add that data to the https://github.com/NIFTI-Imaging/nifti-test-data repo # make a new release, and then update the URL and hash (shasum -a 256 ). + cmake_policy(SET CMP0169 OLD) FetchContent_Declare( fetch_testing_data URL https://github.com/NIFTI-Imaging/nifti-test-data/archive/v3.0.2.tar.gz URL_HASH SHA256=5dafec078151018da7aaf3c941bd31f246f590bc34fa3fef29ce77a773db16a6 + DOWNLOAD_EXTRACT_TIMESTAMP TRUE ) FetchContent_GetProperties(fetch_testing_data) if(NOT fetch_testing_data_POPULATED) @@ -243,7 +268,7 @@ if(NIFTI_INSTALL_EXPORT_NAME STREQUAL "NIFTITargets") # NIFTI libraries into an external project include(CMakePackageConfigHelpers) set(CONFIG_SETUP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}) - set(ConfigPackageLocation share/cmake/${PACKAGE_NAME}) + set(ConfigPackageLocation ${NIFTI_INSTALL_MODULE_DIR}) write_basic_package_version_file( ${CONFIG_SETUP_DIR}/${PACKAGE_NAME}ConfigVersion.cmake diff --git a/Modules/ThirdParty/NIFTI/src/nifti/README.md b/Modules/ThirdParty/NIFTI/src/nifti/README.md index 0796f3eeb69..4dc5e21bffa 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/README.md +++ b/Modules/ThirdParty/NIFTI/src/nifti/README.md @@ -19,7 +19,7 @@ and, to contribute changes and enhancements to niftilib. Please contact us if you would like to contribute additional functionality to the i/o library. The main webpage for this project is [hosted on github](https://nifti-imaging.github.io/). -This web site provde historical information. Additional information from the [NIFTI DFWG](http://nifti.nimh.nih.gov) +This web site provides historical information. Additional information from the [NIFTI DFWG](http://nifti.nimh.nih.gov) The testing dashboard for monitoring the health of the libraries is at [my.cdash.org](https://my.cdash.org/index.php?project=nifti_clib). diff --git a/Modules/ThirdParty/NIFTI/src/nifti/cmake/nifti_macros.cmake b/Modules/ThirdParty/NIFTI/src/nifti/cmake/nifti_macros.cmake index f7fc9105710..8b1fe6ddcd6 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/cmake/nifti_macros.cmake +++ b/Modules/ThirdParty/NIFTI/src/nifti/cmake/nifti_macros.cmake @@ -113,7 +113,7 @@ function(install_nifti_target target_name) elseif(CMAKE_VER_AT_LEAST_3_13 AND NOT IS_PROJECT_DIR) # CMake >=3.13 has support for referencing targets in parent scopes of the # one in which the target is defined. This enables a central management of - # the installation process, along with installating an target export set. + # the installation process, along with installing an target export set. # No installation occurs from the directory in which the target is defined return() endif() @@ -133,6 +133,9 @@ function(install_nifti_target target_name) PUBLIC_HEADER DESTINATION ${NIFTI_INSTALL_INCLUDE_DIR} COMPONENT Development + PRIVATE_HEADER + DESTINATION ${NIFTI_INSTALL_INCLUDE_DIR} + COMPONENT Development INCLUDES DESTINATION ${NIFTI_INSTALL_INCLUDE_DIR} ) diff --git a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/CMakeLists.txt b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/CMakeLists.txt index aeee59f51ef..09d522d263e 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/CMakeLists.txt +++ b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/CMakeLists.txt @@ -17,6 +17,8 @@ if(BUILD_SHARED_LIBS) VERSION ${NIFTI_VERSION} SOVERSION ${NIFTI_MAJOR_VERSION} ) + target_compile_definitions(${NIFTI_NIFTILIB_NAME} PRIVATE NIFTIIO_BUILD_SHARED) + target_compile_definitions(${NIFTI_NIFTILIB_NAME} INTERFACE NIFTIIO_USE_SHARED) endif() install_nifti_target(${NIFTI_NIFTILIB_NAME}) diff --git a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c index da90cae25b4..38eb2e732e1 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c +++ b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c @@ -802,7 +802,7 @@ void nifti_free_NBL( nifti_brick_list * NBL ) if( NBL->bricks ){ for( c = 0; c < NBL->nbricks; c++ ) - if( NBL->bricks[c] ) free(NBL->bricks[c]); + free(NBL->bricks[c]); free(NBL->bricks); NBL->bricks = NULL; } @@ -970,8 +970,8 @@ static int nifti_copynsort(int nbricks, const int * blist, int ** slist, if( !*slist || !*sindex ){ fprintf(stderr,"** NCS: failed to alloc %d ints for sorting\n",nbricks); - if(*slist) free(*slist); /* maybe one succeeded */ - if(*sindex) free(*sindex); + free(*slist); /* maybe one succeeded */ + free(*sindex); return -1; } @@ -1172,16 +1172,15 @@ int nifti_disp_matrix_orient( const char * mesg, mat44 mat ) *//*--------------------------------------------------------------------*/ char *nifti_strdup(const char *str) { - char *dup; - if( !str ) return NULL; /* allow calls passing NULL */ - dup = (char *)malloc(strlen(str) + 1); + size_t length = strlen(str); + char *dup = (char *)malloc(length + 1); /* check for failure */ if( dup ) strcpy(dup, str); - else fprintf(stderr,"** nifti_strdup: failed to alloc %u bytes\n", - (unsigned int)strlen(str)+1); + else fprintf(stderr,"** nifti_strdup: failed to alloc %zu bytes\n", + length+1); return dup; } @@ -1485,35 +1484,35 @@ mat44 nifti_quatern_to_mat44( float qb, float qc, float qd, /* last row is always [ 0 0 0 1 ] */ - R.m[3][0]=R.m[3][1]=R.m[3][2] = 0.0f ; R.m[3][3]= 1.0f ; + R.m[3][0]=R.m[3][1]=R.m[3][2] = 0.0F ; R.m[3][3]= 1.0F ; /* compute a parameter from b,c,d */ - a = 1.0l - (b*b + c*c + d*d) ; - if( a < 1.e-7l ){ /* special case */ - a = 1.0l / sqrt(b*b+c*c+d*d) ; + a = 1.0L - (b*b + c*c + d*d) ; + if( a < 1.e-7L ){ /* special case */ + a = 1.0L / sqrt(b*b+c*c+d*d) ; b *= a ; c *= a ; d *= a ; /* normalize (b,c,d) vector */ - a = 0.0l ; /* a = 0 ==> 180 degree rotation */ + a = 0.0L ; /* a = 0 ==> 180 degree rotation */ } else{ a = sqrt(a) ; /* angle = 2*arccos(a) */ } /* load rotation matrix, including scaling factors for voxel sizes */ - xd = (dx > 0.0) ? dx : 1.0l ; /* make sure are positive */ - yd = (dy > 0.0) ? dy : 1.0l ; - zd = (dz > 0.0) ? dz : 1.0l ; + xd = (dx > 0.0) ? dx : 1.0L ; /* make sure are positive */ + yd = (dy > 0.0) ? dy : 1.0L ; + zd = (dz > 0.0) ? dz : 1.0L ; if( qfac < 0.0 ) zd = -zd ; /* left handedness? */ R.m[0][0] = (float)( (a*a+b*b-c*c-d*d) * xd) ; - R.m[0][1] = 2.0l * (b*c-a*d ) * yd ; - R.m[0][2] = 2.0l * (b*d+a*c ) * zd ; - R.m[1][0] = 2.0l * (b*c+a*d ) * xd ; + R.m[0][1] = 2.0L * (b*c-a*d ) * yd ; + R.m[0][2] = 2.0L * (b*d+a*c ) * zd ; + R.m[1][0] = 2.0L * (b*c+a*d ) * xd ; R.m[1][1] = (float)( (a*a+c*c-b*b-d*d) * yd) ; - R.m[1][2] = 2.0l * (c*d-a*b ) * zd ; - R.m[2][0] = 2.0l * (b*d-a*c ) * xd ; - R.m[2][1] = 2.0l * (c*d+a*b ) * yd ; + R.m[1][2] = 2.0L * (c*d-a*b ) * zd ; + R.m[2][0] = 2.0L * (b*d-a*c ) * xd ; + R.m[2][1] = 2.0L * (c*d+a*b ) * yd ; R.m[2][2] = (float)( (a*a+d*d-c*c-b*b) * zd) ; /* load offsets */ @@ -1574,9 +1573,9 @@ void nifti_mat44_to_quatern( mat44 R , /* if a column length is zero, patch the trouble */ - if( xd == 0.0l ){ r11 = 1.0l ; r21 = r31 = 0.0l ; xd = 1.0l ; } - if( yd == 0.0l ){ r22 = 1.0l ; r12 = r32 = 0.0l ; yd = 1.0l ; } - if( zd == 0.0l ){ r33 = 1.0l ; r13 = r23 = 0.0l ; zd = 1.0l ; } + if( xd == 0.0L ){ r11 = 1.0L ; r21 = r31 = 0.0L ; xd = 1.0L ; } + if( yd == 0.0L ){ r22 = 1.0L ; r12 = r32 = 0.0L ; yd = 1.0L ; } + if( zd == 0.0L ){ r33 = 1.0L ; r13 = r23 = 0.0L ; zd = 1.0L ; } /* assign the output lengths */ @@ -1620,42 +1619,42 @@ void nifti_mat44_to_quatern( mat44 R , +r21*r32*r13+r31*r12*r23-r31*r22*r13 ; /* should be -1 or 1 */ if( zd > 0 ){ /* proper */ - ASSIF(qfac,1.0f) ; + ASSIF(qfac,1.0F) ; } else { /* improper ==> flip 3rd column */ - ASSIF(qfac,-1.0f) ; + ASSIF(qfac,-1.0F) ; r13 = -r13 ; r23 = -r23 ; r33 = -r33 ; } /* now, compute quaternion parameters */ - a = r11 + r22 + r33 + 1.0l ; + a = r11 + r22 + r33 + 1.0L ; - if( a > 0.5l ){ /* simplest case */ - a = 0.5l * sqrt(a) ; - b = 0.25l * (r32-r23) / a ; - c = 0.25l * (r13-r31) / a ; - d = 0.25l * (r21-r12) / a ; + if( a > 0.5L ){ /* simplest case */ + a = 0.5L * sqrt(a) ; + b = 0.25L * (r32-r23) / a ; + c = 0.25L * (r13-r31) / a ; + d = 0.25L * (r21-r12) / a ; } else { /* trickier case */ xd = 1.0 + r11 - (r22+r33) ; /* 4*b*b */ yd = 1.0 + r22 - (r11+r33) ; /* 4*c*c */ zd = 1.0 + r33 - (r11+r22) ; /* 4*d*d */ if( xd > 1.0 ){ - b = 0.5l * sqrt(xd) ; - c = 0.25l* (r12+r21) / b ; - d = 0.25l* (r13+r31) / b ; - a = 0.25l* (r32-r23) / b ; + b = 0.5L * sqrt(xd) ; + c = 0.25L* (r12+r21) / b ; + d = 0.25L* (r13+r31) / b ; + a = 0.25L* (r32-r23) / b ; } else if( yd > 1.0 ){ - c = 0.5l * sqrt(yd) ; - b = 0.25l* (r12+r21) / c ; - d = 0.25l* (r23+r32) / c ; - a = 0.25l* (r13-r31) / c ; + c = 0.5L * sqrt(yd) ; + b = 0.25L* (r12+r21) / c ; + d = 0.25L* (r23+r32) / c ; + a = 0.25L* (r13-r31) / c ; } else { - d = 0.5l * sqrt(zd) ; - b = 0.25l* (r13+r31) / d ; - c = 0.25l* (r23+r32) / d ; - a = 0.25l* (r21-r12) / d ; + d = 0.5L * sqrt(zd) ; + b = 0.25L* (r13+r31) / d ; + c = 0.25L* (r23+r32) / d ; + a = 0.25L* (r21-r12) / d ; } - if( a < 0.0l ){ b=-b ; c=-c ; d=-d;} + if( a < 0.0L ){ b=-b ; c=-c ; d=-d;} } ASSIF(qb,(float)b) ; ASSIF(qc,(float)c) ; ASSIF(qd,(float)d); @@ -1690,7 +1689,7 @@ mat44 nifti_mat44_inverse( mat44 R ) deti = r11*r22*r33-r11*r32*r23-r21*r12*r33 +r21*r32*r13+r31*r12*r23-r31*r22*r13 ; /* determinant */ - if( deti != 0.0l ) deti = 1.0l / deti ; + if( deti != 0.0L ) deti = 1.0L / deti ; Q.m[0][0] = (float)( deti*( r22*r33-r32*r23) ) ; Q.m[0][1] = (float)( deti*(-r12*r33+r32*r13) ) ; @@ -1710,8 +1709,8 @@ mat44 nifti_mat44_inverse( mat44 R ) Q.m[2][3] = (float)( deti*(-r11*r22*v3+r11*r32*v2+r21*r12*v3 -r21*r32*v1-r31*r12*v2+r31*r22*v1) ) ; - Q.m[3][0] = Q.m[3][1] = Q.m[3][2] = 0.0l ; - Q.m[3][3] = (deti == 0.0l) ? 0.0l : 1.0l ; /* failure flag if deti == 0 */ + Q.m[3][0] = Q.m[3][1] = Q.m[3][2] = 0.0L ; + Q.m[3][3] = (deti == 0.0L) ? 0.0L : 1.0L ; /* failure flag if deti == 0 */ return Q ; } @@ -1754,7 +1753,7 @@ mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 , mat33 Q , P ; double val ; - R.m[3][0] = R.m[3][1] = R.m[3][2] = 0.0l ; R.m[3][3] = 1.0l ; + R.m[3][0] = R.m[3][1] = R.m[3][2] = 0.0L ; R.m[3][3] = 1.0L ; Q.m[0][0] = r11 ; Q.m[0][1] = r12 ; Q.m[0][2] = r13 ; /* load Q */ Q.m[1][0] = r21 ; Q.m[1][1] = r22 ; Q.m[1][2] = r23 ; @@ -1763,28 +1762,28 @@ mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 , /* normalize row 1 */ val = Q.m[0][0]*Q.m[0][0] + Q.m[0][1]*Q.m[0][1] + Q.m[0][2]*Q.m[0][2] ; - if( val > 0.0l ){ - val = 1.0l / sqrt(val) ; + if( val > 0.0L ){ + val = 1.0L / sqrt(val) ; Q.m[0][0] *= (float)val ; Q.m[0][1] *= (float)val ; Q.m[0][2] *= (float)val ; } else { - Q.m[0][0] = 1.0l ; Q.m[0][1] = 0.0l ; Q.m[0][2] = 0.0l ; + Q.m[0][0] = 1.0L ; Q.m[0][1] = 0.0L ; Q.m[0][2] = 0.0L ; } /* normalize row 2 */ val = Q.m[1][0]*Q.m[1][0] + Q.m[1][1]*Q.m[1][1] + Q.m[1][2]*Q.m[1][2] ; - if( val > 0.0l ){ - val = 1.0l / sqrt(val) ; + if( val > 0.0L ){ + val = 1.0L / sqrt(val) ; Q.m[1][0] *= (float)val ; Q.m[1][1] *= (float)val ; Q.m[1][2] *= (float)val ; } else { - Q.m[1][0] = 0.0l ; Q.m[1][1] = 1.0l ; Q.m[1][2] = 0.0l ; + Q.m[1][0] = 0.0L ; Q.m[1][1] = 1.0L ; Q.m[1][2] = 0.0L ; } /* normalize row 3 */ val = Q.m[2][0]*Q.m[2][0] + Q.m[2][1]*Q.m[2][1] + Q.m[2][2]*Q.m[2][2] ; - if( val > 0.0l ){ - val = 1.0l / sqrt(val) ; + if( val > 0.0L ){ + val = 1.0L / sqrt(val) ; Q.m[2][0] *= (float)val ; Q.m[2][1] *= (float)val ; Q.m[2][2] *= (float)val ; } else { Q.m[2][0] = Q.m[0][1]*Q.m[1][2] - Q.m[0][2]*Q.m[1][1] ; /* cross */ @@ -1798,7 +1797,7 @@ mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 , R.m[1][0] = P.m[1][0] ; R.m[1][1] = P.m[1][1] ; R.m[1][2] = P.m[1][2] ; R.m[2][0] = P.m[2][0] ; R.m[2][1] = P.m[2][1] ; R.m[2][2] = P.m[2][2] ; - R.m[0][3] = R.m[1][3] = R.m[2][3] = 0.0f ; return R ; + R.m[0][3] = R.m[1][3] = R.m[2][3] = 0.0F ; return R ; } /*----------------------------------------------------------------------*/ @@ -1816,7 +1815,7 @@ mat33 nifti_mat33_inverse( mat33 R ) /* inverse of 3x3 matrix */ deti = r11*r22*r33-r11*r32*r23-r21*r12*r33 +r21*r32*r13+r31*r12*r23-r31*r22*r13 ; - if( deti != 0.0l ) deti = 1.0l / deti ; + if( deti != 0.0L ) deti = 1.0L / deti ; Q.m[0][0] = (float)( deti*( r22*r33-r32*r23) ) ; Q.m[0][1] = (float)( deti*(-r12*r33+r32*r13) ) ; @@ -1903,7 +1902,7 @@ mat33 nifti_mat33_mul( mat33 A , mat33 B ) /* multiply 2 3x3 matrices */ mat33 nifti_mat33_polar( mat33 A ) { mat33 X , Y , Z ; - float alp,bet,gam,gmi , dif=1.0f ; + float alp,bet,gam,gmi , dif=1.0F ; int k=0 ; X = A ; @@ -1925,7 +1924,7 @@ mat33 nifti_mat33_polar( mat33 A ) gam = (float)( sqrt( bet / alp ) ) ; gmi = (float)( 1.0 / gam ) ; } else { - gam = gmi = 1.0f ; /* close to convergence */ + gam = gmi = 1.0F ; /* close to convergence */ } Z.m[0][0] = (float)( 0.5 * ( gam*X.m[0][0] + gmi*Y.m[0][0] ) ) ; Z.m[0][1] = (float)( 0.5 * ( gam*X.m[0][1] + gmi*Y.m[1][0] ) ) ; @@ -2060,7 +2059,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) /* Despite the formidable looking 6 nested loops, there are only 3*3*3*2*2*2 = 216 passes, which will run very quickly. */ - vbest = -666.0f ; ibest=pbest=qbest=rbest=1 ; jbest=2 ; kbest=3 ; + vbest = -666.0F ; ibest=pbest=qbest=rbest=1 ; jbest=2 ; kbest=3 ; for( i=1 ; i <= 3 ; i++ ){ /* i = column number to use for row #1 */ for( j=1 ; j <= 3 ; j++ ){ /* j = column number to use for row #2 */ if( i == j ) continue ; @@ -2068,7 +2067,7 @@ void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) if( i == k || j == k ) continue ; P.m[0][0] = P.m[0][1] = P.m[0][2] = P.m[1][0] = P.m[1][1] = P.m[1][2] = - P.m[2][0] = P.m[2][1] = P.m[2][2] = 0.0f ; + P.m[2][0] = P.m[2][1] = P.m[2][2] = 0.0F ; for( p=-1 ; p <= 1 ; p+=2 ){ /* p,q,r are -1 or +1 */ for( q=-1 ; q <= 1 ; q+=2 ){ /* and go into rows #1,2,3 */ for( r=-1 ; r <= 1 ; r+=2 ){ @@ -2227,22 +2226,22 @@ void nifti_swap_16bytes( size_t n , void *ar ) /* 16 bytes at a time */ #if 0 /* not important: save for version update 6 Jul 2010 [rickr] */ /*----------------------------------------------------------------------*/ -/*! generic: swap siz bytes at a time from the given list of n sets +/*! generic: swap size bytes at a time from the given list of n sets *//*--------------------------------------------------------------------*/ -void nifti_swap_bytes( size_t n , int siz , void *ar ) +void nifti_swap_bytes( size_t n , int size , void *ar ) { size_t ii ; unsigned char * cp0 = (unsigned char *)ar, * cp1, * cp2 ; unsigned char tval ; for( ii=0 ; ii < n ; ii++ ){ - cp1 = cp0; cp2 = cp0+(siz-1); + cp1 = cp0; cp2 = cp0+(size-1); while ( cp2 > cp1 ) { tval = *cp1 ; *cp1 = *cp2 ; *cp2 = tval ; cp1++; cp2--; } - cp0 += siz; + cp0 += size; } return ; } @@ -2251,17 +2250,17 @@ void nifti_swap_bytes( size_t n , int siz , void *ar ) /*---------------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/ -/*! based on siz, call the appropriate nifti_swap_Nbytes() function +/*! based on size, call the appropriate nifti_swap_Nbytes() function *//*--------------------------------------------------------------------*/ -void nifti_swap_Nbytes( size_t n , int siz , void *ar ) /* subsuming case */ +void nifti_swap_Nbytes( size_t n , int size , void *ar ) /* subsuming case */ { - switch( siz ){ + switch( size ){ case 2: nifti_swap_2bytes ( n , ar ) ; break ; case 4: nifti_swap_4bytes ( n , ar ) ; break ; case 8: nifti_swap_8bytes ( n , ar ) ; break ; case 16: nifti_swap_16bytes( n , ar ) ; break ; - default: /* nifti_swap_bytes ( n , siz, ar ) ; */ - fprintf(stderr,"** NIfTI: cannot swap in %d byte blocks\n", siz); + default: /* nifti_swap_bytes ( n , size, ar ) ; */ + fprintf(stderr,"** NIfTI: cannot swap in %d byte blocks\n", size); break ; } } @@ -2587,13 +2586,8 @@ int nifti_validfilename(const char* fname) \return a pointer to the extension substring within the original function input parameter name, or NULL if not found. - \warning Note that if the input parameter is is immutabale - (i.e. a const char *) then this function performs an - implicit casting away of the mutability constraint and - the return parameter will appear as a mutable - even though it is part of the immuttable string. *//*--------------------------------------------------------------------*/ -char * nifti_find_file_extension( const char * name ) +const char * nifti_find_file_extension( const char * name ) { const char * ext; char extcopy[8]; @@ -2625,7 +2619,7 @@ char * nifti_find_file_extension( const char * name ) fprintf(stderr,"** mixed case extension '%s' is not valid\n", ext); return NULL; } - else return (char *)ext; /* Cast away the constness of the input parameter */ + else return ext; } #ifdef HAVE_ZLIB @@ -2645,7 +2639,7 @@ char * nifti_find_file_extension( const char * name ) fprintf(stderr,"** mixed case extension '%s' is not valid\n", ext); return NULL; } - else return (char *)ext; /* Cast away the constness of the input parameter */ + else return ext; } #endif @@ -2664,10 +2658,10 @@ int nifti_is_gzfile(const char* fname) /* return true if the filename ends with .gz */ if (fname == NULL) { return 0; } #ifdef HAVE_ZLIB - { /* just so len doesn't generate compile warning */ + { size_t len = strlen(fname); if (len < 3) return 0; /* so we don't search before the name */ - if (fileext_compare(fname + strlen(fname) - 3,".gz")==0) { return 1; } + if (fileext_compare(fname + len - 3,".gz")==0) { return 1; } } #endif return 0; @@ -2807,7 +2801,23 @@ char * nifti_findhdrname(const char* fname) strcpy(hdrname,basename); strcat(hdrname,elist[efirst]); + #ifdef FSLSTYLE + if (nifti_fileexists(hdrname)) { + free(basename); + char *gzname = (char *)calloc(sizeof(char),strlen(hdrname)+8); + strcpy(gzname, hdrname); + strcat(gzname,extzip); + if (nifti_fileexists(gzname)) { + fprintf(stderr,"Image Exception : Multiple possible filenames detected for basename (*.nii, *.nii.gz): %s\n", basename); + free(gzname); + exit(134); + } + free(gzname); + return hdrname; + } + #else if (nifti_fileexists(hdrname)) { free(basename); return hdrname; } + #endif #ifdef HAVE_ZLIB strcat(hdrname,extzip); if (nifti_fileexists(hdrname)) { free(basename); return hdrname; } @@ -3089,8 +3099,8 @@ int nifti_set_filenames( nifti_image * nim, const char * prefix, int check, if( g_opts.debug > 1 ) fprintf(stderr,"+d modifying output filenames using prefix %s\n", prefix); - if( nim->fname ) free(nim->fname); - if( nim->iname ) free(nim->iname); + free(nim->fname); + free(nim->iname); nim->fname = nifti_makehdrname(prefix, nim->nifti_type, check, comp); nim->iname = nifti_makeimgname(prefix, nim->nifti_type, check, comp); if( !nim->fname || !nim->iname ){ @@ -3712,7 +3722,7 @@ nifti_image* nifti_convert_nhdr2nim(struct nifti_1_header nhdr, for( ii=1 ; ii <= nhdr.dim[0] ; ii++ ){ if( nhdr.pixdim[ii] == 0.0 || - !IS_GOOD_FLOAT(nhdr.pixdim[ii]) ) nhdr.pixdim[ii] = 1.0f ; + !IS_GOOD_FLOAT(nhdr.pixdim[ii]) ) nhdr.pixdim[ii] = 1.0F ; } is_onefile = is_nifti && NIFTI_ONEFILE(nhdr) ; @@ -3768,14 +3778,14 @@ nifti_image* nifti_convert_nhdr2nim(struct nifti_1_header nhdr, /* off diagonal is zero */ - nim->qto_xyz.m[0][1]=nim->qto_xyz.m[0][2]=nim->qto_xyz.m[0][3] = 0.0f; - nim->qto_xyz.m[1][0]=nim->qto_xyz.m[1][2]=nim->qto_xyz.m[1][3] = 0.0f; - nim->qto_xyz.m[2][0]=nim->qto_xyz.m[2][1]=nim->qto_xyz.m[2][3] = 0.0f; + nim->qto_xyz.m[0][1]=nim->qto_xyz.m[0][2]=nim->qto_xyz.m[0][3] = 0.0F; + nim->qto_xyz.m[1][0]=nim->qto_xyz.m[1][2]=nim->qto_xyz.m[1][3] = 0.0F; + nim->qto_xyz.m[2][0]=nim->qto_xyz.m[2][1]=nim->qto_xyz.m[2][3] = 0.0F; /* last row is always [ 0 0 0 1 ] */ - nim->qto_xyz.m[3][0]=nim->qto_xyz.m[3][1]=nim->qto_xyz.m[3][2] = 0.0f; - nim->qto_xyz.m[3][3]= 1.0f ; + nim->qto_xyz.m[3][0]=nim->qto_xyz.m[3][1]=nim->qto_xyz.m[3][2] = 0.0F; + nim->qto_xyz.m[3][3]= 1.0F ; nim->qform_code = NIFTI_XFORM_UNKNOWN ; @@ -3791,7 +3801,7 @@ nifti_image* nifti_convert_nhdr2nim(struct nifti_1_header nhdr, nim->qoffset_y = FIXED_FLOAT(nhdr.qoffset_y) ; nim->qoffset_z = FIXED_FLOAT(nhdr.qoffset_z) ; - nim->qfac = (nhdr.pixdim[0] < 0.0) ? -1.0f : 1.0f ; /* left-handedness? */ + nim->qfac = (nhdr.pixdim[0] < 0.0) ? -1.0F : 1.0F ; /* left-handedness? */ nim->qto_xyz = nifti_quatern_to_mat44( nim->quatern_b, nim->quatern_c, nim->quatern_d, @@ -3838,8 +3848,8 @@ nifti_image* nifti_convert_nhdr2nim(struct nifti_1_header nhdr, /* last row is always [ 0 0 0 1 ] */ - nim->sto_xyz.m[3][0]=nim->sto_xyz.m[3][1]=nim->sto_xyz.m[3][2] = 0.0f; - nim->sto_xyz.m[3][3]= 1.0f ; + nim->sto_xyz.m[3][0]=nim->sto_xyz.m[3][1]=nim->sto_xyz.m[3][2] = 0.0F; + nim->sto_xyz.m[3][3]= 1.0F ; nim->sto_ijk = nifti_mat44_inverse( nim->sto_xyz ) ; @@ -4264,6 +4274,13 @@ nifti_image *nifti_image_read( const char *hname , int read_data ) /**- convert all nhdr fields to nifti_image fields */ nim = nifti_convert_nhdr2nim(nhdr,hfile); + #ifdef REJECT_COMPLEX + if ((nim->datatype == DT_COMPLEX64) || (nim->datatype == DT_COMPLEX128) || (nim->datatype == DT_COMPLEX256)) { + fprintf(stderr,"Image Exception Unsupported datatype (COMPLEX64): use fslcomplex to manipulate: %s\n", hname); + exit(13); + } + #endif + if( nim == NULL ){ znzclose( fp ) ; /* close the file */ if( g_opts.debug > 0 ) @@ -4348,6 +4365,12 @@ nifti_image * nifti_read_ascii_image(znzFile fp, char *fname, int flen, fname); return NULL; } + + if( flen < 0 ){ + LNI_FERR(lfunc,"negative length not allowed", fname); + return NULL; + } + slen = flen; /* slen will be our buffer length */ if( g_opts.debug > 1 ) @@ -4421,7 +4444,7 @@ static int nifti_read_extensions( nifti_image *nim, znzFile fp, int remain ) if( (posn != sizeof(nifti_1_header)) && (nim->nifti_type != NIFTI_FTYPE_ASCII) ) - fprintf(stderr,"** WARNING: posn not header size (%lld, %lu)\n", + fprintf(stderr,"** WARNING: posn not header size (%lld, %zu)\n", (long long)posn, sizeof(nifti_1_header)); if( g_opts.debug > 2 ) @@ -5074,9 +5097,9 @@ void nifti_image_unload( nifti_image *nim ) void nifti_image_free( nifti_image *nim ) { if( nim == NULL ) return ; - if( nim->fname != NULL ) free(nim->fname) ; - if( nim->iname != NULL ) free(nim->iname) ; - if( nim->data != NULL ) free(nim->data ) ; + free(nim->fname) ; + free(nim->iname) ; + free(nim->data ) ; (void)nifti_free_extensions( nim ) ; free(nim) ; } @@ -5098,7 +5121,7 @@ int nifti_free_extensions( nifti_image *nim ) if( nim == NULL ) return -1; if( nim->num_ext > 0 && nim->ext_list ){ for( c = 0; c < nim->num_ext; c++ ) - if ( nim->ext_list[c].edata ) free(nim->ext_list[c].edata); + free(nim->ext_list[c].edata); free(nim->ext_list); } /* or if it is inconsistent, warn the user (if we are not in quiet mode) */ @@ -5297,9 +5320,9 @@ nifti_image* nifti_simple_init_nim(void) nhdr.dim[1] = 1 ; nhdr.dim[2] = 1 ; nhdr.dim[3] = 1 ; nhdr.dim[4] = 0 ; - nhdr.pixdim[0] = 0.0f ; - nhdr.pixdim[1] = 1.0f ; nhdr.pixdim[2] = 1.0f ; - nhdr.pixdim[3] = 1.0f ; + nhdr.pixdim[0] = 0.0F ; + nhdr.pixdim[1] = 1.0F ; nhdr.pixdim[2] = 1.0F ; + nhdr.pixdim[3] = 1.0F ; nhdr.datatype = DT_FLOAT32 ; nifti_datatype_sizes( nhdr.datatype , &nbyper, &swapsize ); @@ -5376,10 +5399,10 @@ nifti_1_header * nifti_make_new_header(const int arg_dims[], int arg_dtype) /* init dim and pixdim */ nhdr->dim[0] = dim[0] ; - nhdr->pixdim[0] = 0.0f; + nhdr->pixdim[0] = 0.0F; for( c = 1; c <= dim[0]; c++ ) { nhdr->dim[c] = dim[c]; - nhdr->pixdim[c] = 1.0f; + nhdr->pixdim[c] = 1.0F; } nhdr->datatype = dtype ; @@ -5465,7 +5488,7 @@ struct nifti_1_header nifti_convert_nim2nhdr(const nifti_image * nim) nhdr.dim[4] = nim->nt ; nhdr.dim[5] = nim->nu ; nhdr.dim[6] = nim->nv ; nhdr.dim[7] = nim->nw ; - nhdr.pixdim[0] = 0.0f ; + nhdr.pixdim[0] = 0.0F ; nhdr.pixdim[1] = nim->dx ; nhdr.pixdim[2] = nim->dy ; nhdr.pixdim[3] = nim->dz ; nhdr.pixdim[4] = nim->dt ; nhdr.pixdim[5] = nim->du ; nhdr.pixdim[6] = nim->dv ; @@ -5524,8 +5547,12 @@ struct nifti_1_header nifti_convert_nim2nhdr(const nifti_image * nim) nhdr.qoffset_x = nim->qoffset_x ; nhdr.qoffset_y = nim->qoffset_y ; nhdr.qoffset_z = nim->qoffset_z ; - nhdr.pixdim[0] = (nim->qfac >= 0.0) ? 1.0f : -1.0f ; + nhdr.pixdim[0] = (nim->qfac >= 0.0) ? 1.0F : -1.0F ; } + #ifdef FSLSTYLE + else //this helps for regression testing between this library and fsl, there is no other purpose. Without this you get false alarms + nhdr.pixdim[0] = 1.0; //default if unknown and not needed + #endif if( nim->sform_code > 0 ){ nhdr.sform_code = nim->sform_code ; @@ -5727,6 +5754,73 @@ znzFile nifti_image_write_hdr_img2(nifti_image *nim, int write_opts, if( imgfile ) *imgfile = fp; \ return 1 ; } while(0) +#ifdef PIGZ +#ifdef HAVE_ZLIB +int doPigz2(nifti_image *nim, struct nifti_1_header nhdr, const nifti_brick_list * NBL) { + FILE *pigzPipe; + char command[768]; + strcpy(command, "pigz" ); + strcat(command, " -n -f > \""); + strcat(command, nim->fname); + strcat(command, "\""); + #ifdef _MSC_VER + if (( pigzPipe = _popen(command, "w")) == NULL) + return -1; + #else + if (( pigzPipe = popen(command, "w")) == NULL) + return -1; + #endif + znzFile fp; + fp = (znzFile) calloc(1,sizeof(struct znzptr)); + fp->zfptr = NULL; + fp->withz = 0; + fp->nzfptr = pigzPipe; + fwrite(&nhdr, sizeof(nhdr), 1, pigzPipe); + if( nim->nifti_type != NIFTI_FTYPE_ANALYZE ) + nifti_write_extensions(fp,nim); + nifti_write_all_data(fp,nim,NBL); + #ifdef _MSC_VER + _pclose(pigzPipe); + #else + pclose(pigzPipe); + #endif + free(fp); + return 0; +} + +int doPigz(nifti_image *nim, struct nifti_1_header nhdr, const nifti_brick_list * NBL) { + FILE *pigzPipe; + char command[768]; + strcpy(command, "pigz" ); + strcat(command, " -n -f > \""); + strcat(command, nim->fname); + strcat(command, "\""); + #ifdef _MSC_VER + if (( pigzPipe = _popen(command, "w")) == NULL) + return -1; + #else + if (( pigzPipe = popen(command, "w")) == NULL) + return -1; + #endif + znzFile fp; + fp = (znzFile) calloc(1,sizeof(struct znzptr)); + fp->zfptr = NULL; + fp->withz = 0; + fp->nzfptr = pigzPipe; + fwrite(&nhdr, sizeof(nhdr), 1, pigzPipe); + if( nim->nifti_type != NIFTI_FTYPE_ANALYZE ) + nifti_write_extensions(fp,nim); + nifti_write_all_data(fp,nim,NBL); + #ifdef _MSC_VER + _pclose(pigzPipe); + #else + pclose(pigzPipe); + #endif + free(fp); + return 0; +} +#endif //HAVE_ZLIB +#endif //PIGZ /* ----------------------------------------------------------------------*/ /*! This writes the header (and optionally the image data) to file @@ -5815,6 +5909,23 @@ static int nifti_image_write_engine(nifti_image *nim, int write_opts, /* we will write the header to a new file */ if( g_opts.debug > 2 ) fprintf(stderr,"+d opening output file %s [%s]\n",nim->fname,opts); + + #ifdef PIGZ + #ifdef HAVE_ZLIB + if ((( nim->nifti_type == NIFTI_FTYPE_NIFTI1_1 )) && (nifti_is_gzfile(nim->fname)) && (!leave_open) && (write_data) ) { + const char *key = "AFNI_COMPRESSOR"; + char *value; + value = getenv(key); + //export AFNI_COMPRESSOR=PIGZ + char pigzKey[5] = "PIGZ"; + if ((value != NULL) && (strstr(value,pigzKey))) { + if (doPigz(nim, nhdr, NBL) == 0) //success writing with pigz + return 0; + } + } + #endif //HAVE_ZLIB + #endif //PIGZ + fp = znzopen( nim->fname , opts , nifti_is_gzfile(nim->fname) ) ; if( znz_isnull(fp) ){ LNI_FERR(func,"cannot open output file",nim->fname); @@ -6483,10 +6594,10 @@ int nifti_short_order(void) /* determine this CPU's byte order */ #define QNUM(nam,tt) QQNUM(nam,nam,tt) /* macro to check lhs string against "nam"; if it matches, - put rhs string into nim->"nam" string, with max length = "ml" */ + put rhs string into nim->"nam" string, with field size = "sz" */ -#define QSTR(nam,ml) if( strcmp(lhs,#nam) == 0 ) \ - strncpy(nim->nam,rhs,ml), nim->nam[ml]='\0' +#define QSTR(nam,sz) if( strcmp(lhs,#nam) == 0 ) \ + strncpy(nim->nam,rhs,sz), nim->nam[sz-1]='\0' /*---------------------------------------------------------------------------*/ /*! Take an XML-ish ASCII string and create a NIFTI image header to match. @@ -6523,7 +6634,7 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) = nim->nu = nim->nv = nim->nw = 1 ; nim->dx = nim->dy = nim->dz = nim->dt = nim->du = nim->dv = nim->dw = 0 ; - nim->qfac = 1.0f ; + nim->qfac = 1.0F ; nim->byteorder = nifti_short_order() ; @@ -6620,12 +6731,12 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) else QNUM(intent_p1,float) ; else QNUM(intent_p2,float) ; else QNUM(intent_p3,float) ; - else QSTR(intent_name,15) ; + else QSTR(intent_name,sizeof(nim->intent_name)) ; else QNUM(toffset,float) ; else QNUM(xyz_units,int) ; else QNUM(time_units,int) ; - else QSTR(descrip,79) ; - else QSTR(aux_file,23) ; + else QSTR(descrip,sizeof(nim->descrip)) ; + else QSTR(aux_file,sizeof(nim->aux_file)) ; else QNUM(qform_code,int) ; else QNUM(quatern_b,float) ; else QNUM(quatern_c,float) ; @@ -6675,8 +6786,8 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) nim->qfac ) ; else nim->qto_xyz = nifti_quatern_to_mat44( - 0.0f , 0.0f , 0.0f , 0.0f , 0.0f , 0.0f , - nim->dx , nim->dy , nim->dz , 0.0f ) ; + 0.0F , 0.0F , 0.0F , 0.0F , 0.0F , 0.0F , + nim->dx , nim->dy , nim->dz , 0.0F ) ; nim->qto_ijk = nifti_mat44_inverse( nim->qto_xyz ) ; diff --git a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.h b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.h index bedd237ec64..10d1270e2f9 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.h +++ b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.h @@ -19,6 +19,30 @@ #include "znzlib.h" +#ifndef NIO_API + #if defined(_WIN32) || defined(__CYGWIN__) + #if defined(NIFTIIO_BUILD_SHARED) + #ifdef __GNUC__ + #define NIO_API __attribute__ ((dllexport)) + #else + #define NIO_API __declspec( dllexport ) + #endif + #elif defined(NIFTIIO_USE_SHARED) + #ifdef __GNUC__ + #define NIO_API __attribute__ ((dllimport)) + #else + #define NIO_API __declspec( dllimport ) + #endif + #else + #define NIO_API + #endif + #elif (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__) + #define NIO_API __attribute__ ((visibility ("default"))) + #else + #define NIO_API + #endif +#endif + /*=================*/ #ifdef __cplusplus extern "C" { @@ -244,133 +268,135 @@ typedef struct { /*****************************************************************************/ /*--------------- Prototypes of functions defined in this file --------------*/ -char const * nifti_datatype_string ( int dt ) ; -char const *nifti_units_string ( int uu ) ; -char const *nifti_intent_string ( int ii ) ; -char const *nifti_xform_string ( int xx ) ; -char const *nifti_slice_string ( int ss ) ; -char const *nifti_orientation_string( int ii ) ; +NIO_API char const * nifti_datatype_string ( int dt ) ; +NIO_API char const *nifti_units_string ( int uu ) ; +NIO_API char const *nifti_intent_string ( int ii ) ; +NIO_API char const *nifti_xform_string ( int xx ) ; +NIO_API char const *nifti_slice_string ( int ss ) ; +NIO_API char const *nifti_orientation_string( int ii ) ; -int nifti_is_inttype( int dt ) ; +NIO_API int nifti_is_inttype( int dt ) ; -mat44 nifti_mat44_inverse( mat44 R ) ; +NIO_API mat44 nifti_mat44_inverse( mat44 R ) ; -mat33 nifti_mat33_inverse( mat33 R ) ; -mat33 nifti_mat33_polar ( mat33 A ) ; -float nifti_mat33_rownorm( mat33 A ) ; -float nifti_mat33_colnorm( mat33 A ) ; -float nifti_mat33_determ ( mat33 R ) ; -mat33 nifti_mat33_mul ( mat33 A , mat33 B ) ; +NIO_API mat33 nifti_mat33_inverse( mat33 R ) ; +NIO_API mat33 nifti_mat33_polar ( mat33 A ) ; +NIO_API float nifti_mat33_rownorm( mat33 A ) ; +NIO_API float nifti_mat33_colnorm( mat33 A ) ; +NIO_API float nifti_mat33_determ ( mat33 R ) ; +NIO_API mat33 nifti_mat33_mul ( mat33 A , mat33 B ) ; -void nifti_swap_2bytes ( size_t n , void *ar ) ; -void nifti_swap_4bytes ( size_t n , void *ar ) ; -void nifti_swap_8bytes ( size_t n , void *ar ) ; -void nifti_swap_16bytes( size_t n , void *ar ) ; -void nifti_swap_Nbytes ( size_t n , int siz , void *ar ) ; +NIO_API void nifti_swap_2bytes ( size_t n , void *ar ) ; +NIO_API void nifti_swap_4bytes ( size_t n , void *ar ) ; +NIO_API void nifti_swap_8bytes ( size_t n , void *ar ) ; +NIO_API void nifti_swap_16bytes( size_t n , void *ar ) ; +NIO_API void nifti_swap_Nbytes ( size_t n , int size , void *ar ) ; -int nifti_datatype_is_valid (int dtype, int for_nifti); -int nifti_datatype_from_string(const char * name); -const char * nifti_datatype_to_string (int dtype); +NIO_API int nifti_datatype_is_valid (int dtype, int for_nifti); +NIO_API int nifti_datatype_from_string(const char * name); +NIO_API const char * nifti_datatype_to_string (int dtype); -int nifti_get_filesize( const char *pathname ) ; -void swap_nifti_header ( struct nifti_1_header *h , int is_nifti ) ; -void old_swap_nifti_header( struct nifti_1_header *h , int is_nifti ); -int nifti_swap_as_analyze( nifti_analyze75 *h ); +NIO_API int nifti_get_filesize( const char *pathname ) ; +NIO_API void swap_nifti_header ( struct nifti_1_header *h , int is_nifti ) ; +NIO_API void old_swap_nifti_header( struct nifti_1_header *h , int is_nifti ); +NIO_API int nifti_swap_as_analyze( nifti_analyze75 *h ); /* main read/write routines */ -nifti_image *nifti_image_read_bricks(const char *hname , int nbricks, - const int *blist, nifti_brick_list * NBL); -int nifti_image_load_bricks(nifti_image *nim , int nbricks, - const int *blist, nifti_brick_list * NBL); -void nifti_free_NBL( nifti_brick_list * NBL ); +NIO_API nifti_image *nifti_image_read_bricks(const char *hname , int nbricks, + const int *blist, nifti_brick_list * NBL); +NIO_API int nifti_image_load_bricks(nifti_image *nim , int nbricks, + const int *blist, nifti_brick_list * NBL); +NIO_API void nifti_free_NBL( nifti_brick_list * NBL ); -nifti_image *nifti_image_read ( const char *hname , int read_data ) ; -int nifti_image_load ( nifti_image *nim ) ; -void nifti_image_unload ( nifti_image *nim ) ; -void nifti_image_free ( nifti_image *nim ) ; +NIO_API nifti_image *nifti_image_read ( const char *hname , int read_data ) ; +NIO_API int nifti_image_load ( nifti_image *nim ) ; +NIO_API void nifti_image_unload ( nifti_image *nim ) ; +NIO_API void nifti_image_free ( nifti_image *nim ) ; -int nifti_read_collapsed_image( nifti_image * nim, const int dims [8], - void ** data ); +NIO_API int nifti_read_collapsed_image( nifti_image * nim, const int dims [8], + void ** data ); -int nifti_read_subregion_image( nifti_image * nim, - const int *start_index, const int *region_size, - void ** data ); +NIO_API int nifti_read_subregion_image( nifti_image * nim, + const int *start_index, const int *region_size, + void ** data ); -void nifti_image_write ( nifti_image * nim ) ; -int nifti_image_write_status( nifti_image *nim ); +NIO_API void nifti_image_write ( nifti_image * nim ) ; +NIO_API int nifti_image_write_status( nifti_image *nim ); -void nifti_image_write_bricks(nifti_image * nim, - const nifti_brick_list * NBL); -int nifti_image_write_bricks_status(nifti_image * nim, - const nifti_brick_list * NBL); -void nifti_image_infodump( const nifti_image * nim ) ; +NIO_API void nifti_image_write_bricks(nifti_image * nim, + const nifti_brick_list * NBL); +NIO_API int nifti_image_write_bricks_status(nifti_image * nim, + const nifti_brick_list * NBL); +NIO_API void nifti_image_infodump( const nifti_image * nim ) ; -void nifti_disp_lib_hist( void ) ; /* to display library history */ -void nifti_disp_lib_version( void ) ; /* to display library version */ -int nifti_disp_matrix_orient( const char * mesg, mat44 mat ); -int nifti_disp_type_list( int which ); +NIO_API void nifti_disp_lib_hist( void ) ; /* to display library history */ +NIO_API void nifti_disp_lib_version( void ) ; /* to display library version */ +NIO_API int nifti_disp_matrix_orient( const char * mesg, mat44 mat ); +NIO_API int nifti_disp_type_list( int which ); -char * nifti_image_to_ascii ( const nifti_image * nim ) ; -nifti_image *nifti_image_from_ascii( const char * str, int * bytes_read ) ; +NIO_API char * nifti_image_to_ascii ( const nifti_image * nim ) ; +NIO_API nifti_image *nifti_image_from_ascii( const char * str, int * bytes_read ) ; -size_t nifti_get_volsize(const nifti_image *nim) ; +NIO_API size_t nifti_get_volsize(const nifti_image *nim) ; /* basic file operations */ -int nifti_set_filenames(nifti_image * nim, const char * prefix, int check, - int set_byte_order); -char * nifti_makehdrname (const char * prefix, int nifti_type, int check, - int comp); -char * nifti_makeimgname (const char * prefix, int nifti_type, int check, - int comp); -int is_nifti_file (const char *hname); -char * nifti_find_file_extension(const char * name); -int nifti_is_complete_filename(const char* fname); -int nifti_validfilename(const char* fname); - -int disp_nifti_1_header(const char * info, const nifti_1_header * hp ) ; -void nifti_set_debug_level( int level ) ; -void nifti_set_skip_blank_ext( int skip ) ; -void nifti_set_allow_upper_fext( int allow ) ; - -int valid_nifti_brick_list(nifti_image * nim , int nbricks, - const int * blist, int disp_error); +NIO_API int nifti_set_filenames( nifti_image * nim, const char * prefix, int check, + int set_byte_order); +NIO_API char * nifti_makehdrname ( const char * prefix, int nifti_type, int check, + int comp); +NIO_API char * nifti_makeimgname ( const char * prefix, int nifti_type, int check, + int comp); +NIO_API int is_nifti_file ( const char *hname); +NIO_API const char * nifti_find_file_extension( const char * name); +NIO_API int nifti_is_complete_filename( const char* fname); +NIO_API int nifti_validfilename( const char* fname); + +NIO_API int disp_nifti_1_header(const char * info, const nifti_1_header * hp ) ; +NIO_API void nifti_set_debug_level( int level ) ; +NIO_API void nifti_set_skip_blank_ext( int skip ) ; +NIO_API void nifti_set_allow_upper_fext( int allow ) ; + +NIO_API int valid_nifti_brick_list( nifti_image * nim , int nbricks, + const int * blist, int disp_error); /* znzFile operations */ -znzFile nifti_image_open(const char * hname, const char * opts, nifti_image ** nim); -znzFile nifti_image_write_hdr_img(nifti_image *nim, int write_data, - const char* opts); -znzFile nifti_image_write_hdr_img2( nifti_image *nim , int write_opts , - const char* opts, znzFile imgfile, const nifti_brick_list * NBL); -size_t nifti_read_buffer(znzFile fp, void* dataptr, size_t ntot, - nifti_image *nim); -int nifti_write_all_data(znzFile fp, nifti_image * nim, - const nifti_brick_list * NBL); -size_t nifti_write_buffer(znzFile fp, const void * buffer, size_t numbytes); -nifti_image *nifti_read_ascii_image(znzFile fp, char *fname, int flen, - int read_data); -znzFile nifti_write_ascii_image(nifti_image *nim, const nifti_brick_list * NBL, - const char * opts, int write_data, int leave_open); +NIO_API znzFile nifti_image_open( const char * hname, const char * opts, nifti_image ** nim); +NIO_API znzFile nifti_image_write_hdr_img( nifti_image *nim, int write_data, + const char* opts); +NIO_API znzFile nifti_image_write_hdr_img2( nifti_image *nim , int write_opts , + const char* opts, znzFile imgfile, + const nifti_brick_list * NBL); +NIO_API size_t nifti_read_buffer( znzFile fp, void* dataptr, size_t ntot, + nifti_image *nim); +NIO_API int nifti_write_all_data( znzFile fp, nifti_image * nim, + const nifti_brick_list * NBL); +NIO_API size_t nifti_write_buffer( znzFile fp, const void * buffer, size_t numbytes); +NIO_API nifti_image *nifti_read_ascii_image( znzFile fp, char *fname, int flen, + int read_data); +NIO_API znzFile nifti_write_ascii_image( nifti_image *nim, const nifti_brick_list * NBL, + const char * opts, int write_data, + int leave_open); -void nifti_datatype_sizes( int datatype , int *nbyper, int *swapsize ) ; +NIO_API void nifti_datatype_sizes( int datatype , int *nbyper, int *swapsize ) ; -void nifti_mat44_to_quatern( mat44 R , - float *qb, float *qc, float *qd, - float *qx, float *qy, float *qz, - float *dx, float *dy, float *dz, float *qfac ) ; +NIO_API void nifti_mat44_to_quatern( mat44 R , + float *qb, float *qc, float *qd, + float *qx, float *qy, float *qz, + float *dx, float *dy, float *dz, float *qfac ) ; -mat44 nifti_quatern_to_mat44( float qb, float qc, float qd, - float qx, float qy, float qz, - float dx, float dy, float dz, float qfac ); +NIO_API mat44 nifti_quatern_to_mat44( float qb, float qc, float qd, + float qx, float qy, float qz, + float dx, float dy, float dz, float qfac ); -mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 , - float r21, float r22, float r23 , - float r31, float r32, float r33 ) ; +NIO_API mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 , + float r21, float r22, float r23 , + float r31, float r32, float r33 ) ; -int nifti_short_order(void) ; /* CPU byte order */ +NIO_API int nifti_short_order(void) ; /* CPU byte order */ /* Orientation codes that might be returned from nifti_mat44_to_orientation().*/ @@ -382,47 +408,47 @@ int nifti_short_order(void) ; /* CPU byte order */ #define NIFTI_I2S 5 /* Inferior to Superior */ #define NIFTI_S2I 6 /* Superior to Inferior */ -void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) ; +NIO_API void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) ; /*--------------------- Low level IO routines ------------------------------*/ -char * nifti_findhdrname (const char* fname); -char * nifti_findimgname (const char* fname , int nifti_type); -int nifti_is_gzfile (const char* fname); +NIO_API char * nifti_findhdrname (const char* fname); +NIO_API char * nifti_findimgname (const char* fname , int nifti_type); +NIO_API int nifti_is_gzfile (const char* fname); -char * nifti_makebasename(const char* fname); +NIO_API char * nifti_makebasename(const char* fname); /* other routines */ -struct nifti_1_header nifti_convert_nim2nhdr(const nifti_image* nim); -nifti_1_header * nifti_make_new_header(const int arg_dims[], int arg_dtype); -nifti_1_header * nifti_read_header(const char *hname, int *swapped, int check); -nifti_image * nifti_copy_nim_info(const nifti_image * src); -nifti_image * nifti_make_new_nim(const int dims[], int datatype, +NIO_API struct nifti_1_header nifti_convert_nim2nhdr(const nifti_image* nim); +NIO_API nifti_1_header * nifti_make_new_header(const int arg_dims[], int arg_dtype); +NIO_API nifti_1_header * nifti_read_header(const char *hname, int *swapped, int check); +NIO_API nifti_image * nifti_copy_nim_info(const nifti_image * src); +NIO_API nifti_image * nifti_make_new_nim(const int dims[], int datatype, int data_fill); -nifti_image * nifti_simple_init_nim(void); -nifti_image * nifti_convert_nhdr2nim(struct nifti_1_header nhdr, +NIO_API nifti_image * nifti_simple_init_nim(void); +NIO_API nifti_image * nifti_convert_nhdr2nim(struct nifti_1_header nhdr, const char * fname); -int nifti_hdr_looks_good (const nifti_1_header * hdr); -int nifti_is_valid_datatype (int dtype); -int nifti_is_valid_ecode (int ecode); -int nifti_nim_is_valid (nifti_image * nim, int complain); -int nifti_nim_has_valid_dims (nifti_image * nim, int complain); -int is_valid_nifti_type (int nifti_type); -int nifti_test_datatype_sizes (int verb); -int nifti_type_and_names_match (nifti_image * nim, int show_warn); -int nifti_update_dims_from_array(nifti_image * nim); -void nifti_set_iname_offset (nifti_image *nim); -int nifti_set_type_from_names (nifti_image * nim); -int nifti_add_extension(nifti_image * nim, const char * data, int len, - int ecode ); -int nifti_compiled_with_zlib (void); -int nifti_copy_extensions (nifti_image *nim_dest,const nifti_image *nim_src); -int nifti_free_extensions (nifti_image *nim); -int * nifti_get_intlist (int nvals , const char *str); -char * nifti_strdup (const char *str); -int valid_nifti_extensions(const nifti_image *nim); +NIO_API int nifti_hdr_looks_good (const nifti_1_header * hdr); +NIO_API int nifti_is_valid_datatype (int dtype); +NIO_API int nifti_is_valid_ecode (int ecode); +NIO_API int nifti_nim_is_valid (nifti_image * nim, int complain); +NIO_API int nifti_nim_has_valid_dims (nifti_image * nim, int complain); +NIO_API int is_valid_nifti_type (int nifti_type); +NIO_API int nifti_test_datatype_sizes (int verb); +NIO_API int nifti_type_and_names_match (nifti_image * nim, int show_warn); +NIO_API int nifti_update_dims_from_array(nifti_image * nim); +NIO_API void nifti_set_iname_offset (nifti_image *nim); +NIO_API int nifti_set_type_from_names (nifti_image * nim); +NIO_API int nifti_add_extension(nifti_image * nim, const char * data, int len, + int ecode ); +NIO_API int nifti_compiled_with_zlib (void); +NIO_API int nifti_copy_extensions (nifti_image *nim_dest,const nifti_image *nim_src); +NIO_API int nifti_free_extensions (nifti_image *nim); +NIO_API int * nifti_get_intlist (int nvals , const char *str); +NIO_API char * nifti_strdup (const char *str); +NIO_API int valid_nifti_extensions(const nifti_image *nim); /*-------------------- Some C convenience macros ----------------------------*/ diff --git a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_tool.c b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_tool.c index f5908cdd190..b439f98bfb7 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_tool.c +++ b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_tool.c @@ -165,6 +165,7 @@ static int g_debug = 1; #include #include #include +#include #include "nifti1_io.h" #include "nifti1_tool.h" @@ -177,7 +178,7 @@ static char * read_file_text(const char * filename, int * length); #define NTL_FERR(func,msg,file) \ fprintf(stderr,"** ERROR (%s): %s '%s'\n",func,msg,file) -/* val may be a function call, so evalulate first, and return result */ +/* val may be a function call, so evaluate first, and return result */ #define FREE_RETURN(val) \ do{ int tval=(val); free_opts_mem(&opts); return tval; } while(0) @@ -345,7 +346,7 @@ int process_opts( int argc, char * argv[], nt_opts * opts ) { ac++; CHECK_NEXT_OPT_MSG(ac,argc,"-cci","7 dimension values are required"); - if( ! isdigit(argv[ac][0]) && strcmp(argv[ac],"-1") ){ + if( ! isdigit(argv[ac][0]) && strcmp(argv[ac],"-1") != 0 ){ fprintf(stderr,"** -cci param %d (= '%s') is not a valid\n" " consider: 'nifti_tool -help'\n",index,argv[ac]); return -1; @@ -389,7 +390,7 @@ int process_opts( int argc, char * argv[], nt_opts * opts ) ac++; CHECK_NEXT_OPT_MSG(ac,argc,"-disp_ci", "7 dimension values are required"); - if( ! isdigit(argv[ac][0]) && strcmp(argv[ac],"-1") ){ + if( ! isdigit(argv[ac][0]) && strcmp(argv[ac],"-1") != 0 ){ fprintf(stderr,"** -disp_ci param %d (= '%s') is not a valid\n" " consider: 'nifti_tool -help'\n",index,argv[ac]); return -1; @@ -464,7 +465,7 @@ int process_opts( int argc, char * argv[], nt_opts * opts ) { ac++; CHECK_NEXT_OPT_MSG(ac,argc,"-new_dim","8 dim values are required"); - if( ! isdigit(argv[ac][0]) && strcmp(argv[ac],"-1") ){ + if( ! isdigit(argv[ac][0]) && strcmp(argv[ac],"-1") != 0 ){ fprintf(stderr,"** -new_dim param %d (= '%s') is not a valid\n" " consider: 'nifti_tool -help'\n",index,argv[ac]); return -1; @@ -689,15 +690,15 @@ int verify_opts( nt_opts * opts, char * prog ) int fill_cmd_string( nt_opts * opts, int argc, char * argv[]) { char * cp; - int len, remain = (int)sizeof(opts->command); /* max command len */ - int c, ac; + size_t len, c, remain = sizeof(opts->command); /* max command len */ + int ac; int has_space; /* arguments containing space must be quoted */ int skip = 0; /* counter to skip some of the arguments */ /* get the first argument separately */ len = snprintf( opts->command, sizeof(opts->command), "\n command: %s", argv[0] ); - if( len < 0 || len >= (int)sizeof(opts->command) ) { + if( len >= sizeof(opts->command) ) { fprintf(stderr,"FCS: no space remaining for command, continuing...\n"); return 1; } @@ -709,7 +710,7 @@ int fill_cmd_string( nt_opts * opts, int argc, char * argv[]) { if( skip ){ skip--; continue; } /* then skip these arguments */ - len = (int)strlen(argv[ac]); + len = strlen(argv[ac]); if( len + 3 >= remain ) { /* extra 3 for space and possible '' */ fprintf(stderr,"FCS: no space remaining for command, continuing...\n"); return 1; @@ -1909,7 +1910,8 @@ static char * read_file_text(const char * filename, int * length) { FILE * fp; char * text; - int len, bytes; + int len; + size_t bytes; if( !filename || !length ) { fprintf(stderr,"** bad params to read_file_text\n"); @@ -1937,11 +1939,11 @@ static char * read_file_text(const char * filename, int * length) return NULL; } - bytes = (int)fread(text, sizeof(char), len, fp); + bytes = fread(text, sizeof(char), len, fp); fclose(fp); /* in any case */ - if( bytes != len ) { - fprintf(stderr,"** RFT: read only %d of %d bytes from %s\n", + if( bytes != (size_t)len ) { + fprintf(stderr,"** RFT: read only %zu of %d bytes from %s\n", bytes, len, filename); free(text); return NULL; @@ -2043,7 +2045,7 @@ int act_rm_ext( nt_opts * opts ) return 1; } else if( opts->overwrite && opts->infiles.len != 1 && - strcmp(opts->elist.list[0], "-1") ) { + strcmp(opts->elist.list[0], "-1") != 0 ) { fprintf(stderr,"** error: for multiple files, can only delete ALL\n"); return 1; } @@ -2896,11 +2898,13 @@ int modify_field(void * basep, field_s * field, const char * data) float fval; const char * posn = data; int val, max, fc, nchars; + size_t dataLength; if( g_debug > 1 ) fprintf(stderr,"+d modifying field '%s' with '%s'\n", field->name, data); - if( !data || strlen(data) == 0 ) + dataLength = data ? strlen(data) : 0; + if( dataLength == 0 ) { fprintf(stderr,"** no data for '%s' field modification\n",field->name); return 1; @@ -3015,7 +3019,7 @@ int modify_field(void * basep, field_s * field, const char * data) case NT_DT_STRING: { char * dest = (char *)basep + field->offset; - nchars = strlen(data); + nchars = dataLength; strncpy(dest, data, field->len); if( nchars < field->len ) /* clear the rest */ memset(dest+nchars, '\0', field->len-nchars); @@ -3032,7 +3036,6 @@ int modify_field(void * basep, field_s * field, const char * data) *----------------------------------------------------------------------*/ int fill_hdr_field_array( field_s * nh_fields ) { - nifti_1_header nhdr; field_s * nhf = nh_fields; int rv, errs; @@ -3043,55 +3046,55 @@ int fill_hdr_field_array( field_s * nh_fields ) nhf++; */ errs = 0; - NT_SFILL(nhdr, nhf, DT_INT32, sizeof_hdr, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, NT_DT_STRING, data_type, 10, rv); errs += rv; - NT_SFILL(nhdr, nhf, NT_DT_STRING, db_name, 18, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT32, extents, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT16, session_error, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, NT_DT_STRING, regular, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT8, dim_info, 1, rv); errs += rv; - - NT_SFILL(nhdr, nhf, DT_INT16, dim, 8, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, intent_p1, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, intent_p2, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, intent_p3, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT16, intent_code, 1, rv); errs += rv; - - NT_SFILL(nhdr, nhf, DT_INT16, datatype, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT16, bitpix, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT16, slice_start, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, pixdim, 8, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, vox_offset, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, scl_slope, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, scl_inter, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT16, slice_end, 1, rv); errs += rv; - - NT_SFILL(nhdr, nhf, DT_INT8, slice_code, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT8, xyzt_units, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, cal_max, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, cal_min, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, slice_duration, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, toffset, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT32, glmax, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT32, glmin, 1, rv); errs += rv; - - NT_SFILL(nhdr, nhf, NT_DT_STRING, descrip, 80, rv); errs += rv; - NT_SFILL(nhdr, nhf, NT_DT_STRING, aux_file, 24, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT16, qform_code, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_INT16, sform_code, 1, rv); errs += rv; - - NT_SFILL(nhdr, nhf, DT_FLOAT32, quatern_b, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, quatern_c, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, quatern_d, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, qoffset_x, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, qoffset_y, 1, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, qoffset_z, 1, rv); errs += rv; - - NT_SFILL(nhdr, nhf, DT_FLOAT32, srow_x, 4, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, srow_y, 4, rv); errs += rv; - NT_SFILL(nhdr, nhf, DT_FLOAT32, srow_z, 4, rv); errs += rv; - NT_SFILL(nhdr, nhf, NT_DT_STRING, intent_name, 16, rv); errs += rv; - NT_SFILL(nhdr, nhf, NT_DT_STRING, magic, 4, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT32, sizeof_hdr, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, NT_DT_STRING, data_type, 10, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, NT_DT_STRING, db_name, 18, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT32, extents, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT16, session_error, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, NT_DT_STRING, regular, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT8, dim_info, 1, rv); errs += rv; + + NT_FILL(nifti_1_header, nhf, DT_INT16, dim, 8, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, intent_p1, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, intent_p2, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, intent_p3, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT16, intent_code, 1, rv); errs += rv; + + NT_FILL(nifti_1_header, nhf, DT_INT16, datatype, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT16, bitpix, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT16, slice_start, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, pixdim, 8, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, vox_offset, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, scl_slope, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, scl_inter, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT16, slice_end, 1, rv); errs += rv; + + NT_FILL(nifti_1_header, nhf, DT_INT8, slice_code, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT8, xyzt_units, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, cal_max, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, cal_min, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, slice_duration, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, toffset, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT32, glmax, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT32, glmin, 1, rv); errs += rv; + + NT_FILL(nifti_1_header, nhf, NT_DT_STRING, descrip, 80, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, NT_DT_STRING, aux_file, 24, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT16, qform_code, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_INT16, sform_code, 1, rv); errs += rv; + + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, quatern_b, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, quatern_c, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, quatern_d, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, qoffset_x, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, qoffset_y, 1, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, qoffset_z, 1, rv); errs += rv; + + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, srow_x, 4, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, srow_y, 4, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, DT_FLOAT32, srow_z, 4, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, NT_DT_STRING, intent_name, 16, rv); errs += rv; + NT_FILL(nifti_1_header, nhf, NT_DT_STRING, magic, 4, rv); errs += rv; if( errs > 0 ){ fprintf(stderr, "** %d fill_fields errors!\n", errs); @@ -3100,7 +3103,7 @@ int fill_hdr_field_array( field_s * nh_fields ) /* failure here is a serious problem */ if( check_total_size("nifti_1_header test: ", nh_fields, - NT_HDR_NUM_FIELDS, sizeof(nhdr)) ) + NT_HDR_NUM_FIELDS, sizeof(nifti_1_header)) ) return 1; if( g_debug > 3 ) @@ -3115,7 +3118,6 @@ int fill_hdr_field_array( field_s * nh_fields ) *----------------------------------------------------------------------*/ int fill_nim_field_array( field_s * nim_fields ) { - nifti_image nim; field_s * nif = nim_fields; int rv, errs; @@ -3123,69 +3125,69 @@ int fill_nim_field_array( field_s * nim_fields ) errs = 0; - NT_SFILL(nim, nif, DT_INT32, ndim, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, nx, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, ny, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, nz, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, nt, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, nu, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, nv, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, nw, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, dim, 8, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, nvox, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, nbyper, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, datatype, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, dx, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, dy, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, dz, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, dt, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, du, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, dv, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, dw, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, pixdim, 8, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, scl_slope, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, scl_inter, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, cal_min, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, cal_max, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, qform_code, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, sform_code, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, freq_dim, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, phase_dim, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, slice_dim, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, slice_code, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, slice_start, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, slice_end, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, slice_duration, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, quatern_b, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, quatern_c, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, quatern_d, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, qoffset_x, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, qoffset_y, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, qoffset_z, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, qfac, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, qto_xyz, 16, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, qto_ijk, 16, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, sto_xyz, 16, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, sto_ijk, 16, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, toffset, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, xyz_units, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, time_units, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, nifti_type, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, intent_code, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, intent_p1, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, intent_p2, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_FLOAT32, intent_p3, 1, rv); errs += rv; - NT_SFILL(nim, nif, NT_DT_STRING, intent_name, 16, rv); errs += rv; - NT_SFILL(nim, nif, NT_DT_STRING, descrip, 80, rv); errs += rv; - NT_SFILL(nim, nif, NT_DT_STRING, aux_file, 24, rv); errs += rv; - NT_SFILL(nim, nif, NT_DT_CHAR_PTR, fname, 1, rv); errs += rv; - NT_SFILL(nim, nif, NT_DT_CHAR_PTR, iname, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, iname_offset, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, swapsize, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, byteorder, 1, rv); errs += rv; - NT_SFILL(nim, nif, NT_DT_POINTER, data, 1, rv); errs += rv; - NT_SFILL(nim, nif, DT_INT32, num_ext, 1, rv); errs += rv; - NT_SFILL(nim, nif, NT_DT_EXT_PTR, ext_list, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, ndim, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, nx, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, ny, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, nz, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, nt, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, nu, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, nv, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, nw, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, dim, 8, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, nvox, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, nbyper, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, datatype, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, dx, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, dy, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, dz, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, dt, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, du, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, dv, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, dw, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, pixdim, 8, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, scl_slope, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, scl_inter, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, cal_min, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, cal_max, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, qform_code, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, sform_code, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, freq_dim, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, phase_dim, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, slice_dim, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, slice_code, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, slice_start, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, slice_end, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, slice_duration, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, quatern_b, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, quatern_c, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, quatern_d, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, qoffset_x, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, qoffset_y, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, qoffset_z, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, qfac, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, qto_xyz, 16, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, qto_ijk, 16, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, sto_xyz, 16, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, sto_ijk, 16, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, toffset, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, xyz_units, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, time_units, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, nifti_type, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, intent_code, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, intent_p1, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, intent_p2, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_FLOAT32, intent_p3, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, NT_DT_STRING, intent_name, 16, rv); errs += rv; + NT_FILL(nifti_image, nif, NT_DT_STRING, descrip, 80, rv); errs += rv; + NT_FILL(nifti_image, nif, NT_DT_STRING, aux_file, 24, rv); errs += rv; + NT_FILL(nifti_image, nif, NT_DT_CHAR_PTR, fname, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, NT_DT_CHAR_PTR, iname, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, iname_offset, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, swapsize, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, byteorder, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, NT_DT_POINTER, data, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, DT_INT32, num_ext, 1, rv); errs += rv; + NT_FILL(nifti_image, nif, NT_DT_EXT_PTR, ext_list, 1, rv); errs += rv; if( errs > 0 ){ fprintf(stderr, "** %d fill_fields errors " @@ -3195,7 +3197,7 @@ int fill_nim_field_array( field_s * nim_fields ) if( g_debug > 3 ) /* failure here is not an error condition */ check_total_size("nifti_image test: ", nim_fields, - NT_NIM_NUM_FIELDS, sizeof(nim)); + NT_NIM_NUM_FIELDS, sizeof(nifti_image)); if( g_debug > 3 ) disp_field_s_list("nim_fields: ", nim_fields, NT_NIM_NUM_FIELDS); @@ -3209,7 +3211,6 @@ int fill_nim_field_array( field_s * nim_fields ) *----------------------------------------------------------------------*/ int fill_ana_field_array( field_s * ah_fields ) { - nifti_analyze75 nhdr; field_s * ahf = ah_fields; int rv, errs; @@ -3220,62 +3221,62 @@ int fill_ana_field_array( field_s * ah_fields ) nhf++; */ errs = 0; - NT_SFILL(nhdr, ahf, DT_INT32, sizeof_hdr, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, data_type, 10, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, db_name, 18, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT32, extents, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, session_error, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, regular, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT8, hkey_un0, 1, rv); errs += rv; - - NT_SFILL(nhdr, ahf, DT_INT16, dim, 8, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, unused8, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, unused9, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, unused10, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, unused11, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, unused12, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, unused13, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, unused14, 1, rv); errs += rv; - - NT_SFILL(nhdr, ahf, DT_INT16, datatype, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, bitpix, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT16, dim_un0, 1, rv); errs += rv; - - NT_SFILL(nhdr, ahf, DT_FLOAT32, pixdim, 8, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_FLOAT32, vox_offset, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_FLOAT32, funused1, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_FLOAT32, funused2, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_FLOAT32, funused3, 1, rv); errs += rv; - - NT_SFILL(nhdr, ahf, DT_FLOAT32, cal_max, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_FLOAT32, cal_min, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_FLOAT32, compressed, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_FLOAT32, verified, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT32, glmax, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT32, glmin, 1, rv); errs += rv; - - NT_SFILL(nhdr, ahf, NT_DT_STRING, descrip, 80, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, aux_file, 24, rv); errs += rv; - - NT_SFILL(nhdr, ahf, DT_INT8, orient, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, sizeof_hdr, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, data_type, 10, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, db_name, 18, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, extents, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, session_error, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, regular, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT8, hkey_un0, 1, rv); errs += rv; + + NT_FILL(nifti_analyze75, ahf, DT_INT16, dim, 8, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, unused8, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, unused9, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, unused10, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, unused11, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, unused12, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, unused13, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, unused14, 1, rv); errs += rv; + + NT_FILL(nifti_analyze75, ahf, DT_INT16, datatype, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, bitpix, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, dim_un0, 1, rv); errs += rv; + + NT_FILL(nifti_analyze75, ahf, DT_FLOAT32, pixdim, 8, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_FLOAT32, vox_offset, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_FLOAT32, funused1, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_FLOAT32, funused2, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_FLOAT32, funused3, 1, rv); errs += rv; + + NT_FILL(nifti_analyze75, ahf, DT_FLOAT32, cal_max, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_FLOAT32, cal_min, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_FLOAT32, compressed, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_FLOAT32, verified, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, glmax, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, glmin, 1, rv); errs += rv; + + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, descrip, 80, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, aux_file, 24, rv); errs += rv; + + NT_FILL(nifti_analyze75, ahf, DT_INT8, orient, 1, rv); errs += rv; /* originator is 5 (3) shorts, not 10 chars 26 Sep 2012 [rickr] */ - NT_SFILL(nhdr, ahf, DT_INT16, originator, 5, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, generated, 10, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, scannum, 10, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, patient_id, 10, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, exp_date, 10, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, exp_time, 10, rv); errs += rv; - NT_SFILL(nhdr, ahf, NT_DT_STRING, hist_un0, 3, rv); errs += rv; - - NT_SFILL(nhdr, ahf, DT_INT32, views , 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT32, vols_added, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT32, start_field, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT32, field_skip, 1, rv); errs += rv; - - NT_SFILL(nhdr, ahf, DT_INT32, omax, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT32, omin, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT32, smax, 1, rv); errs += rv; - NT_SFILL(nhdr, ahf, DT_INT32, smin, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT16, originator, 5, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, generated, 10, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, scannum, 10, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, patient_id, 10, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, exp_date, 10, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, exp_time, 10, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, NT_DT_STRING, hist_un0, 3, rv); errs += rv; + + NT_FILL(nifti_analyze75, ahf, DT_INT32, views , 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, vols_added, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, start_field, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, field_skip, 1, rv); errs += rv; + + NT_FILL(nifti_analyze75, ahf, DT_INT32, omax, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, omin, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, smax, 1, rv); errs += rv; + NT_FILL(nifti_analyze75, ahf, DT_INT32, smin, 1, rv); errs += rv; if( errs > 0 ){ fprintf(stderr, "** %d ana fill_fields errors!\n", errs); @@ -3284,7 +3285,7 @@ int fill_ana_field_array( field_s * ah_fields ) /* failure here is a serious problem */ if( check_total_size("nifti_analyze75 test: ", ah_fields, NT_ANA_NUM_FIELDS, - sizeof(nhdr)) ) + sizeof(nifti_analyze75)) ) return 1; if( g_debug > 3 ) @@ -3343,7 +3344,8 @@ int fill_field( field_s * fp, int type, int offset, int num, const char * name ) fp->size = 1; /* init before check */ fp->len = num; - strncpy(fp->name, name, NT_FIELD_NAME_LEN-1); + strncpy(fp->name, name, sizeof(fp->name)); + fp->name[sizeof(fp->name) - 1] = 0; switch( type ){ case DT_UNKNOWN: @@ -3569,7 +3571,7 @@ int diff_field(field_s *fieldp, void * str0, void * str1, int nfields) /*---------------------------------------------------------------------- * display a single extension *----------------------------------------------------------------------*/ -int disp_nifti1_extension( const char *mesg, nifti1_extension * ext, int maxlen) +int disp_nifti1_extension( const char *mesg, const nifti1_extension * ext, int maxlen) { int len; if( mesg ) fputs(mesg, stdout); @@ -3602,7 +3604,7 @@ int disp_nifti1_extension( const char *mesg, nifti1_extension * ext, int maxlen) /*---------------------------------------------------------------------- - * return the appropritate pointer into the g_hdr_fields struct + * return the appropriate pointer into the g_hdr_fields struct *----------------------------------------------------------------------*/ field_s * get_hdr_field( const char * fname, int show_fail ) { @@ -3627,7 +3629,7 @@ field_s * get_hdr_field( const char * fname, int show_fail ) /*---------------------------------------------------------------------- - * return the appropritate pointer into the g_hdr_fields struct + * return the appropriate pointer into the g_hdr_fields struct *----------------------------------------------------------------------*/ field_s * get_nim_field( const char * fname, int show_fail ) { @@ -4132,7 +4134,7 @@ static int free_opts_mem( nt_opts * nopt ) /*---------------------------------------------------------------------- * wrapper for nifti_image_read * - * this adds the option to generage an empty image, if the + * this adds the option to generate an empty image, if the * filename starts with "MAKE_IM" *----------------------------------------------------------------------*/ nifti_image * nt_image_read( nt_opts * opts, const char * fname, int doread ) @@ -4144,7 +4146,7 @@ nifti_image * nt_image_read( nt_opts * opts, const char * fname, int doread ) } /* if the user does not want an empty image, do normal image_read */ - if( strncmp(fname,NT_MAKE_IM_NAME,strlen(NT_MAKE_IM_NAME)) ) { + if( strncmp(fname,NT_MAKE_IM_NAME,strlen(NT_MAKE_IM_NAME)) != 0 ) { if(g_debug > 1) fprintf(stderr,"-d calling nifti_image_read(%s,%d)\n",fname,doread); return nifti_image_read(fname, doread); @@ -4169,7 +4171,7 @@ nifti_image * nt_image_read( nt_opts * opts, const char * fname, int doread ) /*---------------------------------------------------------------------- * wrapper for nifti_read_header * - * this adds the option to generage an empty image, if the + * this adds the option to generate an empty image, if the * filename starts with "MAKE_IM" *----------------------------------------------------------------------*/ nifti_1_header * nt_read_header(nt_opts * opts, const char * fname, int * swapped, @@ -4183,7 +4185,7 @@ nifti_1_header * nt_read_header(nt_opts * opts, const char * fname, int * swappe } /* if the user does not want an empty image, do normal image_read */ - if( strncmp(fname,NT_MAKE_IM_NAME,strlen(NT_MAKE_IM_NAME)) ) { + if( strncmp(fname,NT_MAKE_IM_NAME,strlen(NT_MAKE_IM_NAME)) != 0 ) { if(g_debug > 1) fprintf(stderr,"-d calling nifti_read_header(%s,...)\n", fname); return nifti_read_header(fname, swapped, check); @@ -4209,7 +4211,7 @@ nifti_1_header * nt_read_header(nt_opts * opts, const char * fname, int * swappe /*---------------------------------------------------------------------- * wrapper for nifti_read_header * - * this adds the option to generage an empty image, if the + * this adds the option to generate an empty image, if the * filename starts with "MAKE_IM" *----------------------------------------------------------------------*/ nifti_image * nt_read_bricks(nt_opts * opts, const char * fname, int len, int * list, @@ -4226,7 +4228,7 @@ nifti_image * nt_read_bricks(nt_opts * opts, const char * fname, int len, int * } /* if the user does not want an empty image, do normal read_bricks */ - if( strncmp(fname,NT_MAKE_IM_NAME,strlen(NT_MAKE_IM_NAME)) ) { + if( strncmp(fname,NT_MAKE_IM_NAME,strlen(NT_MAKE_IM_NAME)) != 0 ) { if(g_debug > 1) fprintf(stderr,"-d calling nifti_image_read_bricks(%s,...)\n",fname); return nifti_image_read_bricks(fname, len, list, NBL); diff --git a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_tool.h b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_tool.h index d2e01169a35..035db3ca47b 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_tool.h +++ b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_tool.h @@ -85,13 +85,10 @@ typedef struct { char name[NT_FIELD_NAME_LEN]; /* actual structure name used */ } field_s; -/* for computing the offset from the start of the struct */ -#define NT_OFF(str,field) ((int)( ((char *)&str.field) - ((char *)&str) )) - /* call fill_field() for a single type, name and number of elements */ /* nstr is the base struct, and fldp is a field pointer */ -#define NT_SFILL(nstr,fldp,type,name,num,rv) do{ \ - rv=fill_field(fldp,type,NT_OFF(nstr,name),num,#name); \ +#define NT_FILL(nstr,fldp,type,name,num,rv) do{ \ + rv=fill_field(fldp,type,offsetof(nstr,name),num,#name); \ fldp++; } while (0) #define NT_MAKE_IM_NAME "MAKE_IM" @@ -133,7 +130,7 @@ int add_string (str_list * slist, const char * str); int check_total_size ( const char *mesg, field_s *fields, int nfields, int tot_size); int clear_float_zeros( char * str ); int diff_field (field_s *fieldp, void * str0, void * str1, int nfields); -int disp_nifti1_extension( const char *mesg, nifti1_extension * ext, int maxlen); +int disp_nifti1_extension( const char *mesg, const nifti1_extension * ext, int maxlen); int disp_field ( const char *mesg,field_s *fieldp,void *str,int nfields,int header); int disp_field_s_list( const char *mesg, field_s *, int nfields); int disp_nt_opts ( const char *mesg, nt_opts * opts); @@ -160,4 +157,4 @@ nifti_1_header * nt_read_header(nt_opts * opts, const char * fname, int * swappe int check); -#endif /* NIFTI1_TOOL_H */ +#endif /* NIFTI1_TOOL_H */ \ No newline at end of file diff --git a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti_tester001.c b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti_tester001.c index 60f033082e0..d22f2b54172 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti_tester001.c +++ b/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti_tester001.c @@ -3,21 +3,17 @@ */ #include #include -enum NIFTITEST_BOOL { - NIFTITEST_TRUE=1, - NIFTITEST_FALSE=0 -}; -static void PrintTest_eng(const int line,const char * message,const int FailureOccured, const enum NIFTITEST_BOOL isFatal,int *ErrorAccum,bool verbose) +static void PrintTest_eng(const int line,const char * message,const int FailureOccured, bool isFatal,int *ErrorAccum,bool verbose) { - if(verbose || FailureOccured==NIFTITEST_TRUE) + if(verbose || FailureOccured==true) { char const * const PREFIX= (FailureOccured)?"==========ERROR":"..........SUCCESS"; char const * const ISFATALPREFIX= (isFatal && FailureOccured)?" FATAL":""; printf("%s%s (LINE %d): %s\n",PREFIX,ISFATALPREFIX,line,message); fflush(stdout); *ErrorAccum+=FailureOccured; - if(isFatal==NIFTITEST_TRUE && FailureOccured==NIFTITEST_TRUE) + if(isFatal==true && FailureOccured==true) { printf("\n\nTOTAL ERRORS=%d\n",*ErrorAccum); exit( *ErrorAccum); @@ -85,8 +81,10 @@ static nifti_image * generate_reference_image( const char * write_image_filename reference_header.magic[2]='1'; reference_header.magic[3]='\0'; /* String is purposfully too long */ - strncpy(reference_header.intent_name,"PHANTOM_DATA to be used for regression testing the nifti reader/writer",16); - strncpy(reference_header.descrip,"This is a very long dialog here to use up more than 80 characters of space to test to see if the code is robust enough to deal appropriately with very long and obnoxious lines.",80); + strncpy(reference_header.intent_name,"PHANTOM_DATA to be used for regression testing the nifti reader/writer",sizeof(reference_header.intent_name)); + reference_header.intent_name[sizeof(reference_header.intent_name) - 1] = 0; + strncpy(reference_header.descrip,"This is a very long dialog here to use up more than 80 characters of space to test to see if the code is robust enough to deal appropriately with very long and obnoxious lines.",sizeof(reference_header.descrip)); + reference_header.descrip[sizeof(reference_header.descrip) - 1] = 0; { int nbyper; @@ -99,7 +97,7 @@ static nifti_image * generate_reference_image( const char * write_image_filename { const unsigned int NumVoxels=reference_image->nx*reference_image->ny*reference_image->nz*reference_image->nt*reference_image->nu; reference_image->data=(signed int *)calloc(NumVoxels,sizeof(signed int)) ; /*!< pointer to data: nbyper*nvox bytes */ - PrintTest("Checking memory allocation",reference_image->data ==0 ,NIFTITEST_TRUE,Errors); + PrintTest("Checking memory allocation",reference_image->data ==0 ,true,Errors); { if(reference_image->data) { @@ -111,10 +109,10 @@ static nifti_image * generate_reference_image( const char * write_image_filename } } } - PrintTest("Setting filenames",nifti_set_filenames( reference_image,write_image_filename, 0, 0 ) != 0, NIFTITEST_TRUE,Errors); - PrintTest("Setting type from names",nifti_set_type_from_names( reference_image ) != 0, NIFTITEST_TRUE,Errors); - /* PrintTest("Checking type and names",nifti_type_and_names_match( reference_image , 1 ) != 1, NIFTITEST_TRUE,Errors); */ - PrintTest("Check reference_image data is non null",(reference_image->data==0),NIFTITEST_TRUE,Errors); + PrintTest("Setting filenames",nifti_set_filenames( reference_image,write_image_filename, 0, 0 ) != 0, true,Errors); + PrintTest("Setting type from names",nifti_set_type_from_names( reference_image ) != 0, true,Errors); + /* PrintTest("Checking type and names",nifti_type_and_names_match( reference_image , 1 ) != 1, true,Errors); */ + PrintTest("Check reference_image data is non null",(reference_image->data==0),true,Errors); return reference_image; } @@ -131,25 +129,25 @@ static void compare_reference_image_values(nifti_image const * const reference_i printf("ERROR: Reloaded image is NULL\n"); exit(-1); } - PrintTest("Checking nifti_type",(reference_image->nifti_type!=reloaded_image->nifti_type),NIFTITEST_FALSE,Errors); - PrintTest("Checking fname",(strcmp(reference_image->fname,reloaded_image->fname)),NIFTITEST_FALSE,Errors); - PrintTest("Checking iname",(strcmp(reference_image->iname,reloaded_image->iname)),NIFTITEST_FALSE,Errors); - PrintTest("Checking ndim",(reference_image->ndim!=reloaded_image->ndim),NIFTITEST_FALSE,Errors); - PrintTest("Checking nx",(reference_image->nx!=reloaded_image->nx),NIFTITEST_FALSE,Errors); - PrintTest("Checking ny",(reference_image->ny!=reloaded_image->ny),NIFTITEST_FALSE,Errors); - PrintTest("Checking nz",(reference_image->nz!=reloaded_image->nz),NIFTITEST_FALSE,Errors); - PrintTest("Checking nt",(reference_image->nt!=reloaded_image->nt),NIFTITEST_FALSE,Errors); - PrintTest("Checking nu",(reference_image->nu!=reloaded_image->nu),NIFTITEST_FALSE,Errors); - PrintTest("Checking dx",(reference_image->dx!=reloaded_image->dx),NIFTITEST_FALSE,Errors); - PrintTest("Checking dy",(reference_image->dy!=reloaded_image->dy),NIFTITEST_FALSE,Errors); - PrintTest("Checking dz",(reference_image->dz!=reloaded_image->dz),NIFTITEST_FALSE,Errors); - PrintTest("Checking dt",(reference_image->dt!=reloaded_image->dt),NIFTITEST_FALSE,Errors); - PrintTest("Checking du",(reference_image->du!=reloaded_image->du),NIFTITEST_FALSE,Errors); - PrintTest("Checking datatype",(reference_image->datatype!=reloaded_image->datatype),NIFTITEST_FALSE,Errors); + PrintTest("Checking nifti_type",(reference_image->nifti_type!=reloaded_image->nifti_type),false,Errors); + PrintTest("Checking fname",(strcmp(reference_image->fname,reloaded_image->fname)),false,Errors); + PrintTest("Checking iname",(strcmp(reference_image->iname,reloaded_image->iname)),false,Errors); + PrintTest("Checking ndim",(reference_image->ndim!=reloaded_image->ndim),false,Errors); + PrintTest("Checking nx",(reference_image->nx!=reloaded_image->nx),false,Errors); + PrintTest("Checking ny",(reference_image->ny!=reloaded_image->ny),false,Errors); + PrintTest("Checking nz",(reference_image->nz!=reloaded_image->nz),false,Errors); + PrintTest("Checking nt",(reference_image->nt!=reloaded_image->nt),false,Errors); + PrintTest("Checking nu",(reference_image->nu!=reloaded_image->nu),false,Errors); + PrintTest("Checking dx",(reference_image->dx!=reloaded_image->dx),false,Errors); + PrintTest("Checking dy",(reference_image->dy!=reloaded_image->dy),false,Errors); + PrintTest("Checking dz",(reference_image->dz!=reloaded_image->dz),false,Errors); + PrintTest("Checking dt",(reference_image->dt!=reloaded_image->dt),false,Errors); + PrintTest("Checking du",(reference_image->du!=reloaded_image->du),false,Errors); + PrintTest("Checking datatype",(reference_image->datatype!=reloaded_image->datatype),false,Errors); { const unsigned int NumVoxels=reference_image->nx*reference_image->ny*reference_image->nz*reference_image->nt*reference_image->nu; - PrintTest("Check loaded data is non null",(reloaded_image->data==0),NIFTITEST_TRUE,Errors); - PrintTest("Check reference_image data is non null",(reference_image->data==0),NIFTITEST_TRUE,Errors); + PrintTest("Check loaded data is non null",(reloaded_image->data==0),true,Errors); + PrintTest("Check reference_image data is non null",(reference_image->data==0),true,Errors); { unsigned int CurrVoxel=0; for(; CurrVoxel < NumVoxels ; CurrVoxel++) @@ -157,16 +155,16 @@ static void compare_reference_image_values(nifti_image const * const reference_i /*printf("%d ",CurrVoxel); fflush(stdout);*/ if( ((int *)(reference_image->data))[CurrVoxel] != ((int *)(reloaded_image->data))[CurrVoxel]) { - PrintTest("Incorrect Pixel Value Found",0,NIFTITEST_FALSE,Errors); + PrintTest("Incorrect Pixel Value Found",0,false,Errors); } } } } - PrintTest("Checking xyz_units",(reference_image->xyz_units!=reloaded_image->xyz_units),NIFTITEST_FALSE,Errors); - PrintTest("Checking time_units",(reference_image->time_units!=reloaded_image->time_units),NIFTITEST_FALSE,Errors); - PrintTest("Checking intent_code",(reference_image->intent_code!=reloaded_image->intent_code),NIFTITEST_FALSE,Errors); - PrintTest("Checking intent_name",(strncmp(reference_image->intent_name,reloaded_image->intent_name,16) )!=0,NIFTITEST_FALSE,Errors); - PrintTest("Checking description",(strncmp(reference_image->descrip,reloaded_image->descrip,80))!=0,NIFTITEST_FALSE,Errors); + PrintTest("Checking xyz_units",(reference_image->xyz_units!=reloaded_image->xyz_units),false,Errors); + PrintTest("Checking time_units",(reference_image->time_units!=reloaded_image->time_units),false,Errors); + PrintTest("Checking intent_code",(reference_image->intent_code!=reloaded_image->intent_code),false,Errors); + PrintTest("Checking intent_name",(strncmp(reference_image->intent_name,reloaded_image->intent_name,16) )!=0,false,Errors); + PrintTest("Checking description",(strncmp(reference_image->descrip,reloaded_image->descrip,80))!=0,false,Errors); } int main (int argc, const char *argv[]) @@ -179,8 +177,8 @@ int main (int argc, const char *argv[]) nifti_set_debug_level(3); int Errors=0; { - PrintTest("NOT REALLY AN ERROR, JUST TESTING THE ERROR TEST REPORTING MECHANISM",1,NIFTITEST_FALSE,&Errors); - PrintTest("NOT REALLY AN ERROR, JUST TESTING THE ERROR COUNTING MECHANISM",Errors==1,NIFTITEST_FALSE,&Errors); + PrintTest("NOT REALLY AN ERROR, JUST TESTING THE ERROR TEST REPORTING MECHANISM",1,false,&Errors); + PrintTest("NOT REALLY AN ERROR, JUST TESTING THE ERROR COUNTING MECHANISM",Errors==1,false,&Errors); Errors=0; } { @@ -220,13 +218,13 @@ int main (int argc, const char *argv[]) nifti_add_extension(reference_image, ext,sizeof(ext), NIFTI_ECODE_COMMENT) == -1, - NIFTITEST_FALSE,&Errors); + false,&Errors); snprintf(buf,sizeof(buf),"valid_nifti_extension %s",write_image_filename[filenameindex]); PrintTest("valid_nifti_extensions", valid_nifti_extensions(reference_image) == 0, - NIFTITEST_FALSE,&Errors); + false,&Errors); } - PrintTest("Create reference image",reference_image==0,NIFTITEST_TRUE,&Errors); + PrintTest("Create reference image",reference_image==0,true,&Errors); if( nifti_image_write_status( reference_image ) ) { printf("ERROR: failed to write nifti_image."); @@ -242,16 +240,16 @@ int main (int argc, const char *argv[]) nifti_image *nim = nifti_simple_init_nim(); PrintTest("nifti_copy_extension", nifti_copy_extensions(nim,reference_image), - NIFTITEST_FALSE,&Errors); + false,&Errors); nifti_image_free(nim); nim = nifti_copy_nim_info(reference_image); PrintTest("nifti_copy_nim_info", nim == 0, - NIFTITEST_FALSE,&Errors); + false,&Errors); PrintTest("nifti_nim_is_valid", nifti_nim_is_valid(nim,0) == 0, - NIFTITEST_FALSE,&Errors); + false,&Errors); nifti_image_free(nim); @@ -259,7 +257,7 @@ int main (int argc, const char *argv[]) } { nifti_image * reloaded_image = (reference_image->fname) ? nifti_image_read(reference_image->fname,1): NULL; - PrintTest("Reload of image ",reloaded_image==0,NIFTITEST_TRUE,&Errors); + PrintTest("Reload of image ",reloaded_image==0,true,&Errors); { /* @@ -272,7 +270,7 @@ int main (int argc, const char *argv[]) snprintf(buf,sizeof(buf),"reload valid_nifti_extensions %s",write_image_filename[filenameindex]); PrintTest(buf, CompressedTwoFile ? result != 0 : result == 0, - NIFTITEST_FALSE,&Errors); + false,&Errors); } nifti_image_infodump(reloaded_image); compare_reference_image_values(reference_image,reloaded_image,&Errors); @@ -290,15 +288,15 @@ int main (int argc, const char *argv[]) * test some error paths in the nifti_image_read_bricks */ nim_orig = nifti_image_read_bricks(reference_image->fname,0,blist, &NB_orig); - PrintTest("invalid arg bricked image read 1",nim_orig != 0,NIFTITEST_FALSE,&Errors); + PrintTest("invalid arg bricked image read 1",nim_orig != 0,false,&Errors); nim_orig = nifti_image_read_bricks(reference_image->fname, 0, NULL, &NB_orig); - PrintTest("Reload of bricked image",nim_orig == 0,NIFTITEST_FALSE,&Errors); + PrintTest("Reload of bricked image",nim_orig == 0,false,&Errors); nifti_free_NBL(&NB_orig); nifti_image_free(nim_orig); nim_select = nifti_image_read_bricks(reference_image->fname, 5, blist, &NB_select); - PrintTest("Reload of bricked image with blist",nim_orig == 0,NIFTITEST_FALSE,&Errors); + PrintTest("Reload of bricked image with blist",nim_orig == 0,false,&Errors); nifti_free_NBL(&NB_select); nifti_image_free(nim_select); @@ -308,18 +306,18 @@ int main (int argc, const char *argv[]) */ PrintTest("nifti_update_dims_from_array -- valid dims", nifti_update_dims_from_array(reference_image) != 0, - NIFTITEST_FALSE,&Errors); + false,&Errors); reference_image->dim[0] = 8; PrintTest("nifti_update_dims_from_array -- invalid dims", nifti_update_dims_from_array(reference_image) == 0, - NIFTITEST_FALSE,&Errors); + false,&Errors); { nifti_1_header x = nifti_convert_nim2nhdr(reference_image); char local_buffer[512]; snprintf(local_buffer,sizeof(local_buffer),"nifti_hdr_looks_good %s",reference_image->fname); PrintTest(local_buffer, !nifti_hdr_looks_good(&x), - NIFTITEST_FALSE,&Errors); + false,&Errors); } nifti_image_free(reference_image); @@ -332,23 +330,23 @@ int main (int argc, const char *argv[]) PrintTest("nifti_findimgname", imgname == 0 || strcmp(imgname,"ATestReferenceImageForReadingAndWriting.img") != 0, - NIFTITEST_FALSE,&Errors); + false,&Errors); free(imgname); } { int IsNiftiFile; IsNiftiFile = is_nifti_file(write_image_filename[0]); PrintTest("is_nifti_file0", - IsNiftiFile != 1,NIFTITEST_FALSE,&Errors); + IsNiftiFile != 1,false,&Errors); IsNiftiFile = is_nifti_file(write_image_filename[1]); PrintTest("is_nifti_file1", - IsNiftiFile != 2,NIFTITEST_FALSE,&Errors); + IsNiftiFile != 2,false,&Errors); IsNiftiFile = is_nifti_file(write_image_filename[3]); PrintTest("is_nifti_file2", - IsNiftiFile != 1,NIFTITEST_FALSE,&Errors); + IsNiftiFile != 1,false,&Errors); IsNiftiFile = is_nifti_file(write_image_filename[4]); PrintTest("is_nifti_file2", - IsNiftiFile != 2,NIFTITEST_FALSE,&Errors); + IsNiftiFile != 2,false,&Errors); } } @@ -367,7 +365,7 @@ int main (int argc, const char *argv[]) nifti_image * reloaded_image = nifti_image_read("TestAsciiImage.nia",1); PrintTest("Read/Write Ascii image", - reloaded_image == 0,NIFTITEST_FALSE,&Errors); + reloaded_image == 0,false,&Errors); nifti_image_free(reference_image); nifti_image_free(reloaded_image); } @@ -422,18 +420,18 @@ int main (int argc, const char *argv[]) { int KnownValid=nifti_validfilename(FILE_NAMES[fni]); snprintf(TEMP_STR,256,"nifti_validfilename(\"%s\")=%d",FILE_NAMES[fni],KnownValid); - PrintTest(TEMP_STR,KnownValid != KNOWN_nifti_validfilename[fni],NIFTITEST_FALSE,&Errors); + PrintTest(TEMP_STR,KnownValid != KNOWN_nifti_validfilename[fni],false,&Errors); } { int KnownValid=nifti_is_complete_filename(FILE_NAMES[fni]); snprintf(TEMP_STR,256,"nifti_is_complete_filename(\"%s\")=%d",FILE_NAMES[fni],KnownValid); - PrintTest(TEMP_STR,KnownValid != KNOWN_nifti_is_complete_filename[fni],NIFTITEST_FALSE,&Errors); + PrintTest(TEMP_STR,KnownValid != KNOWN_nifti_is_complete_filename[fni],false,&Errors); } { char * basename=nifti_makebasename(FILE_NAMES[fni]); snprintf(TEMP_STR,256,"nifti_makebasename(\"%s\")=\"%s\"",FILE_NAMES[fni],basename); - PrintTest(TEMP_STR,strcmp(basename,KNOWN_FILE_BASENAMES[fni]) != 0,NIFTITEST_FALSE,&Errors); + PrintTest(TEMP_STR,strcmp(basename,KNOWN_FILE_BASENAMES[fni]) != 0,false,&Errors); free(basename); } @@ -450,12 +448,12 @@ int main (int argc, const char *argv[]) PrintTest( "nifti_image_read_bricks 1", nifti_image_read_bricks((char *)0,-1,(const int *)0,(nifti_brick_list *)0) != 0, - NIFTITEST_FALSE, + false, &Errors); PrintTest( "nifti_image_read_bricks 1", nifti_image_read_bricks("NOFILE.NOFILE",-1,(const int *)0,(nifti_brick_list *)0) != 0, - NIFTITEST_FALSE, + false, &Errors); } /* @@ -468,7 +466,7 @@ int main (int argc, const char *argv[]) PrintTest( \ buf, \ strcmp(nifti_datatype_string(constant),string) != 0, \ - NIFTITEST_FALSE, \ + false, \ &Errors); \ } nifti_datatype_test(DT_UNKNOWN,"UNKNOWN"); @@ -495,7 +493,7 @@ int main (int argc, const char *argv[]) PrintTest( \ buf, \ nifti_is_inttype(constant) != rval, \ - NIFTITEST_FALSE, \ + false, \ &Errors); \ } nifti_is_inttype_test(DT_UNKNOWN,0); @@ -522,7 +520,7 @@ int main (int argc, const char *argv[]) PrintTest( \ buf, \ strcmp(nifti_units_string(constant),string) != 0, \ - NIFTITEST_FALSE, \ + false, \ &Errors); \ } nifti_units_string_test(NIFTI_UNITS_METER,"m"); @@ -541,7 +539,7 @@ int main (int argc, const char *argv[]) PrintTest( \ buf, \ strcmp(nifti_intent_string(constant),string) != 0, \ - NIFTITEST_FALSE, \ + false, \ &Errors); \ } nifti_intent_string_test(NIFTI_INTENT_CORREL,"Correlation statistic"); @@ -587,7 +585,7 @@ int main (int argc, const char *argv[]) PrintTest( \ buf, \ strcmp(nifti_slice_string(constant),string) != 0, \ - NIFTITEST_FALSE, \ + false, \ &Errors); \ } nifti_slice_string_test(NIFTI_SLICE_SEQ_INC,"sequential_increasing"); @@ -603,7 +601,7 @@ int main (int argc, const char *argv[]) PrintTest( \ buf, \ strcmp(nifti_orientation_string(constant),string) != 0, \ - NIFTITEST_FALSE, \ + false, \ &Errors); \ } nifti_orientation_string_test(NIFTI_L2R,"Left-to-Right"); @@ -623,7 +621,7 @@ int main (int argc, const char *argv[]) PrintTest( \ buf, \ nbyper != Nbyper || swapsize != Swapsize, \ - NIFTITEST_FALSE, \ + false, \ &Errors); \ } @@ -656,10 +654,10 @@ int main (int argc, const char *argv[]) nifti_mat44_to_quatern(R,&qb,&qc,&qd,&qx,&qy,&qz,&dx,&dy,&dz,&qfac); PrintTest("nifti_mat44_to_quatern", qb != 0.000000 || qc != 0.000000 || qd != 0.000000 || - qx != 0.000000 || qy != 0.000000 || qd != 0.000000 || + qx != 0.000000 || qy != 0.000000 || qz != 0.000000 || dx != 1.000000 || dy != 1.000000 || dz != 1.000000 || qfac != 1.000000, - NIFTITEST_FALSE,&Errors); + false,&Errors); } { mat44 x = nifti_make_orthog_mat44(0.14,0.0,0.0, @@ -669,7 +667,7 @@ int main (int argc, const char *argv[]) PrintTest("nifti_make_orthog_mat44", x.m[0][0] != 1.0 || x.m[1][1] != 1.0 || x.m[2][2] != 1.0 || x.m[3][3] != 1.0, - NIFTITEST_FALSE,&Errors); + false,&Errors); } { static char x[16] = { 'a','b','c','d','e','f','g','h', @@ -680,7 +678,7 @@ int main (int argc, const char *argv[]) x[4] != 'E' || x[5] != 'F' || x[6] != 'G' || x[7] != 'H' || x[8] != 'h' || x[9] != 'g' || x[10] != 'f' || x[11] != 'e' || x[12] != 'd' || x[13] != 'c' || x[14] != 'b' || x[15] != 'a', - NIFTITEST_FALSE,&Errors); + false,&Errors); } { @@ -689,7 +687,7 @@ int main (int argc, const char *argv[]) PrintTest("nifti_swap_8bytes", x[0] != 'A' || x[1] != 'B' || x[2] != 'C' || x[3] != 'D' || x[4] != 'd' || x[5] != 'c' || x[6] != 'b' || x[7] != 'a', - NIFTITEST_FALSE,&Errors); + false,&Errors); } { @@ -698,7 +696,7 @@ int main (int argc, const char *argv[]) */ nifti_image *nim = nifti_simple_init_nim(); PrintTest("nifti_simple_init_nim", - nim == 0,NIFTITEST_FALSE,&Errors); + nim == 0,false,&Errors); nifti_image_free(nim); nim = 0; /* * test nifti_image_open @@ -706,14 +704,14 @@ int main (int argc, const char *argv[]) znzFile f = nifti_image_open("ATestReferenceImageForReadingAndWriting.hdr","r",&nim); PrintTest("nifti_image_open", nim == 0 || f == 0, - NIFTITEST_FALSE,&Errors); + false,&Errors); PrintTest("nifti_image_load", nifti_image_load(nim) == -1, - NIFTITEST_FALSE,&Errors); + false,&Errors); nifti_image_unload(nim); PrintTest("nifti_image_unload", nim->data != 0, - NIFTITEST_FALSE,&Errors); + false,&Errors); znzclose(f); nifti_image_free(nim); diff --git a/Modules/ThirdParty/NIFTI/src/nifti/znzlib/CMakeLists.txt b/Modules/ThirdParty/NIFTI/src/nifti/znzlib/CMakeLists.txt index c188d9ba0db..10239be632f 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/znzlib/CMakeLists.txt +++ b/Modules/ThirdParty/NIFTI/src/nifti/znzlib/CMakeLists.txt @@ -2,6 +2,12 @@ set(NIFTI_ZNZLIB_NAME ${NIFTI_PACKAGE_PREFIX}znz) add_nifti_library(${NIFTI_ZNZLIB_NAME} znzlib.c ) target_link_libraries( ${NIFTI_ZNZLIB_NAME} PUBLIC ${NIFTI_ZLIB_LIBRARIES} ) +if(${ZLIB_FOUND}) + target_include_directories(${NIFTI_ZNZLIB_NAME} PUBLIC + ${ZLIB_INCLUDE_DIR} + ) + +endif() set_target_properties( ${NIFTI_ZNZLIB_NAME} PROPERTIES @@ -17,5 +23,7 @@ if(BUILD_SHARED_LIBS) VERSION ${ZNZLIB_VERSION} SOVERSION ${ZNZLIB_MAJOR_VERSION} ) + target_compile_definitions(${NIFTI_ZNZLIB_NAME} PRIVATE ZNZ_BUILD_SHARED) + target_compile_definitions(${NIFTI_ZNZLIB_NAME} INTERFACE ZNZ_USE_SHARED) endif() install_nifti_target(${NIFTI_ZNZLIB_NAME}) diff --git a/Modules/ThirdParty/NIFTI/src/nifti/znzlib/znzlib.c b/Modules/ThirdParty/NIFTI/src/nifti/znzlib/znzlib.c index 4f892e38081..52b5665d7a2 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/znzlib/znzlib.c +++ b/Modules/ThirdParty/NIFTI/src/nifti/znzlib/znzlib.c @@ -301,11 +301,11 @@ int znzprintf(znzFile stream, const char *format, ...) va_start(va, format); #ifdef HAVE_ZLIB if (stream->zfptr!=NULL) { - int size; /* local to HAVE_ZLIB block */ + size_t size; /* local to HAVE_ZLIB block */ size = strlen(format) + 1000000; /* overkill I hope */ tmpstr = (char *)calloc(1, size); if( tmpstr == NULL ){ - fprintf(stderr,"** ERROR: znzprintf failed to alloc %d bytes\n", size); + fprintf(stderr,"** ERROR: znzprintf failed to alloc %zu bytes\n", size); return retval; } vsprintf(tmpstr,format,va); diff --git a/Modules/ThirdParty/NIFTI/src/nifti/znzlib/znzlib.h b/Modules/ThirdParty/NIFTI/src/nifti/znzlib/znzlib.h index 1cd52586b44..ff031687d2d 100644 --- a/Modules/ThirdParty/NIFTI/src/nifti/znzlib/znzlib.h +++ b/Modules/ThirdParty/NIFTI/src/nifti/znzlib/znzlib.h @@ -76,6 +76,30 @@ extern "C" { #endif #endif +#ifndef ZNZ_API + #if defined(_WIN32) || defined(__CYGWIN__) + #if defined(ZNZ_BUILD_SHARED) + #ifdef __GNUC__ + #define ZNZ_API __attribute__ ((dllexport)) + #else + #define ZNZ_API __declspec( dllexport ) + #endif + #elif defined(ZNZ_USE_SHARED) + #ifdef __GNUC__ + #define ZNZ_API __attribute__ ((dllimport)) + #else + #define ZNZ_API __declspec( dllimport ) + #endif + #else + #define ZNZ_API + #endif + #elif (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__) + #define ZNZ_API __attribute__ ((visibility ("default"))) + #else + #define ZNZ_API + #endif +#endif + struct znzptr { int withz; FILE* nzfptr; @@ -98,35 +122,35 @@ typedef struct znzptr * znzFile; use_compression!=0 uses zlib (gzip) compression */ -znzFile znzopen(const char *path, const char *mode, int use_compression); +ZNZ_API znzFile znzopen(const char *path, const char *mode, int use_compression); #ifdef COMPILE_NIFTIUNUSED_CODE -znzFile znzdopen(int fd, const char *mode, int use_compression); +ZNZ_API znzFile znzdopen(int fd, const char *mode, int use_compression); #endif -int Xznzclose(znzFile * file); +ZNZ_API int Xznzclose(znzFile * file); -size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file); +ZNZ_API size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file); -size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file); +ZNZ_API size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file); -znz_off_t znzseek(znzFile file, znz_off_t offset, int whence); +ZNZ_API znz_off_t znzseek(znzFile file, znz_off_t offset, int whence); -int znzrewind(znzFile stream); +ZNZ_API int znzrewind(znzFile stream); -znz_off_t znztell(znzFile file); +ZNZ_API znz_off_t znztell(znzFile file); -int znzputs(const char *str, znzFile file); +ZNZ_API int znzputs(const char *str, znzFile file); #ifdef COMPILE_NIFTIUNUSED_CODE -char * znzgets(char* str, int size, znzFile file); +ZNZ_API char * znzgets(char* str, int size, znzFile file); -int znzputc(int c, znzFile file); +ZNZ_API int znzputc(int c, znzFile file); -int znzgetc(znzFile file); +ZNZ_API int znzgetc(znzFile file); #if !defined(WIN32) -int znzprintf(znzFile stream, const char *format, ...); +ZNZ_API int znzprintf(znzFile stream, const char *format, ...); #endif #endif