diff --git a/Modules/ThirdParty/NrrdIO/src/CMakeLists.txt b/Modules/ThirdParty/NrrdIO/src/CMakeLists.txt index 59a7b768629..c80fd0bfb67 100644 --- a/Modules/ThirdParty/NrrdIO/src/CMakeLists.txt +++ b/Modules/ThirdParty/NrrdIO/src/CMakeLists.txt @@ -3,5 +3,24 @@ set(ITK3P_INSTALL_INCLUDE_DIR "${ITKNrrdIO_INSTALL_INCLUDE_DIR}") set(ITK3P_INSTALL_RUNTIME_DIR "${ITKNrrdIO_INSTALL_RUNTIME_DIR}") set(ITK3P_INSTALL_LIBRARY_DIR "${ITKNrrdIO_INSTALL_LIBRARY_DIR}") set(ITK3P_INSTALL_ARCHIVE_DIR "${ITKNrrdIO_INSTALL_ARCHIVE_DIR}") + +set(NRRDIO_PREFIX ITK) +# ZLIB: +set(NRRDIO_USE_ZLIB OFF) +set(TEEM_ITK_MANGLE 1) # Needed to generate public facing ITKNrrdIO.h from ITKNrrdIO.h.in with TEEM_ITK_MANGLE=1 always +add_definitions(-DTEEM_ITK_MANGLE=${TEEM_ITK_MANGLE}) # Needed for privateNrrd.h (only used when building library, no public api). +add_definitions(-DTEEM_ZLIB=1) # Force setting zlib support here +set(ZLIB_INCLUDE_DIR ${ITKZLIB_INCLUDE_DIRS}) +set(ZLIB_LIBRARY ${ITKZLIB_LIBRARIES}) +list(APPEND NRRDIO_COMPRESSION_LIBRARIES ${ITKZLIB_LIBRARIES}) +if(UNIX) + list(APPEND NRRDIO_COMPRESSION_LIBRARIES m) + list(REMOVE_DUPLICATES NRRDIO_COMPRESSION_LIBRARIES) +endif() + +# BZIP2 +set(NRRDIO_USE_BZIP2 OFF) # Not yet supported in ITK +add_definitions(-UTEEM_BZIP2) # Force unsetting bzip2 support here + add_subdirectory(NrrdIO) itk_module_target(ITKNrrdIO NO_INSTALL) diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/.clang-format b/Modules/ThirdParty/NrrdIO/src/NrrdIO/.clang-format new file mode 100644 index 00000000000..1a1fab165b4 --- /dev/null +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/.clang-format @@ -0,0 +1,28 @@ +# Created by GLK in June 2022 as part of rebooting effort to do a Teem release +# Significant experimentation went into trying to match the existing style, +# except for # columns going up from 79 to 89. +# This file is what provides info to "clang-format -style=file" when run in +# this directory or a subdirectory. The teem/src/_util/clang-format.sh +# script helps do this. +# For more info see: https://clang.llvm.org/docs/ClangFormat.html +--- +Language: C +BasedOnStyle: LLVM +ColumnLimit: 89 +AlwaysBreakAfterDefinitionReturnType: All +AlwaysBreakAfterReturnType: None +PenaltyReturnTypeOnItsOwnLine: 400 +AllowShortIfStatementsOnASingleLine: WithoutElse +PenaltyBreakBeforeFirstCallParameter: 100 +PenaltyBreakAssignment: 50 +AlignOperands: AlignAfterOperator +BreakBeforeBinaryOperators: All +PenaltyBreakOpenParenthesis: 300 +ContinuationIndentWidth: 2 +SortIncludes: false +ExperimentalAutoDetectBinPacking: true +IndentPPDirectives: AfterHash +AllowShortEnumsOnASingleLine: false +AlignConsecutiveMacros: AcrossComments +AllowShortFunctionsOnASingleLine: All +... diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/000-README.txt b/Modules/ThirdParty/NrrdIO/src/NrrdIO/000-README.txt deleted file mode 100644 index 8f4042f9bdb..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/000-README.txt +++ /dev/null @@ -1,122 +0,0 @@ ---------------------------------------------------------------------------- -License ------------------------------------------------------------------- ---------------------------------------------------------------------------- - - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. - ---------------------------------------------------------------------------- -General information ------------------------------------------------------- ---------------------------------------------------------------------------- - -** NOTE: These source files have been copied and/or modified from Teem, -** . Teem is licensed under a weakened GNU Lesser Public -** License (the weakening is to remove burdens on those releasing binaries -** that statically link against Teem) . The non-reciprocal licensing defined -** above applies to only the source files in the NrrdIO distribution, and not -** to Teem. - -NrrdIO is a modified and highly abbreviated version of the Teem. NrrdIO -contains only the source files (or portions thereof) required for -creating and destroying nrrds, and for getting them into and out of -files. The NrrdIO sources are created from the Teem sources by using -GNU Make (pre-GNUmakefile in the NrrdIO distribution). - -NrrdIO makes it very easy to add support for the NRRD file format to your -program, which is a good thing considering and design and flexibility of the -NRRD file format, and the existence of the "unu" command-line tool for -operating on nrrds. Using NrrdIO requires exactly one header file, -"NrrdIO.h", and exactly one library, libNrrdIO. - -Currently, the API presented by NrrdIO is a strict subset of the Teem API. -There is no additional encapsulation or abstraction. This could be annoying -in the sense that you still have to deal with the biff (for error messages) -and the air (for utilities) library function calls. Or it could be good and -sane in the sense that code which uses NrrdIO can be painlessly "upgraded" to -use more of Teem. Also, the API documentation for the same functionality in -Teem will apply directly to NrrdIO. - -NrrdIO was originally created with the help of Josh Cates in order to add -support for the NRRD file format to the Insight Toolkit (ITK). - ---------------------------------------------------------------------------- -NrrdIO API crash course --------------------------------------------------- ---------------------------------------------------------------------------- - -Please read . The functions that -are explained in detail are all present in NrrdIO. Be aware, however, that -NrrdIO currently supports ONLY the NRRD file format, and not: PNG, PNM, VTK, -or EPS. - -The functionality in Teem's nrrd library which is NOT in NrrdIO is basically -all those non-trivial manipulations of the values in the nrrd, or their -ordering in memory. Still, NrrdIO can do a fair amount, namely all the -functions listed in these sections of the "Overview of rest of API" in the -above web page: - -- Basic "methods" -- Manipulation of per-axis meta-information -- Utility functions -- Comments in nrrd -- Key/value pairs -- Endianness (byte ordering) -- Getting/Setting values (crude!) -- Input from, Output to files - ---------------------------------------------------------------------------- -Files comprising NrrdIO --------------------------------------------------- ---------------------------------------------------------------------------- - -NrrdIO.h: The single header file that declares all the functions and variables -that NrrdIO provides. - -sampleIO.c: Tiny little command-line program demonstrating the basic NrrdIO -API. Read this for examples of how NrrdIO is used to read and write NRRD -files. - -CMakeLists.txt: to build NrrdIO with CMake - -pre-GNUmakefile: how NrrdIO sources are created from the Teem -sources. Requires that TEEM_SRC_ROOT be set, and uses the following two files. - -tail.pl, unteem.pl: used to make small modifications to the source files to -convert them from Teem to NrrdIO sources - -mangle.pl: used to generate a #include file for name-mangling the external -symbols in the NrrdIO library, to avoid possible problems with programs -that link with both NrrdIO and the rest of Teem. - -preamble.c: the preamble describing the non-copyleft licensing of NrrdIO. - -qnanhibit.c: discover a variable which, like endianness, is architecture -dependent and which is required for building NrrdIO (as well as Teem), but -unlike endianness, is completely obscure and unheard of. - -encodingBzip2.c, formatEPS.c, formatPNG.c, formatPNM.c, formatText.c, -formatVTK.c: These files create stubs for functionality which is fully present -in Teem, but which has been removed from NrrdIO in the interest of simplicity. -The filenames are in fact unfortunately misleading, but they should be -understood as listing the functionality that is MISSING in NrrdIO. - -All other files: copied/modified from the air, biff, and nrrd libraries of -Teem. diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/754.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/754.c index 8de328ad202..cf9afbce50d 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/754.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/754.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -25,7 +25,69 @@ #include "NrrdIO.h" #include "privateAir.h" -#include "teemQnanhibit.h" + +/* clang-format off */ +static const char *_airFPClass_Str[AIR_FP_MAX+1] = { + "(unknown_class)", + "nan", + "pinf", + "ninf", + "pnorm", + "nnorm", + "pdenorm", + "ndenorm", + "pzero", + "nzero", +}; + +static const char *_airFPClass_Desc[AIR_FP_MAX+1] = { + "unknown_class", + "(quiet) nan", + "positive infinity", + "negative infinity", + "positive normalized", + "negative normalized", + "positive denormalized", + "negative denormalized", + "positive zero", + "negative zero", +}; + +static const char *_airFPClass_StrEqv[] = { + "nan", "qnan", + "pinf", "posinf", "+inf", "inf", + "ninf", "neginf", "-inf", + "pnorm", "posnorm", "+norm", "norm", + "nnorm", "negnorm", "-norm", + "pdenorm", "posdenorm", "+denorm", "denorm", + "ndenorm", "negdenorm", "-denorm", + "pzero", "+0", "+zero", "zero", "0", + "nzero", "-0", "-zero", + "", +}; + +static const int _airFPClass_ValEqv[] = { + airFP_NAN, airFP_NAN, + airFP_POS_INF, airFP_POS_INF, airFP_POS_INF, airFP_POS_INF, + airFP_NEG_INF, airFP_NEG_INF, airFP_NEG_INF, + airFP_POS_NORM, airFP_POS_NORM, airFP_POS_NORM, airFP_POS_NORM, + airFP_NEG_NORM, airFP_NEG_NORM, airFP_NEG_NORM, + airFP_POS_DENORM, airFP_POS_DENORM, airFP_POS_DENORM, airFP_POS_DENORM, + airFP_NEG_DENORM, airFP_NEG_DENORM, airFP_NEG_DENORM, + airFP_POS_ZERO, airFP_POS_ZERO, airFP_POS_ZERO, airFP_POS_ZERO, airFP_POS_ZERO, + airFP_NEG_ZERO, airFP_NEG_ZERO, airFP_NEG_ZERO, +}; + +static const airEnum _airFPClass_ae = {"FP_class", + AIR_FP_MAX, + _airFPClass_Str, + NULL, + _airFPClass_Desc, + _airFPClass_StrEqv, + _airFPClass_ValEqv, + AIR_FALSE}; +const airEnum *const airFPClass_ae = &_airFPClass_ae; +/* clang-format on */ /* ** all this is based on a reading of @@ -39,80 +101,42 @@ ** which includes some discussion on signal-vs-quiet nan */ -/* -** _airFloatEndian{Little,Big}, _airDoubleEndian{Little,Big} -** -** these unions facilitate converting amongst -** i: unsigned integral type -** c: (sign,exp,frac) triples of unsigned integral components -** v: the floating point numbers these bit-patterns represent -*/ -typedef union { - unsigned int i; - struct { - unsigned int mant : 23; - unsigned int expo : 8; - unsigned int sign : 1; - } c; - float v; -} _airFloatEndianLittle; -/* HEY COPY AND PASTE */ -typedef union { - unsigned int i; - struct { - unsigned int sign : 1; - unsigned int expo : 8; - unsigned int mant : 23; - } c; - float v; -} _airFloatEndianBig; - -typedef union { - airULLong i; - /* these next two members are used for printing in airFPFprintf_d */ - struct { /* access to whole double as two unsigned ints */ - unsigned int half0 : 32; - unsigned int half1 : 32; - } h; - struct { /* access to fraction with two unsigned ints */ - unsigned int mant1 : 32; - unsigned int mant0 : 20; - unsigned int expo : 11; - unsigned int sign : 1; - } c; - double v; -} _airDoubleEndianLittle; -/* HEY COPY AND PASTE */ -typedef union { - airULLong i; - /* these next two members are used for printing in airFPFprintf_d */ - struct { /* access to whole double as two unsigned ints */ - unsigned int half1 : 32; - unsigned int half0 : 32; - } h; - struct { /* access to fraction with two unsigned ints */ - unsigned int sign : 1; - unsigned int expo : 11; - unsigned int mant0 : 20; - unsigned int mant1 : 32; - } c; - double v; -} _airDoubleEndianBig; - /* ** The hex numbers in braces are examples of C's "initial member of a union" ** aggregate initialization. */ -#if TEEM_QNANHIBIT == 1 -const int airMyQNaNHiBit = 1; -const airFloat airFloatQNaN = {0x7fffffff}; -const airFloat airFloatSNaN = {0x7fbfffff}; -#else -const int airMyQNaNHiBit = 0; -const airFloat airFloatQNaN = {0x7fbfffff}; -const airFloat airFloatSNaN = {0x7fffffff}; -#endif +/* +With TeemV2, GLK decided to drop configuration-time learning of, and compile-time +handling of, "QNaNHiBit": the most significant bit (MSB) of the fraction bitfield in a +quiet (versus signalling) NaN. + +In ~2000 when this code was written, if you generated a NaN from scratch via floating +point (FP) operations (e.g. create an inf by overflowing multiplication, and then divide +inf by itself), then SGI IRIX machines would set to the MSB fraction bit to 0, rather +than the 1 that other machines used. With the assumption that these operations should +have created what should be a quiet NaN, GLK interpreted this as a platform dependence in +how a quiet NaN with the same bit pattern should be created at compile time. This +motivated handling variable QNaNHiBit at configuration time, and the associated +complication in the code below. + +Now, the world now seems to agree that QNaNHiBit should be 1 (and the +http://en.wikipedia.org/wiki/NaN#Encoding URL, noted above in the first iterations of +754.c and which has happily remained valid over 25 years, now documents this). For +whatever tiny extant fraction of the world wants QNaNHiBit to be 0, they may risk +floating point signal handlers being triggered by the NaN generated here at compile +time. Hopefully they have the wherewithal to disable those signal handlers for that +circumstance. + +With the simplification of how QNaN is handled, the decision was also made to make +"NaN" in Teem code refer to a quiet NaN, with no pretense of generating signalling +NaNs at compile-time. Teem has never invoked an FP signal handler, and has no reason +to start now. So airFloatQNaN turned into airFloatQNaN and airFloatSNaN was dropped. +*/ +/* #if TEEM_QNANHIBIT == 1 ... (no more) */ +/* const unsigned int airMyQNaNHiBit = 1; (no more) */ +#define _QNANHIBIT 1 /* just for this file */ +const airFloat airFloatNaN = {0x7fffffff}; const airFloat airFloatPosInf = {0x7f800000}; const airFloat airFloatNegInf = {0xff800000}; /* why does solaris whine? */ @@ -137,72 +161,23 @@ extern air_export const airDouble airDoubleMin; #define AIR_DBL_MAX (airDoubleMax.d) */ -/* the bit-masking done here quiets gcc -Wconversion warnings */ -#define FP_SET_F(flit, fbig, s, e, m) \ - flit.c.sign = 1u & (s); \ - flit.c.expo = ((1u<8)-1) & (e); \ - flit.c.mant = ((1u<23)-1) & (m); \ - fbig.c.sign = 1u & (s); \ - fbig.c.expo = ((1u<8)-1) & (e); \ - fbig.c.mant = ((1u<23)-1) & (m) - -#define FP_GET_F(s, e, m, flit, fbig) \ - if (airEndianLittle == airMyEndian()) { \ - (s) = flit.c.sign; \ - (e) = flit.c.expo; \ - (m) = flit.c.mant; \ - } else { \ - (s) = fbig.c.sign; \ - (e) = fbig.c.expo; \ - (m) = fbig.c.mant; \ - } - -#define FP_SET_D(dlit, dbig, s, e, m0, m1) \ - dlit.c.sign = 1u & (s); \ - dlit.c.expo = ((1u<<11)-1) & (e); \ - dlit.c.mant0 = ((1u<<20)-1) & (m0); \ - dlit.c.mant1 = (m1); \ - dbig.c.sign = 1u & (s); \ - dbig.c.expo = ((1u<<11)-1) & (e); \ - dbig.c.mant0 = ((1u<<20)-1) & (m0); \ - dbig.c.mant1 = (m1) - -#define FP_GET_D(s, e, m0, m1, dlit, dbig) \ - if (airEndianLittle == airMyEndian()) { \ - (s) = dlit.c.sign; \ - (e) = dlit.c.expo; \ - (m0) = dlit.c.mant0; \ - (m1) = dlit.c.mant1; \ - } else { \ - (s) = dbig.c.sign; \ - (e) = dbig.c.expo; \ - (m0) = dbig.c.mant0; \ - (m1) = dbig.c.mant1; \ - } +#define PARTSHIFT_F(sign, expo, mant) \ + (((sign & 1u) << (8 + 23)) | /* */ \ + ((expo & ((1u << 8) - 1)) << 23) | /* */ \ + (mant & ((1u << 23) - 1))) +#define PARTSHIFT_D(sign, expo, mant0, mant1) \ + (((sign & AIR_ULLONG(1)) << (11 + 52)) | /* */ \ + ((expo & ((AIR_ULLONG(1) << 11) - 1)) << 52) | /* */ \ + ((mant0 & ((AIR_ULLONG(1) << 20) - 1)) << 32) | /* */ \ + (mant1 & ((AIR_ULLONG(1) << 32) - 1))) float -airFPPartsToVal_f(unsigned int sign, - unsigned int expo, - unsigned int mant) { - _airFloatEndianLittle flit; - _airFloatEndianBig fbig; - - FP_SET_F(flit, fbig, sign, expo, mant); - return (airEndianLittle == airMyEndian() - ? flit.v - : fbig.v); -} +airFPPartsToVal_f(unsigned int sign, unsigned int expo, unsigned int mant) { + airFloat af; -void -airFPValToParts_f(unsigned int *signP, - unsigned int *expoP, - unsigned int *mantP, float v) { - _airFloatEndianLittle flit; - _airFloatEndianBig fbig; - - flit.v = fbig.v = v; - FP_GET_F(*signP, *expoP, *mantP, flit, fbig); + af.i = PARTSHIFT_F(sign, expo, mant); + return af.f; } double @@ -210,37 +185,43 @@ airFPPartsToVal_d(unsigned int sign, unsigned int expo, unsigned int mant0, unsigned int mant1) { - _airDoubleEndianLittle dlit; - _airDoubleEndianBig dbig; + airDouble ad; - FP_SET_D(dlit, dbig, sign, expo, mant0, mant1); - return (airEndianLittle == airMyEndian() - ? dlit.v - : dbig.v); + ad.i = PARTSHIFT_D(sign, expo, mant0, mant1); + return ad.d; } -/* -** Disable the 'local variable used without having been initialized' -** warning produced by the MSVC compiler -*/ -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4700) -#endif void -airFPValToParts_d(unsigned int *signP, - unsigned int *expoP, - unsigned int *mant0P, - unsigned int *mant1P, double v) { - _airDoubleEndianLittle dlit; - _airDoubleEndianBig dbig; +airFPValToParts_f(unsigned int *signP, unsigned int *expoP, unsigned int *mantP, + float v) { + airFloat af; + unsigned int ui; + + af.f = v; + ui = af.i; + *mantP = ui & ((1u << 23) - 1); + ui >>= 23; + *expoP = ui & ((1u << 8) - 1); + ui >>= 8; + *signP = ui & 1u; +} - dlit.v = dbig.v = v; - FP_GET_D(*signP, *expoP, *mant0P, *mant1P, dlit, dbig); +void +airFPValToParts_d(unsigned int *signP, unsigned int *expoP, unsigned int *mant0P, + unsigned int *mant1P, double v) { + airDouble ad; + airULLong ui; + + ad.d = v; + ui = ad.i; + *mant1P = AIR_UINT(ui & ((AIR_ULLONG(1) << 32) - 1)); + ui >>= 32; + *mant0P = AIR_UINT(ui & ((AIR_ULLONG(1) << 20) - 1)); + ui >>= 20; + *expoP = AIR_UINT(ui & ((AIR_ULLONG(1) << 11) - 1)); + ui >>= 11; + *signP = AIR_UINT(ui & AIR_ULLONG(1)); } -#ifdef _MSC_VER -#pragma warning(pop) -#endif /* ******** airFPGen_f() @@ -249,51 +230,54 @@ airFPValToParts_d(unsigned int *signP, */ float airFPGen_f(int cls) { - _airFloatEndianLittle flit; - _airFloatEndianBig fbig; + airFloat af; + unsigned int sign, expo, mant; - switch(cls) { - case airFP_SNAN: - /* sgn: anything, mant: anything non-zero with high bit !TEEM_QNANHIBIT */ - FP_SET_F(flit, fbig, 0, 0xff, (!TEEM_QNANHIBIT << 22) | 0x3fffff); - break; - case airFP_QNAN: - /* sgn: anything, mant: anything non-zero with high bit TEEM_QNANHIBIT */ - FP_SET_F(flit, fbig, 0, 0xff, (TEEM_QNANHIBIT << 22) | 0x3fffff); +#define SET_SEM(ss, ee, mm) \ + sign = (ss); \ + expo = (ee); \ + mant = (mm) + + switch (cls) { + case airFP_NAN: + /* (no separate handling of signalling NaN) */ + SET_SEM(0, 0xff, (_QNANHIBIT << 22) | 0x3fffff); break; case airFP_POS_INF: - FP_SET_F(flit, fbig, 0, 0xff, 0); + SET_SEM(0, 0xff, 0); break; case airFP_NEG_INF: - FP_SET_F(flit, fbig, 1, 0xff, 0); + SET_SEM(1, 0xff, 0); break; case airFP_POS_NORM: /* exp: anything non-zero but < 0xff, mant: anything */ - FP_SET_F(flit, fbig, 0, 0x80, 0x7ff000); + SET_SEM(0, 0x80, 0x7ff000); break; case airFP_NEG_NORM: /* exp: anything non-zero but < 0xff, mant: anything */ - FP_SET_F(flit, fbig, 1, 0x80, 0x7ff000); + SET_SEM(1, 0x80, 0x7ff000); break; case airFP_POS_DENORM: /* mant: anything non-zero */ - FP_SET_F(flit, fbig, 0, 0, 0xff); + SET_SEM(0, 0, 0xff); break; case airFP_NEG_DENORM: /* mant: anything non-zero */ - FP_SET_F(flit, fbig, 1, 0, 0xff); + SET_SEM(1, 0, 0xff); break; case airFP_NEG_ZERO: - FP_SET_F(flit, fbig, 1, 0, 0); + SET_SEM(1, 0, 0); break; case airFP_POS_ZERO: default: - FP_SET_F(flit, fbig, 0, 0, 0); + SET_SEM(0, 0, 0); break; } - return (airEndianLittle == airMyEndian() - ? flit.v - : fbig.v); +#undef SET_SEM + af.i = PARTSHIFT_F(sign, expo, mant); + /* printf("%s(0x%x, 0x%x, 0x%x) = 0x%x -> %.9g\n", __func__, sign, expo, mant, af.i, + af.f); */ + return af.f; } /* @@ -303,69 +287,60 @@ airFPGen_f(int cls) { */ double airFPGen_d(int cls) { - _airDoubleEndianLittle dlit; - _airDoubleEndianBig dbig; + airDouble ad; + unsigned int sign, expo, mant0, mant1; - switch(cls) { - case airFP_SNAN: - /* sgn: anything, mant: anything non-zero with high bit !TEEM_QNANHIBIT */ - FP_SET_D(dlit, dbig, 0, 0x7ff, (!TEEM_QNANHIBIT << 19) | 0x7ffff, 0xffffffff); - break; - case airFP_QNAN: - /* sgn: anything, mant anything non-zero with high bit TEEM_QNANHIBIT */ - FP_SET_D(dlit, dbig, 0, 0x7ff, (TEEM_QNANHIBIT << 19) | 0x7ffff, 0xffffffff); +#define SET_SEM(ss, ee, m0, m1) \ + sign = (ss); \ + expo = (ee); \ + mant0 = (m0); \ + mant1 = (m1) + + switch (cls) { + case airFP_NAN: + /* (no separate handling of signalling NaN) */ + /* sgn: anything, mant anything non-zero with high bit _QNANHIBIT */ + SET_SEM(0, 0x7ff, (_QNANHIBIT << 19) | 0x7ffff, 0xffffffff); break; case airFP_POS_INF: - FP_SET_D(dlit, dbig, 0, 0x7ff, 0, 0); + SET_SEM(0, 0x7ff, 0, 0); break; case airFP_NEG_INF: - FP_SET_D(dlit, dbig, 1, 0x7ff, 0, 0); + SET_SEM(1, 0x7ff, 0, 0); break; case airFP_POS_NORM: /* exp: anything non-zero but < 0xff, mant: anything */ - FP_SET_D(dlit, dbig, 0, 0x400, 0x0ff00, 0); + SET_SEM(0, 0x400, 0x0ff00, 0); break; case airFP_NEG_NORM: /* exp: anything non-zero but < 0xff, mant: anything */ - FP_SET_D(dlit, dbig, 1, 0x400, 0x0ff00, 0); + SET_SEM(1, 0x400, 0x0ff00, 0); break; case airFP_POS_DENORM: /* mant: anything non-zero */ - FP_SET_D(dlit, dbig, 0, 0, 0xff, 0); + SET_SEM(0, 0, 0xff, 0); break; case airFP_NEG_DENORM: /* mant: anything non-zero */ - FP_SET_D(dlit, dbig, 1, 0, 0xff, 0); + SET_SEM(1, 0, 0xff, 0); break; case airFP_NEG_ZERO: - FP_SET_D(dlit, dbig, 1, 0, 0, 0); + SET_SEM(1, 0, 0, 0); break; case airFP_POS_ZERO: default: - FP_SET_D(dlit, dbig, 0, 0, 0, 0); + SET_SEM(0, 0, 0, 0); break; } - return (airEndianLittle == airMyEndian() - ? dlit.v - : dbig.v); +#undef SET_SEM + ad.i = PARTSHIFT_D(sign, expo, mant0, mant1); + return ad.d; } -/* -******** airFPClass_f() -** -** given a floating point number, tells which class its in -*/ -int -airFPClass_f(float val) { - _airFloatEndianLittle flit; - _airFloatEndianBig fbig; - unsigned int sign, expv, mant; - int indexv, ret = 0; - - flit.v = fbig.v = val; - FP_GET_F(sign, expv, mant, flit, fbig); - indexv = ((!!sign) << 2) | ((!!expv) << 1) | (!!mant); - switch(indexv) { +static int +wutClass(unsigned int index, int expoMax) { + int ret = airFP_Unknown; + switch (index) { case 0: /* all fields are zero */ ret = airFP_POS_ZERO; @@ -376,7 +351,7 @@ airFPClass_f(float val) { break; case 2: /* only exponent field is non-zero */ - if (0xff == expv) { + if (expoMax) { ret = airFP_POS_INF; } else { ret = airFP_POS_NORM; @@ -384,12 +359,9 @@ airFPClass_f(float val) { break; case 3: /* exponent and mantissa fields are non-zero */ - if (0xff == expv) { - if (TEEM_QNANHIBIT == mant >> 22) { - ret = airFP_QNAN; - } else { - ret = airFP_SNAN; - } + if (expoMax) { + /* we don't distinguish (any longer) between qnan and snan */ + ret = airFP_NAN; } else { ret = airFP_POS_NORM; } @@ -404,36 +376,39 @@ airFPClass_f(float val) { break; case 6: /* sign and exponent fields are non-zero */ - if (0xff > expv) { - ret = airFP_NEG_NORM; - } else { + if (expoMax) { ret = airFP_NEG_INF; + } else { + ret = airFP_NEG_NORM; } break; case 7: /* all fields are non-zero */ - if (0xff > expv) { - ret = airFP_NEG_NORM; + if (expoMax) { + /* we don't distinguish (any longer) between qnan and snan */ + ret = airFP_NAN; } else { - if (TEEM_QNANHIBIT == mant >> 22) { - ret = airFP_QNAN; - } else { - ret = airFP_SNAN; - } + ret = airFP_NEG_NORM; } break; } return ret; } - /* -** Disable the 'local variable used without having been initialized' -** warning produced by the MSVC compiler +******** airFPClass_f() +** +** given a floating point number, tells which class its in */ -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4700) -#endif +int +airFPClass_f(float val) { + unsigned int sign, expo, mant, indexv; + + airFPValToParts_f(&sign, &expo, &mant, val); + /* "!" produces an int: https://en.cppreference.com/w/c/language/operator_logical */ + indexv = (AIR_UINT(!!sign) << 2) | (AIR_UINT(!!expo) << 1) | AIR_UINT(!!mant); + return wutClass(indexv, 0xff == expo); +} + /* ******** airFPClass_d() ** @@ -441,84 +416,13 @@ airFPClass_f(float val) { */ int airFPClass_d(double val) { - _airDoubleEndianLittle dlit; - _airDoubleEndianBig dbig; - unsigned int sign, expo, mant0, mant1; - int indexv, ret=0; - unsigned char hibit; - - dlit.v = dbig.v = val; - /* "expo = d.c.expo" had been annotated with: "this seems to be a - WIN32 bug: on a quiet-NaN, d.c.exp should be non-zero, but it was - completely zero, so that this function returned airFP_NEG_DENORM - instead of airFP_QNAN" */ - FP_GET_D(sign, expo, mant0, mant1, dlit, dbig); - hibit = AIR_CAST(unsigned char, mant0 >> 19); /* mant0 20 bits wide: ok */ - - indexv = ((!!sign) << 2) | ((!!expo) << 1) | (!!mant0 || !!mant1); - switch(indexv) { - case 0: - /* all fields are zero */ - ret = airFP_POS_ZERO; - break; - case 1: - /* only fractional field is non-zero */ - ret = airFP_POS_DENORM; - break; - case 2: - /* only exponent field is non-zero */ - if (0x7ff > expo) { - ret = airFP_POS_NORM; - } else { - ret = airFP_POS_INF; - } - break; - case 3: - /* exponent and fractional fields are non-zero */ - if (0x7ff > expo) { - ret = airFP_POS_NORM; - } else { - if (TEEM_QNANHIBIT == hibit) { - ret = airFP_QNAN; - } else { - ret = airFP_SNAN; - } - } - break; - case 4: - /* only sign field is non-zero */ - ret = airFP_NEG_ZERO; - break; - case 5: - /* sign and fractional fields are non-zero */ - ret = airFP_NEG_DENORM; - break; - case 6: - /* sign and exponent fields are non-zero */ - if (0x7ff > expo) { - ret = airFP_NEG_NORM; - } else { - ret = airFP_NEG_INF; - } - break; - case 7: - /* all fields are non-zero */ - if (0x7ff > expo) - ret = airFP_NEG_NORM; - else { - if (TEEM_QNANHIBIT == hibit) { - ret = airFP_QNAN; - } else { - ret = airFP_SNAN; - } - } - break; - } - return ret; + unsigned int sign, expo, mant0, mant1, indexv; + + airFPValToParts_d(&sign, &expo, &mant0, &mant1, val); + indexv = (AIR_UINT(!!sign) << 2) | (AIR_UINT(!!expo) << 1) + | (AIR_UINT(!!mant0) || AIR_UINT(!!mant1)); + return wutClass(indexv, 0x7ff == expo); } -#ifdef _MSC_VER -#pragma warning(pop) -#endif /* ******** airIsNaN() @@ -531,12 +435,9 @@ airFPClass_d(double val) { */ int airIsNaN(double g) { - _airFloatEndianLittle flit; - _airFloatEndianBig fbig; unsigned int sign, expo, mant; - flit.v = fbig.v = AIR_CAST(float, g); - FP_GET_F(sign, expo, mant, flit, fbig); + airFPValToParts_f(&sign, &expo, &mant, AIR_FLOAT(g)); AIR_UNUSED(sign); return (0xff == expo && mant); } @@ -590,13 +491,13 @@ airIsInf_d(double d) { */ int airExists(double val) { - _airDoubleEndianLittle dlit; - _airDoubleEndianBig dbig; + airDouble ad; + airULLong ui; - dbig.v = dlit.v = val; - return (airEndianLittle == airMyEndian() - ? 0x7ff != dlit.c.expo - : 0x7ff != dbig.c.expo); + ad.d = val; + ui = ad.i; + ui >>= 52; + return 0x7ff != AIR_UINT(ui & 0x7ff); } /* @@ -607,7 +508,7 @@ airExists(double val) { float airNaN(void) { - return airFPGen_f(airFP_QNAN); + return airFPGen_f(airFP_NAN); } /* @@ -617,25 +518,24 @@ airNaN(void) { */ void airFPFprintf_f(FILE *file, float val) { - int i; + int i, cls; unsigned int sign, expo, mant; - _airFloatEndianLittle flit; - _airFloatEndianBig fbig; + airFloat af; if (file) { - flit.v = fbig.v = val; - FP_GET_F(sign, expo, mant, flit, fbig); - fprintf(file, "%f: class %d; 0x%08x = ",val, airFPClass_f(val), - airEndianLittle == airMyEndian() ? flit.i : fbig.i); - fprintf(file, "sign:0x%x, expo:0x%02x, mant:0x%06x = \n", - sign, expo, mant); + af.f = val; + airFPValToParts_f(&sign, &expo, &mant, val); + cls = airFPClass_f(val); + fprintf(file, "%.9g (class %d=%s) 0x%08x = ", (double)val, cls, + airEnumStr(airFPClass_ae, cls), af.i); + fprintf(file, "sign:0x%x, expo:0x%02x, mant:0x%06x = \n", sign, expo, mant); fprintf(file, " S [ . . Exp . . ] " - "[ . . . . . . . . . Mant. . . . . . . . . . ]\n"); + "[ . . . . . . . . . Mant. . . . . . . . . . ]\n"); fprintf(file, " %d ", sign); - for (i=7; i>=0; i--) { + for (i = 7; i >= 0; i--) { fprintf(file, "%d ", (expo >> i) & 1); } - for (i=22; i>=0; i--) { + for (i = 22; i >= 0; i--) { fprintf(file, "%d ", (mant >> i) & 1); } fprintf(file, "\n"); @@ -649,32 +549,34 @@ airFPFprintf_f(FILE *file, float val) { */ void airFPFprintf_d(FILE *file, double val) { - int i; - _airDoubleEndianLittle dlit; - _airDoubleEndianBig dbig; - unsigned int sign, expo, mant0, mant1; + int i, cls; + unsigned int sign, expo, mant0, mant1, half0, half1; + airDouble ad; + airULLong ui; if (file) { - dlit.v = dbig.v = val; - fprintf(file, "%f: class %d; 0x%08x %08x = \n", - val, airFPClass_d(val), - (airEndianLittle == airMyEndian() ? dlit.h.half1 : dbig.h.half1), - (airEndianLittle == airMyEndian() ? dlit.h.half0 : dbig.h.half0)); - FP_GET_D(sign, expo, mant0, mant1, dlit, dbig); - fprintf(file, "sign:0x%x, expo:0x%03x, mant:0x%05x %08x = \n", - sign, expo, mant0, mant1); + ad.d = val; + ui = ad.i; + half1 = AIR_UINT(ui & 0xffffffff); + ui >>= 32; + half0 = AIR_UINT(ui & 0xffffffff); + cls = airFPClass_d(val); + fprintf(file, "%.17g (class %d=%s) 0x%08x %08x = \n", val, cls, + airEnumStr(airFPClass_ae, cls), half0, half1); + airFPValToParts_d(&sign, &expo, &mant0, &mant1, val); + fprintf(file, "sign:0x%x, expo:0x%03x, mant:0x%05x %08x = \n", sign, expo, mant0, + mant1); fprintf(file, "S[...Exp...][.......................Mant.......................]\n"); fprintf(file, "%d", sign); - for (i=10; i>=0; i--) { + for (i = 10; i >= 0; i--) { fprintf(file, "%d", (expo >> i) & 1); } - for (i=19; i>=0; i--) { + for (i = 19; i >= 0; i--) { fprintf(file, "%d", (mant0 >> i) & 1); } - for (i=31; i>=0; i--) { + for (i = 31; i >= 0; i--) { fprintf(file, "%d", (mant1 >> i) & 1); } fprintf(file, "\n"); } } - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMake/TestQnanhibit.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMake/TestQnanhibit.c deleted file mode 100644 index 71aae3f00fe..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMake/TestQnanhibit.c +++ /dev/null @@ -1,40 +0,0 @@ -/*========================================================================= - * - * Copyright NumFOCUS - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0.txt - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *=========================================================================*/ -#include -#include - -int -main(int argc, char *argv[]) -{ - const char * const me=argv[0]; - const float zero=0.0F; - union { - float flt32bit; - int int32bit; - } qnan; - - if (sizeof(float) != sizeof(int)) - { - fprintf(stderr, "%s: MADNESS: sizeof(float)=%d != sizeof(int)=%d\n", - me, (int)sizeof(float), (int)sizeof(int)); - return -1; - } - qnan.flt32bit=zero/zero; - printf("-DTEEM_QNANHIBIT=%d\n", (qnan.int32bit >> 22) & 1); - return (int)((qnan.int32bit >> 22) & 1); -} diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMake/TestQnanhibit.cmake b/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMake/TestQnanhibit.cmake deleted file mode 100644 index edd8cb20fb6..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMake/TestQnanhibit.cmake +++ /dev/null @@ -1,36 +0,0 @@ -# -# Checks whether the 22nd bit of a 32-bit quiet-NaN is 1 (1) or 0 (0). This -# distinction is needed in handling of IEEE floating point special values. -# This quantity is independent of endian-ness. -# -# VARIABLE - variable to store the result to -# - -macro(TEST_QNANHIBIT VARIABLE LOCAL_TEST_DIR) - if(NOT DEFINED "HAVE_${VARIABLE}") - try_run(${VARIABLE} HAVE_${VARIABLE} - ${CMAKE_BINARY_DIR} - ${LOCAL_TEST_DIR}/TestQnanhibit.c - OUTPUT_VARIABLE OUTPUT) - message(STATUS "Check the value of the 22nd bit of a 32-bit quiet-NaN") - if(HAVE_${VARIABLE}) - if(${VARIABLE} LESS 0) - message(ERROR " A test (qnanhibit.c) necessary for NrrdIO configuration returned error code. NrrdIO may not properly handle NaN's.") - endif(${VARIABLE} LESS 0) - if(${VARIABLE}) - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Value of the 22nd bit of a 32-bit quiet-NaN is 1") - message(STATUS "Check the value of the 22nd bit of a 32-bit quiet-NaN - 1") - else(${VARIABLE}) - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Value of the 22nd bit of a 32-bit quiet-NaN is 0") - message(STATUS "Check the value of the 22nd bit of a 32-bit quiet-NaN - 0") - endif(${VARIABLE}) - else(HAVE_${VARIABLE}) - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "\tFailed to compile a test (TestQnanhibit.c) necessary to configure for proper handling of IEEE floating point NaN's.\n") - message(STATUS "Failed to compile a test (TestQnanhibit.c) necessary to configure for proper handling of IEEE floating point NaN's") - endif(HAVE_${VARIABLE}) - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "TestQnanhibit.c produced following output:\n${OUTPUT}\n\n") - endif() -endmacro(TEST_QNANHIBIT) diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMakeLists.txt b/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMakeLists.txt index c70ca0f7e70..f1156c45173 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMakeLists.txt +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/CMakeLists.txt @@ -1,96 +1,165 @@ -PROJECT(ITK3P_NrrdIO) -INCLUDE_REGULAR_EXPRESSION("^.*.h$") - # -# This CMake file configures the NrrdIO library build. NrrdIO -# is used by Insight/Code/IO/itkNrrdIO for reading/writing -# "Nearly Raw Raster Data" within the open-source Teem software -# package. See http://teem.sourceforge.net for more information. +# NrrdIO: C library for NRRD file IO (with optional compressions) +# Copyright (C) 2009--2025 University of Chicago +# Copyright (C) 2005--2008 Gordon Kindlmann +# Copyright (C) 1998--2004 University of Utah +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any +# damages arising from the use of this software. +# +# Permission is granted to anyone to use this software for any +# purpose, including commercial applications, and to alter it and +# redistribute it freely, subject to the following restrictions: # +# 1. The origin of this software must not be misrepresented; you must +# not claim that you wrote the original software. If you use this +# software in a product, an acknowledgment in the product +# documentation would be appreciated but is not required. +# +# 2. Altered source versions must be plainly marked as such, and must +# not be misrepresented as being the original software. +# +# 3. This notice may not be removed or altered from any source distribution. + +# NrrdIO can be used in bigger applications (e.g. ITK) to add support for the +# "Nearly Raw Raster Data" NRRD format: https://teem.sf.net/nrrd/format.html +# See ./0-README.txt for more information about how these source files are +# generated automatically from a checkout of Teem. The use of Teem source +# files (with modifications and relicensing) is why "TEEM" shows up in some +# compilation flags, but our job here is to build NrrdIO aka NRRDIO, hence +# the NrrdIO/NRRDIO naming of CMake things that are externally visible. + +# CMake Version 3.12 came out July 17, 2018 +# https://www.kitware.com/cmake-3-12-0-available-for-download/ +# No need to copy Teem's use of 3.25 because we don't need "try_compile" since +# here the AIR_EXISTS macro always expands into a airExists() function call. +# 3.12 improved find_package() (including its use for ZLIB and BZip2). +cmake_minimum_required(VERSION 3.12...3.31) +project(NrrdIO + DESCRIPTION "NrrdIO: C library for NRRD file IO (with optional compressions)" + LANGUAGES C) + +# Set NRRDIO_PREFIX manually when configuring with cmake +# so that the generated library does not conflict with the +# public name of the Teem library. By default this variable +# is empty and the library name defaults to the project name +# of NrrdIO. +set(NRRDIO_LIBRARY_NAME ${NRRDIO_PREFIX}${PROJECT_NAME}) + +set(nrrdio_SRCS + 754.c + accessors.c + array.c + arraysNrrd.c + axis.c + biffbiff.c + biffmsg.c + comment.c + defaultsNrrd.c + encoding.c + encodingAscii.c + encodingBzip2.c + encodingGzip.c + encodingHex.c + encodingRaw.c + encodingZRL.c + endianAir.c + endianNrrd.c + enum.c + enumsNrrd.c + format.c + formatEPS.c + formatNRRD.c + formatPNG.c + formatPNM.c + formatText.c + formatVTK.c + gzio.c + keyvalue.c + methodsNrrd.c + miscAir.c + mop.c + parseAir.c + parseNrrd.c + preamble.c + read.c + reorder.c + sampleIO.c + sane.c + simple.c + string.c + subset.c + write.c +) -SET(nrrdio_SRCS 754.c mop.c array.c parseAir.c dio.c sane.c endianAir.c -string.c enum.c miscAir.c biffbiff.c biffmsg.c accessors.c defaultsNrrd.c -enumsNrrd.c arraysNrrd.c methodsNrrd.c reorder.c axis.c simple.c comment.c -keyvalue.c endianNrrd.c parseNrrd.c gzio.c read.c write.c format.c -formatNRRD.c encoding.c encodingRaw.c encodingAscii.c encodingHex.c -encodingGzip.c subset.c encodingBzip2.c formatEPS.c formatPNG.c -formatPNM.c formatText.c formatVTK.c ) +# Turn on TEEM_BUILD when compiling .c files so that on Windows +# the proper dll export def's are used. +add_definitions(-DTEEM_BUILD=1) -# Turn on TEEM_BUILD and TEEM_STATIIC so that the proper dll export -# def's are used on windows builds. -ADD_DEFINITIONS(-DTEEM_BUILD) +# Configure (and learn how to find) NrrdIO.h +configure_file(${NrrdIO_SOURCE_DIR}/NrrdIO.h.in ${NrrdIO_BINARY_DIR}/NrrdIO.h) +include_directories( ${NrrdIO_BINARY_DIR} ) + +if ( NOT "${NRRDIO_PREFIX}" STREQUAL "ITK" ) # <-- ITK START_REMOVE +## Override configuring zlib in ../CMakeLists.txt + +option(NRRDIO_USE_ZLIB "Enable support for ZLIB compression" ON) +if(NRRDIO_USE_ZLIB) + # Possibly turn on usage of zlib compression (requires linking with libz) + # (i.e., programs compiled with ${NRRDIO_LIBRARY_NAME}NrrdIO must also be compiled with zlib) + add_definitions(-DTEEM_ZLIB=1) + find_package(ZLIB) + list(APPEND NRRDIO_COMPRESSION_LIBRARIES ZLIB::ZLIB) +endif() -if(NOT BUILD_SHARED_LIBS) - set(TEEM_STATIC 1) +option(NRRDIO_USE_BZIP2 "Enable support for BZIP2 compression" OFF) +if(NRRDIO_USE_BZIP2) + # Possibly turn on usage of bzip2 compression (requires linking with bz2) + # (i.e., programs compiled with ${NRRDIO_LIBRARY_NAME}NrrdIO must also be compiled with bz2) + add_definitions(-DTEEM_BZIP2=1) + find_package(BZip2) + list(APPEND NRRDIO_COMPRESSION_LIBRARIES BZip2::BZip2) endif() -# Configure (and learn how to find) NrrdIO.h -CONFIGURE_FILE(${ITK3P_NrrdIO_SOURCE_DIR}/NrrdIO.h.in - ${ITK3P_NrrdIO_BINARY_DIR}/NrrdIO.h) -INCLUDE_DIRECTORIES( - ${ITK3P_NrrdIO_BINARY_DIR} -) +# Build the library +add_library(${NRRDIO_LIBRARY_NAME} ${nrrdio_SRCS} ) +# Link optional compression libs +if(NRRDIO_USE_ZLIB OR NRRDIO_USE_BZIP2) + target_link_libraries(${NRRDIO_LIBRARY_NAME} PRIVATE ${NRRDIO_COMPRESSION_LIBRARIES}) +endif() -set(MANGLE_PREFIX itk) -configure_file(${ITK3P_NrrdIO_SOURCE_DIR}/itk_NrrdIO_mangle.h.in - ${ITK3P_NrrdIO_BINARY_DIR}/itk_NrrdIO_mangle.h - @ONLY) - -#----------------------------------------------------------------------------- -# Find platform-specific differences in the handling of IEEE floating point -# special values. - -include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/TestQnanhibit.cmake) -test_qnanhibit(QNANHIBIT_VALUE ${CMAKE_CURRENT_SOURCE_DIR}/CMake) -if(QNANHIBIT_VALUE) - set(QNANHIBIT 1 CACHE INTERNAL "The 22nd bit of 32-bit floating-point quiet NaN.") -else(QNANHIBIT_VALUE) - set(QNANHIBIT 0 CACHE INTERNAL "The 22nd bit of 32-bit floating-point quiet NaN.") -endif(QNANHIBIT_VALUE) - -#The QNANHIBIT variable is configured by the root level CMakeLists.txt -IF(QNANHIBIT) - ADD_DEFINITIONS(-DTEEM_QNANHIBIT=1) -ELSE(QNANHIBIT) - ADD_DEFINITIONS(-DTEEM_QNANHIBIT=0) -ENDIF(QNANHIBIT) - -#DirectIO is the fast way to do multi-gigabyte I/O and currently only available -#for SGI platforms. Use of DirectIO is enabled manually for now. -#OPTION(USE_DIRECTIO "Use DirectIO for Nrrd file IO. Only valid on SGI systems." 0) -#MARK_AS_ADVANCED(USE_DIRECTIO) -#IF(USE_DIRECTIO) -# ADD_DEFINITIONS(-DTEEM_DIO=1) -#ELSE(USE_DIRECTIO) - ADD_DEFINITIONS(-DTEEM_DIO=0) -#ENDIF(USE_DIRECTIO) - -# Tell NRRD to enable nrrdEncodingGzip -ADD_DEFINITIONS(-DTEEM_ZLIB=1) - -ADD_LIBRARY(ITKNrrdIO ${nrrdio_SRCS} ) - -IF(UNIX) - TARGET_LINK_LIBRARIES(ITKNrrdIO ${ITKZLIB_LIBRARIES} m) -ELSE(UNIX) - TARGET_LINK_LIBRARIES(ITKNrrdIO ${ITKZLIB_LIBRARIES}) -ENDIF(UNIX) - -IF(ITK_LIBRARY_PROPERTIES) - SET_TARGET_PROPERTIES(ITKNrrdIO PROPERTIES ${ITK_LIBRARY_PROPERTIES}) -ENDIF(ITK_LIBRARY_PROPERTIES) - -INSTALL(TARGETS ITKNrrdIO - EXPORT ${ITK3P_INSTALL_EXPORT_NAME} - RUNTIME DESTINATION ${ITK3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries - LIBRARY DESTINATION ${ITK3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries - ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development +else() # <-- ITK START_REPLACE +## These are ITK-specific + # Build the library + add_library(${NRRDIO_LIBRARY_NAME} ${nrrdio_SRCS} ) + target_link_libraries(${NRRDIO_LIBRARY_NAME} PRIVATE ${NRRDIO_COMPRESSION_LIBRARIES}) + if(NOT BUILD_SHARED_LIBS) + set(TEEM_STATIC 1) + endif() + + set(MANGLE_PREFIX itk) + configure_file(${NrrdIO_SOURCE_DIR}/itk_NrrdIO_mangle.h.in + ${NrrdIO_BINARY_DIR}/itk_NrrdIO_mangle.h + @ONLY ) -INSTALL(FILES ${ITK3P_NrrdIO_BINARY_DIR}/NrrdIO.h ${ITK3P_NrrdIO_BINARY_DIR}/itk_NrrdIO_mangle.h - DESTINATION ${ITK3P_INSTALL_INCLUDE_DIR} # TODO: itk_NrrdIO.h #include "itkNrrdIO/NrrdIO.h" - COMPONENT Development) - -IF(CMAKE_COMPILER_IS_GNUCXX) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing") -ENDIF(CMAKE_COMPILER_IS_GNUCXX) + if(ITK_LIBRARY_PROPERTIES) + set_target_properties(${NRRDIO_LIBRARY_NAME} PROPERTIES ${ITK_LIBRARY_PROPERTIES}) + endif() + + install(TARGETS ${NRRDIO_LIBRARY_NAME} + EXPORT ${ITK3P_INSTALL_EXPORT_NAME} + RUNTIME DESTINATION ${ITK3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries + LIBRARY DESTINATION ${ITK3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries + ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development + ) + + install(FILES ${NrrdIO_BINARY_DIR}/NrrdIO.h ${NrrdIO_BINARY_DIR}/itk_NrrdIO_mangle.h + DESTINATION ${ITK3P_INSTALL_INCLUDE_DIR} # TODO: itk_NrrdIO.h #include "itkNrrdIO/NrrdIO.h" + COMPONENT Development) + + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing") + endif() +endif() # <-- ITK END_REPLACE diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/LICENSE b/Modules/ThirdParty/NrrdIO/src/NrrdIO/LICENSE new file mode 100644 index 00000000000..f898390cfa1 --- /dev/null +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/LICENSE @@ -0,0 +1,21 @@ +Copyright (C) 2009--2025 University of Chicago +Copyright (C) 2005--2008 Gordon Kindlmann +Copyright (C) 1998--2004 University of Utah + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source distribution. diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/NrrdIO.h.in b/Modules/ThirdParty/NrrdIO/src/NrrdIO/NrrdIO.h.in index b30dbca244b..610646046c1 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/NrrdIO.h.in +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/NrrdIO.h.in @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -23,7 +23,6 @@ 3. This notice may not be removed or altered from any source distribution. */ - #include #include #include @@ -35,36 +34,35 @@ /* ******** TEEM_VERSION ** -** TEEM_VERSION is a single (decimal) number that will always increase -** monotically, and the _MAJOR, _MINOR, _PATCH are also numbers that -** can be used to implement pre-processor logic about specifc -** versions. The TEEM_VERSION_STRING is used in the (existing) char -** *airTeemVersion (added in version 1.9.0). Yes, keeping these in -** sync is currently a manual operation. -** -** NOTE: Significant API changes (aside from API additions) should NOT -** occur with changes in patch level, only with major or minor version -** changes. -** -** NOTE: ../../CMakeLists.txt's Teem_VERSION variables must be in sync +** How Teem documents its Semantic Version number https://semver.org/ +** TEEM_VERSION is a single number, TEEM_VERSION_STRING is a string, and the +** _MAJOR, _MINOR, _PATCH numbers are the components. +** NOTE: In ../../CMakeLists.txt, Teem_VERSION variables record the same values. +** Yes, keeping the below in sync, and in sync with ../../CMakeLists.txt, +** is a manual operation. See also airTeemReleaseDate in miscAir.c */ -#define TEEM_VERSION_MAJOR 1 /* must be 1 digit */ -#define TEEM_VERSION_MINOR 11 /* 1 or 2 digits */ -#define TEEM_VERSION_PATCH 01 /* 1 or 2 digits */ -#define TEEM_VERSION 11101 /* must be 5 digits, to facilitate +/* clang-format off */ +#define TEEM_VERSION_MAJOR 2 /* must be 1 digit */ +#define TEEM_VERSION_MINOR 0 /* 1 or 2 digits (no leading 0) */ +#define TEEM_VERSION_PATCH 0 /* 1 or 2 digits (no leading 0) */ +#define TEEM_VERSION 20000 /* must be 5 digits, to facilitate easy numerical comparison */ -#define TEEM_VERSION_STRING "1.11.1" /* cannot be so easily compared */ +#define TEEM_VERSION_STRING "2.0.0" /* THIS is the semantic version "number" */ +/* clang-format on */ +#cmakedefine TEEM_ITK_MANGLE @TEEM_ITK_MANGLE@ +#if TEEM_ITK_MANGLE /* THE FOLLOWING INCLUDE IS ONLY FOR THE ITK DISTRIBUTION. This header mangles the symbols in the NrrdIO library, preventing conflicts in applications linked against two versions of NrrdIO. */ -#include "itk_NrrdIO_mangle.h" +# include "itk_NrrdIO_mangle.h" +#cmakedefine TEEM_STATIC +#endif #ifdef __cplusplus extern "C" { #endif -#cmakedefine TEEM_STATIC #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(TEEM_STATIC) # if defined(TEEM_BUILD) || defined(air_EXPORTS) || defined(teem_EXPORTS) # define NRRDIO_EXPORT extern __declspec(dllexport) @@ -78,44 +76,36 @@ extern "C" { #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__) typedef signed __int64 airLLong; typedef unsigned __int64 airULLong; -# define AIR_LLONG_FMT "%I64d" +# define AIR_LLONG_FMT "%I64d" # define AIR_ULLONG_FMT "%I64u" -# define AIR_LLONG(x) x##i64 -# define AIR_ULLONG(x) x##ui64 +# define AIR_LLONG(x) x##i64 +# define AIR_ULLONG(x) x##ui64 #else typedef signed long long airLLong; typedef unsigned long long airULLong; -# define AIR_LLONG_FMT "%lld" +# define AIR_LLONG_FMT "%lld" # define AIR_ULLONG_FMT "%llu" -# define AIR_LLONG(x) x##ll -# define AIR_ULLONG(x) x##ull +# define AIR_LLONG(x) x##ll +# define AIR_ULLONG(x) x##ull #endif - /* -** These serve as conservative estimates on how large various strings -** might end up being. It would be theoretically better to completely -** avoid the use of fixed-size buffers, but in many contexts the -** implementation complexity of handling them reliably is distracts -** from more urgent implementation goals. In the mean time, these can -** be used safely as long as the lengths are used consistently. -** -** The possibly unfortunate convention that has become established in -** Teem is code using these tends to NOT add the "+1", to explicitly -** indicate the space for 0-termination, and instead assumes it is -** part of the numbers below, even though this is at the cost of -** confusion about how the maximal strlen() will be less than each of -** these numbers. This will be addressed in Teem 2.0. + * These serve as conservative estimates on how large various strings might end up being. + * It would be theoretically better to completely avoid the use of fixed-size buffers, + * but in many contexts the implementation complexity of handling them reliably is + * distracts from more urgent implementation goals. In the mean time, these can be used + * safely as long as the lengths are used consistently. + */ +#define AIR_STRLEN_SMALL 128 +/* SMALL has to be big enough to hold: + - printed value of size_t and + - ptrdiff_t, line of text that + - should contain file format "magic" */ -#define AIR_STRLEN_SMALL (128+1) /* has to be big enough to hold: - - printed value of size_t and ptrdiff_t, - - line of text that should contain file - format "magic" - */ -#define AIR_STRLEN_MED (256+1) -#define AIR_STRLEN_LARGE (512+1) -#define AIR_STRLEN_HUGE (1024+1) /* has to be big enough to hold - a biff error message (one line of it) */ +#define AIR_STRLEN_MED 256 +#define AIR_STRLEN_LARGE 512 +#define AIR_STRLEN_HUGE 1024 +/* HUGE has to be big enough to hold one line of biff error message */ /* ******** airPtrPtrUnion @@ -135,6 +125,7 @@ typedef union { short **s; unsigned int **ui; int **i; + long int **li; float **f; double **d; void **v; @@ -148,39 +139,37 @@ typedef union { */ typedef struct { const char *name; - /* what are these things? */ + /* what are these things? */ unsigned int M; - /* str[0]: string for the unknown/invalid value; - * str[1] .. str[M]: canonical strings for the enum values; - * "val" NULL: unknown/invalid = 0; - * valid values are 1 .. M - * "val" non-NULL: unknown/invalid = val[0]; - * valid are val[1].. val[M] - */ - const char **str; - /* see above */ - const int *val; - /* see above */ + /* str[0]: string for the unknown/invalid value; + str[1] .. str[M]: canonical strings for the enum values; + "val" NULL: unknown/invalid = 0; + valid values are 1 .. M + "val" non-NULL: unknown/invalid = val[0]; + valid are val[1].. val[M] + */ + const char **str; /* see above */ + const int *val; /* see above */ const char **desc; - /* desc[i] is a short description of the enum values represented - by str[i] (thereby starting with the unknown value), to be - used to by things like hest */ + /* desc[i] is a short description of the enum values represented by + str[i] (thereby starting with the unknown value), to be used to + by things like hest */ const char **strEqv; - /* If non-NULL, all the variations in strings recognized in - mapping from string to value (the values in valEqv). - This **MUST** be terminated by a zero-length string ("") so - as to signify the end of the list. This should *not* - contain the string for unknown/invalid. - If "strEqv" is NULL, then mapping from string to value is - done only by traversing "str", and "valEqv" is ignored. */ + /* If non-NULL, all the variations in strings recognized in mapping + from string to value (the values in valEqv). This **MUST** be + terminated by a zero-length string ("") so as to signify the end + of the list. This should *not* contain the string for + unknown/invalid. If "strEqv" is NULL, then mapping from string + to value is done only by traversing "str", and "valEqv" is + ignored. */ const int *valEqv; - /* If strEqv non-NULL, valEqv holds the values corresponding - to the strings in strEqv, with one integer for each - non-zero-length string in strEqv: strEqv[i] is a valid - string representation for value valEqv[i]. This should *not* - contain the value for unknown/invalid. - This "valEqv" is ignored if "strEqv" is NULL. */ - int sense; /* require case matching on strings */ + /* If strEqv non-NULL, valEqv holds the values corresponding to the + strings in strEqv, with one integer for each non-zero-length + string in strEqv: strEqv[i] is a valid string representation for + value valEqv[i]. This should *not* contain the value for + unknown/invalid. This "valEqv" is ignored if "strEqv" is + NULL. */ + int sense; /* require case matching on strings */ } airEnum; NRRDIO_EXPORT int airEnumUnknown(const airEnum *enm); NRRDIO_EXPORT int airEnumValCheck(const airEnum *enm, int val); @@ -188,7 +177,7 @@ NRRDIO_EXPORT const char *airEnumStr(const airEnum *enm, int val); NRRDIO_EXPORT const char *airEnumDesc(const airEnum *enm, int val); NRRDIO_EXPORT int airEnumVal(const airEnum *enm, const char *str); NRRDIO_EXPORT char *airEnumFmtDesc(const airEnum *enm, int val, int canon, - const char *fmt); + const char *fmt); NRRDIO_EXPORT void airEnumPrint(FILE *file, const airEnum *enm); /* @@ -199,9 +188,9 @@ NRRDIO_EXPORT void airEnumPrint(FILE *file, const airEnum *enm); ** architecture. */ enum { - airEndianUnknown, /* 0: nobody knows */ - airEndianLittle = 1234, /* 1234: Intel and friends */ - airEndianBig = 4321, /* 4321: the rest */ + airEndianUnknown, /* 0: nobody knows */ + airEndianLittle = 1234, /* 1234: Intel and friends */ + airEndianBig = 4321, /* 4321: the rest */ airEndianLast }; /* endianAir.c */ @@ -210,23 +199,23 @@ NRRDIO_EXPORT int airMyEndian(void); /* array.c: poor-man's dynamically resizable arrays */ typedef struct { - void *data, /* where the data is */ - **dataP; /* (possibly NULL) address of user's data variable, - kept in sync with internal "data" variable */ - unsigned int len, /* length of array: # units for which there is - considered to be data (which is <= total # units - allocated). The # bytes which contain data is - len*unit. Always updated (unlike "*lenP") */ - *lenP, /* (possibly NULL) address of user's length variable, - kept in sync with internal "len" variable */ - incr, /* the granularity of the changes in amount of space - allocated: when the length reaches a multiple of - "incr", then the array is resized */ - size; /* array is allocated to have "size" increments, or, - size*incr elements, or, - size*incr*unit bytes */ - size_t unit; /* the size in bytes of one element in the array */ - int noReallocWhenSmaller; /* as it says */ + void *data, /* where the data is */ + **dataP; /* (possibly NULL) address of user's data variable, + kept in sync with internal "data" variable */ + unsigned int len, /* length of array: # units for which there is + considered to be data (which is <= total # units + allocated). The # bytes which contain data is + len*unit. Always updated (unlike "*lenP") */ + *lenP, /* (possibly NULL) address of user's length variable, + kept in sync with internal "len" variable */ + incr, /* the granularity of the changes in amount of space + allocated: when the length reaches a multiple of + "incr", then the array is resized */ + size; /* array is allocated to have "size" increments, or, + size*incr elements, or, + size*incr*unit bytes */ + size_t unit; /* the size in bytes of one element in the array */ + int noReallocWhenSmaller; /* as it says */ /* the following are all callbacks useful for maintaining either an array of pointers (allocCB and freeCB) or array of structs (initCB and @@ -248,45 +237,45 @@ typedef struct { } airArray; NRRDIO_EXPORT airArray *airArrayNew(void **dataP, unsigned int *lenP, size_t unit, - unsigned int incr); + unsigned int incr); NRRDIO_EXPORT void airArrayStructCB(airArray *a, void (*initCB)(void *), - void (*doneCB)(void *)); + void (*doneCB)(void *)); NRRDIO_EXPORT void airArrayPointerCB(airArray *a, void *(*allocCB)(void), - void *(*freeCB)(void *)); + void *(*freeCB)(void *)); NRRDIO_EXPORT void airArrayLenSet(airArray *a, unsigned int newlen); NRRDIO_EXPORT unsigned int airArrayLenIncr(airArray *a, int delta); NRRDIO_EXPORT airArray *airArrayNix(airArray *a); NRRDIO_EXPORT airArray *airArrayNuke(airArray *a); - /* ******** airFP enum ** ** the different kinds of floating point number afforded by IEEE 754, ** and the values returned by airFPClass_f(). ** -** The values probably won't agree with those in #include's like +** The numeric enum values probably won't agree with those in #include's like ** ieee.h, ieeefp.h, fp_class.h. This is because IEEE 754 hasn't -** defined standard values for these, so everyone does it differently. +** defined standard values for these, so everyone does it differently +** (or at least that was so around AD 2000 when this code was born) ** ** This enum uses underscores (against Teem convention) to help ** legibility while also conforming to the spirit of the somewhat ** standard naming conventions */ enum { - airFP_Unknown, /* 0: nobody knows */ - airFP_SNAN, /* 1: signalling NaN */ - airFP_QNAN, /* 2: quiet NaN */ - airFP_POS_INF, /* 3: positive infinity */ - airFP_NEG_INF, /* 4: negative infinity */ - airFP_POS_NORM, /* 5: positive normalized non-zero */ - airFP_NEG_NORM, /* 6: negative normalized non-zero */ - airFP_POS_DENORM, /* 7: positive denormalized non-zero */ - airFP_NEG_DENORM, /* 8: negative denormalized non-zero */ - airFP_POS_ZERO, /* 9: +0.0, positive zero */ - airFP_NEG_ZERO, /* 10: -0.0, negative zero */ - airFP_Last /* after the last valid one */ + airFP_Unknown, /* 0: nobody knows */ + airFP_NAN, /* 1: (quiet) NaN */ + airFP_POS_INF, /* 2: positive infinity */ + airFP_NEG_INF, /* 3: negative infinity */ + airFP_POS_NORM, /* 4: positive normalized non-zero */ + airFP_NEG_NORM, /* 5: negative normalized non-zero */ + airFP_POS_DENORM, /* 6: positive denormalized non-zero */ + airFP_NEG_DENORM, /* 7: negative denormalized non-zero */ + airFP_POS_ZERO, /* 8: +0.0, positive zero */ + airFP_NEG_ZERO, /* 9: -0.0, negative zero */ + airFP_Last /* after the last valid one */ }; +#define AIR_FP_MAX 9 /* 754.c: IEEE-754 related stuff values */ typedef union { unsigned int i; @@ -296,30 +285,28 @@ typedef union { airULLong i; double d; } airDouble; -NRRDIO_EXPORT const int airMyQNaNHiBit; +NRRDIO_EXPORT const airEnum *const airFPClass_ae; NRRDIO_EXPORT float airFPPartsToVal_f(unsigned int sign, - unsigned int expo, - unsigned int mant); -NRRDIO_EXPORT void airFPValToParts_f(unsigned int *signP, - unsigned int *expoP, - unsigned int *mantP, float v); + unsigned int expo, + unsigned int mant); +NRRDIO_EXPORT void airFPValToParts_f(unsigned int *signP, unsigned int *expoP, + unsigned int *mantP, float v); NRRDIO_EXPORT double airFPPartsToVal_d(unsigned int sign, - unsigned int expo, - unsigned int mant0, - unsigned int mant1); + unsigned int expo, + unsigned int mant0, + unsigned int mant1); NRRDIO_EXPORT void airFPValToParts_d(unsigned int *signP, - unsigned int *expoP, - unsigned int *mant0P, - unsigned int *mant1P, - double v); + unsigned int *expoP, + unsigned int *mant0P, + unsigned int *mant1P, + double v); NRRDIO_EXPORT float airFPGen_f(int cls); NRRDIO_EXPORT double airFPGen_d(int cls); NRRDIO_EXPORT int airFPClass_f(float val); NRRDIO_EXPORT int airFPClass_d(double val); NRRDIO_EXPORT void airFPFprintf_f(FILE *file, float val); NRRDIO_EXPORT void airFPFprintf_d(FILE *file, double val); -NRRDIO_EXPORT const airFloat airFloatQNaN; -NRRDIO_EXPORT const airFloat airFloatSNaN; +NRRDIO_EXPORT const airFloat airFloatNaN; NRRDIO_EXPORT const airFloat airFloatPosInf; NRRDIO_EXPORT const airFloat airFloatNegInf; NRRDIO_EXPORT float airNaN(void); @@ -328,70 +315,67 @@ NRRDIO_EXPORT int airIsInf_f(float f); NRRDIO_EXPORT int airIsInf_d(double d); NRRDIO_EXPORT int airExists(double d); - -/* -******** airType -** -** Different types which air cares about. -** Currently only used in the command-line parsing, but perhaps will -** be used elsewhere in air later -*/ -enum { - airTypeUnknown, /* 0 */ - airTypeBool, /* 1 */ - airTypeInt, /* 2 */ - airTypeUInt, /* 3 */ - airTypeLongInt, /* 4 */ - airTypeULongInt, /* 5 */ - airTypeSize_t, /* 6 */ - airTypeFloat, /* 7 */ - airTypeDouble, /* 8 */ - airTypeChar, /* 9 */ - airTypeString, /* 10 */ - airTypeEnum, /* 11 */ - airTypeOther, /* 12 */ - airTypeLast -}; -#define AIR_TYPE_MAX 12 +/* changes for for TeemV2: + *** airParseStrT() are no longer var-args; it was a mistaken way to enforce uniformity + * across parsers for different types, but it was really only airParseStrE (for + * parsing airEnum values) that needed it. Then airParseStrS sneakily used it for + * its final "greedy" argument, which was also a bad idea to overcome bad ideas in + * hestParse(), which have since been fixed with its 2025 re-write. + *** Renamed airParseStrLI, airParseStrULI --> airParseStrL, airParseStrUL + *** Added airParseStrH and airParseStrUH for signed and unsigned shorts + *** Removed airStrtokQuoting (another bad idea; used only for "unu make") + *** Moved the airTypeT enum values from air to hest, since hest was the motivation for + * creating them so they should be localized to hest. To avoid needlessly breaking code + * that uses hestOptAdd(), which depends on the airTypeT enum values, those have kept + * their names, except: + * *** added airTypeShort and airTypeUShort + * *** renamed airTypeLongInt --> airTypeLong + * *** renamed airTypeULongInt --> airTypeULong + *** Moved the following from air to hest, renamed them, and made them private. + * They were only used to implement hest, no where else in Teem, so they never + * deserved to be in air: + * #define AIR_TYPE_MAX --> _HEST_TYPE_MAX + * const char airTypeStr[HEST_TYPE_MAX + 1][AIR_STRLEN_SMALL + 1] --> _hestTypeStr + * const size_t airTypeSize[HEST_TYPE_MAX + 1] --> _hestTypeSize + *** Removed the following, since it was only used in the pre-TeemV2 hest + * unsigned int (*const airParseStr[AIR_TYPE_MAX + 1])(void *, + * const char *, *const char *, + * *unsigned int); + */ /* parseAir.c */ NRRDIO_EXPORT double airAtod(const char *str); NRRDIO_EXPORT int airSingleSscanf(const char *str, const char *fmt, void *ptr); NRRDIO_EXPORT const airEnum *const airBool; -NRRDIO_EXPORT unsigned int airParseStrB(int *out, const char *s, - const char *ct, unsigned int n, - ... /* (nothing used) */); -NRRDIO_EXPORT unsigned int airParseStrI(int *out, const char *s, - const char *ct, unsigned int n, - ... /* (nothing used) */); +NRRDIO_EXPORT unsigned int airParseStrB(int *out, const char *s, const char *ct, + unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrH(short *out, const char *s, const char *ct, + unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrUH(unsigned short *out, const char *s, + const char *ct, unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrI(int *out, const char *s, const char *ct, + unsigned int n); NRRDIO_EXPORT unsigned int airParseStrUI(unsigned int *out, const char *s, - const char *ct, unsigned int n, - ... /* (nothing used) */); -NRRDIO_EXPORT unsigned int airParseStrZ(size_t *out, const char *s, - const char *ct, unsigned int n, - ... /* (nothing used) */); -NRRDIO_EXPORT unsigned int airParseStrF(float *out, const char *s, - const char *ct, unsigned int n, - ... /* (nothing used) */); -NRRDIO_EXPORT unsigned int airParseStrD(double *out, const char *s, - const char *ct, unsigned int n, - ... /* (nothing used) */); -NRRDIO_EXPORT unsigned int airParseStrC(char *out, const char *s, - const char *ct, unsigned int n, - ... /* (nothing used) */); -NRRDIO_EXPORT unsigned int airParseStrS(char **out, const char *s, - const char *ct, unsigned int n, - ... /* REQ'D even if n>1: int greedy */); -NRRDIO_EXPORT unsigned int airParseStrE(int *out, const char *s, - const char *ct, unsigned int n, - ... /* REQUIRED: airEnum *e */); -NRRDIO_EXPORT unsigned int (*airParseStr[AIR_TYPE_MAX+1])(void *, const char *, - const char *, - unsigned int, ...); + const char *ct, unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrL(long int *out, const char *s, const char *ct, + unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrUL(unsigned long int *out, const char *s, + const char *ct, unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrZ(size_t *out, const char *s, const char *ct, + unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrF(float *out, const char *s, const char *ct, + unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrD(double *out, const char *s, const char *ct, + unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrC(char *out, const char *s, const char *ct, + unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrS(char **out, const char *s, const char *ct, + unsigned int n); +NRRDIO_EXPORT unsigned int airParseStrE(int *out, const char *s, const char *ct, + unsigned int n, const airEnum *enm); /* string.c */ NRRDIO_EXPORT char *airStrdup(const char *s); NRRDIO_EXPORT size_t airStrlen(const char *s); -NRRDIO_EXPORT int airStrtokQuoting; NRRDIO_EXPORT char *airStrtok(char *s, const char *ct, char **last); NRRDIO_EXPORT unsigned int airStrntok(const char *s, const char *ct); NRRDIO_EXPORT char *airStrtrans(char *s, char from, char to); @@ -416,62 +400,31 @@ enum { airInsane_pInfExists, /* 2: AIR_EXISTS(positive infinity) was true */ airInsane_nInfExists, /* 3: AIR_EXISTS(negative infinity) was true */ airInsane_NaNExists, /* 4: AIR_EXISTS(NaN) was true */ - airInsane_FltDblFPClass, /* 5: double -> float assignment messed up the - airFPClass_f() of the value */ - airInsane_QNaNHiBit, /* 6: airMyQNaNHiBit is wrong */ - airInsane_AIR_NAN, /* 7: airFPClass_f(AIR_QNAN) wrong - (no longer checking on problematic SNAN) */ - airInsane_dio, /* 8: airMyDio set to something invalid */ - airInsane_UCSize, /* 9: unsigned char isn't 8 bits */ - airInsane_FISize, /* 10: sizeof(float), sizeof(int) not 4 */ - airInsane_DLSize /* 11: sizeof(double), sizeof(airLLong) not 8 */ + airInsane_ExistsBad, /* 5: AIR_EXISTS of some finite values was false */ + airInsane_FltDblFPClass, /* 6: double -> float assignment messed up the + airFPClass_f() of the value */ + airInsane_AIR_NAN, /* 7: airFPClass_f(AIR_NAN) wrong */ + airInsane_UCSize, /* 8: unsigned char isn't 8 bits */ + airInsane_FISize, /* 9: sizeof(float), sizeof(int) not 4 */ + airInsane_DLSize, /* 10: sizeof(double), sizeof(airLLong) not 8 */ + airInsane_last }; -#define AIR_INSANE_MAX 11 +#define AIR_INSANE_MAX 10 NRRDIO_EXPORT const char *airInsaneErr(int insane); NRRDIO_EXPORT int airSanity(void); /* miscAir.c */ -NRRDIO_EXPORT const char *airTeemVersion; -NRRDIO_EXPORT const char *airTeemReleaseDate; +NRRDIO_EXPORT const char *const airTeemVersion; +NRRDIO_EXPORT const int airTeemReleaseDone; +NRRDIO_EXPORT const char *const airTeemReleaseDate; +NRRDIO_EXPORT void airTeemVersionSprint(char buff[AIR_STRLEN_LARGE + 1]); NRRDIO_EXPORT void *airNull(void); NRRDIO_EXPORT void *airSetNull(void **ptrP); NRRDIO_EXPORT void *airFree(void *ptr); NRRDIO_EXPORT FILE *airFopen(const char *name, FILE *std, const char *mode); NRRDIO_EXPORT FILE *airFclose(FILE *file); NRRDIO_EXPORT int airSinglePrintf(FILE *file, char *str, const char *fmt, ...); -NRRDIO_EXPORT char *airSprintSize_t(char str[AIR_STRLEN_SMALL], size_t val); - -/* dio.c */ -/* -******** airNoDio enum -** -** reasons for why direct I/O won't be used with a particular -** file/pointer combination -*/ -enum { - airNoDio_okay, /* 0: actually, you CAN do direct I/O */ - airNoDio_arch, /* 1: Teem thinks this architecture can't do it */ - airNoDio_format, /* 2: Teem thinks given data file format can't use it */ - airNoDio_std, /* 3: DIO isn't possible for std{in|out|err} */ - airNoDio_fd, /* 4: couldn't get underlying file descriptor */ - airNoDio_dioinfo, /* 5: calling fcntl() to get direct I/O info failed */ - airNoDio_small, /* 6: requested size is too small */ - airNoDio_size, /* 7: requested size not a multiple of d_miniosz */ - airNoDio_ptr, /* 8: pointer not multiple of d_mem */ - airNoDio_fpos, /* 9: current file position not multiple of d_miniosz */ - airNoDio_setfl, /* 10: fcntl(fd, SETFL, FDIRECT) failed */ - airNoDio_test, /* 11: couldn't memalign() even a small bit of memory */ - airNoDio_disable /* 12: someone disabled it with airDisableDio */ -}; -#define AIR_NODIO_MAX 12 -NRRDIO_EXPORT const char *airNoDioErr(int noDio); -NRRDIO_EXPORT const int airMyDio; -NRRDIO_EXPORT int airDisableDio; -NRRDIO_EXPORT void airDioInfo(int *align, int *min, int *max, int fd); -NRRDIO_EXPORT int airDioTest(int fd, const void *ptr, size_t size); -NRRDIO_EXPORT void *airDioMalloc(size_t size, int fd); -NRRDIO_EXPORT size_t airDioRead(int fd, void *ptr, size_t size); -NRRDIO_EXPORT size_t airDioWrite(int fd, const void *ptr, size_t size); +NRRDIO_EXPORT char *airSprintSize_t(char str[AIR_STRLEN_SMALL + 1], size_t val); /* mop.c: clean-up utilities */ enum { @@ -482,9 +435,9 @@ enum { }; typedef void *(*airMopper)(void *); typedef struct { - void *ptr; /* the thing to be processed */ - airMopper mop; /* the function to which does the processing */ - int when; /* from the airMopWhen enum */ + void *ptr; /* the thing to be processed */ + airMopper mop; /* the function to which does the processing */ + int when; /* from the airMopWhen enum */ } airMop; NRRDIO_EXPORT airArray *airMopNew(void); NRRDIO_EXPORT int airMopAdd(airArray *arr, void *ptr, airMopper mop, int when); @@ -492,17 +445,15 @@ NRRDIO_EXPORT void airMopSub(airArray *arr, void *ptr, airMopper mop); NRRDIO_EXPORT void airMopMem(airArray *arr, void *_ptrP, int when); NRRDIO_EXPORT void airMopUnMem(airArray *arr, void *_ptrP); NRRDIO_EXPORT void airMopPrint(airArray *arr, const void *_str, int when); -NRRDIO_EXPORT void airMopDone(airArray *arr, int error); -NRRDIO_EXPORT void airMopError(airArray *arr); -NRRDIO_EXPORT void airMopOkay(airArray *arr); +NRRDIO_EXPORT airArray *airMopDone(airArray *arr, int error); +NRRDIO_EXPORT airArray *airMopError(airArray *arr); +NRRDIO_EXPORT airArray *airMopOkay(airArray *arr); NRRDIO_EXPORT void airMopDebug(airArray *arr); - /******* the interminable sea of defines and macros *******/ -#define AIR_TRUE 1 +#define AIR_TRUE 1 #define AIR_FALSE 0 -#define AIR_WHITESPACE " \t\n\r\v\f" /* K+R pg. 157 */ /* ******** AIR_UNUSED @@ -513,14 +464,19 @@ NRRDIO_EXPORT void airMopDebug(airArray *arr); #define AIR_UNUSED(x) (void)(x) /* -******** AIR_CAST, AIR_UINT, AIR_INT +******** AIR_CAST, AIR_UINT, AIR_INT, ... ** ** just casts, but with the added ability to grep for them more easily, ** since casts should probably always be revisited and reconsidered. */ #define AIR_CAST(t, v) ((t)(v)) -#define AIR_UINT(x) AIR_CAST(unsigned int, x) -#define AIR_INT(x) AIR_CAST(int, x) +#define AIR_UCHAR(x) AIR_CAST(unsigned char, x) +#define AIR_USHORT(x) AIR_CAST(unsigned short, x) +#define AIR_UINT(x) AIR_CAST(unsigned int, x) +#define AIR_SIZE_T(x) AIR_CAST(size_t, x) +#define AIR_INT(x) AIR_CAST(int, x) +#define AIR_FLOAT(x) AIR_CAST(float, x) +#define AIR_DOUBLE(x) AIR_CAST(double, x) /* ******** AIR_VOIDP, AIR_CVOIDP @@ -529,7 +485,7 @@ NRRDIO_EXPORT void airMopDebug(airArray *arr); ** is strictly speaking needed for the %p format specifier in printf-like ** functions; this is a slightly more convenient form */ -#define AIR_VOIDP(x) AIR_CAST(void *, x) +#define AIR_VOIDP(x) AIR_CAST(void *, x) #define AIR_CVOIDP(x) AIR_CAST(const void *, x) /* @@ -540,24 +496,11 @@ NRRDIO_EXPORT void airMopDebug(airArray *arr); ** HEY note that "T" is not guarded by parentheses in its first usage, ** as arguments in Teem macros normally are */ -#define AIR_MALLOC(N, T) (T*)(malloc((N)*sizeof(T))) -#define AIR_CALLOC(N, T) (T*)(calloc((N), sizeof(T))) - -/* -******** AIR_ENDIAN, AIR_QNANHIBIT, AIR_DIO -** -** These reflect particulars of hardware which we're running on. The -** difference from the things starting with TEEM_ is that the TEEM_ -** values are for passing architecture-specific to compilation of source -** files, and thes AIR_ variables are for advertising that information -** to anyone linking against air (or Teem) and including air.h. -*/ -#define AIR_ENDIAN (airMyEndian()) -#define AIR_QNANHIBIT (airMyQNaNHiBit) -#define AIR_DIO (airMyDio) +#define AIR_MALLOC(N, T) (T *)(malloc((N) * sizeof(T))) +#define AIR_CALLOC(N, T) (T *)(calloc((N), sizeof(T))) /* -******** AIR_NAN, AIR_QNAN, AIR_SNAN, AIR_POS_INF, AIR_NEG_INF +******** AIR_NAN, AIR_POS_INF, AIR_NEG_INF ** ** its nice to have these values available without the cost of a ** function call. @@ -567,74 +510,21 @@ NRRDIO_EXPORT void airMopDebug(airArray *arr); ** the NaNs, however, they are only one of many possible ** representations. */ -#define AIR_NAN (airFloatQNaN.f) -#define AIR_QNAN (airFloatQNaN.f) -#define AIR_SNAN (airFloatSNaN.f) +#define AIR_NAN (airFloatNaN.f) #define AIR_POS_INF (airFloatPosInf.f) #define AIR_NEG_INF (airFloatNegInf.f) -/* -******** AIR_EXISTS -** -** is non-zero (true) only for values which are not NaN or +/-infinity -** -** You'd think that (x == x) might work, but no no no, some optimizing -** compilers (e.g. SGI's cc) say "well of course they're equal, for all -** possible values". Bastards! -** -** One of the benefits of IEEE 754 floating point numbers is that -** gradual underflow means that x = y <==> x - y = 0 for any (positive -** or negative) normalized or denormalized float. Otherwise this -** macro could not be valid; some floating point conventions say that -** a zero-valued exponent means zero, regardless of the mantissa. -** -** However, there MAY be problems on machines which use extended -** (80-bit) floating point registers, such as Intel chips- where the -** same initial value 1) directly read from the register, versus 2) -** saved to memory and loaded back, may end up being different. I -** have yet to produce this behavior, or convince myself it can't happen. -** -** The reason to #define AIR_EXISTS as airExists is that on some -** optimizing compilers, the !((x) - (x)) doesn't work. This has been -** the case on Windows and 64-bit irix6 (64 bit) with -Ofast. If -** airSanity fails because a special value "exists", then use the -** first version of AIR_EXISTS. -** -** There is a performance consequence of using airExists(x), in that it -** is a function call, although (HEY) we should facilitate inline'ing it -** for compilers that know how to. -** -** gcc 4.5.3 -std=c89, at least on cygwin, has problems with -** the type of "!((x) - (x))" when used with bit-wise xor ^, saying -** "invalid operands to binary ^ (have ‘int’ and ‘int’)" but these -** problems oddly went away with the explicit cast to int. -*/ -#if 1 +/* turn AIR_EXISTS() into airExists(), which is like isfinite() */ #define AIR_EXISTS(x) (airExists(x)) -#else -#define AIR_EXISTS(x) (AIR_CAST(int, !((x) - (x)))) -#endif - /* ******** AIR_MAX(a,b), AIR_MIN(a,b), AIR_ABS(a) ** ** the usual */ -#define AIR_MAX(a,b) ((a) > (b) ? (a) : (b)) -#define AIR_MIN(a,b) ((a) < (b) ? (a) : (b)) -#define AIR_ABS(a) ((a) > 0.0f ? (a) : -(a)) - -/* -******** AIR_COMPARE(a,b) -** -** the sort of compare that qsort() wants for ascending sort -*/ -#define AIR_COMPARE(a,b) ((a) < (b) \ - ? -1 \ - : ((a) > (b) \ - ? 1 \ - : 0)) +#define AIR_MAX(a, b) ((a) > (b) ? (a) : (b)) +#define AIR_MIN(a, b) ((a) < (b) ? (a) : (b)) +#define AIR_ABS(a) ((a) > 0.0f ? (a) : -(a)) /* ******** AIR_IN_OP(a,b,c), AIR_IN_CL(a,b,c) @@ -645,8 +535,8 @@ NRRDIO_EXPORT void airMopDebug(airArray *arr); ** AIR_IN_OP is new name for old AIR_BETWEEN ** AIR_IN_CL is new name for old AIR_INSIDE */ -#define AIR_IN_OP(a,b,c) ((a) < (b) && (b) < (c)) /* closed interval */ -#define AIR_IN_CL(a,b,c) ((a) <= (b) && (b) <= (c)) /* open interval */ +#define AIR_IN_OP(a, b, c) ((a) < (b) && (b) < (c)) /* closed interval */ +#define AIR_IN_CL(a, b, c) ((a) <= (b) && (b) <= (c)) /* open interval */ /* ******** AIR_CLAMP(a,b,c) @@ -654,31 +544,7 @@ NRRDIO_EXPORT void airMopDebug(airArray *arr); ** returns the middle argument, after being clamped to the closed ** interval defined by the first and third arguments */ -#define AIR_CLAMP(a,b,c) ((b) < (a) \ - ? (a) \ - : ((b) > (c) \ - ? (c) \ - : (b))) - -/* -******** AIR_MOD(i, N) -** -** returns that integer in [0, N-1] which is i plus a multiple of N. It -** may be unfortunate that the expression (i)%(N) appears three times; -** this should be inlined. Or perhaps the compiler's optimizations -** (common sub-expression elimination) will save us. -** -** Note: integer divisions are not very fast on some modern chips; -** don't go silly using this one. -*/ -#define AIR_MOD(i, N) ((i)%(N) >= 0 ? (i)%(N) : N + (i)%(N)) - -/* -******** AIR_LERP(w, a, b) -** -** returns a when w=0, and b when w=1, and linearly varies in between -*/ -#define AIR_LERP(w, a, b) ((w)*((b) - (a)) + (a)) +#define AIR_CLAMP(a, b, c) ((b) < (a) ? (a) : ((b) > (c) ? (c) : (b))) /* ******** AIR_AFFINE(i,x,I,o,O) @@ -699,46 +565,13 @@ NRRDIO_EXPORT void airMopDebug(airArray *arr); ** as is "I" and "O" (usually not so important); "i" and "o" are each ** evaluated twice */ -#define AIR_AFFINE(i,x,I,o,O) ( \ -((double)(O)-(o))*((double)(x)-(i)) / ((double)(I)-(i)) + (o)) - -/* -******** AIR_DELTA(i,x,I,o,O) -** -** given intervals [i,I] and [o,O], calculates the number y such that -** a change of x within [i,I] is proportional to a change of y within -** [o,O]. Or: -** -** y x -** ------- = ------- -** O - o I - i -** -** It is the callers responsibility to make sure I-i and O-o are -** both non-zero -** -** NOTE that all arguments are evaluated only once -*/ -#define AIR_DELTA(i,x,I,o,O) ( \ -((double)(O)-(o))*((double)(x)) / ((double)(I)-(i)) ) - -/* -******** AIR_ROUNDUP, AIR_ROUNDDOWN -** -** rounds integers up or down; just wrappers around floor and ceil -*/ -#define AIR_ROUNDUP(x) ((int)(floor((x)+0.5))) -#define AIR_ROUNDDOWN(x) ((int)(ceil((x)-0.5))) -#define AIR_ROUNDUP_UI(x) ((unsigned int)(floor((x)+0.5))) -#define AIR_ROUNDDOWN_UI(x) ((unsigned int)(ceil((x)-0.5))) +#define AIR_AFFINE(i, x, I, o, O) \ + (((double)(O) - (o)) * ((double)(x) - (i)) / ((double)(I) - (i)) + (o)) #ifdef __cplusplus } #endif - - - - #ifdef __cplusplus extern "C" { #endif @@ -749,42 +582,28 @@ extern "C" { ** externally usable thing for holding error messages */ typedef struct { - char *key; /* string for identifying the general source - of the error message; set once, at time - of biffMsg creation */ - char **err; /* array of error strings; the err array itself - is NOT null-terminated */ - unsigned int errNum; /* length of "err" == # strings stored */ - airArray *errArr; /* air array for err and num */ + char *key; /* string for identifying the general source + of the error message; set once, at time + of biffMsg creation */ + char **err; /* array of error strings; the err array itself + is NOT null-terminated */ + unsigned int errNum; /* length of "err" == # strings stored */ + airArray *errArr; /* air array for err and num */ } biffMsg; -/* biffmsg.c */ -NRRDIO_EXPORT biffMsg *biffMsgNew(const char *key); -NRRDIO_EXPORT biffMsg *biffMsgNix(biffMsg *msg); -NRRDIO_EXPORT void biffMsgAdd(biffMsg *msg, const char *err); -NRRDIO_EXPORT void biffMsgClear(biffMsg *msg); -NRRDIO_EXPORT unsigned int biffMsgLineLenMax(const biffMsg *msg); -NRRDIO_EXPORT void biffMsgMove(biffMsg *dest, biffMsg *src, - const char *err); -NRRDIO_EXPORT unsigned int biffMsgErrNum(const biffMsg *msg); -NRRDIO_EXPORT unsigned int biffMsgStrlen(const biffMsg *msg); -NRRDIO_EXPORT void biffMsgStrSet(char *ret, const biffMsg *msg); -NRRDIO_EXPORT biffMsg *biffMsgNoop; - /* biffbiff.c */ NRRDIO_EXPORT void biffAdd(const char *key, const char *err); NRRDIO_EXPORT void biffAddf(const char *key, const char *errfmt, ...) #ifdef __GNUC__ - __attribute__ ((format(printf,2,3))) + __attribute__((format(printf, 2, 3))) #endif -; + ; NRRDIO_EXPORT void biffMaybeAdd(const char *key, const char *err, int useBiff); -NRRDIO_EXPORT void biffMaybeAddf(int useBiff, const char *key, - const char *errfmt, ... ) +NRRDIO_EXPORT void biffMaybeAddf(int useBiff, const char *key, const char *errfmt, ...) #ifdef __GNUC__ -__attribute__ ((format(printf,3,4))) + __attribute__((format(printf, 3, 4))) #endif -; + ; NRRDIO_EXPORT char *biffGet(const char *key); NRRDIO_EXPORT unsigned int biffGetStrlen(const char *key); NRRDIO_EXPORT void biffSetStr(char *str, const char *key); @@ -795,8 +614,6 @@ NRRDIO_EXPORT char *biffGetDone(const char *key); } #endif - - #include #ifdef __cplusplus @@ -804,31 +621,20 @@ extern "C" { #endif /* feel free to set these to higher values and recompile */ -#define NRRD_DIM_MAX 16 /* Max array dimension (nrrd->dim) */ -#define NRRD_SPACE_DIM_MAX 8 /* Max dimension of "space" around array - (nrrd->spaceDim) */ - -#define NRRD_EXT_NRRD ".nrrd" -#define NRRD_EXT_NHDR ".nhdr" -#define NRRD_EXT_PGM ".pgm" -#define NRRD_EXT_PPM ".ppm" -#define NRRD_EXT_PNG ".png" -#define NRRD_EXT_VTK ".vtk" -#define NRRD_EXT_TEXT ".txt" -#define NRRD_EXT_EPS ".eps" - -/* HEY: should this be renamed -> MAXNUM ? Would be more consistent - with other Teem pound-define names */ -#define NRRD_KERNEL_PARMS_NUM 8 /* max # arguments to a kernel- - this is weird: it isn't the max - of any of the NrrdKernels - defined by the nrrd library - (that is more like 3), but is - the max number of parms of any - NrrdKernel used by anyone using - Teem, such as in gage. - Enforcing one global max - simplifies implementation. */ +#define NRRD_DIM_MAX 16 +/* Max array dimension (nrrd->dim) */ +#define NRRD_SPACE_DIM_MAX 8 +/* Max dimension of "space" around array + (nrrd->spaceDim) */ + +#define NRRD_EXT_NRRD ".nrrd" +#define NRRD_EXT_NHDR ".nhdr" +#define NRRD_EXT_PGM ".pgm" +#define NRRD_EXT_PPM ".ppm" +#define NRRD_EXT_PNG ".png" +#define NRRD_EXT_VTK ".vtk" +#define NRRD_EXT_TEXT ".txt" +#define NRRD_EXT_EPS ".eps" /* ** For the 64-bit integer types (not standard except in C99), we used @@ -840,41 +646,43 @@ extern "C" { ** terms of explicit values (which agree with those defined by C99). */ -#define NRRD_LLONG_MAX AIR_LLONG(9223372036854775807) -#define NRRD_LLONG_MIN (-NRRD_LLONG_MAX-AIR_LLONG(1)) +#define NRRD_LLONG_MAX AIR_LLONG(9223372036854775807) +#define NRRD_LLONG_MIN (-NRRD_LLONG_MAX - AIR_LLONG(1)) #define NRRD_ULLONG_MAX AIR_ULLONG(18446744073709551615) /* ** Chances are, you shouldn't mess with these */ -#define NRRD_COMMENT_CHAR '#' +#define NRRD_COMMENT_CHAR '#' #define NRRD_FILENAME_INCR 32 -#define NRRD_COMMENT_INCR 16 +#define NRRD_COMMENT_INCR 16 #define NRRD_KEYVALUE_INCR 32 -#define NRRD_LIST_FLAG "LIST" -#define NRRD_PNM_COMMENT "# NRRD>" /* this is designed to be robust against - the mungling that xv does, but no - promises for any other image - programs */ - -#define NRRD_PNG_FIELD_KEY "NRRD" /* this is the key used for getting nrrd - fields into/out of png comments */ -#define NRRD_PNG_COMMENT_KEY "NRRD#" /* this is the key used for getting nrrd - comments into/out of png comments */ - -#define NRRD_UNKNOWN "???" /* how to represent something unknown in - a field of the nrrd header, when it - being unknown is not an error */ -#define NRRD_NONE "none" /* like NRRD_UNKNOWN, but with an air - of certainty */ +#define NRRD_LIST_FLAG "LIST" +#define NRRD_SKIPLIST_FLAG "SKIPLIST" +#define NRRD_PNM_COMMENT "# NRRD>" +/* this is designed to be robust against the + mungling that xv does, but no promises for + any other image programs */ + +#define NRRD_PNG_FIELD_KEY "NRRD" +/* this is the key used for getting nrrd + fields into/out of png comments */ +#define NRRD_PNG_COMMENT_KEY "NRRD#" +/* this is the key used for getting nrrd + comments into/out of png comments */ +#define NRRD_UNKNOWN "???" +/* how to represent something unknown in a + field of the nrrd header, when it being + unknown is not an error */ +#define NRRD_NONE "none" +/* like NRRD_UNKNOWN, but with an air of + certainty */ #ifdef __cplusplus } #endif - - #ifdef __cplusplus extern "C" { #endif @@ -892,11 +700,15 @@ extern "C" { ** ** the various things it makes sense to get and set in nrrdIoState struct ** via nrrdIoStateGet and nrrdIoStateSet +** BUT HEY are those functions actually used (as opposed to directly reading +** or setting fields in the nio)? GLK honestly forgot about those functions +** until working on adding nio->moreThanFloatInText */ enum { nrrdIoStateUnknown, nrrdIoStateDetachedHeader, nrrdIoStateBareText, + nrrdIoStateMoreThanFloatInText, nrrdIoStateCharsPerLine, nrrdIoStateValsPerLine, nrrdIoStateSkipData, @@ -914,34 +726,19 @@ enum { */ enum { nrrdFormatTypeUnknown, - nrrdFormatTypeNRRD, /* 1: basic nrrd format (associated with any of - the magics starting with "NRRD") */ - nrrdFormatTypePNM, /* 2: PNM image */ - nrrdFormatTypePNG, /* 3: PNG image */ - nrrdFormatTypeVTK, /* 4: VTK Structured Points datasets (v1.0 and 2.0) */ - nrrdFormatTypeText, /* 5: bare ASCII text for 2D arrays */ - nrrdFormatTypeEPS, /* 6: Encapsulated PostScript (write-only) */ + nrrdFormatTypeNRRD, /* 1: basic nrrd format (associated with any of + the magics starting with "NRRD") */ + nrrdFormatTypePNM, /* 2: PNM image */ + nrrdFormatTypePNG, /* 3: PNG image */ + nrrdFormatTypeVTK, /* 4: VTK Structured Points datasets (v1.0 and 2.0) */ + nrrdFormatTypeText, /* 5: ASCII text for 2D arrays, which may or may + not be bare (i.e. just numbers, no header + lines that start with "#") according + to NrrdIoState->bareText */ + nrrdFormatTypeEPS, /* 6: Encapsulated PostScript (write-only) */ nrrdFormatTypeLast }; -#define NRRD_FORMAT_TYPE_MAX 6 - -/* -******** nrrdBoundary* enum -** -** when resampling, how to deal with the ends of a scanline -*/ -enum { - nrrdBoundaryUnknown, - nrrdBoundaryPad, /* 1: fill with some user-specified value */ - nrrdBoundaryBleed, /* 2: copy the last/first value out as needed */ - nrrdBoundaryWrap, /* 3: wrap-around */ - nrrdBoundaryWeight, /* 4: normalize the weighting on the existing samples; - ONLY sensible for a strictly positive kernel - which integrates to unity (as in blurring) */ - nrrdBoundaryMirror, /* 5: mirror folding */ - nrrdBoundaryLast -}; -#define NRRD_BOUNDARY_MAX 5 +#define NRRD_FORMAT_TYPE_MAX 6 /* ******** nrrdType* enum @@ -957,26 +754,27 @@ enum { ** and being simply default. */ enum { - nrrdTypeUnknown=0, /* 0: signifies "type is unset/unknown" */ - nrrdTypeDefault=0, /* 0: signifies "determine output type for me" */ - nrrdTypeChar, /* 1: signed 1-byte integer */ - nrrdTypeUChar, /* 2: unsigned 1-byte integer */ - nrrdTypeShort, /* 3: signed 2-byte integer */ - nrrdTypeUShort, /* 4: unsigned 2-byte integer */ - nrrdTypeInt, /* 5: signed 4-byte integer */ - nrrdTypeUInt, /* 6: unsigned 4-byte integer */ - nrrdTypeLLong, /* 7: signed 8-byte integer */ - nrrdTypeULLong, /* 8: unsigned 8-byte integer */ - nrrdTypeFloat, /* 9: 4-byte floating point */ - nrrdTypeDouble, /* 10: 8-byte floating point */ - nrrdTypeBlock, /* 11: size user defined at run time; MUST BE LAST */ + nrrdTypeUnknown = 0, /* 0: signifies "type is unset/unknown" */ + nrrdTypeDefault = 0, /* 0: signifies "determine output type for me" */ + nrrdTypeChar, /* 1: signed 1-byte integer */ + nrrdTypeUChar, /* 2: unsigned 1-byte integer */ + nrrdTypeShort, /* 3: signed 2-byte integer */ + nrrdTypeUShort, /* 4: unsigned 2-byte integer */ + nrrdTypeInt, /* 5: signed 4-byte integer */ + nrrdTypeUInt, /* 6: unsigned 4-byte integer */ + nrrdTypeLLong, /* 7: signed 8-byte integer */ + nrrdTypeULLong, /* 8: unsigned 8-byte integer */ + nrrdTypeFloat, /* 9: 4-byte floating point */ + nrrdTypeDouble, /* 10: 8-byte floating point */ + nrrdTypeBlock, /* 11: size user defined at run time; MUST BE LAST */ nrrdTypeLast }; -#define NRRD_TYPE_MAX 11 -#define NRRD_TYPE_SIZE_MAX 8 /* max(sizeof()) over all scalar types */ -#define NRRD_TYPE_BIGGEST double /* this should be a basic C type which - requires for storage the maximum size - of all the basic C types */ +#define NRRD_TYPE_MAX 11 +#define NRRD_TYPE_SIZE_MAX 8 /* max(sizeof()) over all scalar types */ +#define NRRD_TYPE_BIGGEST \ + double /* this should be a basic C type which \ + requires for storage the maximum size \ + of all the basic C types */ /* ******** nrrdEncodingType enum @@ -985,14 +783,15 @@ enum { */ enum { nrrdEncodingTypeUnknown, - nrrdEncodingTypeRaw, /* 1: same as memory layout (modulo endianness) */ - nrrdEncodingTypeAscii, /* 2: decimal values are spelled out in ascii */ - nrrdEncodingTypeHex, /* 3: hexidecimal (two chars per byte) */ - nrrdEncodingTypeGzip, /* 4: gzip'ed raw data */ - nrrdEncodingTypeBzip2, /* 5: bzip2'ed raw data */ + nrrdEncodingTypeRaw, /* 1: same as memory layout (modulo endianness) */ + nrrdEncodingTypeAscii, /* 2: decimal values are spelled out in ascii */ + nrrdEncodingTypeHex, /* 3: hexidecimal (two chars per byte) */ + nrrdEncodingTypeGzip, /* 4: gzip'ed raw data */ + nrrdEncodingTypeBzip2, /* 5: bzip2'ed raw data */ + nrrdEncodingTypeZRL, /* 6: zero run-length compresion */ nrrdEncodingTypeLast }; -#define NRRD_ENCODING_TYPE_MAX 5 +#define NRRD_ENCODING_TYPE_MAX 6 /* ******** nrrdZlibStrategy enum @@ -1001,12 +800,12 @@ enum { */ enum { nrrdZlibStrategyUnknown, - nrrdZlibStrategyDefault, /* 1: default (Huffman + string match) */ - nrrdZlibStrategyHuffman, /* 2: Huffman only */ - nrrdZlibStrategyFiltered, /* 3: specialized for filtered data */ + nrrdZlibStrategyDefault, /* 1: default (Huffman + string match) */ + nrrdZlibStrategyHuffman, /* 2: Huffman only */ + nrrdZlibStrategyFiltered, /* 3: specialized for filtered data */ nrrdZlibStrategyLast }; -#define NRRD_ZLIB_STRATEGY_MAX 3 +#define NRRD_ZLIB_STRATEGY_MAX 3 /* ******** nrrdCenter enum @@ -1014,18 +813,18 @@ enum { ** node-centered vs. cell-centered */ enum { - nrrdCenterUnknown, /* 0: no centering known for this axis */ - nrrdCenterNode, /* 1: samples at corners of things - (how "voxels" are usually imagined) - |\______/|\______/|\______/| - X X X X */ - nrrdCenterCell, /* 2: samples at middles of things - (characteristic of histogram bins) - \___|___/\___|___/\___|___/ - X X X */ + nrrdCenterUnknown, /* 0: no centering known for this axis */ + nrrdCenterNode, /* 1: samples at corners of things + (how "voxels" are usually imagined) + |\______/|\______/|\______/| + X X X X */ + nrrdCenterCell, /* 2: samples at middles of things + (characteristic of histogram bins) + \___|___/\___|___/\___|___/ + X X X */ nrrdCenterLast }; -#define NRRD_CENTER_MAX 2 +#define NRRD_CENTER_MAX 2 /* ******** nrrdKind enum @@ -1060,16 +859,16 @@ enum { */ enum { nrrdKindUnknown, - nrrdKindDomain, /* 1: any image domain */ - nrrdKindSpace, /* 2: a spatial domain */ - nrrdKindTime, /* 3: a temporal domain */ + nrrdKindDomain, /* 1: any image domain */ + nrrdKindSpace, /* 2: a spatial domain */ + nrrdKindTime, /* 3: a temporal domain */ /* -------------------------- end domain kinds */ /* -------------------------- begin range kinds */ - nrrdKindList, /* 4: any list of values, non-resample-able */ - nrrdKindPoint, /* 5: coords of a point */ - nrrdKindVector, /* 6: coeffs of (contravariant) vector */ - nrrdKindCovariantVector, /* 7: coeffs of covariant vector (eg gradient) */ - nrrdKindNormal, /* 8: coeffs of unit-length covariant vector */ + nrrdKindList, /* 4: any list of values, non-resample-able */ + nrrdKindPoint, /* 5: coords of a point */ + nrrdKindVector, /* 6: coeffs of (contravariant) vector */ + nrrdKindCovariantVector, /* 7: coeffs of covariant vector (eg gradient) */ + nrrdKindNormal, /* 8: coeffs of unit-length covariant vector */ /* -------------------------- end arbitrary size kinds */ /* -------------------------- begin size-specific kinds */ nrrdKindStub, /* 9: axis with one sample (a placeholder) */ @@ -1097,13 +896,14 @@ enum { nrrdKind3DMaskedMatrix, /* 31: mask Mxx Mxy Mxz Myx Myy Myz Mzx Mzy Mzz */ nrrdKindLast }; -#define NRRD_KIND_MAX 31 +#define NRRD_KIND_MAX 31 /* ******** nrrdAxisInfo enum ** ** the different pieces of per-axis information recorded in a nrrd */ +/* clang-format off */ enum { nrrdAxisInfoUnknown, nrrdAxisInfoSize, /* 1: number of samples along axis */ @@ -1187,6 +987,7 @@ enum { | NRRD_BASIC_INFO_SPACEORIGIN_BIT \ | NRRD_BASIC_INFO_MEASUREMENTFRAME_BIT) #define NRRD_BASIC_INFO_NONE 0 +/* clang-format on */ /* ******** nrrdField enum @@ -1251,7 +1052,7 @@ enum { nrrdField_data_file, /* 32 */ nrrdField_last }; -#define NRRD_FIELD_MAX 32 +#define NRRD_FIELD_MAX 32 /* ******** nrrdHasNonExist* enum @@ -1266,10 +1067,10 @@ enum { ** probably harmlessly conservative. Time will tell. */ enum { - nrrdHasNonExistFalse, /* 0: no non-existent values were seen */ - nrrdHasNonExistTrue, /* 1: some non-existent values were seen */ - nrrdHasNonExistOnly, /* 2: NOTHING BUT non-existent values were seen */ - nrrdHasNonExistUnknown, /* 3 */ + nrrdHasNonExistFalse, /* 0: no non-existent values were seen */ + nrrdHasNonExistTrue, /* 1: some non-existent values were seen */ + nrrdHasNonExistOnly, /* 2: NOTHING BUT non-existent values were seen */ + nrrdHasNonExistUnknown, /* 3 */ nrrdHasNonExistLast }; #define NRRD_HAS_NON_EXIST_MAX 3 @@ -1308,21 +1109,25 @@ enum { */ enum { nrrdSpaceUnknown, - nrrdSpaceRightAnteriorSuperior, /* 1: NIFTI-1 (right-handed) */ - nrrdSpaceLeftAnteriorSuperior, /* 2: standard Analyze (left-handed) */ - nrrdSpaceLeftPosteriorSuperior, /* 3: DICOM 3.0 (right-handed) */ - nrrdSpaceRightAnteriorSuperiorTime, /* 4: */ - nrrdSpaceLeftAnteriorSuperiorTime, /* 5: */ - nrrdSpaceLeftPosteriorSuperiorTime, /* 6: */ - nrrdSpaceScannerXYZ, /* 7: ACR/NEMA 2.0 (pre-DICOM 3.0) */ - nrrdSpaceScannerXYZTime, /* 8: */ - nrrdSpace3DRightHanded, /* 9: */ - nrrdSpace3DLeftHanded, /* 10: */ - nrrdSpace3DRightHandedTime, /* 11: */ - nrrdSpace3DLeftHandedTime, /* 12: */ + nrrdSpaceRightUp, /* 1: 2-D, oriented like upper right + Cartesian quadrant, number I */ + nrrdSpaceRightDown, /* 2: 2-D, oriented like raster + coordinates */ + nrrdSpaceRightAnteriorSuperior, /* 3: NIFTI-1 (right-handed) */ + nrrdSpaceLeftAnteriorSuperior, /* 4: standard Analyze (left-handed) */ + nrrdSpaceLeftPosteriorSuperior, /* 5: DICOM 3.0 (right-handed) */ + nrrdSpaceRightAnteriorSuperiorTime, /* 6: */ + nrrdSpaceLeftAnteriorSuperiorTime, /* 7: */ + nrrdSpaceLeftPosteriorSuperiorTime, /* 8: */ + nrrdSpaceScannerXYZ, /* 9: ACR/NEMA 2.0 (pre-DICOM 3.0) */ + nrrdSpaceScannerXYZTime, /* 10: */ + nrrdSpace3DRightHanded, /* 11: */ + nrrdSpace3DLeftHanded, /* 12: */ + nrrdSpace3DRightHandedTime, /* 13: */ + nrrdSpace3DLeftHandedTime, /* 14: */ nrrdSpaceLast }; -#define NRRD_SPACE_MAX 12 +#define NRRD_SPACE_MAX 14 /* ******** nrrdSpacingStatus* enum @@ -1331,22 +1136,22 @@ enum { ** given axis, as determined by nrrdSpacingCalculate */ enum { - nrrdSpacingStatusUnknown, /* 0: nobody knows, - or invalid axis choice */ - nrrdSpacingStatusNone, /* 1: neither axis->spacing nor - axis->spaceDirection is set */ - nrrdSpacingStatusScalarNoSpace, /* 2: axis->spacing set, - w/out space info */ - nrrdSpacingStatusScalarWithSpace, /* 3: axis->spacing set, but there *is* - space info, which means the spacing - does *not* live in the surrounding - space */ - nrrdSpacingStatusDirection, /* 4: axis->spaceDirection set, and - measured according to surrounding - space */ + nrrdSpacingStatusUnknown, /* 0: nobody knows, + or invalid axis choice */ + nrrdSpacingStatusNone, /* 1: neither axis->spacing nor + axis->spaceDirection is set */ + nrrdSpacingStatusScalarNoSpace, /* 2: axis->spacing set, + w/out space info */ + nrrdSpacingStatusScalarWithSpace, /* 3: axis->spacing set, but there *is* + space info, which means the spacing + does *not* live in the surrounding + space */ + nrrdSpacingStatusDirection, /* 4: axis->spaceDirection set, and + measured according to surrounding + space */ nrrdSpacingStatusLast }; -#define NRRD_SPACING_STATUS_MAX 4 +#define NRRD_SPACING_STATUS_MAX 4 /* ******** nrrdOriginStatus* enum @@ -1362,13 +1167,10 @@ enum { nrrdOriginStatusLast }; - #ifdef __cplusplus } #endif - - #ifdef __cplusplus extern "C" { #endif @@ -1385,46 +1187,16 @@ extern "C" { ** is either nrrdCenterCell or nrrdCenterNode, but not nrrdCenterUnknown. */ /* index to position, cell centering */ -#define NRRD_CELL_POS(min, max, size, idx) \ +#define NRRD_CELL_POS(min, max, size, idx) \ AIR_AFFINE(0, (idx) + 0.5, (size), (min), (max)) /* index to position, node centering */ -#define NRRD_NODE_POS(min, max, size, idx) \ - AIR_AFFINE(0, (idx), (size)-1, (min), (max)) +#define NRRD_NODE_POS(min, max, size, idx) AIR_AFFINE(0, (idx), (size) - 1, (min), (max)) /* index to position, either centering */ -#define NRRD_POS(center, min, max, size, idx) \ - (nrrdCenterCell == (center) \ - ? NRRD_CELL_POS((min), (max), (size), (idx)) \ - : NRRD_NODE_POS((min), (max), (size), (idx))) - -/* position to index, cell centering */ -#define NRRD_CELL_IDX(min, max, size, pos) \ - (AIR_AFFINE((min), (pos), (max), 0, (size)) - 0.5) - -/* position to index, node centering */ -#define NRRD_NODE_IDX(min, max, size, pos) \ - AIR_AFFINE((min), (pos), (max), 0, (size)-1) - -/* position to index, either centering */ -#define NRRD_IDX(center, min, max, size, pos) \ - (nrrdCenterCell == (center) \ - ? NRRD_CELL_IDX((min), (max), (size), (pos)) \ - : NRRD_NODE_IDX((min), (max), (size), (pos))) - -/* -******** NRRD_SPACING -** -** the guts of nrrdAxisSpacing(), determines the inter-sample -** spacing, given centering, min and max "position", and number of samples -** -** Unlike nrrdAxisSpacing, this assumes that center is either -** nrrdCenterCell or nrrdCenterNode, but not nrrdCenterUnknown. -*/ -#define NRRD_SPACING(center, min, max, size) \ - (nrrdCenterCell == center \ - ? ((max) - (min))/AIR_CAST(double, size) \ - : ((max) - (min))/(AIR_CAST(double, (size)- 1))) \ +#define NRRD_POS(center, min, max, size, idx) \ + (nrrdCenterCell == (center) ? NRRD_CELL_POS((min), (max), (size), (idx)) \ + : NRRD_NODE_POS((min), (max), (size), (idx))) /* ******** NRRD_COORD_UPDATE @@ -1447,18 +1219,16 @@ extern "C" { ** The "ddd" variable name in this and subsequent macros is an effort to ** avoid possible symbol name shadowing. */ -#define NRRD_COORD_UPDATE(coord, size, dim) \ - { \ - unsigned int ddd; \ - for (ddd=0; \ - ddd+1 < (dim) && (coord)[ddd] >= (size)[ddd]; \ - ddd++) { \ - (coord)[ddd] = 0; \ - (coord)[ddd+1]++; \ - } \ - if (dim) { \ - (coord)[(dim)-1] = AIR_MIN((coord)[(dim)-1], (size)[(dim)-1]-1); \ - } \ +#define NRRD_COORD_UPDATE(coord, size, dim) \ + { \ + unsigned int ddd; \ + for (ddd = 0; ddd + 1 < (dim) && (coord)[ddd] >= (size)[ddd]; ddd++) { \ + (coord)[ddd] = 0; \ + (coord)[ddd + 1]++; \ + } \ + if (dim) { \ + (coord)[(dim) - 1] = AIR_MIN((coord)[(dim) - 1], (size)[(dim) - 1] - 1); \ + } \ } /* @@ -1469,10 +1239,10 @@ extern "C" { ** nothing if idx>=dim, since that would be an invalid index into ** coord[] and size[] */ -#define NRRD_COORD_INCR(coord, size, dim, idx) \ - if ((idx) < (dim)) { \ - (coord)[(idx)]++; \ - NRRD_COORD_UPDATE((coord)+(idx), (size)+(idx), (dim)-(idx)); \ +#define NRRD_COORD_INCR(coord, size, dim, idx) \ + if ((idx) < (dim)) { \ + (coord)[(idx)]++; \ + NRRD_COORD_UPDATE((coord) + (idx), (size) + (idx), (dim) - (idx)); \ } /* @@ -1483,14 +1253,14 @@ extern "C" { ** coordinates are for *faster* axes), and stores it in "I". Has the same ** assumptions as NRRD_COORD_UPDATE. */ -#define NRRD_INDEX_GEN(I, coord, size, dim) \ - { \ - unsigned int ddd = (dim); \ - (I) = 0; \ - while (ddd) { \ - ddd--; \ - (I) = (coord)[ddd] + (size)[ddd]*(I); \ - } \ +#define NRRD_INDEX_GEN(I, coord, size, dim) \ + { \ + unsigned int ddd = (dim); \ + (I) = 0; \ + while (ddd) { \ + ddd--; \ + (I) = (coord)[ddd] + (size)[ddd] * (I); \ + } \ } /* @@ -1499,26 +1269,22 @@ extern "C" { ** opposite of NRRD_INDEX_GEN: going from linear index "I" to ** coordinate array "coord". */ -#define NRRD_COORD_GEN(coord, size, dim, I) \ - { \ - unsigned int ddd; \ - size_t myI = (I); \ - for (ddd=0; ddd<(dim); ddd++) { \ - (coord)[ddd] = myI % (size)[ddd]; \ - myI /= (size)[ddd]; \ - } \ +#define NRRD_COORD_GEN(coord, size, dim, I) \ + { \ + unsigned int ddd; \ + size_t myI = (I); \ + for (ddd = 0; ddd < (dim); ddd++) { \ + (coord)[ddd] = myI % (size)[ddd]; \ + myI /= (size)[ddd]; \ + } \ } #ifdef __cplusplus } #endif - - #include -#include /* for ptrdiff_t */ - - +#include /* for ptrdiff_t */ #ifdef __cplusplus extern "C" { @@ -1551,33 +1317,38 @@ extern "C" { ** (see nrrdField* enum in nrrdEnums.h), and the various methods in axis.c */ typedef struct { - size_t size; /* number of elements along each axis */ - double spacing; /* if non-NaN, distance between samples */ - double thickness; /* if non-NaN, nominal thickness of region - represented by one sample along the axis. No - semantics relative to spacing are assumed or - imposed, and unlike spacing, there is no - sensible way to alter thickness- it is either - copied (as with cropping and slicing) or set to - NaN (when resampled). */ - double min, max; /* if non-NaN, range of positions spanned by the - samples on this axis. Obviously, one can set - "spacing" to something incompatible with min - and max: the idea is that only one (min and - max, or spacing) should be taken to be - significant at any time. */ + size_t size; + /* number of elements along each axis */ + double spacing; + /* if non-NaN, distance between samples */ + double thickness; + /* if non-NaN, nominal thickness of region represented by one + sample along the axis. No semantics relative to spacing are + assumed or imposed, and unlike spacing, there is no + sensible way to alter thickness- it is either copied (as + with cropping and slicing) or set to NaN (when + resampled). */ + double min, max; + /* if non-NaN, range of positions spanned by the samples on + this axis. Obviously, one can set "spacing" to something + incompatible with min and max: the idea is that only one + (min and max, or spacing) should be taken to be significant + at any time. */ double spaceDirection[NRRD_SPACE_DIM_MAX]; - /* the vector, in "space" (as described by - nrrd->space and/or nrrd->spaceDim), from one - sample to the next sample along this axis. It - is the column vector of the transform from - index space to "space" space */ - int center; /* cell vs. node centering (value should be one of - nrrdCenter{Unknown,Node,Cell} */ - int kind; /* what kind of information is along this axis - (from the nrrdKind* enum) */ - char *label, /* short info string for each axis */ - *units; /* string identifying the unit */ + /* the vector, in "space" (as described by nrrd->space and/or + nrrd->spaceDim), from one sample to the next sample along + this axis. It is the column vector of the transform from + index space to "space" space */ + int center; + /* cell vs. node centering (value should be one of + nrrdCenter{Unknown,Node,Cell} */ + int kind; + /* what kind of information is along this axis (from the + nrrdKind* enum) */ + char *label; + /* short info string for each axis */ + char *units; + /* string identifying the unit */ } NrrdAxisInfo; /* @@ -1592,69 +1363,77 @@ typedef struct { ** or at the time that the nrrd is wrapped around an existing array */ - void *data; /* the data in memory */ - int type; /* a value from the nrrdType enum */ - unsigned int dim; /* the dimension (rank) of the array */ + void *data; + /* the data in memory */ + int type; + /* a value from the nrrdType enum */ + unsigned int dim; + /* the dimension (rank) of the array */ /* ** All per-axis specific information */ - NrrdAxisInfo axis[NRRD_DIM_MAX]; /* axis[0] is the fastest axis in the scan- - line ordering, the one who's coordinates - change the fastest as the elements are - accessed in the order in which they - appear in memory */ + NrrdAxisInfo axis[NRRD_DIM_MAX]; + /* axis[0] is the fastest axis in the scan- + line ordering, the one who's coordinates + change the fastest as the elements are + accessed in the order in which they appear + in memory */ /* ** Optional information descriptive of whole array, some of which is ** meaningfuly for only some uses of a nrrd */ - char *content; /* brief account of what this data is */ - char *sampleUnits; /* units of measurement of the values - stored in the array itself (not the - array axes and not space coordinates). - The logical name might be "dataUnits", - but that's perhaps ambiguous. Note that - these units may apply to non-scalar - kinds (e.g. coefficients of a vector - have the same units) */ - int space; /* from nrrdSpace* enum, and often - implies the value of spaceDim */ - unsigned int spaceDim; /* if non-zero, the dimension of the space - in which the regular sampling grid - conceptually lies. This is a separate - variable because this dimension can be - different than the array dimension. - The non-zero-ness of this value is in - fact the primary indicator that space - and orientation information is set. - This identifies the number of entries in - "origin" and the per-axis "direction" - vectors that are taken as meaningful */ + char *content; + /* brief account of what this data is */ + char *sampleUnits; + /* units of measurement of the values stored in + the array itself (not the array axes and not + space coordinates). The logical name might + be "dataUnits", but that's perhaps + ambiguous. Note that these units may apply + to non-scalar kinds (e.g. coefficients of a + vector have the same units) */ + int space; + /* from nrrdSpace* enum, and often implies the + value of spaceDim */ + unsigned int spaceDim; + /* if non-zero, the dimension of the space in + which the regular sampling grid conceptually + lies. This is a separate variable because + this dimension can be different than the + array dimension. The non-zero-ness of this + value is in fact the primary indicator that + space and orientation information is set. + This identifies the number of entries in + "origin" and the per-axis "direction" + vectors that are taken as meaningful */ char *spaceUnits[NRRD_SPACE_DIM_MAX]; - /* units for coordinates of space */ + /* units for coordinates of space */ double spaceOrigin[NRRD_SPACE_DIM_MAX]; - /* the location of the center the first - (lowest memory address) array sample, - regardless of node-vs-cell centering */ + /* the location of the center the first (lowest + memory address) array sample, regardless of + node-vs-cell centering */ double measurementFrame[NRRD_SPACE_DIM_MAX][NRRD_SPACE_DIM_MAX]; - /* if spaceDim is non-zero, this may store - a spaceDim-by-spaceDim matrix which - transforms vector/matrix coefficients - in the "measurement frame" to those in - the world space described by spaceDim - (and hopefully space). Coeff [i][j] is - *column* i & *row* j, which is probably - the *transpose* of what you expect. - There are no semantics linking this to - the "kind" of any axis, for a variety - of reasons */ - size_t blockSize; /* for nrrdTypeBlock, block byte size */ - double oldMin, oldMax; /* if non-NaN, and if nrrd is of integral - type, extremal values for the array - BEFORE it was quantized */ - void *ptr; /* never read or set by nrrd; use/abuse - as you see fit */ + /* if spaceDim is non-zero, this may store a + spaceDim-by-spaceDim matrix which transforms + vector/matrix coefficients in the + "measurement frame" to those in the world + space described by spaceDim (and hopefully + space). Coeff [i][j] is *column* i & *row* + j, which is probably the *transpose* of what + you expect. There are no semantics linking + this to the "kind" of any axis, for a + variety of reasons */ + size_t blockSize; + /* for nrrdTypeBlock, block byte size */ + double oldMin, oldMax; + /* if non-NaN, and if nrrd is of integral type, + extremal values for the array BEFORE it was + quantized */ + void *ptr; + /* never read or set by nrrd; use/abuse as you + see fit */ /* ** Comments. Read from, and written to, header. @@ -1680,12 +1459,11 @@ struct NrrdEncoding_t; ** All information and behavior relevent to one datafile format */ typedef struct { - char name[AIR_STRLEN_SMALL]; /* short identifying string */ - int isImage, /* this format is intended solely for "2D" images, which - controls the invocation of _nrrdReshapeUpGrayscale() - if nrrdStateGrayscaleImage3D */ - readable, /* we can read as well as write this format */ - usesDIO; /* this format can use Direct IO */ + char name[AIR_STRLEN_SMALL + 1]; /* short identifying string */ + int isImage, /* this format is intended solely for "2D" images, which + controls the invocation of nrrdAxesInsert() + if nrrdStateGrayscaleImage3D */ + readable; /* we can read as well as write this format */ /* tests if this format is currently available in this build */ int (*available)(void); @@ -1696,14 +1474,13 @@ typedef struct { /* (for writing) returns non-zero if a given nrrd/encoding pair will fit in this format */ - int (*fitsInto)(const Nrrd *nrrd, const struct NrrdEncoding_t *encoding, - int useBiff); + int (*fitsInto)(const Nrrd *nrrd, const struct NrrdEncoding_t *encoding, int useBiff); /* (for reading) returns non-zero if what has been read in so far is recognized as the beginning of this format */ int (*contentStartsLike)(struct NrrdIoState_t *nio); - /* reader and writer */ + /* reader and writer. Both are expected to use biff */ int (*read)(FILE *file, Nrrd *nrrd, struct NrrdIoState_t *nio); int (*write)(FILE *file, const Nrrd *nrrd, struct NrrdIoState_t *nio); } NrrdFormat; @@ -1717,10 +1494,9 @@ typedef struct { ** This is necessitated by the memory restrictions of direct I/O */ typedef struct NrrdEncoding_t { - char name[AIR_STRLEN_SMALL], /* short identifying string */ - suffix[AIR_STRLEN_SMALL]; /* costumary filename suffix */ - int endianMatters, - isCompression; + char name[AIR_STRLEN_SMALL + 1], /* short identifying string */ + suffix[AIR_STRLEN_SMALL + 1]; /* customary filename suffix */ + int endianMatters, isCompression; int (*available)(void); /* The "data" and "elementNum" values have to be passed explicitly to read/wrote because they will be different from nrrd->data and @@ -1733,11 +1509,12 @@ typedef struct NrrdEncoding_t { nrrd->axis[0].size: need for proper formatting of nrrdEncodingAscii nrrd->type: needed for nrrdEncodingAscii, since its action is entirely parameterized by type - nrrd->blockSize: needed for nrrdElementSize in case of nrrdTypeBlock */ - int (*read)(FILE *file, void *data, size_t elementNum, - Nrrd *nrrd, struct NrrdIoState_t *nio); - int (*write)(FILE *file, const void *data, size_t elementNum, - const Nrrd *nrrd, struct NrrdIoState_t *nio); + nrrd->blockSize: needed for nrrdElementSize in case of nrrdTypeBlock + Both read and write functions are expected to use biff. */ + int (*read)(FILE *file, void *data, size_t elementNum, Nrrd *nrrd, + struct NrrdIoState_t *nio); + int (*write)(FILE *file, const void *data, size_t elementNum, const Nrrd *nrrd, + struct NrrdIoState_t *nio); } NrrdEncoding; /* @@ -1751,41 +1528,42 @@ typedef struct NrrdEncoding_t { ** it took to read it in. */ typedef struct NrrdIoState_t { - char *path, /* allows us to remember the directory - from whence this nrrd was "load"ed, or - to whence this nrrd is "save"ed, MINUS the - trailing "/", so as to facilitate games with - header-relative data files */ - *base, /* when "save"ing a nrrd into separate - header and data, the name of the header - file (e.g. "output.nhdr") MINUS the ".nhdr". - This is massaged to produce a header- - relative data filename. */ - *line, /* buffer for saving one line from file */ - *dataFNFormat, /* if non-NULL, the format string (containing - something like "%d" as a substring) to be - used to identify multiple detached datafiles. - NB: This is "format" in the sense of a printf- - style format string, not in the sense of a - file format. This may need header-relative - path processing. */ - **dataFN, /* ON READ + WRITE: array of data filenames. These - are not passed directly to fopen, they may need - header-relative path processing. Like the - cmtArr in the Nrrd, this array is not NULL- - terminated */ - *headerStringWrite; /* ON WRITE: string from to which the header can - be written. On write, it is assumed allocated - for as long as it needs to be (probably via a - first pass with learningHeaderStrlen). NOTE: - It is the non-NULL-ity of this which signifies - the intent to do string-based writing */ - const char - *headerStringRead; /* ON READ: like headerStringWrite, but for - reading the header from. NOTE: It is the - non-NULL-ity of this which signifies the - intent to do string-based reading */ - airArray *dataFNArr; /* for managing the above */ + int verbose; /* new for TeemV2: replacing the old global + nrrdStateVerboseIO */ + char *path, /* allows us to remember the directory + from whence this nrrd was "load"ed, or + to whence this nrrd is "save"ed, MINUS the + trailing "/", so as to facilitate games with + header-relative data files */ + *base, /* when "save"ing a nrrd into separate + header and data, the name of the header + file (e.g. "output.nhdr") MINUS the ".nhdr". + This is massaged to produce a header- + relative data filename. */ + *line, /* buffer for saving one line from file */ + *dataFNFormat, /* if non-NULL, the format string (containing + something like "%d" as a substring) to be + used to identify multiple detached datafiles. + NB: This is "format" in the sense of a printf- + style format string, not in the sense of a + file format. This may need header-relative + path processing. */ + **dataFN, /* ON READ + WRITE: array of data filenames. These + are not passed directly to fopen, they may need + header-relative path processing. Like the + cmtArr in the Nrrd, this array is not NULL- + terminated */ + *headerStringWrite; /* ON WRITE: string from to which the header can + be written. On write, it is assumed allocated + for as long as it needs to be (probably via a + first pass with learningHeaderStrlen). NOTE: + It is the non-NULL-ity of this which signifies + the intent to do string-based writing */ + const char *headerStringRead; /* ON READ: like headerStringWrite, but for + reading the header from. NOTE: It is the + non-NULL-ity of this which signifies the + intent to do string-based reading */ + airArray *dataFNArr; /* for managing the above */ FILE *headerFile, /* if non-NULL, the file from which the NRRD header is being read */ @@ -1822,6 +1600,13 @@ typedef struct NrrdIoState_t { long int byteSkip; /* exactly like lineSkip, but bytes instead of lines. First the lines are skipped, then the bytes */ + long int *dataFSkip; /* skip per-data-file line from a NRRD0006 "data + file: SKIPLIST" specification; THIS OVERRIDES + the single byteSkip above. The non-NULL-ity of + this indicates there is a per-file byte skip. + Line skip still precedes per-file byte skip. */ + airArray *dataFSkipArr; /* for managing the above */ + /* Note that the NRRD0004 and NRRD0005 file formats indicate that a numbered sequence of data filenames should be indexed via a "%d" format specification, and that the format doc says nothing about the "min" and @@ -1831,61 +1616,65 @@ typedef struct NrrdIoState_t { from _nrrdDataFNNumber(), which gives the total number of file names, is still appropriately an unsigned int. This may be revisited if the file format itself is adjusted. */ - int dataFNMin, /* used with dataFNFormat to identify .. */ - dataFNMax, /* .. all the multiple detached datafiles */ - dataFNStep; /* how to step from max to min */ + int dataFNMin, /* used with dataFNFormat to identify .. */ + dataFNMax, /* .. all the multiple detached datafiles */ + dataFNStep; /* how to step from max to min */ /* On the other hand, dataFNIndex ranges from 0 to (#datafiles-1), and not dataFNMin to dataFNMax, so it really should be unsigned */ - unsigned int dataFNIndex; /* which of the data files are being read */ - int pos, /* line[pos] is beginning of stuff which - still has yet to be parsed */ - endian, /* endian-ness of the data in file, for - those encoding/type combinations for - which it matters (from nrrdEndian) */ - seen[NRRD_FIELD_MAX+1], /* for error checking in header parsing */ - detachedHeader, /* ON WRITE: request for file (NRRD format only) - to be split into distinct header and data. - This only has an effect if detaching the header - is not already necessary, as it is with multiple - data files */ - bareText, /* when writing a plain text file, is there any - effort made to record the nrrd struct - info in the text file */ - skipData, /* if non-zero (all formats): - ON READ: don't allocate memory for, and don't - read in, the data portion of the file (but we - do verify that for nrrds, detached datafiles - can be opened). Note: Does NOT imply - keepNrrdDataFileOpen. Warning: resulting - nrrd struct will have "data" pointer NULL. - ON WRITE: don't write data portion of file - (for nrrds, don't even try to open detached - datafiles). Warning: can result in broken - noncomformant files. - (be careful with this) */ - skipFormatURL, /* if non-zero for NRRD format ON WRITE: - skip the comment lines that document where - to find the NRRD file format specs */ - keepNrrdDataFileOpen, /* ON READ: when there is only a single dataFile, - don't close nio->dataFile when - you otherwise would, when reading the - nrrd format. Probably used in conjunction with - skipData. (currently for "unu data") - ON WRITE: no semantics */ - zlibLevel, /* zlib compression level (0-9, -1 for - default[6], 0 for no compression). */ - zlibStrategy, /* zlib compression strategy, can be one - of the nrrdZlibStrategy enums, default is - nrrdZlibStrategyDefault. */ - bzip2BlockSize, /* block size used for compression, - roughly equivalent to better but slower - (1-9, -1 for default[9]). */ - learningHeaderStrlen; /* ON WRITE, for nrrds, learn and save the total - length of header into headerStrlen. This is - used to allocate a buffer for header */ - void *oldData; /* ON READ: if non-NULL, pointer to space that - has already been allocated for oldDataSize */ - size_t oldDataSize; /* ON READ: size of mem pointed to by oldData */ + unsigned int dataFNIndex; /* which of the data files are being read */ + int pos, /* line[pos] is beginning of stuff which + still has yet to be parsed */ + endian, /* endian-ness of the data in file, for + those encoding/type combinations for + which it matters (from nrrdEndian) */ + seen[NRRD_FIELD_MAX + 1], /* for error checking in header parsing */ + detachedHeader, /* ON WRITE: request for file (NRRD format only) + to be split into distinct header and data. + This only has an effect if detaching the header + is not already necessary, as it is with multiple + data files */ + bareText, /* when writing a plain text file, is there any + effort made to record the nrrd struct + info in the text file */ + moreThanFloatInText, /* when writing a plain text file, instead of the + usual behavior of silently converting to float, + explicitly record the type, and also ensure + that the ascii encoding is lossless */ + skipData, /* if non-zero (all formats): + ON READ: don't allocate memory for, and don't + read in, the data portion of the file (but we + do verify that for nrrds, detached datafiles + can be opened). Note: Does NOT imply + keepNrrdDataFileOpen. Warning: resulting + nrrd struct will have "data" pointer NULL. + ON WRITE: don't write data portion of file + (for nrrds, don't even try to open detached + datafiles). Warning: can result in broken + noncomformant files. + (be careful with this) */ + skipFormatURL, /* if non-zero for NRRD format ON WRITE: + skip the comment lines that document where + to find the NRRD file format specs */ + keepNrrdDataFileOpen, /* ON READ: when there is only a single dataFile, + don't close nio->dataFile when + you otherwise would, when reading the + nrrd format. Probably used in conjunction with + skipData. (currently for "unu data") + ON WRITE: no semantics */ + zlibLevel, /* zlib compression level (0-9, -1 for + default[6], 0 for no compression). */ + zlibStrategy, /* zlib compression strategy, can be one + of the nrrdZlibStrategy enums, default is + nrrdZlibStrategyDefault. */ + bzip2BlockSize, /* block size used for compression, + roughly equivalent to better but slower + (1-9, -1 for default[9]). */ + learningHeaderStrlen; /* ON WRITE, for nrrds, learn and save the total + length of header into headerStrlen. This is + used to allocate a buffer for header */ + void *oldData; /* ON READ: if non-NULL, pointer to space that + has already been allocated for oldDataSize */ + size_t oldDataSize; /* ON READ: size of mem pointed to by oldData */ /* The format and encoding. These are initialized to nrrdFormatUnknown and nrrdEncodingUnknown, respectively. USE THESE VALUES for @@ -1894,16 +1683,17 @@ typedef struct NrrdIoState_t { const NrrdEncoding *encoding; } NrrdIoState; - /******** defaults (nrrdDefault..) and state (nrrdState..) */ /* defaultsNrrd.c */ NRRDIO_EXPORT int nrrdDefaultWriteEncodingType; NRRDIO_EXPORT int nrrdDefaultWriteBareText; +NRRDIO_EXPORT int nrrdDefaultWriteMoreThanFloatInText; NRRDIO_EXPORT unsigned int nrrdDefaultWriteCharsPerLine; NRRDIO_EXPORT unsigned int nrrdDefaultWriteValsPerLine; NRRDIO_EXPORT int nrrdDefaultCenter; -NRRDIO_EXPORT double nrrdDefaultSpacing; -NRRDIO_EXPORT int nrrdStateVerboseIO; +/* TeemV2: nrrdStateVerboseIO --> nrrdDefaultVerboseIO, + and added NrrdIoState->verbose which is initialized by this */ +NRRDIO_EXPORT int nrrdDefaultVerboseIO; NRRDIO_EXPORT int nrrdStateKeyValuePairsPropagate; NRRDIO_EXPORT int nrrdStateAlwaysSetContent; NRRDIO_EXPORT int nrrdStateDisableContent; @@ -1930,12 +1720,12 @@ NRRDIO_EXPORT const airEnum *const nrrdSpacingStatus; /******** arrays of things (poor-man's functions/predicates) */ /* arraysNrrd.c */ -NRRDIO_EXPORT const char nrrdTypePrintfStr[NRRD_TYPE_MAX+1][AIR_STRLEN_SMALL]; -NRRDIO_EXPORT const size_t nrrdTypeSize[NRRD_TYPE_MAX+1]; -NRRDIO_EXPORT const double nrrdTypeMin[NRRD_TYPE_MAX+1]; -NRRDIO_EXPORT const double nrrdTypeMax[NRRD_TYPE_MAX+1]; -NRRDIO_EXPORT const int nrrdTypeIsIntegral[NRRD_TYPE_MAX+1]; -NRRDIO_EXPORT const int nrrdTypeIsUnsigned[NRRD_TYPE_MAX+1]; +NRRDIO_EXPORT const char nrrdTypePrintfStr[NRRD_TYPE_MAX + 1][AIR_STRLEN_SMALL + 1]; +NRRDIO_EXPORT const size_t nrrdTypeSize[NRRD_TYPE_MAX + 1]; +NRRDIO_EXPORT const double nrrdTypeMin[NRRD_TYPE_MAX + 1]; +NRRDIO_EXPORT const double nrrdTypeMax[NRRD_TYPE_MAX + 1]; +NRRDIO_EXPORT const int nrrdTypeIsIntegral[NRRD_TYPE_MAX + 1]; +NRRDIO_EXPORT const int nrrdTypeIsUnsigned[NRRD_TYPE_MAX + 1]; /******** pseudo-constructors, pseudo-destructors, and such */ /* methodsNrrd.c */ @@ -1947,80 +1737,71 @@ NRRDIO_EXPORT Nrrd *nrrdNew(void); NRRDIO_EXPORT Nrrd *nrrdNix(Nrrd *nrrd); NRRDIO_EXPORT Nrrd *nrrdEmpty(Nrrd *nrrd); NRRDIO_EXPORT Nrrd *nrrdNuke(Nrrd *nrrd); -NRRDIO_EXPORT int nrrdWrap_nva(Nrrd *nrrd, void *data, int type, - unsigned int dim, const size_t *size); +NRRDIO_EXPORT int nrrdWrap_nva(Nrrd *nrrd, void *data, int type, unsigned int dim, + const size_t *size); NRRDIO_EXPORT int nrrdWrap_va(Nrrd *nrrd, void *data, int type, unsigned int dim, - ... /* size_t sx, sy, .., axis(dim-1) size */); + ... /* size_t sx, sy, .., axis(dim-1) size */); NRRDIO_EXPORT void nrrdBasicInfoInit(Nrrd *nrrd, int excludeBitflag); -NRRDIO_EXPORT int nrrdBasicInfoCopy(Nrrd *nout, const Nrrd *nin, - int excludeBitflag); +NRRDIO_EXPORT int nrrdBasicInfoCopy(Nrrd *nout, const Nrrd *nin, int excludeBitflag); NRRDIO_EXPORT int nrrdCopy(Nrrd *nout, const Nrrd *nin); NRRDIO_EXPORT int nrrdAlloc_nva(Nrrd *nrrd, int type, unsigned int dim, - const size_t *size); + const size_t *size); NRRDIO_EXPORT int nrrdAlloc_va(Nrrd *nrrd, int type, unsigned int dim, - ... /* size_t sx, sy, .., axis(dim-1) size */); + ... /* size_t sx, sy, .., axis(dim-1) size */); NRRDIO_EXPORT int nrrdMaybeAlloc_nva(Nrrd *nrrd, int type, unsigned int dim, - const size_t *size); + const size_t *size); NRRDIO_EXPORT int nrrdMaybeAlloc_va(Nrrd *nrrd, int type, unsigned int dim, - ... /* size_t sx, sy, .., ax(dim-1) size */); + ... /* size_t sx, sy, .., ax(dim-1) size */); /******** axis info related */ /* axis.c */ NRRDIO_EXPORT int nrrdKindIsDomain(int kind); NRRDIO_EXPORT unsigned int nrrdKindSize(int kind); -NRRDIO_EXPORT int nrrdAxisInfoCopy(Nrrd *nout, const Nrrd *nin, - const int *axmap, int excludeBitflag); +NRRDIO_EXPORT int nrrdAxisInfoCopy(Nrrd *nout, const Nrrd *nin, const int *axmap, + int excludeBitflag); NRRDIO_EXPORT void nrrdAxisInfoSet_nva(Nrrd *nin, int axInfo, const void *info); -NRRDIO_EXPORT void nrrdAxisInfoSet_va(Nrrd *nin, int axInfo, - ... /* const void* */); +NRRDIO_EXPORT void nrrdAxisInfoSet_va(Nrrd *nin, int axInfo, ... /* const void* */); NRRDIO_EXPORT void nrrdAxisInfoGet_nva(const Nrrd *nrrd, int axInfo, void *info); -NRRDIO_EXPORT void nrrdAxisInfoGet_va(const Nrrd *nrrd, int axInfo, - ... /* ??? */); -NRRDIO_EXPORT double nrrdAxisInfoPos(const Nrrd *nrrd, unsigned int ax, - double idx); -NRRDIO_EXPORT double nrrdAxisInfoIdx(const Nrrd *nrrd, unsigned int ax, - double pos); -NRRDIO_EXPORT void nrrdAxisInfoPosRange(double *loP, double *hiP, - const Nrrd *nrrd, unsigned int ax, - double loIdx, double hiIdx); -NRRDIO_EXPORT void nrrdAxisInfoIdxRange(double *loP, double *hiP, - const Nrrd *nrrd, unsigned int ax, - double loPos, double hiPos); +NRRDIO_EXPORT void nrrdAxisInfoGet_va(const Nrrd *nrrd, int axInfo, ... /* ??? */); +NRRDIO_EXPORT double nrrdAxisInfoPos(const Nrrd *nrrd, unsigned int ax, double idx); +NRRDIO_EXPORT double nrrdAxisInfoIdx(const Nrrd *nrrd, unsigned int ax, double pos); +NRRDIO_EXPORT void nrrdAxisInfoPosRange(double *loP, double *hiP, const Nrrd *nrrd, + unsigned int ax, double loIdx, double hiIdx); +NRRDIO_EXPORT void nrrdAxisInfoIdxRange(double *loP, double *hiP, const Nrrd *nrrd, + unsigned int ax, double loPos, double hiPos); NRRDIO_EXPORT void nrrdAxisInfoSpacingSet(Nrrd *nrrd, unsigned int ax); -NRRDIO_EXPORT void nrrdAxisInfoMinMaxSet(Nrrd *nrrd, unsigned int ax, - int defCenter); +NRRDIO_EXPORT void nrrdAxisInfoMinMaxSet(Nrrd *nrrd, unsigned int ax, int defCenter); NRRDIO_EXPORT unsigned int nrrdDomainAxesGet(const Nrrd *nrrd, - unsigned int axisIdx[NRRD_DIM_MAX]); + unsigned int axisIdx[NRRD_DIM_MAX]); NRRDIO_EXPORT unsigned int nrrdRangeAxesGet(const Nrrd *nrrd, - unsigned int axisIdx[NRRD_DIM_MAX]); + unsigned int axisIdx[NRRD_DIM_MAX]); NRRDIO_EXPORT unsigned int nrrdSpatialAxesGet(const Nrrd *nrrd, - unsigned int - axisIdx[NRRD_DIM_MAX]); + unsigned int axisIdx[NRRD_DIM_MAX]); NRRDIO_EXPORT unsigned int nrrdNonSpatialAxesGet(const Nrrd *nrrd, - unsigned int - axisIdx[NRRD_DIM_MAX]); + unsigned int axisIdx[NRRD_DIM_MAX]); NRRDIO_EXPORT int nrrdSpacingCalculate(const Nrrd *nrrd, unsigned int ax, - double *spacing, - double vector[NRRD_SPACE_DIM_MAX]); + double *spacing, + double vector[NRRD_SPACE_DIM_MAX]); NRRDIO_EXPORT int nrrdOrientationReduce(Nrrd *nout, const Nrrd *nin, - int setMinsFromOrigin); + int setMinsFromOrigin); /******** simple things */ /* simple.c */ -NRRDIO_EXPORT const char *nrrdBiffKey; +NRRDIO_EXPORT const char *const nrrdBiffKey; NRRDIO_EXPORT unsigned int nrrdSpaceDimension(int space); NRRDIO_EXPORT int nrrdSpaceSet(Nrrd *nrrd, int space); NRRDIO_EXPORT int nrrdSpaceDimensionSet(Nrrd *nrrd, unsigned int spaceDim); NRRDIO_EXPORT unsigned int nrrdSpaceOriginGet(const Nrrd *nrrd, - double vector[NRRD_SPACE_DIM_MAX]); + double vector[NRRD_SPACE_DIM_MAX]); NRRDIO_EXPORT int nrrdSpaceOriginSet(Nrrd *nrrd, const double *vector); -NRRDIO_EXPORT int nrrdOriginCalculate(const Nrrd *nrrd, - unsigned int *axisIdx, - unsigned int axisIdxNum, - int defaultCenter, double *origin); -NRRDIO_EXPORT int nrrdContentSet_va(Nrrd *nout, const char *func, - const Nrrd *nin, const char *format, - ... /* printf-style arg list */ ); +NRRDIO_EXPORT int nrrdOriginCalculate(const Nrrd *nrrd, unsigned int *axisIdx, + unsigned int axisIdxNum, int defaultCenter, + double *origin); +NRRDIO_EXPORT int nrrdContentSet_va(Nrrd *nout, const char *func, const Nrrd *nin, + const char *format, ... /* printf-style arg list */); +NRRDIO_EXPORT void nrrdDescribeMore(FILE *file, const Nrrd *nrrd, const char *pfx, + int showPtrs, int elideNonExist, int elideUnknown, + const char *sepStr, unsigned int sepWidth); NRRDIO_EXPORT void nrrdDescribe(FILE *file, const Nrrd *nrrd); NRRDIO_EXPORT int nrrdCheck(const Nrrd *nrrd); NRRDIO_EXPORT int _nrrdCheck(const Nrrd *nrrd, int checkData, int useBiff); @@ -2029,19 +1810,19 @@ NRRDIO_EXPORT size_t nrrdElementNumber(const Nrrd *nrrd); NRRDIO_EXPORT int nrrdSanity(void); NRRDIO_EXPORT int nrrdSameSize(const Nrrd *n1, const Nrrd *n2, int useBiff); NRRDIO_EXPORT void nrrdSpaceVecCopy(double dst[NRRD_SPACE_DIM_MAX], - const double src[NRRD_SPACE_DIM_MAX]); + const double src[NRRD_SPACE_DIM_MAX]); NRRDIO_EXPORT void nrrdSpaceVecScaleAdd2(double sum[NRRD_SPACE_DIM_MAX], - double sclA, - const double vecA[NRRD_SPACE_DIM_MAX], - double sclB, - const double vecB[NRRD_SPACE_DIM_MAX]); + double sclA, + const double vecA[NRRD_SPACE_DIM_MAX], + double sclB, + const double vecB[NRRD_SPACE_DIM_MAX]); NRRDIO_EXPORT void nrrdSpaceVecScale(double out[NRRD_SPACE_DIM_MAX], - double scl, - const double vec[NRRD_SPACE_DIM_MAX]); + double scl, + const double vec[NRRD_SPACE_DIM_MAX]); NRRDIO_EXPORT double nrrdSpaceVecNorm(unsigned int sdim, - const double vec[NRRD_SPACE_DIM_MAX]); + const double vec[NRRD_SPACE_DIM_MAX]); NRRDIO_EXPORT int nrrdSpaceVecExists(unsigned int sdim, - double vec[NRRD_SPACE_DIM_MAX]); + const double vec[NRRD_SPACE_DIM_MAX]); NRRDIO_EXPORT void nrrdSpaceVecSetNaN(double vec[NRRD_SPACE_DIM_MAX]); /******** comments related */ @@ -2053,12 +1834,10 @@ NRRDIO_EXPORT int nrrdCommentCopy(Nrrd *nout, const Nrrd *nin); /******** key/value pairs */ /* keyvalue.c */ NRRDIO_EXPORT unsigned int nrrdKeyValueSize(const Nrrd *nrrd); -NRRDIO_EXPORT int nrrdKeyValueAdd(Nrrd *nrrd, - const char *key, const char *value); +NRRDIO_EXPORT int nrrdKeyValueAdd(Nrrd *nrrd, const char *key, const char *value); NRRDIO_EXPORT char *nrrdKeyValueGet(const Nrrd *nrrd, const char *key); -NRRDIO_EXPORT void nrrdKeyValueIndex(const Nrrd *nrrd, - char **keyP, char **valueP, - unsigned int ki); +NRRDIO_EXPORT void nrrdKeyValueIndex(const Nrrd *nrrd, char **keyP, char **valueP, + unsigned int ki); NRRDIO_EXPORT int nrrdKeyValueErase(Nrrd *nrrd, const char *key); NRRDIO_EXPORT void nrrdKeyValueClear(Nrrd *nrrd); NRRDIO_EXPORT int nrrdKeyValueCopy(Nrrd *nout, const Nrrd *nin); @@ -2077,8 +1856,7 @@ NRRDIO_EXPORT const NrrdFormat *const nrrdFormatText; NRRDIO_EXPORT const NrrdFormat *const nrrdFormatEPS; /* format.c */ NRRDIO_EXPORT const NrrdFormat *const nrrdFormatUnknown; -NRRDIO_EXPORT const NrrdFormat * - const nrrdFormatArray[NRRD_FORMAT_TYPE_MAX+1]; +NRRDIO_EXPORT const NrrdFormat *const nrrdFormatArray[NRRD_FORMAT_TYPE_MAX + 1]; /* encodingXXX.c */ NRRDIO_EXPORT const NrrdEncoding *const nrrdEncodingRaw; @@ -2086,97 +1864,89 @@ NRRDIO_EXPORT const NrrdEncoding *const nrrdEncodingAscii; NRRDIO_EXPORT const NrrdEncoding *const nrrdEncodingHex; NRRDIO_EXPORT const NrrdEncoding *const nrrdEncodingGzip; NRRDIO_EXPORT const NrrdEncoding *const nrrdEncodingBzip2; +NRRDIO_EXPORT const NrrdEncoding *const nrrdEncodingZRL; /* encoding.c */ NRRDIO_EXPORT const NrrdEncoding *const nrrdEncodingUnknown; -NRRDIO_EXPORT const NrrdEncoding * - const nrrdEncodingArray[NRRD_ENCODING_TYPE_MAX+1]; +NRRDIO_EXPORT const NrrdEncoding *const nrrdEncodingArray[NRRD_ENCODING_TYPE_MAX + 1]; /* parseNrrd.c */ /* this needs the "FILE *file" first arg for the sole reason that parsing a "data file: " field which identifies a LIST must then read in all the data filenames from the same file */ -NRRDIO_EXPORT int (*nrrdFieldInfoParse[NRRD_FIELD_MAX+1])(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, - int useBiff); +NRRDIO_EXPORT int (*const nrrdFieldInfoParse[NRRD_FIELD_MAX + 1])(FILE *file, Nrrd *nrrd, + NrrdIoState *nio, + int useBiff); NRRDIO_EXPORT unsigned int _nrrdDataFNNumber(NrrdIoState *nio); -NRRDIO_EXPORT int _nrrdContainsPercentThisAndMore(const char *str, char thss); +NRRDIO_EXPORT int nrrdContainsPercentThisAndMore(const char *str, char thss); NRRDIO_EXPORT int _nrrdDataFNCheck(NrrdIoState *nio, Nrrd *nrrd, int useBiff); +NRRDIO_EXPORT size_t (*const nrrdStringValsParse[NRRD_TYPE_MAX + 1])(void *out, + const char *s, + const char *sep, + size_t n); /* read.c */ -NRRDIO_EXPORT int _nrrdOneLine(unsigned int *lenP, NrrdIoState *nio, FILE *file); +NRRDIO_EXPORT int nrrdOneLine(unsigned int *lenP, NrrdIoState *nio, FILE *file); NRRDIO_EXPORT int nrrdLineSkip(FILE *dataFile, NrrdIoState *nio); NRRDIO_EXPORT int nrrdByteSkip(FILE *dataFile, Nrrd *nrrd, NrrdIoState *nio); NRRDIO_EXPORT int nrrdLoad(Nrrd *nrrd, const char *filename, NrrdIoState *nio); NRRDIO_EXPORT int nrrdLoadMulti(Nrrd *const *nin, unsigned int ninLen, - const char *fnameFormat, - unsigned int numStart, NrrdIoState *nio); + const char *fnameFormat, unsigned int numStart, + NrrdIoState *nio); NRRDIO_EXPORT int nrrdRead(Nrrd *nrrd, FILE *file, NrrdIoState *nio); -NRRDIO_EXPORT int nrrdStringRead(Nrrd *nrrd, const char *string, - NrrdIoState *nio); +NRRDIO_EXPORT int nrrdStringRead(Nrrd *nrrd, const char *string, NrrdIoState *nio); /* write.c */ NRRDIO_EXPORT int nrrdIoStateSet(NrrdIoState *nio, int parm, int value); -NRRDIO_EXPORT int nrrdIoStateEncodingSet(NrrdIoState *nio, - const NrrdEncoding *encoding); -NRRDIO_EXPORT int nrrdIoStateFormatSet(NrrdIoState *nio, - const NrrdFormat *format); +NRRDIO_EXPORT int nrrdIoStateEncodingSet(NrrdIoState *nio, const NrrdEncoding *encoding); +NRRDIO_EXPORT int nrrdIoStateFormatSet(NrrdIoState *nio, const NrrdFormat *format); NRRDIO_EXPORT int nrrdIoStateGet(NrrdIoState *nio, int parm); NRRDIO_EXPORT const NrrdEncoding *nrrdIoStateEncodingGet(NrrdIoState *nio); NRRDIO_EXPORT const NrrdFormat *nrrdIoStateFormatGet(NrrdIoState *nio); -NRRDIO_EXPORT int nrrdSave(const char *filename, const Nrrd *nrrd, - NrrdIoState *nio); -NRRDIO_EXPORT int nrrdSaveMulti(const char *fnameFormat, - const Nrrd *const *nin, unsigned int ninLen, - unsigned int numStart, NrrdIoState *nio); -NRRDIO_EXPORT int nrrdWrite(FILE *file, const Nrrd *nrrd, - NrrdIoState *nio); -NRRDIO_EXPORT int nrrdStringWrite(char **stringP, const Nrrd *nrrd, +NRRDIO_EXPORT int nrrdSave(const char *filename, const Nrrd *nrrd, NrrdIoState *nio); +NRRDIO_EXPORT int nrrdSaveMulti(const char *fnameFormat, const Nrrd *const *nin, + unsigned int ninLen, unsigned int numStart, NrrdIoState *nio); +NRRDIO_EXPORT int nrrdWrite(FILE *file, const Nrrd *nrrd, NrrdIoState *nio); +NRRDIO_EXPORT int nrrdStringWrite(char **stringP, const Nrrd *nrrd, NrrdIoState *nio); /******** getting value into and out of an array of general type, and all other simplistic functionality pseudo-parameterized by type */ /* accessors.c */ -NRRDIO_EXPORT double (*nrrdDLoad[NRRD_TYPE_MAX+1])(const void *v); -NRRDIO_EXPORT float (*nrrdFLoad[NRRD_TYPE_MAX+1])(const void *v); -NRRDIO_EXPORT int (*nrrdILoad[NRRD_TYPE_MAX+1])(const void *v); -NRRDIO_EXPORT unsigned int (*nrrdUILoad[NRRD_TYPE_MAX+1])(const void *v); -NRRDIO_EXPORT double (*nrrdDStore[NRRD_TYPE_MAX+1])(void *v, double d); -NRRDIO_EXPORT float (*nrrdFStore[NRRD_TYPE_MAX+1])(void *v, float f); -NRRDIO_EXPORT int (*nrrdIStore[NRRD_TYPE_MAX+1])(void *v, int j); -NRRDIO_EXPORT unsigned int (*nrrdUIStore[NRRD_TYPE_MAX+1])(void *v, - unsigned int j); -NRRDIO_EXPORT double (*nrrdDLookup[NRRD_TYPE_MAX+1])(const void *v, size_t I); -NRRDIO_EXPORT float (*nrrdFLookup[NRRD_TYPE_MAX+1])(const void *v, size_t I); -NRRDIO_EXPORT int (*nrrdILookup[NRRD_TYPE_MAX+1])(const void *v, size_t I); -NRRDIO_EXPORT unsigned int (*nrrdUILookup[NRRD_TYPE_MAX+1])(const void *v, - size_t I); -NRRDIO_EXPORT double (*nrrdDInsert[NRRD_TYPE_MAX+1])(void *v, size_t I, - double d); -NRRDIO_EXPORT float (*nrrdFInsert[NRRD_TYPE_MAX+1])(void *v, size_t I, - float f); -NRRDIO_EXPORT int (*nrrdIInsert[NRRD_TYPE_MAX+1])(void *v, size_t I, - int j); -NRRDIO_EXPORT unsigned int (*nrrdUIInsert[NRRD_TYPE_MAX+1])(void *v, size_t I, - unsigned int j); -NRRDIO_EXPORT int (*nrrdSprint[NRRD_TYPE_MAX+1])(char *, const void *); - +NRRDIO_EXPORT double (*const nrrdDLoad[NRRD_TYPE_MAX + 1])(const void *v); +NRRDIO_EXPORT float (*const nrrdFLoad[NRRD_TYPE_MAX + 1])(const void *v); +NRRDIO_EXPORT int (*const nrrdILoad[NRRD_TYPE_MAX + 1])(const void *v); +NRRDIO_EXPORT unsigned int (*const nrrdUILoad[NRRD_TYPE_MAX + 1])(const void *v); +NRRDIO_EXPORT double (*const nrrdDStore[NRRD_TYPE_MAX + 1])(void *v, double d); +NRRDIO_EXPORT float (*const nrrdFStore[NRRD_TYPE_MAX + 1])(void *v, float f); +NRRDIO_EXPORT int (*const nrrdIStore[NRRD_TYPE_MAX + 1])(void *v, int j); +NRRDIO_EXPORT unsigned int (*const nrrdUIStore[NRRD_TYPE_MAX + 1])(void *v, + unsigned int j); +NRRDIO_EXPORT double (*const nrrdDLookup[NRRD_TYPE_MAX + 1])(const void *v, size_t I); +NRRDIO_EXPORT float (*const nrrdFLookup[NRRD_TYPE_MAX + 1])(const void *v, size_t I); +NRRDIO_EXPORT int (*const nrrdILookup[NRRD_TYPE_MAX + 1])(const void *v, size_t I); +NRRDIO_EXPORT unsigned int (*const nrrdUILookup[NRRD_TYPE_MAX + 1])(const void *v, + size_t I); +NRRDIO_EXPORT double (*const nrrdDInsert[NRRD_TYPE_MAX + 1])(void *v, size_t I, + double d); +NRRDIO_EXPORT float (*const nrrdFInsert[NRRD_TYPE_MAX + 1])(void *v, size_t I, float f); +NRRDIO_EXPORT int (*const nrrdIInsert[NRRD_TYPE_MAX + 1])(void *v, size_t I, int j); +NRRDIO_EXPORT unsigned int (*const nrrdUIInsert[NRRD_TYPE_MAX + 1])(void *v, size_t I, + unsigned int j); +NRRDIO_EXPORT int (*const nrrdSprint[NRRD_TYPE_MAX + 1])(char *, const void *); /******** permuting, shuffling, and all flavors of reshaping */ /* reorder.c */ NRRDIO_EXPORT int nrrdAxesInsert(Nrrd *nout, const Nrrd *nin, unsigned int ax); NRRDIO_EXPORT int nrrdInvertPerm(unsigned int *invp, const unsigned int *perm, - unsigned int n); -NRRDIO_EXPORT int nrrdAxesPermute(Nrrd *nout, const Nrrd *nin, - const unsigned int *axes); + unsigned int n); +NRRDIO_EXPORT int nrrdAxesPermute(Nrrd *nout, const Nrrd *nin, const unsigned int *axes); NRRDIO_EXPORT int nrrdShuffle(Nrrd *nout, const Nrrd *nin, unsigned int axis, - const size_t *perm); + const size_t *perm); /******** sampling, slicing, cropping */ /* subset.c */ -NRRDIO_EXPORT int nrrdSlice(Nrrd *nout, const Nrrd *nin, - unsigned int axis, size_t pos); -NRRDIO_EXPORT int nrrdCrop(Nrrd *nout, const Nrrd *nin, - size_t *min, size_t *max); +NRRDIO_EXPORT int nrrdSlice(Nrrd *nout, const Nrrd *nin, unsigned int axis, size_t pos); +NRRDIO_EXPORT int nrrdCrop(Nrrd *nout, const Nrrd *nin, size_t *min, size_t *max); #ifdef __cplusplus } diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/NrrdIO_Srcs.txt b/Modules/ThirdParty/NrrdIO/src/NrrdIO/NrrdIO_Srcs.txt index c226dc564d0..01268bb2e66 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/NrrdIO_Srcs.txt +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/NrrdIO_Srcs.txt @@ -1 +1 @@ -754.c mop.c array.c parseAir.c dio.c sane.c endianAir.c string.c enum.c miscAir.c biffbiff.c biffmsg.c accessors.c defaultsNrrd.c enumsNrrd.c arraysNrrd.c methodsNrrd.c reorder.c axis.c simple.c comment.c keyvalue.c endianNrrd.c parseNrrd.c gzio.c read.c write.c format.c formatNRRD.c encoding.c encodingRaw.c encodingAscii.c encodingHex.c encodingGzip.c subset.c encodingBzip2.c formatEPS.c formatPNG.c formatPNM.c formatText.c formatVTK.c +754.c mop.c array.c parseAir.c sane.c endianAir.c string.c enum.c miscAir.c biffbiff.c biffmsg.c accessors.c defaultsNrrd.c enumsNrrd.c arraysNrrd.c methodsNrrd.c reorder.c axis.c simple.c comment.c keyvalue.c endianNrrd.c parseNrrd.c gzio.c read.c write.c format.c formatNRRD.c encodingRaw.c encodingAscii.c encodingHex.c encodingGzip.c encodingZRL.c encodingBzip2.c encoding.c subset.c formatEPS.c formatPNG.c formatPNM.c formatText.c formatVTK.c diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/accessors.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/accessors.c index 966658d2923..74b96a7d5ad 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/accessors.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/accessors.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -23,6 +23,7 @@ 3. This notice may not be removed or altered from any source distribution. */ +/* clang-format off */ #include "NrrdIO.h" #include "privateNrrd.h" #include "float.h" @@ -78,19 +79,19 @@ MAP(LOAD_DEF, JN) MAP(LOAD_DEF, FL) MAP(LOAD_DEF, DB) -unsigned int (* +unsigned int (* const nrrdUILoad[NRRD_TYPE_MAX+1])(const void*) = { NULL, MAP(LOAD_LIST, UI) NULL }; -int (* +int (* const nrrdILoad[NRRD_TYPE_MAX+1])(const void*) = { NULL, MAP(LOAD_LIST, JN) NULL }; -float (* +float (* const nrrdFLoad[NRRD_TYPE_MAX+1])(const void*) = { NULL, MAP(LOAD_LIST, FL) NULL }; -double (* +double (* const nrrdDLoad[NRRD_TYPE_MAX+1])(const void*) = { NULL, MAP(LOAD_LIST, DB) NULL }; @@ -116,19 +117,19 @@ MAP(STORE_DEF, JN) MAP(STORE_DEF, FL) MAP(STORE_DEF, DB) -unsigned int (* +unsigned int (* const nrrdUIStore[NRRD_TYPE_MAX+1])(void *, unsigned int) = { NULL, MAP(STORE_LIST, UI) NULL }; -int (* +int (* const nrrdIStore[NRRD_TYPE_MAX+1])(void *, int) = { NULL, MAP(STORE_LIST, JN) NULL }; -float (* +float (* const nrrdFStore[NRRD_TYPE_MAX+1])(void *, float) = { NULL, MAP(STORE_LIST, FL) NULL }; -double (* +double (* const nrrdDStore[NRRD_TYPE_MAX+1])(void *, double) = { NULL, MAP(STORE_LIST, DB) NULL }; @@ -152,19 +153,19 @@ MAP(LOOKUP_DEF, JN) MAP(LOOKUP_DEF, FL) MAP(LOOKUP_DEF, DB) -unsigned int (* +unsigned int (* const nrrdUILookup[NRRD_TYPE_MAX+1])(const void *, size_t) = { NULL, MAP(LOOKUP_LIST, UI) NULL }; -int (* +int (* const nrrdILookup[NRRD_TYPE_MAX+1])(const void *, size_t) = { NULL, MAP(LOOKUP_LIST, JN) NULL }; -float (* +float (* const nrrdFLookup[NRRD_TYPE_MAX+1])(const void *, size_t) = { NULL, MAP(LOOKUP_LIST, FL) NULL }; -double (* +double (* const nrrdDLookup[NRRD_TYPE_MAX+1])(const void *, size_t) = { NULL, MAP(LOOKUP_LIST, DB) NULL }; @@ -190,19 +191,19 @@ MAP(INSERT_DEF, JN) MAP(INSERT_DEF, FL) MAP(INSERT_DEF, DB) -unsigned int (* +unsigned int (* const nrrdUIInsert[NRRD_TYPE_MAX+1])(void *, size_t, unsigned int) = { NULL, MAP(INSERT_LIST, UI) NULL }; -int (* +int (* const nrrdIInsert[NRRD_TYPE_MAX+1])(void *, size_t, int) = { NULL, MAP(INSERT_LIST, JN) NULL }; -float (* +float (* const nrrdFInsert[NRRD_TYPE_MAX+1])(void *, size_t, float) = { NULL, MAP(INSERT_LIST, FL) NULL }; -double (* +double (* const nrrdDInsert[NRRD_TYPE_MAX+1])(void *, size_t, double) = { NULL, MAP(INSERT_LIST, DB) NULL }; @@ -228,14 +229,12 @@ static int _nrrdSprintLL(char *s, const LL *v) { static int _nrrdSprintUL(char *s, const UL *v) { return sprintf(s, AIR_ULLONG_FMT, *v); } -/* HEY: sizeof(float) and sizeof(double) assumed here, since we're - basing "8" and "17" on 6 == FLT_DIG and 15 == DBL_DIG, which are - digits of precision for floats and doubles, respectively */ static int _nrrdSprintFL(char *s, const FL *v) { - return airSinglePrintf(NULL, s, "%.8g", (double)(*v)); } + /* having %.8g instead of %.9g was a roughly 20-year old bug */ + return airSinglePrintf(NULL, s, "%.9g", (double)(*v)); } static int _nrrdSprintDB(char *s, const DB *v) { return airSinglePrintf(NULL, s, "%.17g", *v); } -int (* +int (* const nrrdSprint[NRRD_TYPE_MAX+1])(char *, const void *) = { NULL, (int (*)(char *, const void *))_nrrdSprintCH, @@ -249,4 +248,3 @@ nrrdSprint[NRRD_TYPE_MAX+1])(char *, const void *) = { (int (*)(char *, const void *))_nrrdSprintFL, (int (*)(char *, const void *))_nrrdSprintDB, NULL}; - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/array.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/array.c index 13d6027dd36..243e329c1ca 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/array.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/array.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -68,7 +68,7 @@ airArray * airArrayNew(void **dataP, unsigned int *lenP, size_t unit, unsigned int incr) { airArray *a; - if (unit<=0 || incr<=0) { + if (!unit || !incr) { return NULL; } @@ -99,8 +99,7 @@ airArrayNew(void **dataP, unsigned int *lenP, size_t unit, unsigned int incr) { ** set callbacks to maintain array of structs */ void -airArrayStructCB(airArray *a, - void (*initCB)(void *), void (*doneCB)(void *)) { +airArrayStructCB(airArray *a, void (*initCB)(void *), void (*doneCB)(void *)) { if (a) { a->initCB = initCB; @@ -116,8 +115,7 @@ airArrayStructCB(airArray *a, ** set callbacks to maintain array of pointers */ void -airArrayPointerCB(airArray *a, - void *(*allocCB)(void), void *(*freeCB)(void *)) { +airArrayPointerCB(airArray *a, void *(*allocCB)(void), void *(*freeCB)(void *)) { if (a) { a->initCB = NULL; @@ -127,27 +125,23 @@ airArrayPointerCB(airArray *a, } } - /* ******** airArrayLenSet() ** ** Set the length of the array, allocating or freeing as needed ** -** returns 1 on error, otherwise 0 if okay -** possible errors: bogus arguments, or couldn't allocate new memory segment -** ** In case we can't allocate the new space, the old space is left untouched, ** however if the new length is smaller, the free/done callbacks will ** have been called on invalidated elements ** -** NB: this used to have a "boolean" return to indicate allocation -** error, but almost nothing in Teem actually did the error checking. -** Now conscientious users can look at NULL-ity of a->data to detect -** such an error. +** NB: this used to have a "boolean" return to indicate allocation error, but almost +** nothing in Teem actually did the error checking. Now conscientious users can look at +** NULL-ity of a->data to detect such an error (e.g. bogus arguments, or couldn't +** allocate new memory segment) */ void airArrayLenSet(airArray *a, unsigned int newlen) { - /* char me[]="airArrayLenSet"; */ + /* static const char me[] = "airArrayLenSet"; */ unsigned int ii, newsize; void *addr, *newdata; @@ -165,31 +159,29 @@ airArrayLenSet(airArray *a, unsigned int newlen) { /* Wed Sep 12 14:40:45 EDT 2007: the order in which these called is now ascending, instead of descending (as was the way before) */ if (newlen < a->len && (a->freeCB || a->doneCB)) { - for (ii=newlen; iilen; ii++) { - addr = (char*)(a->data) + ii*a->unit; + for (ii = newlen; ii < a->len; ii++) { + addr = (char *)(a->data) + ii * a->unit; if (a->freeCB) { - (a->freeCB)(*((void**)addr)); + (a->freeCB)(*((void **)addr)); } else { (a->doneCB)(addr); } } } - newsize = newlen ? (newlen-1)/a->incr + 1 : 0; + newsize = newlen ? (newlen - 1) / a->incr + 1 : 0; if (newsize != a->size) { /* we have to change the size of the array */ if (newsize) { /* array should be bigger or smaller, but not zero-length */ - if (newsize > a->size - || (newsize < a->size && !(a->noReallocWhenSmaller)) ) { - newdata = calloc(newsize*a->incr, a->unit); + if (newsize > a->size || (newsize < a->size && !(a->noReallocWhenSmaller))) { + newdata = calloc(newsize * a->incr, a->unit); if (!newdata) { free(a->data); _airSetData(a, NULL); return; } - memcpy(newdata, a->data, AIR_MIN(a->len*a->unit, - newsize*a->incr*a->unit)); + memcpy(newdata, a->data, AIR_MIN(a->len * a->unit, newsize * a->incr * a->unit)); free(a->data); _airSetData(a, newdata); a->size = newsize; @@ -206,10 +198,10 @@ airArrayLenSet(airArray *a, unsigned int newlen) { /* call allocCB/initCB on newly created elements */ if (newlen > a->len && (a->allocCB || a->initCB)) { - for (ii=a->len; iidata) + ii*a->unit; + for (ii = a->len; ii < newlen; ii++) { + addr = (char *)(a->data) + ii * a->unit; if (a->allocCB) { - *((void**)addr) = (a->allocCB)(); + *((void **)addr) = (a->allocCB)(); } else { (a->initCB)(addr); } @@ -237,24 +229,20 @@ airArrayLenSet(airArray *a, unsigned int newlen) { */ unsigned int airArrayLenIncr(airArray *a, int delta) { - /* char me[]="airArrayLenIncr"; */ + /* static const char me[] = "airArrayLenIncr"; */ unsigned int oldlen, ret, negdel; if (!a) { return 0; } - negdel = (delta < 0 - ? AIR_UINT(-delta) - : 0); + negdel = (delta < 0 ? AIR_UINT(-delta) : 0); if (delta < 0 && negdel > a->len) { /* error: asked for newlength to be negative */ airArrayLenSet(a, 0); return 0; } oldlen = a->len; - airArrayLenSet(a, (delta >= 0 - ? oldlen + AIR_UINT(delta) - : oldlen - negdel)); + airArrayLenSet(a, (delta >= 0 ? oldlen + AIR_UINT(delta) : oldlen - negdel)); if (!a->data) { /* allocation error */ ret = 0; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/arraysNrrd.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/arraysNrrd.c index 5084302989f..c3436b496c3 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/arraysNrrd.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/arraysNrrd.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -30,8 +30,7 @@ const int blah[] array in an object file if it hasn't been declared as "extern" */ -const char -nrrdTypePrintfStr[NRRD_TYPE_MAX+1][AIR_STRLEN_SMALL] = { +const char nrrdTypePrintfStr[NRRD_TYPE_MAX + 1][AIR_STRLEN_SMALL + 1] = { "%*d", /* nrrdTypeUnknown: what else? the effect will be "skip" for sscanf, and "minimum precision" for printf */ "%d", /* nrrdTypeChar: char */ @@ -50,52 +49,56 @@ nrrdTypePrintfStr[NRRD_TYPE_MAX+1][AIR_STRLEN_SMALL] = { /* ** the setting of NRRD_TYPE_BIGGEST has to be in accordance with this */ -const size_t -nrrdTypeSize[NRRD_TYPE_MAX+1] = { - 0, /* nrrdTypeUnknown: unknown */ - 1, /* nrrdTypeChar: char */ - 1, /* nrrdTypeUChar: unsigned char */ - 2, /* nrrdTypeShort: short */ - 2, /* nrrdTypeUShort: unsigned short */ - 4, /* nrrdTypeInt: int */ - 4, /* nrrdTypeUInt: unsigned int */ - 8, /* nrrdTypeLLong: long long */ - 8, /* nrrdTypeULLong: unsigned long long */ - 4, /* nrrdTypeFloat: float */ - 8, /* nrrdTypeDouble: double */ - 0 /* nrrdTypeBlock: effectively unknown; user has to set explicitly */ +const size_t nrrdTypeSize[NRRD_TYPE_MAX + 1] = { + 0, /* nrrdTypeUnknown: unknown */ + 1, /* nrrdTypeChar: char */ + 1, /* nrrdTypeUChar: unsigned char */ + 2, /* nrrdTypeShort: short */ + 2, /* nrrdTypeUShort: unsigned short */ + 4, /* nrrdTypeInt: int */ + 4, /* nrrdTypeUInt: unsigned int */ + 8, /* nrrdTypeLLong: long long */ + 8, /* nrrdTypeULLong: unsigned long long */ + 4, /* nrrdTypeFloat: float */ + 8, /* nrrdTypeDouble: double */ + 0 /* nrrdTypeBlock: effectively unknown; user has to set explicitly */ }; -const int -nrrdTypeIsIntegral[NRRD_TYPE_MAX+1] = { - 0, /* nrrdTypeUnknown: unknown */ - 1, /* nrrdTypeChar: char */ - 1, /* nrrdTypeUChar: unsigned char */ - 1, /* nrrdTypeShort: short */ - 1, /* nrrdTypeUShort: unsigned short */ - 1, /* nrrdTypeInt: int */ - 1, /* nrrdTypeUInt: unsigned int */ - 1, /* nrrdTypeLLong: long long */ - 1, /* nrrdTypeULLong: unsigned long long */ - 0, /* nrrdTypeFloat: float */ - 0, /* nrrdTypeDouble: double */ - 1 /* nrrdTypeBlock: for some reason we pretend that blocks are integers */ +const int nrrdTypeIsIntegral[NRRD_TYPE_MAX + 1] = { + 0, /* nrrdTypeUnknown: unknown */ + 1, /* nrrdTypeChar: char */ + 1, /* nrrdTypeUChar: unsigned char */ + 1, /* nrrdTypeShort: short */ + 1, /* nrrdTypeUShort: unsigned short */ + 1, /* nrrdTypeInt: int */ + 1, /* nrrdTypeUInt: unsigned int */ + 1, /* nrrdTypeLLong: long long */ + 1, /* nrrdTypeULLong: unsigned long long */ + 0, /* nrrdTypeFloat: float */ + 0, /* nrrdTypeDouble: double */ + 0 /* nrrdTypeBlock: "for some reason we pretend that blocks are integers" is what this + used to say since ~2002 when this array was created (under the name nrrdTypeFixed[], + as opposed to floating point), but that was never justified or necessary (afaik). + For 2023 TeemV2 hacking, GLK got annoyed that CC code in cc.c didn't immediately + complain that nrrdTypeBloack was a useless type for output CC IDs. */ }; -const int -nrrdTypeIsUnsigned[NRRD_TYPE_MAX+1] = { - 0, /* nrrdTypeUnknown: unknown */ - 0, /* nrrdTypeChar: char */ - 1, /* nrrdTypeUChar: unsigned char */ - 0, /* nrrdTypeShort: short */ - 1, /* nrrdTypeUShort: unsigned short */ - 0, /* nrrdTypeInt: int */ - 1, /* nrrdTypeUInt: unsigned int */ - 0, /* nrrdTypeLLong: long long */ - 1, /* nrrdTypeULLong: unsigned long long */ - 0, /* nrrdTypeFloat: float */ - 0, /* nrrdTypeDouble: double */ - 0 /* nrrdTypeBlock: for some reason we pretend that blocks are signed */ +const int nrrdTypeIsUnsigned[NRRD_TYPE_MAX + 1] = { + 0, /* nrrdTypeUnknown: unknown */ + 0, /* nrrdTypeChar: char */ + 1, /* nrrdTypeUChar: unsigned char */ + 0, /* nrrdTypeShort: short */ + 1, /* nrrdTypeUShort: unsigned short */ + 0, /* nrrdTypeInt: int */ + 1, /* nrrdTypeUInt: unsigned int */ + 0, /* nrrdTypeLLong: long long */ + 1, /* nrrdTypeULLong: unsigned long long */ + 0, /* nrrdTypeFloat: float */ + 0, /* nrrdTypeDouble: double */ + 0 /* nrrdTypeBlock: "for some reason we pretend that blocks are signed" See note about + nrrdTypeIsIntegral[nrrdTypeBlock] above. While the value of + nrrdTypeIsUnsigned[nrrdTypeBlock] has not changed; we don't pretend that nrrdTypeBlock + is any kind of number. */ }; /* @@ -145,8 +148,7 @@ nrrdTypeMax[NRRD_TYPE_MAX+1] = { ** This does NOT include the fields who's values are constrained ** by the image format (and in the case of PNM, magic) itself. */ -const int -_nrrdFieldValidInImage[NRRD_FIELD_MAX+1] = { +const int _nrrdFieldValidInImage[NRRD_FIELD_MAX + 1] = { 0, /* nrrdField_unknown */ 1, /* nrrdField_comment */ 1, /* nrrdField_content */ @@ -187,8 +189,7 @@ _nrrdFieldValidInImage[NRRD_FIELD_MAX+1] = { ** ** whether or not you need one value per axis, like labels and spacings */ -const int -_nrrdFieldOnePerAxis[NRRD_FIELD_MAX+1] = { +const int _nrrdFieldOnePerAxis[NRRD_FIELD_MAX + 1] = { 0, /* nrrdField_unknown */ 0, /* nrrdField_comment */ 0, /* nrrdField_content */ @@ -231,18 +232,21 @@ _nrrdFieldOnePerAxis[NRRD_FIELD_MAX+1] = { ** This does NOT include the fields who's values are constrained ** the plain text format itself. */ -const int -_nrrdFieldValidInText[NRRD_FIELD_MAX+1] = { +const int _nrrdFieldValidInText[NRRD_FIELD_MAX + 1] = { 0, /* nrrdField_unknown */ 1, /* nrrdField_comment */ 1, /* nrrdField_content */ 0, /* nrrdField_number */ - 0, /* nrrdField_type: decided AGAINST plain text holding general type - (but I forget why ...) */ + 1, /* nrrdField_type: after revision 6359 (2019 T-day @ Hyatt Lost Pines), + decided that long-standing but unnecessary restriction of plain text + files only holding float (and not, say, double) had to go; hence the + new nio->moreThanFloatInText. With that, this value changed from 0 + to 1. However, nio->moreThanFloatInText defaults to false (i.e. only + float in text), so this should not be disruptive. */ 0, /* nrrdField_block_size */ 1, /* nrrdField_dimension: but can only be 1 or 2 */ - 0, /* nrrdField_space */ - 0, /* nrrdField_space_dimension */ + 1, /* nrrdField_space */ + 1, /* nrrdField_space_dimension */ 0, /* nrrdField_sizes */ 1, /* nrrdField_spacings */ 1, /* nrrdField_thicknesses */ @@ -263,8 +267,12 @@ _nrrdFieldValidInText[NRRD_FIELD_MAX+1] = { 0, /* nrrdField_byte_skip */ 1, /* nrrdField_keyvalue */ 0, /* nrrdField_sample_units */ - 0, /* nrrdField_space_units */ - 0, /* nrrdField_space_origin */ + 1, /* nrrdField_space_units */ + 1, /* nrrdField_space_origin: with revision 2368, which was part of adding new "space" + orientation meta-data, nrrdField_space_directions WERE said to be valid in text + (above in this array), but not space, space dimension, space units, or space + origin; this was probably a bug. Now that nio->bareText can be false, these + should all be allowed in text files. */ 0, /* nrrdField_measurement_frame */ 0 /* nrrdField_data_file */ }; @@ -275,8 +283,7 @@ _nrrdFieldValidInText[NRRD_FIELD_MAX+1] = { ** regardless of whether its a nrrd, PNM, or plain text, these things ** need to be conveyed, either explicity or implicitly */ -const int -_nrrdFieldRequired[NRRD_FIELD_MAX+1] = { +const int _nrrdFieldRequired[NRRD_FIELD_MAX + 1] = { 0, /* "Ernesto \"Che\" Guevara" */ 0, /* "#" */ 0, /* nrrdField_content */ @@ -311,4 +318,3 @@ _nrrdFieldRequired[NRRD_FIELD_MAX+1] = { 0, /* nrrdField_measurement_frame */ 0 /* nrrdField_data file */ }; - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/axis.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/axis.c index 08432b80c7e..5a64179f251 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/axis.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/axis.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -36,7 +36,7 @@ _nrrdAxisInfoInit(NrrdAxisInfo *axis) { axis->size = 0; axis->spacing = axis->thickness = AIR_NAN; axis->min = axis->max = AIR_NAN; - for (dd=0; ddspaceDirection[dd] = AIR_NAN; } axis->center = nrrdCenterUnknown; @@ -65,12 +65,10 @@ _nrrdAxisInfoNewInit(NrrdAxisInfo *axis) { ** axes, or independent variable axes, or resample-able axes, all ** different ways of describing the same thing */ -int +int /* Biff: nope */ nrrdKindIsDomain(int kind) { - return (nrrdKindDomain == kind - || nrrdKindSpace == kind - || nrrdKindTime == kind); + return (nrrdKindDomain == kind || nrrdKindSpace == kind || nrrdKindTime == kind); } /* @@ -80,12 +78,12 @@ nrrdKindIsDomain(int kind) { ** 0 if either (1) there is no suggested size because the axis is the ** kind of an independent or domain variable or (2) the kind is invalid */ -unsigned int +unsigned int /* Biff: nope */ nrrdKindSize(int kind) { - static const char me[]="nrrdKindSize"; + static const char me[] = "nrrdKindSize"; unsigned int ret; - if (!( AIR_IN_OP(nrrdKindUnknown, kind, nrrdKindLast) )) { + if (!(AIR_IN_OP(nrrdKindUnknown, kind, nrrdKindLast))) { /* they gave us invalid or unknown kind */ return 0; } @@ -165,7 +163,7 @@ nrrdKindSize(int kind) { ** implements logic for how kind should be updated when samples ** along the axis are altered */ -int +int /* Biff: (private) nope */ _nrrdKindAltered(int kindIn, int resampling) { int kindOut; @@ -175,8 +173,7 @@ _nrrdKindAltered(int kindIn, int resampling) { It is more like pointedly and stubbornly simplistic. So maybe nrrdStateKindNoop could be renamed .. */ } else { - if (nrrdKindIsDomain(kindIn) - || (0 == nrrdKindSize(kindIn) && !resampling)) { + if (nrrdKindIsDomain(kindIn) || (0 == nrrdKindSize(kindIn) && !resampling)) { kindOut = kindIn; } else { kindOut = nrrdKindUnknown; @@ -211,7 +208,7 @@ _nrrdAxisInfoCopy(NrrdAxisInfo *dest, const NrrdAxisInfo *src, int bitflag) { dest->max = src->max; } if (!(NRRD_AXIS_INFO_SPACEDIRECTION_BIT & bitflag)) { - for (ii=0; iispaceDirection[ii] = src->spaceDirection[ii]; } } @@ -259,7 +256,7 @@ _nrrdAxisInfoCopy(NrrdAxisInfo *dest, const NrrdAxisInfo *src, int bitflag) { ** Sun Feb 27 21:12:57 EST 2005: decided to allow nout==nin, so now ** use a local array of NrrdAxisInfo as buffer. */ -int +int /* Biff: nope */ nrrdAxisInfoCopy(Nrrd *nout, const Nrrd *nin, const int *axmap, int bitflag) { NrrdAxisInfo axisBuffer[NRRD_DIM_MAX]; const NrrdAxisInfo *axis; @@ -269,18 +266,18 @@ nrrdAxisInfoCopy(Nrrd *nout, const Nrrd *nin, const int *axmap, int bitflag) { return 1; } if (axmap) { - for (axi=0; axidim; axi++) { + for (axi = 0; axi < nout->dim; axi++) { if (-1 == axmap[axi]) { continue; } - if (!AIR_IN_CL(0, axmap[axi], (int)nin->dim-1)) { + if (!AIR_IN_CL(0, axmap[axi], (int)nin->dim - 1)) { return 3; } } } if (nout == nin) { /* copy axis info to local buffer */ - for (axi=0; axidim; axi++) { + for (axi = 0; axi < nin->dim; axi++) { _nrrdAxisInfoNewInit(axisBuffer + axi); _nrrdAxisInfoCopy(axisBuffer + axi, nin->axis + axi, bitflag); } @@ -288,7 +285,7 @@ nrrdAxisInfoCopy(Nrrd *nout, const Nrrd *nin, const int *axmap, int bitflag) { } else { axis = nin->axis; } - for (axi=0; axidim; axi++) { + for (axi = 0; axi < nout->dim; axi++) { if (axmap && -1 == axmap[axi]) { /* for this axis, we don't touch a thing */ continue; @@ -298,7 +295,7 @@ nrrdAxisInfoCopy(Nrrd *nout, const Nrrd *nin, const int *axmap, int bitflag) { } if (nout == nin) { /* free dynamically allocated stuff */ - for (axi=0; axidim; axi++) { + for (axi = 0; axi < nin->dim; axi++) { _nrrdAxisInfoInit(axisBuffer + axi); } } @@ -332,15 +329,13 @@ nrrdAxisInfoSet_nva(Nrrd *nrrd, int axInfo, const void *_info) { int exists; unsigned int ai, si, minsi; - if (!( nrrd - && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) - && AIR_IN_OP(nrrdAxisInfoUnknown, axInfo, nrrdAxisInfoLast) - && _info )) { + if (!(nrrd && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) + && AIR_IN_OP(nrrdAxisInfoUnknown, axInfo, nrrdAxisInfoLast) && _info)) { return; } info.P = _info; - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { switch (axInfo) { case nrrdAxisInfoSize: nrrd->axis[ai].size = info.ST[ai]; @@ -361,14 +356,14 @@ nrrdAxisInfoSet_nva(Nrrd *nrrd, int axInfo, const void *_info) { /* we won't allow setting an invalid direction */ exists = AIR_EXISTS(info.V[ai][0]); minsi = nrrd->spaceDim; - for (si=0; sispaceDim; si++) { + for (si = 0; si < nrrd->spaceDim; si++) { nrrd->axis[ai].spaceDirection[si] = info.V[ai][si]; if (exists ^ AIR_EXISTS(info.V[ai][si])) { minsi = 0; break; } } - for (si=minsi; siaxis[ai].spaceDirection[si] = AIR_NAN; } break; @@ -389,8 +384,8 @@ nrrdAxisInfoSet_nva(Nrrd *nrrd, int axInfo, const void *_info) { } } if (nrrdAxisInfoSpaceDirection == axInfo) { - for (ai=nrrd->dim; aidim; ai < NRRD_DIM_MAX; ai++) { + for (si = 0; si < NRRD_SPACE_DIM_MAX; si++) { nrrd->axis[ai].spaceDirection[si] = AIR_NAN; } } @@ -423,15 +418,14 @@ nrrdAxisInfoSet_va(Nrrd *nrrd, int axInfo, ...) { va_list ap; double *dp, svec[NRRD_DIM_MAX][NRRD_SPACE_DIM_MAX]; - if (!( nrrd - && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) - && AIR_IN_OP(nrrdAxisInfoUnknown, axInfo, nrrdAxisInfoLast) )) { + if (!(nrrd && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) + && AIR_IN_OP(nrrdAxisInfoUnknown, axInfo, nrrdAxisInfoLast))) { return; } info.P = buffer; va_start(ap, axInfo); - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { switch (axInfo) { case nrrdAxisInfoSize: info.ST[ai] = va_arg(ap, size_t); @@ -440,16 +434,16 @@ nrrdAxisInfoSet_va(Nrrd *nrrd, int axInfo, ...) { */ break; case nrrdAxisInfoSpaceDirection: - dp = va_arg(ap, double*); /* punting on using info enum */ + dp = va_arg(ap, double *); /* punting on using info enum */ /* printf("!%s: got dp = %lu\n", "nrrdAxisInfoSet", (unsigned long)(dp)); */ - for (si=0; sispaceDim; si++) { + for (si = 0; si < nrrd->spaceDim; si++) { /* nrrd->axis[ai].spaceDirection[si] = dp[si]; */ svec[ai][si] = dp[si]; } - for (si=nrrd->spaceDim; sispaceDim; si < NRRD_SPACE_DIM_MAX; si++) { /* nrrd->axis[ai].spaceDirection[si] = AIR_NAN; */ svec[ai][si] = dp[si]; } @@ -526,14 +520,13 @@ nrrdAxisInfoGet_nva(const Nrrd *nrrd, int axInfo, void *_info) { _nrrdAxisInfoGetPtrs info; unsigned int ai, si; - if (!( nrrd - && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) - && AIR_IN_OP(nrrdAxisInfoUnknown, axInfo, nrrdAxisInfoLast) )) { + if (!(nrrd && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) + && AIR_IN_OP(nrrdAxisInfoUnknown, axInfo, nrrdAxisInfoLast))) { return; } info.P = _info; - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { switch (axInfo) { case nrrdAxisInfoSize: info.ST[ai] = nrrd->axis[ai].size; @@ -551,10 +544,10 @@ nrrdAxisInfoGet_nva(const Nrrd *nrrd, int axInfo, void *_info) { info.D[ai] = nrrd->axis[ai].max; break; case nrrdAxisInfoSpaceDirection: - for (si=0; sispaceDim; si++) { + for (si = 0; si < nrrd->spaceDim; si++) { info.V[ai][si] = nrrd->axis[ai].spaceDirection[si]; } - for (si=nrrd->spaceDim; sispaceDim; si < NRRD_SPACE_DIM_MAX; si++) { info.V[ai][si] = AIR_NAN; } break; @@ -575,8 +568,8 @@ nrrdAxisInfoGet_nva(const Nrrd *nrrd, int axInfo, void *_info) { } } if (nrrdAxisInfoSpaceDirection == axInfo) { - for (ai=nrrd->dim; aidim; ai < NRRD_DIM_MAX; ai++) { + for (si = 0; si < NRRD_SPACE_DIM_MAX; si++) { info.V[ai][si] = AIR_NAN; } } @@ -605,9 +598,8 @@ nrrdAxisInfoGet_va(const Nrrd *nrrd, int axInfo, ...) { va_list ap; double svec[NRRD_DIM_MAX][NRRD_SPACE_DIM_MAX]; - if (!( nrrd - && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) - && AIR_IN_OP(nrrdAxisInfoUnknown, axInfo, nrrdAxisInfoLast) )) { + if (!(nrrd && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) + && AIR_IN_OP(nrrdAxisInfoUnknown, axInfo, nrrdAxisInfoLast))) { return; } @@ -619,35 +611,35 @@ nrrdAxisInfoGet_va(const Nrrd *nrrd, int axInfo, ...) { } va_start(ap, axInfo); - for (ai=0; aidim; ai++) { - ptr = va_arg(ap, void*); + for (ai = 0; ai < nrrd->dim; ai++) { + ptr = va_arg(ap, void *); /* printf("!%s(%d): ptr = %lu\n", "nrrdAxisInfoGet", d, (unsigned long)ptr); */ switch (axInfo) { case nrrdAxisInfoSize: - *((size_t*)ptr) = info.ST[ai]; + *((size_t *)ptr) = info.ST[ai]; break; case nrrdAxisInfoSpacing: case nrrdAxisInfoThickness: case nrrdAxisInfoMin: case nrrdAxisInfoMax: - *((double*)ptr) = info.D[ai]; + *((double *)ptr) = info.D[ai]; /* printf("!%s: got double[%d] = %lg\n", "nrrdAxisInfoGet", d, *((double*)ptr)); */ break; case nrrdAxisInfoSpaceDirection: - for (si=0; sispaceDim; si++) { - ((double*)ptr)[si] = svec[ai][si]; + for (si = 0; si < nrrd->spaceDim; si++) { + ((double *)ptr)[si] = svec[ai][si]; } - for (si=nrrd->spaceDim; sispaceDim; si < NRRD_SPACE_DIM_MAX; si++) { + ((double *)ptr)[si] = AIR_NAN; } break; case nrrdAxisInfoCenter: case nrrdAxisInfoKind: - *((int*)ptr) = info.I[ai]; + *((int *)ptr) = info.I[ai]; /* printf("!%s: got int[%d] = %d\n", "nrrdAxisInfoGet", d, *((int*)ptr)); */ break; @@ -655,7 +647,7 @@ nrrdAxisInfoGet_va(const Nrrd *nrrd, int axInfo, ...) { case nrrdAxisInfoUnits: /* we DO NOT do the airStrdup() here because this pointer value just came from nrrdAxisInfoGet_nva(), which already did the airStrdup() */ - *((char**)ptr) = info.CP[ai]; + *((char **)ptr) = info.CP[ai]; /* printf("!%s: got char*[%d] = |%s|\n", "nrrdAxisInfoSet", d, *((char**)ptr)); */ break; @@ -676,43 +668,36 @@ nrrdAxisInfoGet_va(const Nrrd *nrrd, int axInfo, ...) { ** Thus, this ALWAYS returns nrrdCenterNode or nrrdCenterCell ** (as long as those are the only two centering schemes). */ -int +int /* Biff: (private) nope */ _nrrdCenter(int center) { - center = (nrrdCenterUnknown == center - ? nrrdDefaultCenter - : center); - center = AIR_CLAMP(nrrdCenterUnknown+1, center, nrrdCenterLast-1); + center = (nrrdCenterUnknown == center ? nrrdDefaultCenter : center); + center = AIR_CLAMP(nrrdCenterUnknown + 1, center, nrrdCenterLast - 1); return center; } -int +int /* Biff: (private) nope */ _nrrdCenter2(int center, int defCenter) { - center = (nrrdCenterUnknown == center - ? defCenter - : center); - center = AIR_CLAMP(nrrdCenterUnknown+1, center, nrrdCenterLast-1); + center = (nrrdCenterUnknown == center ? defCenter : center); + center = AIR_CLAMP(nrrdCenterUnknown + 1, center, nrrdCenterLast - 1); return center; } - /* ******** nrrdAxisInfoPos() ** ** given a nrrd, an axis, and a (floating point) index space position, ** return the position implied the axis's min, max, and center ** Does the opposite of nrrdAxisIdx(). -** -** does not use biff */ -double +double /* Biff: nope */ nrrdAxisInfoPos(const Nrrd *nrrd, unsigned int ax, double idx) { int center; size_t size; double min, max; - if (!( nrrd && ax <= nrrd->dim-1 )) { + if (!(nrrd && ax <= nrrd->dim - 1)) { return AIR_NAN; } center = _nrrdCenter(nrrd->axis[ax].center); @@ -723,32 +708,6 @@ nrrdAxisInfoPos(const Nrrd *nrrd, unsigned int ax, double idx) { return NRRD_POS(center, min, max, size, idx); } -/* -******** nrrdAxisInfoIdx() -** -** given a nrrd, an axis, and a (floating point) world space position, -** return the index implied the axis's min, max, and center. -** Does the opposite of nrrdAxisPos(). -** -** does not use biff -*/ -double -nrrdAxisInfoIdx(const Nrrd *nrrd, unsigned int ax, double pos) { - int center; - size_t size; - double min, max; - - if (!( nrrd && ax <= nrrd->dim-1 )) { - return AIR_NAN; - } - center = _nrrdCenter(nrrd->axis[ax].center); - min = nrrd->axis[ax].min; - max = nrrd->axis[ax].max; - size = nrrd->axis[ax].size; - - return NRRD_IDX(center, min, max, size, pos); -} - /* ******** nrrdAxisInfoPosRange() ** @@ -757,15 +716,15 @@ nrrdAxisInfoIdx(const Nrrd *nrrd, unsigned int ax, double pos) { ** The opposite of nrrdAxisIdxRange() */ void -nrrdAxisInfoPosRange(double *loP, double *hiP, - const Nrrd *nrrd, unsigned int ax, +nrrdAxisInfoPosRange(double *loP, double *hiP, const Nrrd *nrrd, unsigned int ax, double loIdx, double hiIdx) { int center, flip = 0; size_t size; double min, max, tmp; - if (!( loP && hiP && nrrd && ax <= nrrd->dim-1 )) { - *loP = *hiP = AIR_NAN; + if (!(loP && hiP && nrrd && ax <= nrrd->dim - 1)) { + if (loP) *loP = AIR_NAN; + if (hiP) *hiP = AIR_NAN; return; } center = _nrrdCenter(nrrd->axis[ax].center); @@ -775,131 +734,21 @@ nrrdAxisInfoPosRange(double *loP, double *hiP, if (loIdx > hiIdx) { flip = 1; - tmp = loIdx; loIdx = hiIdx; hiIdx = tmp; + tmp = loIdx; + loIdx = hiIdx; + hiIdx = tmp; } if (nrrdCenterCell == center) { *loP = AIR_AFFINE(0, loIdx, size, min, max); - *hiP = AIR_AFFINE(0, hiIdx+1, size, min, max); + *hiP = AIR_AFFINE(0, hiIdx + 1, size, min, max); } else { - *loP = AIR_AFFINE(0, loIdx, size-1, min, max); - *hiP = AIR_AFFINE(0, hiIdx, size-1, min, max); + *loP = AIR_AFFINE(0, loIdx, size - 1, min, max); + *hiP = AIR_AFFINE(0, hiIdx, size - 1, min, max); } if (flip) { - tmp = *loP; *loP = *hiP; *hiP = tmp; - } - - return; -} - -/* -******** nrrdAxisInfoIdxRange() -** -** given a nrrd, an axis, and two (floating point) world space positions, -** return the range of index space implied the axis's min, max, and center -** The opposite of nrrdAxisPosRange(). -** -** Actually- there are situations where sending an interval through -** nrrdAxisIdxRange -> nrrdAxisPosRange -> nrrdAxisIdxRange -** such as in cell centering, when the range of positions given does -** not even span one sample. Such as: -** axis->size = 4, axis->min = -4, axis->max = 4, loPos = 0, hiPos = 1 -** --> nrrdAxisIdxRange == (2, 1.5) --> nrrdAxisPosRange == (2, -1) -** The basic problem is that because of the 0.5 offset inherent in -** cell centering, there are situations where (in terms of the arguments -** to nrrdAxisIdxRange()) loPos < hiPos, but *loP > *hiP. -*/ -void -nrrdAxisInfoIdxRange(double *loP, double *hiP, - const Nrrd *nrrd, unsigned int ax, - double loPos, double hiPos) { - int center, flip = 0; - size_t size; - double min, max, tmp; - - if (!( loP && hiP && nrrd && ax <= nrrd->dim-1 )) { - *loP = *hiP = AIR_NAN; - return; - } - center = _nrrdCenter(nrrd->axis[ax].center); - min = nrrd->axis[ax].min; - max = nrrd->axis[ax].max; - size = nrrd->axis[ax].size; - - if (loPos > hiPos) { - flip = 1; - tmp = loPos; loPos = hiPos; hiPos = tmp; - } - if (nrrdCenterCell == center) { - if (min < max) { - *loP = AIR_AFFINE(min, loPos, max, 0, size); - *hiP = AIR_AFFINE(min, hiPos, max, -1, size-1); - } else { - *loP = AIR_AFFINE(min, loPos, max, -1, size-1); - *hiP = AIR_AFFINE(min, hiPos, max, 0, size); - } - } else { - *loP = AIR_AFFINE(min, loPos, max, 0, size-1); - *hiP = AIR_AFFINE(min, hiPos, max, 0, size-1); - } - if (flip) { - tmp = *loP; *loP = *hiP; *hiP = tmp; - } - - return; -} - -void -nrrdAxisInfoSpacingSet(Nrrd *nrrd, unsigned int ax) { - int sign; - double min, max, tmp; - - if (!( nrrd && ax <= nrrd->dim-1 )) { - return; - } - - min = nrrd->axis[ax].min; - max = nrrd->axis[ax].max; - if (!( AIR_EXISTS(min) && AIR_EXISTS(max) )) { - /* there's no actual basis on which to set the spacing information, - but we have to set it something, so here goes .. */ - nrrd->axis[ax].spacing = nrrdDefaultSpacing; - return; - } - - if (min > max) { - tmp = min; min = max; max = tmp; - sign = -1; - } else { - sign = 1; - } - - /* the skinny */ - nrrd->axis[ax].spacing = NRRD_SPACING(_nrrdCenter(nrrd->axis[ax].center), - min, max, nrrd->axis[ax].size); - nrrd->axis[ax].spacing *= sign; - - return; -} - -void -nrrdAxisInfoMinMaxSet(Nrrd *nrrd, unsigned int ax, int defCenter) { - int center; - double spacing; - - if (!( nrrd && ax <= nrrd->dim-1 )) { - return; - } - - center = _nrrdCenter2(nrrd->axis[ax].center, defCenter); - spacing = nrrd->axis[ax].spacing; - if (!AIR_EXISTS(spacing)) - spacing = nrrdDefaultSpacing; - if (nrrdCenterCell == center) { - nrrd->axis[ax].min = 0; - nrrd->axis[ax].max = spacing*AIR_CAST(double, nrrd->axis[ax].size); - } else { - nrrd->axis[ax].min = 0; - nrrd->axis[ax].max = spacing*AIR_CAST(double, nrrd->axis[ax].size - 1); + tmp = *loP; + *loP = *hiP; + *hiP = tmp; } return; @@ -917,15 +766,15 @@ nrrdAxisInfoMinMaxSet(Nrrd *nrrd, unsigned int ax, int defCenter) { ** NOTE: this takes a wild guess that an unset (nrrdKindUnknown) kind ** is a domain axis. */ -unsigned int +unsigned int /* Biff: nope */ nrrdDomainAxesGet(const Nrrd *nrrd, unsigned int axisIdx[NRRD_DIM_MAX]) { unsigned int domAxi, axi; - if (!( nrrd && axisIdx )) { + if (!(nrrd && axisIdx)) { return 0; } domAxi = 0; - for (axi=0; axidim; axi++) { + for (axi = 0; axi < nrrd->dim; axi++) { if (nrrdKindUnknown == nrrd->axis[axi].kind || nrrdKindIsDomain(nrrd->axis[axi].kind)) { axisIdx[domAxi++] = axi; @@ -934,31 +783,31 @@ nrrdDomainAxesGet(const Nrrd *nrrd, unsigned int axisIdx[NRRD_DIM_MAX]) { return domAxi; } -int +static int _nrrdSpaceVecExists(const Nrrd *nrrd, unsigned int axi) { unsigned int sai; int ret; - if (!( nrrd && axi < nrrd->dim && nrrd->spaceDim )) { + if (!(nrrd && axi < nrrd->dim && nrrd->spaceDim)) { ret = AIR_FALSE; } else { ret = AIR_TRUE; - for (sai=0; saispaceDim; sai++) { + for (sai = 0; sai < nrrd->spaceDim; sai++) { ret &= AIR_EXISTS(nrrd->axis[axi].spaceDirection[sai]); } } return ret; } -unsigned int +unsigned int /* Biff: nope */ nrrdSpatialAxesGet(const Nrrd *nrrd, unsigned int axisIdx[NRRD_DIM_MAX]) { unsigned int spcAxi, axi; - if (!( nrrd && axisIdx && nrrd->spaceDim)) { + if (!(nrrd && axisIdx && nrrd->spaceDim)) { return 0; } spcAxi = 0; - for (axi=0; axidim; axi++) { + for (axi = 0; axi < nrrd->dim; axi++) { if (_nrrdSpaceVecExists(nrrd, axi)) { axisIdx[spcAxi++] = axi; } @@ -978,18 +827,18 @@ nrrdSpatialAxesGet(const Nrrd *nrrd, unsigned int axisIdx[NRRD_DIM_MAX]) { ** Note: this really is as simple as returning the complement of the ** axis selected by nrrdDomainAxesGet() */ -unsigned int +unsigned int /* Biff: nope */ nrrdRangeAxesGet(const Nrrd *nrrd, unsigned int axisIdx[NRRD_DIM_MAX]) { unsigned int domNum, domIdx[NRRD_DIM_MAX], rngAxi, axi, ii, isDom; - if (!( nrrd && axisIdx )) { + if (!(nrrd && axisIdx)) { return 0; } domNum = nrrdDomainAxesGet(nrrd, domIdx); rngAxi = 0; - for (axi=0; axidim; axi++) { + for (axi = 0; axi < nrrd->dim; axi++) { isDom = AIR_FALSE; - for (ii=0; iidim; axi++) { + for (axi = 0; axi < nrrd->dim; axi++) { isSpc = AIR_FALSE; - for (ii=0; iidim-1 - && !_nrrdCheck(nrrd, AIR_FALSE, AIR_FALSE) )) { + if (!(nrrd && spacing && vector && ax <= nrrd->dim - 1 + && !_nrrdCheck(nrrd, AIR_FALSE, AIR_FALSE))) { /* there's a problem with the arguments. Note: the _nrrdCheck() call does not check on non-NULL-ity of nrrd->data */ ret = nrrdSpacingStatusUnknown; @@ -1093,10 +940,8 @@ nrrdSpacingCalculate(const Nrrd *nrrd, unsigned int ax, } else { if (nrrd->spaceDim > 0 && _nrrdSpaceVecExists(nrrd, ax)) { ret = nrrdSpacingStatusDirection; - *spacing = nrrdSpaceVecNorm(nrrd->spaceDim, - nrrd->axis[ax].spaceDirection); - nrrdSpaceVecScale(vector, 1.0/(*spacing), - nrrd->axis[ax].spaceDirection); + *spacing = nrrdSpaceVecNorm(nrrd->spaceDim, nrrd->axis[ax].spaceDirection); + nrrdSpaceVecScale(vector, 1.0 / (*spacing), nrrd->axis[ax].spaceDirection); } else { ret = nrrdSpacingStatusNone; *spacing = AIR_NAN; @@ -1107,15 +952,14 @@ nrrdSpacingCalculate(const Nrrd *nrrd, unsigned int ax, return ret; } -int -nrrdOrientationReduce(Nrrd *nout, const Nrrd *nin, - int setMinsFromOrigin) { - static const char me[]="nrrdOrientationReduce"; +int /* Biff: 1 */ +nrrdOrientationReduce(Nrrd *nout, const Nrrd *nin, int setMinsFromOrigin) { + static const char me[] = "nrrdOrientationReduce"; unsigned int spatialAxisNum, spatialAxisIdx[NRRD_DIM_MAX], saxii; NrrdAxisInfo *axis; if (!(nout && nin)) { - biffAddf(NRRD, "%s: got NULL spacing", me); + biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } @@ -1130,18 +974,14 @@ nrrdOrientationReduce(Nrrd *nout, const Nrrd *nin, return 0; } spatialAxisNum = nrrdSpatialAxesGet(nout, spatialAxisIdx); - for (saxii=0; saxiiaxis + spatialAxisIdx[saxii]; - axis->spacing = nrrdSpaceVecNorm(nout->spaceDim, - axis->spaceDirection); + axis->spacing = nrrdSpaceVecNorm(nout->spaceDim, axis->spaceDirection); if (setMinsFromOrigin) { - axis->min = (saxii < nout->spaceDim - ? nout->spaceOrigin[saxii] - : AIR_NAN); + axis->min = (saxii < nout->spaceDim ? nout->spaceOrigin[saxii] : AIR_NAN); } } nrrdSpaceSet(nout, nrrdSpaceUnknown); return 0; } - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/biffbiff.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/biffbiff.c index 4a3ea609d39..833905fb161 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/biffbiff.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/biffbiff.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -34,12 +34,9 @@ # define snprintf _snprintf #endif -static biffMsg ** -_bmsg=NULL; /* master array of biffMsg pointers */ -static unsigned int -_bmsgNum=0; /* length of _biffErr == # keys maintained */ -static airArray * -_bmsgArr=NULL; /* air array of _biffErr and _biffNum */ +static biffMsg **_bmsg = NULL; /* master array of biffMsg pointers */ +static unsigned int _bmsgNum = 0; /* length of _biffErr == # keys maintained */ +static airArray *_bmsgArr = NULL; /* air array of _biffErr and _biffNum */ #define __INCR 2 @@ -58,7 +55,7 @@ typedef union { */ static void _bmsgStart(void) { - static const char me[]="[biff] _bmsgStart"; + static const char me[] = "[biff] _bmsgStart"; _beu uu; if (_bmsgArr) { @@ -66,7 +63,7 @@ _bmsgStart(void) { return; } uu.b = &_bmsg; - _bmsgArr = airArrayNew(uu.v, &_bmsgNum, sizeof(biffMsg*), __INCR); + _bmsgArr = airArrayNew(uu.v, &_bmsgNum, sizeof(biffMsg *), __INCR); if (!_bmsgArr) { fprintf(stderr, "%s: PANIC: couldn't allocate internal data\n", me); /* exit(1); */ @@ -94,7 +91,7 @@ _bmsgFinish(void) { */ static biffMsg * _bmsgFind(const char *key) { - static const char me[]="[biff] _bmsgFind"; + static const char me[] = "[biff] _bmsgFind"; biffMsg *msg; unsigned int ii; @@ -104,7 +101,7 @@ _bmsgFind(const char *key) { } msg = NULL; if (_bmsgNum) { - for (ii=0; ii<_bmsgNum; ii++) { + for (ii = 0; ii < _bmsgNum; ii++) { if (!strcmp(_bmsg[ii]->key, key)) { msg = _bmsg[ii]; break; @@ -121,7 +118,7 @@ static unsigned int _bmsgFindIdx(biffMsg *msg) { unsigned int ii; - for (ii=0; ii<_bmsgNum; ii++) { + for (ii = 0; ii < _bmsgNum; ii++) { if (msg == _bmsg[ii]) { break; } @@ -138,13 +135,13 @@ _bmsgFindIdx(biffMsg *msg) { */ static biffMsg * _bmsgAdd(const char *key) { - static const char me[]="[biff] _bmsgAdd"; + static const char me[] = "[biff] _bmsgAdd"; unsigned int ii; biffMsg *msg; msg = NULL; /* find if key exists already */ - for (ii=0; ii<_bmsgNum; ii++) { + for (ii = 0; ii < _bmsgNum; ii++) { if (!strcmp(key, _bmsg[ii]->key)) { msg = _bmsg[ii]; break; @@ -258,7 +255,6 @@ biffMaybeAddf(int useBiff, const char *key, const char *errfmt, ...) { return; } - /* ******** biffGet() ** @@ -267,19 +263,19 @@ biffMaybeAddf(int useBiff, const char *key, const char *errfmt, ...) { ** be considered a glorified strdup(): it is the callers responsibility ** to free() this string later */ -char * /*Teem: allocates char* */ /* this comment is an experiment */ +char * biffGet(const char *key) { - static const char me[]="biffGet"; + static const char me[] = "biffGet"; char *ret; biffMsg *msg; _bmsgStart(); msg = _bmsgFind(key); if (!msg) { - static const char err[]="[%s] No information for this key!"; + static const char err[] = "[%s] No information for this key!"; size_t errlen; fprintf(stderr, "%s: WARNING: no information for key \"%s\"\n", me, key); - errlen = strlen(err)+strlen(key)+1; + errlen = strlen(err) + strlen(key) + 1; ret = AIR_CALLOC(errlen, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); @@ -289,7 +285,7 @@ biffGet(const char *key) { return ret; } - ret = AIR_CALLOC(biffMsgStrlen(msg)+1, char); + ret = AIR_CALLOC(biffMsgStrlen(msg) + 1, char); if (!ret) { fprintf(stderr, "%s: PANIC: unable to allocate buffer\n", me); return NULL; /* exit(1); */ @@ -306,7 +302,7 @@ biffGet(const char *key) { */ unsigned int biffGetStrlen(const char *key) { - static const char me[]="biffGetStrlen"; + static const char me[] = "biffGetStrlen"; biffMsg *msg; unsigned int len; @@ -317,8 +313,8 @@ biffGetStrlen(const char *key) { return 0; } len = biffMsgStrlen(msg); - len += 1; /* GLK forgets if the convention is that the caller allocates - for one more to include '\0'; this is safer */ + len += 1; /* GLK forgets if the convention is that the caller allocates + for one more to include '\0'; this is safer */ return len; } @@ -330,7 +326,7 @@ biffGetStrlen(const char *key) { */ void biffSetStr(char *str, const char *key) { - static const char me[]="biffSetStr"; + static const char me[] = "biffSetStr"; biffMsg *msg; if (!str) { @@ -370,7 +366,7 @@ biffCheck(const char *key) { */ void biffDone(const char *key) { - static const char me[]="biffDone"; + static const char me[] = "biffDone"; unsigned int idx; biffMsg *msg; @@ -386,7 +382,7 @@ biffDone(const char *key) { if (_bmsgNum > 1) { /* if we have more than one key in action, move the last biffMsg to the position that was just cleared up */ - _bmsg[idx] = _bmsg[_bmsgNum-1]; + _bmsg[idx] = _bmsg[_bmsgNum - 1]; } airArrayLenIncr(_bmsgArr, -1); /* if that was the last key, close shop */ @@ -399,7 +395,7 @@ biffDone(const char *key) { void biffMove(const char *destKey, const char *err, const char *srcKey) { - static const char me[]="biffMove"; + static const char me[] = "biffMove"; biffMsg *dest, *src; _bmsgStart(); @@ -414,9 +410,8 @@ biffMove(const char *destKey, const char *err, const char *srcKey) { } static void -_biffMoveVL(const char *destKey, const char *srcKey, - const char *errfmt, va_list args) { - static const char me[]="biffMovev"; +_biffMoveVL(const char *destKey, const char *srcKey, const char *errfmt, va_list args) { + static const char me[] = "_biffMoveVL"; biffMsg *dest, *src; _bmsgStart(); @@ -427,12 +422,12 @@ _biffMoveVL(const char *destKey, const char *srcKey, return; } _biffMsgMoveVL(dest, src, errfmt, args); + biffDone(srcKey); return; } void -biffMovef(const char *destKey, const char *srcKey, - const char *errfmt, ...) { +biffMovef(const char *destKey, const char *srcKey, const char *errfmt, ...) { va_list args; va_start(args, errfmt); @@ -448,7 +443,7 @@ biffGetDone(const char *key) { _bmsgStart(); ret = biffGet(key); - biffDone(key); /* will call _bmsgFinish if this is the last key */ + biffDone(key); /* will call _bmsgFinish if this is the last key */ return ret; } diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/biffmsg.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/biffmsg.c index 9d1c6d271fa..0806a63e53d 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/biffmsg.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/biffmsg.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,19 +26,34 @@ #include "NrrdIO.h" #include "privateBiff.h" +/* +With the Nov'09 re-write of biff, this sourcefile becomes the only place where a static +buffer is used for message handling; this should eventually be avoided by using things +like asprintf and vasprintf which allocated the string as needed. However (writing here +in 2025), vasprintf is not apparently part of any C standard (as per +https://en.cppreference.com/w/c/experimental/dynamic/asprintf), so we make do with +snprintf and vsnprintf +*/ +#define _HACK_STRLEN AIR_STRLEN_HUGE +#define _MSG_INCR 2 +static const biffMsg _biffMsgNoop = {NULL, NULL, 0, NULL}; /* -** with the Nov'09 re-write of biff, this sourcefile becomes the only -** place where a static buffer is used for message handling; this -** should eventually be avoided by using things like asprintf and -** vasprintf which allocated the string as needed +******** _biffMsgNoop +** +** pass this instead of a real biffMsg (allocated by biffMsgNew) as a +** flag to say, "don't bother, really". This turns all the biffMsg +** functions into no-ops (except that var-args are still consumed +** where they are used) +*/ +/* with the privitization of biffMsg stuff this alas became unavailable: + biffMsg *const biffMsgNoop = &_biffMsgNoop; + However all the code below for handling the Noop has been preserved fwiw */ -#define _HACK_STRLEN AIR_STRLEN_HUGE -#define _MSG_INCR 2 biffMsg * biffMsgNew(const char *key) { - static const char me[]="biffMsgNew"; + static const char me[] = "biffMsgNew"; biffMsg *msg; if (!key) { @@ -53,13 +68,12 @@ biffMsgNew(const char *key) { msg->err = NULL; msg->errNum = 0; appu.cp = &(msg->err); - msg->errArr = airArrayNew(appu.v, &(msg->errNum), - sizeof(char*), _MSG_INCR); + msg->errArr = airArrayNew(appu.v, &(msg->errNum), sizeof(char *), _MSG_INCR); if (msg->errArr) { airArrayPointerCB(msg->errArr, NULL, airFree); } } - if (!( msg && msg->key && msg->errArr )) { + if (!(msg && msg->key && msg->errArr)) { fprintf(stderr, "%s: PANIC couldn't calloc new msg\n", me); return NULL; /* exit(1); */ } @@ -69,7 +83,7 @@ biffMsgNew(const char *key) { biffMsg * biffMsgNix(biffMsg *msg) { - if (msg && msg != biffMsgNoop) { + if (msg && msg != &_biffMsgNoop) { airFree(msg->key); airArrayLenSet(msg->errArr, 0); /* frees all msg->err[i] */ airArrayNuke(msg->errArr); @@ -85,43 +99,43 @@ biffMsgNix(biffMsg *msg) { */ void biffMsgAdd(biffMsg *msg, const char *err) { - static const char me[]="biffMsgAdd"; + static const char me[] = "biffMsgAdd"; unsigned int idx; - if (biffMsgNoop == msg) { + if (&_biffMsgNoop == msg) { return; } - if (!( msg && err )) { - fprintf(stderr, "%s: PANIC got NULL msg (%p) or err (%p)\n", me, - AIR_VOIDP(msg), AIR_CVOIDP(err)); - /* exit(1); */ + if (!(msg && err)) { + fprintf(stderr, "%s: PANIC got NULL msg (%p) or err (%p)\n", me, AIR_VOIDP(msg), + AIR_CVOIDP(err)); + return; /* exit(1); */ } idx = airArrayLenIncr(msg->errArr, 1); if (!msg->err) { fprintf(stderr, "%s: PANIC: couldn't add message to %s\n", me, msg->key); - /* exit(1); */ + return; /* exit(1); */ } - if (!( msg->err[idx] = airOneLinify(airStrdup(err)) )) { + if (!(msg->err[idx] = airOneLinify(airStrdup(err)))) { fprintf(stderr, "%s: PANIC: couldn't alloc message to %s\n", me, msg->key); - /* exit(1); */ + return; /* exit(1); */ } return; } void _biffMsgAddVL(biffMsg *msg, const char *errfmt, va_list args) { - char errstr[_HACK_STRLEN]; + char errstr[_HACK_STRLEN + 1]; - vsprintf(errstr, errfmt, args); + /* h/t Jorik Blaas for highlighting need for vsnprintf over vsprintf */ + vsnprintf(errstr, _HACK_STRLEN + 1, errfmt, args); biffMsgAdd(msg, errstr); return; } - void biffMsgClear(biffMsg *msg) { - if (biffMsgNoop == msg) { + if (&_biffMsgNoop == msg) { return; } airArrayLenSet(msg->errArr, 0); /* frees all msg->err[i] */ @@ -132,15 +146,15 @@ biffMsgClear(biffMsg *msg) { /* ** max length of line formatted "[] \n" */ -unsigned int -biffMsgLineLenMax(const biffMsg *msg) { +static unsigned int +_biffMsgLineLenMax(const biffMsg *msg) { unsigned int ii, len, maxlen; - if (biffMsgNoop == msg) { + if (&_biffMsgNoop == msg) { return 0; } maxlen = 0; - for (ii=0; iierrNum; ii++) { + for (ii = 0; ii < msg->errNum; ii++) { len = AIR_UINT(strlen(msg->err[ii]) + strlen(msg->key) + strlen("[] \n")); maxlen = AIR_MAX(maxlen, len); } @@ -154,17 +168,18 @@ biffMsgLineLenMax(const biffMsg *msg) { */ void biffMsgMove(biffMsg *dest, biffMsg *src, const char *err) { - static const char me[]="biffMsgMove"; + static const char me[] = "biffMsgMove"; unsigned int ii; + size_t bsize; char *buff; - if (biffMsgNoop == dest || biffMsgNoop == src) { + if (&_biffMsgNoop == dest || &_biffMsgNoop == src) { return; } - if (!( dest && src )) { - fprintf(stderr, "%s: PANIC got NULL msg (%p %p)\n", me, - AIR_VOIDP(dest), AIR_VOIDP(src)); - /* exit(1); */ + if (!(dest && src)) { + fprintf(stderr, "%s: PANIC got NULL msg (%p %p)\n", me, AIR_VOIDP(dest), + AIR_VOIDP(src)); + return; /* exit(1); */ } /* if src and dest are same, this degenerates to biffMsgAdd */ if (dest == src && airStrlen(err)) { @@ -172,13 +187,14 @@ biffMsgMove(biffMsg *dest, biffMsg *src, const char *err) { return; } - buff = AIR_CALLOC(biffMsgLineLenMax(src)+1, char); + bsize = _biffMsgLineLenMax(src) + 1; + buff = AIR_CALLOC(bsize, char); if (!buff) { fprintf(stderr, "%s: PANIC: can't allocate buffer\n", me); - /* exit(1); */ + return; /* exit(1); */ } - for (ii=0; iierrNum; ii++) { - sprintf(buff, "[%s] %s", src->key, src->err[ii]); + for (ii = 0; ii < src->errNum; ii++) { + snprintf(buff, bsize, "[%s] %s", src->key, src->err[ii]); biffMsgAdd(dest, buff); } free(buff); @@ -190,11 +206,10 @@ biffMsgMove(biffMsg *dest, biffMsg *src, const char *err) { } void -_biffMsgMoveVL(biffMsg *dest, biffMsg *src, - const char *errfmt, va_list args) { - char errstr[_HACK_STRLEN]; +_biffMsgMoveVL(biffMsg *dest, biffMsg *src, const char *errfmt, va_list args) { + char errstr[_HACK_STRLEN + 1]; - vsprintf(errstr, errfmt, args); + vsnprintf(errstr, _HACK_STRLEN + 1, errfmt, args); biffMsgMove(dest, src, errstr); return; } @@ -217,7 +232,7 @@ biffMsgMovef(biffMsg *dest, biffMsg *src, const char *errfmt, ...) { unsigned int biffMsgErrNum(const biffMsg *msg) { - if (biffMsgNoop == msg) { + if (&_biffMsgNoop == msg) { return 0; } if (!msg) { @@ -234,36 +249,35 @@ biffMsgErrNum(const biffMsg *msg) { */ unsigned int biffMsgStrlen(const biffMsg *msg) { - static const char me[]="biffMsgStrlen"; + static const char me[] = "biffMsgStrlen"; unsigned int ii, len; - if (biffMsgNoop == msg) { + if (&_biffMsgNoop == msg) { return 0; } - if (!( msg )) { + if (!(msg)) { fprintf(stderr, "%s: PANIC got NULL msg %p\n", me, AIR_CVOIDP(msg)); return 0; /* exit(1); */ } len = 0; - for (ii=0; iierrNum; ii++) { - len += AIR_UINT(strlen(msg->key) - + strlen(msg->err[ii]) + strlen("[] \n")); + for (ii = 0; ii < msg->errNum; ii++) { + len += AIR_UINT(strlen(msg->key) + strlen(msg->err[ii]) + strlen("[] \n")); } - return len+1; + return len + 1; } -char * -biffMsgStrAlloc(const biffMsg *msg) { - static const char me[]="biffMsgStrAlloc"; +static char * +_biffMsgStrAlloc(const biffMsg *msg) { + static const char me[] = "_biffMsgStrAlloc"; char *ret; unsigned int len; - if (biffMsgNoop == msg) { + if (&_biffMsgNoop == msg) { return NULL; } len = biffMsgStrlen(msg); - ret = AIR_CALLOC(len+1, char); + ret = AIR_CALLOC(len + 1, char); if (!ret) { fprintf(stderr, "%s: PANIC couldn't alloc string", me); return NULL; /* exit(1); */ @@ -273,25 +287,31 @@ biffMsgStrAlloc(const biffMsg *msg) { /* ** ret is assumed to be allocated for biffMsgStrlen()+1, or is the -** the return from biffMsgStrAlloc +** the return from _biffMsgStrAlloc */ void biffMsgStrSet(char *ret, const biffMsg *msg) { - static const char me[]="biffMsgStrSet"; + static const char me[] = "biffMsgStrSet"; char *buff; + size_t bsize; unsigned int ii; - if (biffMsgNoop == msg) { + if (&_biffMsgNoop == msg) { + return; + } + if (!ret) { + fprintf(stderr, "%s: PANIC got NULL ret", me); return; } - buff = AIR_CALLOC(biffMsgLineLenMax(msg)+1, char); + bsize = _biffMsgLineLenMax(msg) + 1; + buff = AIR_CALLOC(bsize, char); if (!buff) { fprintf(stderr, "%s: PANIC couldn't alloc buffer", me); - /* exit(1); */ + return; /* exit(1); */ } strcpy(ret, ""); - for (ii=msg->errNum; ii>0; ii--) { - sprintf(buff, "[%s] %s\n", msg->key, msg->err[ii-1]); + for (ii = msg->errNum; ii > 0; ii--) { + snprintf(buff, bsize, "[%s] %s\n", msg->key, msg->err[ii - 1]); strcat(ret, buff); } free(buff); @@ -301,29 +321,10 @@ char * biffMsgStrGet(const biffMsg *msg) { char *ret; - if (biffMsgNoop == msg) { + if (&_biffMsgNoop == msg) { return NULL; } - ret = biffMsgStrAlloc(msg); + ret = _biffMsgStrAlloc(msg); biffMsgStrSet(ret, msg); return ret; } - -biffMsg -_biffMsgNoop = { - NULL, - NULL, - 0, - NULL -}; - -/* -******** biffMsgNoop -** -** pass this instead of a real biffMsg (allocated by biffMsgNew) as a -** flag to say, "don't bother, really". This turns all the biffMsg -** functions into no-ops (except that var-args are still consumed -** where they are used) -*/ -biffMsg * -biffMsgNoop = &_biffMsgNoop; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/comment.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/comment.c index 7888383a5de..8f71925aecb 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/comment.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/comment.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -31,20 +31,15 @@ ** ** Adds a given string to the list of comments ** Leading spaces (' ') and comment chars ('#') are not included. -** -** This function does NOT use biff. */ -int +int /* Biff: nope */ nrrdCommentAdd(Nrrd *nrrd, const char *_str) { - /* static const char me[]="nrrdCommentAdd";*/ + /* static const char me[] = "nrrdCommentAdd";*/ char *str; unsigned int ii; if (!(nrrd && _str)) { - /* - sprintf(err, "%s: got NULL pointer", me); - biffMaybeAdd(NRRD, err, useBiff); - */ + /* got NULL pointer */ return 1; } _str += strspn(_str, " #"); @@ -52,27 +47,20 @@ nrrdCommentAdd(Nrrd *nrrd, const char *_str) { /* we don't bother adding comments with no length */ return 0; } - if (!strcmp(_str, _nrrdFormatURLLine0) - || !strcmp(_str, _nrrdFormatURLLine1)) { + if (!strcmp(_str, _nrrdFormatURLLine0) || !strcmp(_str, _nrrdFormatURLLine1)) { /* sneaky hack: don't store the format URL comment lines */ return 0; } str = airStrdup(_str); if (!str) { - /* - sprintf(err, "%s: couldn't strdup given string", me); - biffMaybeAdd(NRRD, err, useBiff); - */ + /* couldn't strdup given string */ return 1; } /* clean out carraige returns that would screw up reader */ airOneLinify(str); ii = airArrayLenIncr(nrrd->cmtArr, 1); if (!nrrd->cmtArr->data) { - /* - sprintf(err, "%s: couldn't lengthen comment array", me); - biffMaybeAdd(NRRD, err, useBiff); - */ + /* couldn't lengthen comment array */ return 1; } nrrd->cmt[ii] = str; @@ -84,7 +72,7 @@ nrrdCommentAdd(Nrrd *nrrd, const char *_str) { ** ** blows away comments, but does not blow away the comment airArray */ -void +void /* Biff: nope */ nrrdCommentClear(Nrrd *nrrd) { if (nrrd) { @@ -97,20 +85,15 @@ nrrdCommentClear(Nrrd *nrrd) { ** ** copies comments from one nrrd to another ** Existing comments in nout are blown away -** -** This does NOT use biff. */ -int +int /* Biff: nope */ nrrdCommentCopy(Nrrd *nout, const Nrrd *nin) { - /* static const char me[]="nrrdCommentCopy"; */ + /* static const char me[] = "nrrdCommentCopy"; */ int E; unsigned int numc, ii; if (!(nout && nin)) { - /* - sprintf(err, "%s: got NULL pointer", me); - biffMaybeAdd(NRRD, err, useBiff); - */ + /* got NULL pointer */ return 1; } if (nout == nin) { @@ -120,14 +103,11 @@ nrrdCommentCopy(Nrrd *nout, const Nrrd *nin) { nrrdCommentClear(nout); numc = nin->cmtArr->len; E = 0; - for (ii=0; iicmt[ii]); } if (E) { - /* - sprintf(err, "%s: couldn't add all comments", me); - biffMaybeAdd(NRRD, err, useBiff); - */ + /* couldn't add all comments */ return 3; } return 0; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/defaultsNrrd.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/defaultsNrrd.c index a0b2d800f07..5c33cff90ef 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/defaultsNrrd.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/defaultsNrrd.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -42,16 +42,17 @@ int nrrdDefaultWriteEncodingType = nrrdEncodingTypeRaw; int nrrdDefaultWriteBareText = AIR_TRUE; +int nrrdDefaultWriteMoreThanFloatInText = AIR_FALSE; unsigned int nrrdDefaultWriteCharsPerLine = 75; unsigned int nrrdDefaultWriteValsPerLine = 8; int nrrdDefaultCenter = nrrdCenterCell; -double nrrdDefaultSpacing = 1.0; +/* matches how nrrdStateVerboseIO (gone in Teem2) was initialized */ +int nrrdDefaultVerboseIO = 0; /* these aren't really "defaults" because there's no other channel for specifying this information. It is just global state. Obviously, like defaults, they are not thread-safe if different threads ever set them differently. */ -int nrrdStateVerboseIO = 0; int nrrdStateKeyValuePairsPropagate = AIR_FALSE; int nrrdStateAlwaysSetContent = AIR_TRUE; int nrrdStateDisableContent = AIR_FALSE; @@ -66,15 +67,15 @@ int nrrdStateKeyValueReturnInternalPointers = AIR_FALSE; int nrrdStateKindNoop = AIR_FALSE; /* these are helper functions for min/max testing */ -airLLong +airLLong /* Biff: (private) nope */ _nrrdLLongMaxHelp(airLLong val) { - return val*2 + 1; + return val * 2 + 1; } -airLLong +airLLong /* Biff: (private) nope */ _nrrdLLongMinHelp(airLLong val) { - return val*2; + return val * 2; } -airULLong +airULLong /* Biff: (private) nope */ _nrrdULLongMaxHelp(airULLong val) { return val + 1; } @@ -84,4 +85,3 @@ _nrrdULLongMaxHelp(airULLong val) { /* Are there other assumptions currently built into nrrd which could stand to be user-controllable? */ - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/dio.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/dio.c deleted file mode 100644 index d7ef9c7581d..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/dio.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "NrrdIO.h" -#include "teemDio.h" - -#if TEEM_DIO == 0 -#else -/* HEY: these may be SGI-specific */ -#include -#include -#include -#endif - -#if TEEM_DIO == 0 -const int airMyDio = 0; -#else -const int airMyDio = 1; -#endif - -int airDisableDio = AIR_FALSE; - -static const char -_airNoDioErr[AIR_NODIO_MAX+2][AIR_STRLEN_SMALL] = { - "(invalid noDio value)", - "CAN TOO do direct I/O!", - "direct I/O apparently not available on this architecture", - "direct I/O apparently not suitable for given file format", - "won't do direct I/O on std{in|out|err}", - "got -1 as file descriptor", - "fcntl(F_DIOINFO) to learn direct I/O specifics failed", - "requested transfer size is too small", - "requested transfer size not a multiple of d_miniosz", - "data memory address not multiple of d_mem", - "current file position not multiple of d_miniosz", - "fcntl(F_SETFL, FDIRECT) to turn on direct I/O failed", - "memalign() test (on a small chuck of memory) failed", - "direct I/O (in air library) has been disabled with airDisableDio" -}; - -const char * -airNoDioErr(int noDio) { - - if (AIR_IN_CL(0, noDio, AIR_NODIO_MAX)) { - return _airNoDioErr[noDio+1]; - } - else { - return _airNoDioErr[0]; - } -} - -/* -******** airDioTest -** -** does everything necessary to assess whether direct IO can be used -** to read a data segment of a given size, from a given file -** descriptor, into a given pointer. The given pointer ptr can be -** NULL, and/or the size can be 0, in order to test the other aspects -** of direct IO. The return value of this is from the airNoDio_* enum. -** Note that airNoDio_okay means, "actually, direct IO *does* seem to -** be possible here". -*/ -#if TEEM_DIO == 0 -int -airDioTest(int fd, const void *ptr, size_t size) { - AIR_UNUSED(fd); - AIR_UNUSED(ptr); - AIR_UNUSED(size); - - /* Teem makefiles think no direct IO is possible on this architecture */ - return airNoDio_arch; -} -#else -int -airDioTest(int fd, const void *ptr, size_t size) { - struct dioattr dioinfo; - void *tmp; - int flags; - - if (airDisableDio) { - /* user turned direct I/O off */ - return airNoDio_disable; - } - if (0 == fd || 1 == fd || 2 == fd) { - /* This was added because I was noticing a problem with piping - between unrrdu programs- sometimes the fread() of the receiving - data through a unix pipe ("|") failed to read all the data. If - the body of this function was bypassed (with "return - airNoDio_disable;", for instance), then the problem went away. - The problematic call seemed to be the fflush() below (Tue Feb 1 - 06:47:33 EST 2005: which has since been removed with the change - of this function's argument from a FILE * to an integral file - descriptor). I don't think direct I/O is possible on stdin, - stdout, or stdout, since the fcntl() call below fails on stdin - and stdout. However, something about making that fcntl() call - changes something which means that about half the time, the - read() on a piped stdin fails (on an irix6.n32 O2, at - least). So, seems to be safest to just explicitly say that - direct I/O is unavailable, based solely on the file descriptor - number (0, 1, 2). */ - return airNoDio_std; - } - if (-1 == fd) { - /* caller probably couldn't get the underlying file descriptor */ - return airNoDio_fd; - } - if (0 != fcntl(fd, F_DIOINFO, &dioinfo)) { - /* couldn't learn direct I/O specifics */ - return airNoDio_dioinfo; - } - - if (size) { - /* - ** direct I/O requirements: - ** 1) xfer size between d_miniosz and d_maxiosz - ** 2) xfer size a multiple of d_miniosz - ** 3) memory buffer on d_mem-byte boundary - ** 4) file position on d_miniosz-byte boundary - ** - ** As long as xfer size is >= d_miniosz and meets req. #2, then - ** we can break the xfer into d_maxiosz-size pieces of need be. - ** We can test #3 here if we're given non-NULL ptr - ** We can always test #4 - */ - if (size < dioinfo.d_miniosz) { - /* fails req. #1 above */ - return airNoDio_small; - } - /* we don't actually check for being too large, since we can always - do IO on d_maxiosz-sized pieces */ - if (size % dioinfo.d_miniosz) { - /* fails req. #2 above */ - return airNoDio_size; - } - } - if (ptr) { - if ((unsigned long)(ptr) % dioinfo.d_mem) { - /* fails req. #3 above */ - return airNoDio_ptr; - } - } else { - tmp = memalign(dioinfo.d_mem, dioinfo.d_miniosz); - if (!tmp) { - /* couldn't even alloc (via memalign) the minimum size */ - return airNoDio_test; - } - free(tmp); - } - if (lseek(fd, 0, SEEK_CUR) % dioinfo.d_miniosz) { - /* fails req. #4 above */ - return airNoDio_fpos; - } - flags = fcntl(fd, F_GETFL); - if (-1 == fcntl(fd, F_SETFL, flags | FDIRECT)) { - /* couln't turn on direct I/O */ - return airNoDio_setfl; - } - /* put things back the way they were */ - fcntl(fd, F_SETFL, flags); - - /* as far as we know, direct I/O seems workable */ - return airNoDio_okay; -} -#endif - -/* -******** airDioInfo -** -** does the fcntl stuff to learn the direct IO parameters: -** align: required alignment of memory (pointer must be multiple of this) -** min: minimum size of dio transfer -** max: maximum size of dio transfer -** -** NOTE: this does not try to do any error checking, because it assumes -** that you've already called airDioTest without incident. -*/ -#if TEEM_DIO == 0 -void -airDioInfo(int *align, int *min, int *max, int fd) { - AIR_UNUSED(align); - AIR_UNUSED(min); - AIR_UNUSED(max); - AIR_UNUSED(fd); - return; -} -#else -void -airDioInfo(int *align, int *min, int *max, int fd) { - struct dioattr dioinfo; - - if (align && min && max && !fcntl(fd, F_DIOINFO, &dioinfo)) { - *align = dioinfo.d_mem; - *min = dioinfo.d_miniosz; - *max = dioinfo.d_maxiosz; - } - return; -} -#endif - -/* -******** airDioMalloc -** -** does direct IO compatible memory allocation. -** -** NOTE: like airDioInfo, this assumes that you've called airDioTest -** without incident -*/ -#if TEEM_DIO == 0 -void * -airDioMalloc(size_t size, int fd) { - AIR_UNUSED(size); - AIR_UNUSED(fd); - - return NULL; -} -#else -void * -airDioMalloc(size_t size, int fd) { - int align, min, max; - - airDioInfo(&align, &min, &max, fd); - return memalign(align, size); -} -#endif - -/* -******** airDioRead -** -** like read(), but for direct IO. The idea is that you call this on as -** big a chunk of memory as possible. -** -** NOTE: like airDioInfo, this assumes that you've called airDioTest -** without incident -*/ -#if TEEM_DIO == 0 -size_t -airDioRead(int fd, void *_ptr, size_t size) { - AIR_UNUSED(fd); - AIR_UNUSED(_ptr); - AIR_UNUSED(size); - - return 0; -} -#else -size_t -airDioRead(int fd, void *_ptr, size_t size) { - size_t red, totalred; - int align, min, max, flags; - size_t remain, part; - char *ptr; - - if (!( _ptr && airNoDio_okay == airDioTest(fd, _ptr, size) )) { - return 0; - } - - flags = fcntl(fd, F_GETFL); - fcntl(fd, F_SETFL, flags | FDIRECT); - airDioInfo(&align, &min, &max, fd); - remain = size; - totalred = 0; - ptr = (char*)_ptr; - do { - part = AIR_MIN(remain, max); - red = read(fd, ptr, part); - totalred += red; - if (red != part) { - break; - } - ptr += red; - remain -= red; - } while (remain); - fcntl(fd, F_SETFL, flags); - - return totalred; -} -#endif - -/* -******** airDioWrite -** -** like write(), but for direct IO. The idea is that you call this on as -** big a chunk of memory as possible. -** -** NOTE: like airDioInfo, this assumes that you've called airDioTest -** without incident -*/ -#if TEEM_DIO == 0 -size_t -airDioWrite(int fd, const void *_ptr, size_t size) { - AIR_UNUSED(fd); - AIR_UNUSED(_ptr); - AIR_UNUSED(size); - - return 0; -} -#else -size_t -airDioWrite(int fd, const void *_ptr, size_t size) { - size_t rit, totalrit; - int align, min, max, flags; - size_t remain, part; - char *ptr; - - if (!( _ptr && (airNoDio_okay == airDioTest(fd, _ptr, size)) )) { - return 0; - } - - flags = fcntl(fd, F_GETFL); - fcntl(fd, F_SETFL, flags | FDIRECT); - airDioInfo(&align, &min, &max, fd); - remain = size; - totalrit = 0; - ptr = (char*)_ptr; - do { - part = AIR_MIN(remain, max); - rit = write(fd, ptr, part); - totalrit += rit; - if (rit != part) { - break; - } - ptr += rit; - remain -= rit; - } while (remain); - fcntl(fd, F_SETFL, flags); - - return totalrit; -} -#endif diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encoding.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encoding.c index 30ff64a5f1e..377b042a3d1 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encoding.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encoding.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -52,11 +52,10 @@ _nrrdEncodingUnknown_available(void) { return AIR_FALSE; } -static int -_nrrdEncodingUnknown_read(FILE *file, void *data, - size_t elementNum, Nrrd *nrrd, +static int /* Biff: 1 */ +_nrrdEncodingUnknown_read(FILE *file, void *data, size_t elementNum, Nrrd *nrrd, struct NrrdIoState_t *nio) { - static const char me[]="_nrrdEncodingUnknown_read"; + static const char me[] = "_nrrdEncodingUnknown_read"; /* insert code here, and remove error handling below */ AIR_UNUSED(file); @@ -69,11 +68,10 @@ _nrrdEncodingUnknown_read(FILE *file, void *data, return 1; } -static int -_nrrdEncodingUnknown_write(FILE *file, const void *data, - size_t elementNum, const Nrrd *nrrd, - struct NrrdIoState_t *nio) { - static const char me[]="_nrrdEncodingUnknown_write"; +static int /* Biff: 1 */ +_nrrdEncodingUnknown_write(FILE *file, const void *data, size_t elementNum, + const Nrrd *nrrd, struct NrrdIoState_t *nio) { + static const char me[] = "_nrrdEncodingUnknown_write"; /* insert code here, and remove error handling below */ AIR_UNUSED(file); @@ -86,27 +84,17 @@ _nrrdEncodingUnknown_write(FILE *file, const void *data, return 1; } -const NrrdEncoding -_nrrdEncodingUnknown = { - "unknown", /* name */ - "unknown", /* suffix */ - AIR_FALSE, /* endianMatters */ - AIR_FALSE, /* isCompression */ - _nrrdEncodingUnknown_available, - _nrrdEncodingUnknown_read, - _nrrdEncodingUnknown_write -}; +static const NrrdEncoding _nrrdEncodingUnknown = {"unknown", /* name */ + "unknown", /* suffix */ + AIR_FALSE, /* endianMatters */ + AIR_FALSE, /* isCompression */ + _nrrdEncodingUnknown_available, + _nrrdEncodingUnknown_read, + _nrrdEncodingUnknown_write}; -const NrrdEncoding *const -nrrdEncodingUnknown = &_nrrdEncodingUnknown; - -const NrrdEncoding *const -nrrdEncodingArray[NRRD_ENCODING_TYPE_MAX+1] = { - &_nrrdEncodingUnknown, - &_nrrdEncodingRaw, - &_nrrdEncodingAscii, - &_nrrdEncodingHex, - &_nrrdEncodingGzip, - &_nrrdEncodingBzip2 -}; +const NrrdEncoding *const nrrdEncodingUnknown = &_nrrdEncodingUnknown; +const NrrdEncoding *const nrrdEncodingArray[NRRD_ENCODING_TYPE_MAX + 1] = { + &_nrrdEncodingUnknown, &_nrrdEncodingRaw, &_nrrdEncodingAscii, &_nrrdEncodingHex, + &_nrrdEncodingGzip, &_nrrdEncodingBzip2, &_nrrdEncodingZRL, +}; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingAscii.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingAscii.c index 94fcb1bd1ce..56ac9348709 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingAscii.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingAscii.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,7 +26,10 @@ #include "NrrdIO.h" #include "privateNrrd.h" -static FILE *_fileSave = NULL; +/* this was part of an old hail Mary debugging effort; + bug has probably been found :) + Removing this since it is a weird symbol to see in the "nm" output */ +/* static FILE *_fileSave = NULL; */ static int _nrrdEncodingAscii_available(void) { @@ -34,50 +37,52 @@ _nrrdEncodingAscii_available(void) { return AIR_TRUE; } -static int -_nrrdEncodingAscii_read(FILE *file, void *_data, size_t elNum, - Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="_nrrdEncodingAscii_read"; - char numbStr[AIR_STRLEN_HUGE]; /* HEY: fix this */ +static int /* Biff: 1 */ +_nrrdEncodingAscii_read(FILE *file, void *_data, size_t elNum, Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingAscii_read"; + char numbStr[AIR_STRLEN_HUGE + 1]; /* HEY: fix this */ char *nstr; size_t I; char *data; int tmp; AIR_UNUSED(nio); - _fileSave = file; + /* _fileSave = file; */ if (nrrdTypeBlock == nrrd->type) { biffAddf(NRRD, "%s: can't read nrrd type %s from %s", me, - airEnumStr(nrrdType, nrrdTypeBlock), - nrrdEncodingAscii->name); + airEnumStr(nrrdType, nrrdTypeBlock), nrrdEncodingAscii->name); return 1; } - data = (char*)_data; + data = (char *)_data; I = 0; while (I < elNum) { - char stmp1[AIR_STRLEN_SMALL], stmp2[AIR_STRLEN_SMALL]; + char stmp[2][AIR_STRLEN_SMALL + 1]; /* HEY: we can easily suffer here from a standard buffer overflow problem; this was a source of a mysterious unu crash: echo "0 0 0 0 1 0 0 0 0" \ | unu reshape -s 9 1 1 \ | unu pad -min 0 0 0 -max 8 8 8 \ - | unu make -s 9 9 9 -t float -e ascii -ls 9 \ + | unu make -s 9 9 9 -t float -e ascii -ls 10 \ -spc LPS -orig "(0,0,0)" -dirs "(1,0,0) (0,1,0) (0,0,1)" This particular case is resolved by changing AIR_STRLEN_HUGE to AIR_STRLEN_HUGE*100, but the general problem remains. This - motivated adding the memory corruption test */ + motivated adding the memory corruption test + HEY HEY: 2023 GLK does not know what buffer AIR_STRLEN_HUGE*100 + could be describing; what was this?? */ if (1 != fscanf(file, "%s", numbStr)) { biffAddf(NRRD, "%s: couldn't parse element %s of %s", me, - airSprintSize_t(stmp1, I+1), - airSprintSize_t(stmp2, elNum)); + airSprintSize_t(stmp[0], I + 1), airSprintSize_t(stmp[1], elNum)); return 1; } + /* if (file != _fileSave) { fprintf(stderr, "%s: PANIC memory corruption detected\n", me); - /* this may crash, hence the fprintf above to help debug */ + / * this may crash, hence the fprintf above to help debug * / biffAddf(NRRD, "%s: PANIC memory corruption detected", me); return 1; } + */ if (!strcmp(",", numbStr)) { /* its an isolated comma, not a value, pass over this */ continue; @@ -86,20 +91,19 @@ _nrrdEncodingAscii_read(FILE *file, void *_data, size_t elNum, nstr = numbStr + strspn(numbStr, ","); if (nrrd->type >= nrrdTypeInt) { /* sscanf supports putting value directly into this type */ - if (1 != airSingleSscanf(nstr, nrrdTypePrintfStr[nrrd->type], - (void*)(data + I*nrrdElementSize(nrrd)))) { + if (1 + != airSingleSscanf(nstr, nrrdTypePrintfStr[nrrd->type], + (void *)(data + I * nrrdElementSize(nrrd)))) { biffAddf(NRRD, "%s: couldn't parse %s %s of %s (\"%s\")", me, - airEnumStr(nrrdType, nrrd->type), - airSprintSize_t(stmp1, I+1), - airSprintSize_t(stmp2, elNum), nstr); + airEnumStr(nrrdType, nrrd->type), airSprintSize_t(stmp[0], I + 1), + airSprintSize_t(stmp[1], elNum), nstr); return 1; } } else { /* sscanf value into an int first */ if (1 != airSingleSscanf(nstr, "%d", &tmp)) { biffAddf(NRRD, "%s: couldn't parse element %s of %s (\"%s\")", me, - airSprintSize_t(stmp1, I+1), - airSprintSize_t(stmp2, elNum), nstr); + airSprintSize_t(stmp[0], I + 1), airSprintSize_t(stmp[1], elNum), nstr); return 1; } nrrdIInsert[nrrd->type](data, I, tmp); @@ -110,59 +114,61 @@ _nrrdEncodingAscii_read(FILE *file, void *_data, size_t elNum, return 0; } -static int -_nrrdEncodingAscii_write(FILE *file, const void *_data, size_t elNum, - const Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="_nrrdEncodingAscii_write"; - char buff[AIR_STRLEN_MED]; +static int /* Biff: 1 */ +_nrrdEncodingAscii_write(FILE *file, const void *_data, size_t elNum, const Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingAscii_write"; + char buff[AIR_STRLEN_MED + 1]; size_t bufflen, linelen; const char *data; size_t I; + int newlined = AIR_FALSE; if (nrrdTypeBlock == nrrd->type) { biffAddf(NRRD, "%s: can't write nrrd type %s to %s", me, - airEnumStr(nrrdType, nrrdTypeBlock), - nrrdEncodingAscii->name); + airEnumStr(nrrdType, nrrdTypeBlock), nrrdEncodingAscii->name); return 1; } - data = AIR_CAST(const char*, _data); + data = AIR_CAST(const char *, _data); linelen = 0; - for (I=0; Itype](buff, data); if (1 == nrrd->dim) { fprintf(file, "%s\n", buff); - } else if (nrrd->dim == 2 - && nrrd->axis[0].size <= nio->valsPerLine) { - fprintf(file, "%s%c", buff, - (I+1)%(nrrd->axis[0].size) ? ' ' : '\n'); + newlined = AIR_TRUE; + } else if (nrrd->dim == 2 && nrrd->axis[0].size <= nio->valsPerLine) { + int nonewline = AIR_INT((I + 1) % (nrrd->axis[0].size)); + fprintf(file, "%s%c", buff, nonewline ? ' ' : '\n'); + newlined = !nonewline; } else { bufflen = strlen(buff); - if (linelen+bufflen+1 <= nio->charsPerLine) { + if (linelen + bufflen + 1 <= nio->charsPerLine) { fprintf(file, "%s%s", I ? " " : "", buff); linelen += (I ? 1 : 0) + bufflen; } else { fprintf(file, "\n%s", buff); linelen = bufflen; } + newlined = AIR_FALSE; } data += nrrdElementSize(nrrd); } - /* just to be sure, we always end with a carraige return */ - fprintf(file, "\n"); + if (!newlined) { + /* always end file with a carraige return; but guard with this + conditional so we don't create a final blank line */ + fprintf(file, "\n"); + } + fflush(file); return 0; } -const NrrdEncoding -_nrrdEncodingAscii = { - "ASCII", /* name */ - "ascii", /* suffix */ - AIR_FALSE, /* endianMatters */ - AIR_FALSE, /* isCompression */ - _nrrdEncodingAscii_available, - _nrrdEncodingAscii_read, - _nrrdEncodingAscii_write -}; - -const NrrdEncoding *const -nrrdEncodingAscii = &_nrrdEncodingAscii; +const NrrdEncoding _nrrdEncodingAscii = {"ASCII", /* name */ + "ascii", /* suffix */ + AIR_FALSE, /* endianMatters */ + AIR_FALSE, /* isCompression */ + _nrrdEncodingAscii_available, + _nrrdEncodingAscii_read, + _nrrdEncodingAscii_write}; + +const NrrdEncoding *const nrrdEncodingAscii = &_nrrdEncodingAscii; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingBzip2.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingBzip2.c index 043c347bc3b..e34b033a2b6 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingBzip2.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingBzip2.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,52 +26,217 @@ #include "NrrdIO.h" #include "privateNrrd.h" -int +#if TEEM_BZIP2 +# include +#endif + +static int _nrrdEncodingBzip2_available(void) { +#if TEEM_BZIP2 + return AIR_TRUE; +#else return AIR_FALSE; +#endif } -int -_nrrdEncodingBzip2_read(FILE *file, void *data, size_t elementNum, - Nrrd *nrrd, struct NrrdIoState_t *nio) { - char me[]="_nrrdEncodingBzip2_read", err[AIR_STRLEN_MED]; +static int /* Biff: 1 */ +_nrrdEncodingBzip2_read(FILE *file, void *_data, size_t elNum, Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingBzip2_read"; +#if TEEM_BZIP2 + size_t bsize, total_read, block_size; + int read, bzerror = BZ_OK; + long int bi; + char *data; + BZFILE *bzfin; + + bsize = nrrdElementSize(nrrd) * elNum; + + /* Create the BZFILE* for reading in the gzipped data. */ + bzfin = BZ2_bzReadOpen(&bzerror, file, 0, 0, NULL, 0); + if (bzerror != BZ_OK) { + /* there was a problem */ + biffAddf(NRRD, "%s: error opening BZFILE: %s", me, BZ2_bzerror(bzfin, &bzerror)); + BZ2_bzReadClose(&bzerror, bzfin); + return 1; + } + + /* Here is where we do the byte skipping. */ + for (bi = 0; bi < nio->byteSkip; bi++) { + unsigned char b; + /* Check to see if a single byte was able to be read. */ + read = BZ2_bzRead(&bzerror, bzfin, &b, 1); + if (read != 1 || bzerror != BZ_OK) { + biffAddf(NRRD, "%s: hit an error skipping byte %ld of %ld: %s", me, bi, + nio->byteSkip, BZ2_bzerror(bzfin, &bzerror)); + return 1; + } + } + + /* bzip2 can handle data sizes up to INT_MAX, so we can't just + pass in the bsize, because it might be too large for an int. + Therefore it must be read in chunks if the size is larger + than INT_MAX. */ + if (bsize <= INT_MAX) { + block_size = bsize; + } else { + block_size = INT_MAX; + } + + /* This counter will help us to make sure that we read as much data + as we think we should. */ + total_read = 0; + /* Pointer to the blocks as we read them. */ + data = (char *)_data; + + /* Ok, now we can begin reading. */ + bzerror = BZ_OK; + while ((read = BZ2_bzRead(&bzerror, bzfin, data, block_size)) + && (BZ_OK == bzerror || BZ_STREAM_END == bzerror)) { + /* Increment the data pointer to the next available spot. */ + data += read; + total_read += read; + /* We only want to read as much data as we need, so we need to check + to make sure that we don't request data that might be there but that + we don't want. This will reduce block_size when we get to the last + block (which may be smaller than block_size). + */ + if (bsize >= total_read && bsize - total_read < block_size) + block_size = bsize - total_read; + } + + if (!(BZ_OK == bzerror || BZ_STREAM_END == bzerror)) { + biffAddf(NRRD, "%s: error reading from BZFILE: %s", me, + BZ2_bzerror(bzfin, &bzerror)); + return 1; + } + + /* Close the BZFILE. */ + BZ2_bzReadClose(&bzerror, bzfin); + if (BZ_OK != bzerror) { + biffAddf(NRRD, "%s: error closing BZFILE: %s", me, BZ2_bzerror(bzfin, &bzerror)); + return 1; + } + + /* Check to see if we got out as much as we thought we should. */ + if (total_read != bsize) { + char stmp[2][AIR_STRLEN_SMALL + 1]; + biffAddf(NRRD, "%s: expected %s bytes but received %s", me, + airSprintSize_t(stmp[0], bsize), airSprintSize_t(stmp[1], total_read)); + return 1; + } + return 0; +#else AIR_UNUSED(file); - AIR_UNUSED(data); - AIR_UNUSED(elementNum); + AIR_UNUSED(_data); + AIR_UNUSED(elNum); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s encoding not available in NrrdIO", - me, nrrdEncodingBzip2->name); - biffAdd(NRRD, err); return 1; + biffAddf(NRRD, "%s: sorry, this nrrd not compiled with bzip2 enabled", me); + return 1; +#endif } -int -_nrrdEncodingBzip2_write(FILE *file, const void *data, size_t elementNum, - const Nrrd *nrrd, struct NrrdIoState_t *nio) { - char me[]="_nrrdEncodingBzip2_write", err[AIR_STRLEN_MED]; +static int /* Biff: 1 */ +_nrrdEncodingBzip2_write(FILE *file, const void *_data, size_t elNum, const Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingBzip2_write"; +#if TEEM_BZIP2 + size_t bsize, total_written, block_size; + int bs, bzerror = BZ_OK; + char *data; + BZFILE *bzfout; + bsize = nrrdElementSize(nrrd) * elNum; + + /* Set compression block size. */ + if (1 <= nio->bzip2BlockSize && nio->bzip2BlockSize <= 9) { + bs = nio->bzip2BlockSize; + } else { + bs = 9; + } + /* Open bzfile for writing. Verbosity and work factor are set + to default values. */ + bzfout = BZ2_bzWriteOpen(&bzerror, file, bs, 0, 0); + if (BZ_OK != bzerror) { + biffAddf(NRRD, "%s: error opening BZFILE: %s", me, BZ2_bzerror(bzfout, &bzerror)); + BZ2_bzWriteClose(&bzerror, bzfout, 0, NULL, NULL); + return 1; + } + + /* bzip2 can handle data sizes up to INT_MAX, so we can't just + pass in the bsize, because it might be too large for an int. + Therefore it must be read in chunks if the bsize is larger + than INT_MAX. */ + if (bsize <= INT_MAX) { + block_size = bsize; + } else { + block_size = INT_MAX; + } + + /* This counter will help us to make sure that we write as much data + as we think we should. */ + total_written = 0; + /* Pointer to the blocks as we write them. */ + data = (char *)_data; + + /* Ok, now we can begin writing. */ + bzerror = BZ_OK; + while (bsize - total_written > block_size) { + BZ2_bzWrite(&bzerror, bzfout, data, block_size); + if (BZ_OK != bzerror) break; + /* Increment the data pointer to the next available spot. */ + data += block_size; + total_written += block_size; + } + /* write the last (possibly smaller) block when its humungous data; + write the whole data when its small */ + if (BZ_OK == bzerror) { + block_size = bsize >= total_written ? bsize - total_written : 0; + BZ2_bzWrite(&bzerror, bzfout, data, block_size); + total_written += block_size; + } + + if (BZ_OK != bzerror) { + biffAddf(NRRD, "%s: error writing to BZFILE: %s", me, BZ2_bzerror(bzfout, &bzerror)); + return 1; + } + + /* Close the BZFILE. */ + BZ2_bzWriteClose(&bzerror, bzfout, 0, NULL, NULL); + if (BZ_OK != bzerror) { + biffAddf(NRRD, "%s: error closing BZFILE: %s", me, BZ2_bzerror(bzfout, &bzerror)); + return 1; + } + + /* Check to see if we got out as much as we thought we should. */ + if (total_written != bsize) { + char stmp[2][AIR_STRLEN_SMALL + 1]; + biffAddf(NRRD, "%s: expected to write %s bytes, but only wrote %s", me, + airSprintSize_t(stmp[0], bsize), airSprintSize_t(stmp[1], total_written)); + return 1; + } + + return 0; +#else AIR_UNUSED(file); - AIR_UNUSED(data); - AIR_UNUSED(elementNum); + AIR_UNUSED(_data); + AIR_UNUSED(elNum); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s encoding not available in NrrdIO", - me, nrrdEncodingBzip2->name); - biffAdd(NRRD, err); return 1; + biffAddf(NRRD, "%s: sorry, this nrrd not compiled with bzip2 enabled", me); + return 1; +#endif } -const NrrdEncoding -_nrrdEncodingBzip2 = { - "bzip2", /* name */ - "raw.bz2", /* suffix */ - AIR_TRUE, /* endianMatters */ - AIR_TRUE, /* isCompression */ - _nrrdEncodingBzip2_available, - _nrrdEncodingBzip2_read, - _nrrdEncodingBzip2_write -}; - -const NrrdEncoding *const -nrrdEncodingBzip2 = &_nrrdEncodingBzip2; +const NrrdEncoding _nrrdEncodingBzip2 = {"bzip2", /* name */ + "raw.bz2", /* suffix */ + AIR_TRUE, /* endianMatters */ + AIR_TRUE, /* isCompression */ + _nrrdEncodingBzip2_available, + _nrrdEncodingBzip2_read, + _nrrdEncodingBzip2_write}; + +const NrrdEncoding *const nrrdEncodingBzip2 = &_nrrdEncodingBzip2; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingGzip.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingGzip.c index 243bfd711df..21e425a5fdc 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingGzip.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingGzip.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -36,21 +36,22 @@ _nrrdEncodingGzip_available(void) { #endif } +#if TEEM_ZLIB /* ** Maximum size that allow zlib to try to read or write at once. ** The real limit is UINT_MAX, but a smaller value here permits ** exercising the multi-chunk capability of the code below. */ -static unsigned int -_nrrdZlibMaxChunk = UINT_MAX; +static unsigned int _nrrdZlibMaxChunk = UINT_MAX; +#endif /* ** nio->byteSkip < 0 functionality contributed by Katharina Quintus */ -static int -_nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, - Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="_nrrdEncodingGzip_read"; +static int /* Biff: 1 */ +_nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingGzip_read"; #if TEEM_ZLIB size_t sizeData, sizeRed; int error; @@ -60,7 +61,7 @@ _nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, gzFile gzfin; airPtrPtrUnion appu; - sizeData = nrrdElementSize(nrrd)*elNum; + sizeData = nrrdElementSize(nrrd) * elNum; /* Create the gzFile for reading in the gzipped data. */ if ((gzfin = _nrrdGzOpen(file, "rb")) == Z_NULL) { /* there was a problem */ @@ -76,8 +77,8 @@ _nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, _nrrdZlibMaxChunk around UINT_MAX for testing purposes. Given how sizeChunk is used below, we also cap chunk size at _nrrdZlibMaxChunk/2 to prevent overflow. */ - maxChunk = _nrrdZlibMaxChunk/2; - sizeChunk = AIR_CAST(unsigned int, AIR_MIN(sizeData, maxChunk)); + maxChunk = _nrrdZlibMaxChunk / 2; + sizeChunk = AIR_UINT(AIR_MIN(sizeData, maxChunk)); if (nio->byteSkip < 0) { /* We don't know the size of the size to skip before the data, so @@ -94,9 +95,9 @@ _nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, the reading in terms of bytes (sizeof(char)==1 by definition) */ buff = NULL; appu.c = &buff; - buffArr = airArrayNew(appu.v, NULL, 1, 2*sizeChunk); + buffArr = airArrayNew(appu.v, NULL, 1, 2 * sizeChunk); airArrayLenSet(buffArr, sizeChunk); - if (!( buffArr && buffArr->data )) { + if (!(buffArr && buffArr->data)) { biffAddf(NRRD, "%s: couldn't initialize airArray\n", me); return 1; } @@ -106,8 +107,7 @@ _nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, code below (for positive byteskip), we are obligated to read until the bitter end, and can't update sizeChunk to encompass only the required data. */ - while (!(error = _nrrdGzRead(gzfin, buff + sizeRed, - sizeChunk, &didread)) + while (!(error = _nrrdGzRead(gzfin, buff + sizeRed, sizeChunk, &didread)) && didread > 0) { sizeRed += didread; if (didread >= sizeChunk) { @@ -131,11 +131,11 @@ _nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, } /* backwards is (positive) number of bytes AFTER data that we ignore */ backwards = -nio->byteSkip - 1; - if (sizeRed < sizeData + AIR_CAST(size_t, backwards)) { - char stmp1[AIR_STRLEN_SMALL], stmp2[AIR_STRLEN_SMALL]; + if (sizeRed < sizeData + AIR_SIZE_T(backwards)) { + char stmp[2][AIR_STRLEN_SMALL + 1]; biffAddf(NRRD, "%s: expected %s bytes but received only %s", me, - airSprintSize_t(stmp1, sizeData + AIR_CAST(size_t, backwards)), - airSprintSize_t(stmp2, sizeRed)); + airSprintSize_t(stmp[0], sizeData + AIR_SIZE_T(backwards)), + airSprintSize_t(stmp[1], sizeRed)); return 1; } /* also handles nio->byteSkip == -N-1 signifying extra N bytes at end */ @@ -145,20 +145,19 @@ _nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, /* no negative byteskip: after byteskipping, we can read directly into given data buffer */ if (nio->byteSkip > 0) { - for (bi=0; bibyteSkip; bi++) { + for (bi = 0; bi < nio->byteSkip; bi++) { unsigned char b; /* Check to see if a single byte was able to be read. */ if (_nrrdGzRead(gzfin, &b, 1, &didread) != 0 || didread != 1) { - biffAddf(NRRD, "%s: hit an error skipping byte %ld of %ld", - me, bi, nio->byteSkip); + biffAddf(NRRD, "%s: hit an error skipping byte %ld of %ld", me, bi, + nio->byteSkip); return 1; } } } /* Pointer to chunks as we read them. */ data = AIR_CAST(char *, _data); - while (!(error = _nrrdGzRead(gzfin, data, sizeChunk, &didread)) - && didread > 0) { + while (!(error = _nrrdGzRead(gzfin, data, sizeChunk, &didread)) && didread > 0) { /* Increment the data pointer to the next available chunk. */ data += didread; sizeRed += didread; @@ -166,9 +165,8 @@ _nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, to make sure that we don't request data that might be there but that we don't want. This will reduce sizeChunk when we get to the last block (which may be smaller than the original sizeChunk). */ - if (sizeData >= sizeRed - && sizeData - sizeRed < sizeChunk) { - sizeChunk = AIR_CAST(unsigned int, sizeData - sizeRed); + if (sizeData >= sizeRed && sizeData - sizeRed < sizeChunk) { + sizeChunk = AIR_UINT(sizeData - sizeRed); } } if (error) { @@ -177,10 +175,9 @@ _nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, } /* Check to see if we got out as much as we thought we should. */ if (sizeRed != sizeData) { - char stmp1[AIR_STRLEN_SMALL], stmp2[AIR_STRLEN_SMALL]; + char stmp[2][AIR_STRLEN_SMALL + 1]; biffAddf(NRRD, "%s: expected %s bytes but received %s", me, - airSprintSize_t(stmp1, sizeData), - airSprintSize_t(stmp2, sizeRed)); + airSprintSize_t(stmp[0], sizeData), airSprintSize_t(stmp[1], sizeRed)); return 1; } } @@ -204,19 +201,19 @@ _nrrdEncodingGzip_read(FILE *file, void *_data, size_t elNum, #endif } -static int -_nrrdEncodingGzip_write(FILE *file, const void *_data, size_t elNum, - const Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="_nrrdEncodingGzip_write"; +static int /* Biff: 1 */ +_nrrdEncodingGzip_write(FILE *file, const void *_data, size_t elNum, const Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingGzip_write"; #if TEEM_ZLIB size_t sizeData, sizeWrit; - int fmt_i=0, error; + int fmt_i = 0, error; const char *data; char fmt[4]; gzFile gzfout; unsigned int wrote, sizeChunk; - sizeData = nrrdElementSize(nrrd)*elNum; + sizeData = nrrdElementSize(nrrd) * elNum; /* Set format string based on the NrrdIoState parameters. */ fmt[fmt_i++] = 'w'; @@ -245,7 +242,7 @@ _nrrdEncodingGzip_write(FILE *file, const void *_data, size_t elNum, /* zlib can only handle data sizes up to UINT_MAX ==> if there's more than UINT_MAX bytes to write out, we write out in chunks. As above, we wrap _nrrdZlibMaxChunk around UINT_MAX for testing purposes. */ - sizeChunk = AIR_CAST(unsigned int, AIR_MIN(sizeData, _nrrdZlibMaxChunk)); + sizeChunk = AIR_UINT(AIR_MIN(sizeData, _nrrdZlibMaxChunk)); /* keeps track of what how much has been successfully written */ sizeWrit = 0; @@ -253,8 +250,7 @@ _nrrdEncodingGzip_write(FILE *file, const void *_data, size_t elNum, data = AIR_CAST(const char *, _data); /* Ok, now we can begin writing. */ - while ((error = _nrrdGzWrite(gzfout, AIR_CVOIDP(data), - sizeChunk, &wrote)) == 0 + while ((error = _nrrdGzWrite(gzfout, AIR_CVOIDP(data), sizeChunk, &wrote)) == 0 && wrote > 0) { /* Increment the data pointer to the next available spot. */ data += wrote; @@ -264,9 +260,8 @@ _nrrdEncodingGzip_write(FILE *file, const void *_data, size_t elNum, will reduce sizeChunk when we get to the last block (which may be smaller than the original sizeChunk). */ - if (sizeData >= sizeWrit - && sizeData - sizeWrit < sizeChunk) - sizeChunk = AIR_CAST(unsigned int, sizeData - sizeWrit); + if (sizeData >= sizeWrit && sizeData - sizeWrit < sizeChunk) + sizeChunk = AIR_UINT(sizeData - sizeWrit); } if (error) { @@ -276,10 +271,9 @@ _nrrdEncodingGzip_write(FILE *file, const void *_data, size_t elNum, /* Check to see if we wrote out as much as we thought we should. */ if (sizeWrit != sizeData) { - char stmp1[AIR_STRLEN_SMALL], stmp2[AIR_STRLEN_SMALL]; + char stmp[2][AIR_STRLEN_SMALL + 1]; biffAddf(NRRD, "%s: expected to write %s bytes, but only wrote %s", me, - airSprintSize_t(stmp1, sizeData), - airSprintSize_t(stmp2, sizeWrit)); + airSprintSize_t(stmp[0], sizeData), airSprintSize_t(stmp[1], sizeWrit)); return 1; } @@ -297,22 +291,20 @@ _nrrdEncodingGzip_write(FILE *file, const void *_data, size_t elNum, AIR_UNUSED(elNum); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - biffAddf(NRRD, "%s: sorry, this nrrd not compiled with zlib " - "(needed for gzip) enabled", me); + biffAddf(NRRD, + "%s: sorry, this nrrd not compiled with zlib " + "(needed for gzip) enabled", + me); return 1; #endif } -const NrrdEncoding -_nrrdEncodingGzip = { - "gzip", /* name */ - "raw.gz", /* suffix */ - AIR_TRUE, /* endianMatters */ - AIR_TRUE, /* isCompression */ - _nrrdEncodingGzip_available, - _nrrdEncodingGzip_read, - _nrrdEncodingGzip_write -}; +const NrrdEncoding _nrrdEncodingGzip = {"gzip", /* name */ + "raw.gz", /* suffix */ + AIR_TRUE, /* endianMatters */ + AIR_TRUE, /* isCompression */ + _nrrdEncodingGzip_available, + _nrrdEncodingGzip_read, + _nrrdEncodingGzip_write}; -const NrrdEncoding *const -nrrdEncodingGzip = &_nrrdEncodingGzip; +const NrrdEncoding *const nrrdEncodingGzip = &_nrrdEncodingGzip; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingHex.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingHex.c index 21ff9e819b5..b78736910b1 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingHex.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingHex.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,17 +26,15 @@ #include "NrrdIO.h" #include "privateNrrd.h" -static const int -_nrrdWriteHexTable[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' -}; +static const int _nrrdWriteHexTable[16] = {'0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; /* ** -2: not allowed, error ** -1: whitespace ** [0,15]: values */ +/* clang-format off */ static const int _nrrdReadHexTable[128] = { /* 0 1 2 3 4 5 6 7 8 9 */ @@ -54,7 +52,7 @@ _nrrdReadHexTable[128] = { -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, /* 110 */ -2, -2, -2, -2, -2, -2, -2, -2 /* 120 */ }; - +/* clang-format on */ static int _nrrdEncodingHex_available(void) { @@ -62,19 +60,19 @@ _nrrdEncodingHex_available(void) { return AIR_TRUE; } -static int -_nrrdEncodingHex_read(FILE *file, void *_data, size_t elNum, - Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="_nrrdEncodingHex_read"; +static int /* Biff: 1 */ +_nrrdEncodingHex_read(FILE *file, void *_data, size_t elNum, Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingHex_read"; size_t nibIdx, nibNum; unsigned char *data; - int car=0, nib; + int car = 0, nib; AIR_UNUSED(nio); data = AIR_CAST(unsigned char *, _data); nibIdx = 0; - nibNum = 2*elNum*nrrdElementSize(nrrd); - if (nibNum/elNum != 2*nrrdElementSize(nrrd)) { + nibNum = 2 * elNum * nrrdElementSize(nrrd); + if (nibNum / elNum != 2 * nrrdElementSize(nrrd)) { biffAddf(NRRD, "%s: size_t can't hold 2*(#bytes in array)\n", me); return 1; } @@ -92,45 +90,50 @@ _nrrdEncodingHex_read(FILE *file, void *_data, size_t elNum, continue; } /* else it is a valid character, representing a value from 0 to 15 */ - nibshift = AIR_CAST(unsigned char, nib << (4*(1-(nibIdx & 1)))); + nibshift = AIR_UCHAR(nib << (4 * (1 - (nibIdx & 1)))); /* HEY not sure why the cast is needed with gcc v4.8 -Wconversion */ - *data = AIR_CAST(unsigned char, *data + nibshift); + *data = AIR_UCHAR(*data + nibshift); data += nibIdx & 1; nibIdx++; } if (nibIdx != nibNum) { - char stmp1[AIR_STRLEN_SMALL], stmp2[AIR_STRLEN_SMALL]; + char stmp[2][AIR_STRLEN_SMALL + 1]; if (EOF == car) { biffAddf(NRRD, "%s: hit EOF getting byte %s of %s", me, - airSprintSize_t(stmp1, nibIdx/2), - airSprintSize_t(stmp2, nibNum/2)); + airSprintSize_t(stmp[0], nibIdx / 2), + airSprintSize_t(stmp[1], nibNum / 2)); } else { - biffAddf(NRRD, "%s: hit invalid character ('%c') getting " - "byte %s of %s", me, car, - airSprintSize_t(stmp1, nibIdx/2), - airSprintSize_t(stmp2, nibNum/2)); + biffAddf(NRRD, + "%s: hit invalid character ('%c') getting " + "byte %s of %s", + me, car, airSprintSize_t(stmp[0], nibIdx / 2), + airSprintSize_t(stmp[1], nibNum / 2)); } return 1; } return 0; } -static int -_nrrdEncodingHex_write(FILE *file, const void *_data, size_t elNum, - const Nrrd *nrrd, NrrdIoState *nio) { - /* static const char me[]="_nrrdEncodingHex_write"; */ +static int /* Biff: 1 */ +_nrrdEncodingHex_write(FILE *file, const void *_data, size_t elNum, const Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingHex_write"; const unsigned char *data; size_t byteIdx, byteNum; unsigned int bytesPerLine; - bytesPerLine = AIR_MAX(1, nio->charsPerLine/2); - data = AIR_CAST(const unsigned char*, _data); - byteNum = elNum*nrrdElementSize(nrrd); - for (byteIdx=0; byteIdx>4], - _nrrdWriteHexTable[(*data)&15]); - if (bytesPerLine-1 == byteIdx % bytesPerLine) { + if (!(file && _data && nrrd && nio)) { + biffAddf(NRRD, "%s: got NULL pointer (%p,%p,%p,%p)", me, (void *)file, + (const void *)_data, (const void *)nrrd, (void *)nio); + return 1; + } + bytesPerLine = AIR_MAX(1, nio->charsPerLine / 2); + data = AIR_CAST(const unsigned char *, _data); + byteNum = elNum * nrrdElementSize(nrrd); + for (byteIdx = 0; byteIdx < byteNum; byteIdx++) { + fprintf(file, "%c%c", _nrrdWriteHexTable[(*data) >> 4], + _nrrdWriteHexTable[(*data) & 15]); + if (bytesPerLine - 1 == byteIdx % bytesPerLine) { fprintf(file, "\n"); } data++; @@ -140,16 +143,12 @@ _nrrdEncodingHex_write(FILE *file, const void *_data, size_t elNum, return 0; } -const NrrdEncoding -_nrrdEncodingHex = { - "hex", /* name */ - "hex", /* suffix */ - AIR_TRUE, /* endianMatters */ - AIR_FALSE, /* isCompression */ - _nrrdEncodingHex_available, - _nrrdEncodingHex_read, - _nrrdEncodingHex_write -}; +const NrrdEncoding _nrrdEncodingHex = {"hex", /* name */ + "hex", /* suffix */ + AIR_TRUE, /* endianMatters */ + AIR_FALSE, /* isCompression */ + _nrrdEncodingHex_available, + _nrrdEncodingHex_read, + _nrrdEncodingHex_write}; -const NrrdEncoding *const -nrrdEncodingHex = &_nrrdEncodingHex; +const NrrdEncoding *const nrrdEncodingHex = &_nrrdEncodingHex; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingRaw.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingRaw.c index 3b41ffcfb05..afdf126d3d6 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingRaw.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingRaw.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -32,189 +32,131 @@ _nrrdEncodingRaw_available(void) { return AIR_TRUE; } -static int -_nrrdEncodingRaw_read(FILE *file, void *data, size_t elementNum, - Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="_nrrdEncodingRaw_read"; +static int /* Biff: 1 */ +_nrrdEncodingRaw_read(FILE *file, void *data, size_t elementNum, Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingRaw_read"; size_t ret, bsize; - int fd, dio, car; + int car; long savePos; char *data_c; size_t elementSize, maxChunkSize, remainderValue, chunkSize; size_t retTmp; - char stmp[3][AIR_STRLEN_SMALL]; - - bsize = nrrdElementSize(nrrd)*elementNum; - if (nio->format->usesDIO) { - fd = fileno(file); - dio = airDioTest(fd, data, bsize); - } else { - fd = -1; - dio = airNoDio_format; - } - if (airNoDio_okay == dio) { - if (2 <= nrrdStateVerboseIO) { - fprintf(stderr, "with direct I/O ... "); + char stmp[3][AIR_STRLEN_SMALL + 1]; + + bsize = nrrdElementSize(nrrd) * elementNum; + + /* HEY: There's a bug in fread/fwrite in gcc 4.2.1 (with SnowLeopard). + When it reads/writes a >=2GB data array, it pretends to succeed + (i.e. the return value is the right number) but it hasn't + actually read/written the data. The work-around is to loop + over the data, reading/writing 1GB (or smaller) chunks. */ + ret = 0; + data_c = (char *)data; + elementSize = nrrdElementSize(nrrd); + maxChunkSize = 1024 * 1024 * 1024 / elementSize; + while (ret < elementNum) { + remainderValue = elementNum - ret; + if (remainderValue < maxChunkSize) { + chunkSize = remainderValue; + } else { + chunkSize = maxChunkSize; } - ret = airDioRead(fd, data, bsize); - if (ret != bsize) { - biffAddf(NRRD, "%s: airDioRead got read only %s of %sbytes " - "(%g%% of expected)", me, - airSprintSize_t(stmp[0], ret), - airSprintSize_t(stmp[1], bsize), - 100.0*AIR_CAST(double, ret)/AIR_CAST(double, bsize)); + retTmp = fread(&(data_c[ret * elementSize]), elementSize, chunkSize, file); + ret += retTmp; + if (retTmp != chunkSize) { + biffAddf(NRRD, + "%s: fread got only %s %s-sized things, not %s " + "(%g%% of expected)", + me, airSprintSize_t(stmp[0], ret), + airSprintSize_t(stmp[1], nrrdElementSize(nrrd)), + airSprintSize_t(stmp[2], elementNum), + 100.0 * AIR_CAST(double, ret) / AIR_CAST(double, elementNum)); return 1; } - } else { - if (2 <= nrrdStateVerboseIO) { - if (AIR_DIO && nio->format->usesDIO) { - fprintf(stderr, "with fread(), not DIO: %s ...", airNoDioErr(dio)); - } - } - - /* HEY: There's a bug in fread/fwrite in gcc 4.2.1 (with SnowLeopard). - When it reads/writes a >=2GB data array, it pretends to succeed - (i.e. the return value is the right number) but it hasn't - actually read/written the data. The work-around is to loop - over the data, reading/writing 1GB (or smaller) chunks. */ - ret = 0; - data_c = (char *)data; - elementSize = nrrdElementSize(nrrd); - maxChunkSize = 1024 * 1024 * 1024 / elementSize; - while(ret < elementNum) { - remainderValue = elementNum-ret; - if (remainderValue < maxChunkSize) { - chunkSize = remainderValue; - } else { - chunkSize = maxChunkSize; - } - retTmp = - fread(&(data_c[ret*elementSize]), elementSize, chunkSize, file); - ret += retTmp; - if (retTmp != chunkSize) { - biffAddf(NRRD, "%s: fread got only %s %s-sized things, not %s " - "(%g%% of expected)", me, - airSprintSize_t(stmp[0], ret), - airSprintSize_t(stmp[1], nrrdElementSize(nrrd)), - airSprintSize_t(stmp[2], elementNum), - 100.0*AIR_CAST(double, ret)/AIR_CAST(double, elementNum)); - return 1; - } - } + } - car = fgetc(file); - if (EOF != car) { - if (1 <= nrrdStateVerboseIO) { - fprintf(stderr, "%s: WARNING: finished reading raw data, " - "but file not at EOF\n", me); - } - ungetc(car, file); + car = fgetc(file); + if (EOF != car) { + if (nio && nio->verbose >= 1) { + fprintf(stderr, + "%s: WARNING: finished reading raw data, " + "but file not at EOF\n", + me); } - if (2 <= nrrdStateVerboseIO && nio->byteSkip && stdin != file) { - savePos = ftell(file); - if (!fseek(file, 0, SEEK_END)) { - double frac = (AIR_CAST(double, bsize) - /AIR_CAST(double, ftell(file) + 1)); - fprintf(stderr, "(%s: used %g%% of file for nrrd data)\n", me, - 100.0*frac); - fseek(file, savePos, SEEK_SET); - } + ungetc(car, file); + } + if (nio && nio->verbose >= 2 && nio->byteSkip && stdin != file) { + savePos = ftell(file); + if (!fseek(file, 0, SEEK_END)) { + double frac = (AIR_CAST(double, bsize) / AIR_CAST(double, ftell(file) + 1)); + fprintf(stderr, "(%s: used %g%% of file for nrrd data)\n", me, 100.0 * frac); + fseek(file, savePos, SEEK_SET); } } return 0; } -static int -_nrrdEncodingRaw_write(FILE *file, const void *data, size_t elementNum, - const Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="_nrrdEncodingRaw_write"; - int fd, dio; - size_t ret, bsize; +static int /* Biff: 1 */ +_nrrdEncodingRaw_write(FILE *file, const void *data, size_t elementNum, const Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingRaw_write"; + size_t ret; const char *data_c; size_t elementSize, maxChunkSize, remainderValue, chunkSize; size_t retTmp; - char stmp[3][AIR_STRLEN_SMALL]; - - bsize = nrrdElementSize(nrrd)*elementNum; - if (nio->format->usesDIO) { - fd = fileno(file); - dio = airDioTest(fd, data, bsize); - } else { - fd = -1; - dio = airNoDio_format; - } - if (airNoDio_okay == dio) { - if (2 <= nrrdStateVerboseIO) { - fprintf(stderr, "with direct I/O ... "); + char stmp[3][AIR_STRLEN_SMALL + 1]; + + AIR_UNUSED(nio); + + /* HEY: There's a bug in fread/fwrite in gcc 4.2.1 (with SnowLeopard). + When it reads/writes a >=2GB data array, it pretends to succeed + (i.e. the return value is the right number) but it hasn't + actually read/written the data. The work-around is to loop + over the data, reading/writing 1GB (or smaller) chunks. */ + ret = 0; + data_c = AIR_CAST(const char *, data); + elementSize = nrrdElementSize(nrrd); + maxChunkSize = 1024 * 1024 * 1024 / elementSize; + while (ret < elementNum) { + remainderValue = elementNum - ret; + if (remainderValue < maxChunkSize) { + chunkSize = remainderValue; + } else { + chunkSize = maxChunkSize; } - ret = airDioWrite(fd, data, bsize); - if (ret != bsize) { - biffAddf(NRRD, "%s: airDioWrite wrote only %s of %s bytes " - "(%g%% of expected)", me, - airSprintSize_t(stmp[0], ret), - airSprintSize_t(stmp[1], bsize), - 100.0*AIR_CAST(double, ret)/AIR_CAST(double, bsize)); + retTmp = fwrite(&(data_c[ret * elementSize]), elementSize, chunkSize, file); + ret += retTmp; + if (retTmp != chunkSize) { + biffAddf(NRRD, + "%s: fwrite wrote only %s %s-sized things, not %s " + "(%g%% of expected)", + me, airSprintSize_t(stmp[0], ret), + airSprintSize_t(stmp[1], nrrdElementSize(nrrd)), + airSprintSize_t(stmp[2], elementNum), + 100.0 * AIR_CAST(double, ret) / AIR_CAST(double, elementNum)); return 1; } - } else { - if (2 <= nrrdStateVerboseIO) { - if (AIR_DIO && nio->format->usesDIO) { - fprintf(stderr, "with fread(), not DIO: %s ...", airNoDioErr(dio)); - } - } - - /* HEY: There's a bug in fread/fwrite in gcc 4.2.1 (with SnowLeopard). - When it reads/writes a >=2GB data array, it pretends to succeed - (i.e. the return value is the right number) but it hasn't - actually read/written the data. The work-around is to loop - over the data, reading/writing 1GB (or smaller) chunks. */ - ret = 0; - data_c = AIR_CAST(const char *, data); - elementSize = nrrdElementSize(nrrd); - maxChunkSize = 1024 * 1024 * 1024 / elementSize; - while(ret < elementNum) { - remainderValue = elementNum-ret; - if (remainderValue < maxChunkSize) { - chunkSize = remainderValue; - } else { - chunkSize = maxChunkSize; - } - retTmp = - fwrite(&(data_c[ret*elementSize]), elementSize, chunkSize, file); - ret += retTmp; - if (retTmp != chunkSize) { - biffAddf(NRRD, "%s: fwrite wrote only %s %s-sized things, not %s " - "(%g%% of expected)", me, - airSprintSize_t(stmp[0], ret), - airSprintSize_t(stmp[1], nrrdElementSize(nrrd)), - airSprintSize_t(stmp[2], elementNum), - 100.0*AIR_CAST(double, ret)/AIR_CAST(double, elementNum)); - return 1; - } - } + } - fflush(file); - /* - if (ferror(file)) { - biffAddf(NRRD, "%s: ferror returned non-zero", me); - return 1; - } - */ + fflush(file); + /* + if (ferror(file)) { + biffAddf(NRRD, "%s: ferror returned non-zero", me); + return 1; } + */ + return 0; } -const NrrdEncoding -_nrrdEncodingRaw = { - "raw", /* name */ - "raw", /* suffix */ - AIR_TRUE, /* endianMatters */ - AIR_FALSE, /* isCompression */ - _nrrdEncodingRaw_available, - _nrrdEncodingRaw_read, - _nrrdEncodingRaw_write -}; - -const NrrdEncoding *const -nrrdEncodingRaw = &_nrrdEncodingRaw; +const NrrdEncoding _nrrdEncodingRaw = {"raw", /* name */ + "raw", /* suffix */ + AIR_TRUE, /* endianMatters */ + AIR_FALSE, /* isCompression */ + _nrrdEncodingRaw_available, + _nrrdEncodingRaw_read, + _nrrdEncodingRaw_write}; + +const NrrdEncoding *const nrrdEncodingRaw = &_nrrdEncodingRaw; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingZRL.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingZRL.c new file mode 100644 index 00000000000..7b49f70eef0 --- /dev/null +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/encodingZRL.c @@ -0,0 +1,97 @@ +/* + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any + damages arising from the use of this software. + + Permission is granted to anyone to use this software for any + purpose, including commercial applications, and to alter it and + redistribute it freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "NrrdIO.h" +#include "privateNrrd.h" + +static int +_nrrdEncodingZRL_available(void) { + + return AIR_TRUE; +} + +static int +_nrrdEncodingZRL_read(FILE *file, void *data, size_t elementNum, Nrrd *nrrd, + NrrdIoState *nio) { + unsigned char *output_buffer = (unsigned char *)data; + size_t toread = elementNum * nrrdElementSize(nrrd); + int cc, dd; + unsigned int j = 0; + AIR_UNUSED(nio); + + while (j < toread) { + cc = fgetc(file); + if (cc == 0) { + dd = fgetc(file); + if (dd == 0) { + dd = fgetc(file); + j += dd + fgetc(file) * 256; + } else { + j += (unsigned char)dd; + } + } else { + output_buffer[j] = (unsigned char)cc; + j++; + } + } + + return 0; +} + +static int /* Biff: 0 */ +_nrrdEncodingZRL_write(FILE *file, const void *data, size_t elementNum, const Nrrd *nrrd, + NrrdIoState *nio) { + static const char me[] = "_nrrdEncodingZRL_write"; + + AIR_UNUSED(file); + AIR_UNUSED(data); + AIR_UNUSED(elementNum); + AIR_UNUSED(nrrd); + AIR_UNUSED(nio); + biffAddf(NRRD, "%s: sorry, currently a read-only encoding", me); + + return 0; +} + +const NrrdEncoding _nrrdEncodingZRL + = {"zrl", /* name */ + "zrl", /* suffix */ + AIR_TRUE, /* endianMatters */ + AIR_FALSE, /* isCompression: HEY this is a hack: this IS certainly a + compression. However, with compressed encodings the nrrd + format has no way of specifying whether a byteskip + between be outside the encoding (in the uncompressed + data) vs inside the encoding (within the compuressed + data). To date the convention has been that byte skip is + done *inside* compressions, but for the ZRL-encoded data + as currently generated, the relevant byte skipping is + certainly *outside* the compression. Thus we claim + ignorance about how ZRL is a compression, so that byte + skipping can be used. */ + _nrrdEncodingZRL_available, + _nrrdEncodingZRL_read, + _nrrdEncodingZRL_write}; + +const NrrdEncoding *const nrrdEncodingZRL = &_nrrdEncodingZRL; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/endianAir.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/endianAir.c index 000b834e2de..b2096c335b4 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/endianAir.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/endianAir.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -44,7 +44,7 @@ airMyEndian(void) { (the "first" byte in memory ordering). On big endian, we're getting the most significant byte (0); on little endian, we're getting least significant byte (1) */ - leastbyte = *(AIR_CAST(char*, &tmpI)); + leastbyte = *(AIR_CAST(char *, &tmpI)); if (leastbyte) { ret = airEndianLittle; } else { @@ -53,6 +53,7 @@ airMyEndian(void) { return ret; } +/* clang-format off */ static const char * _airEndianStr[] = { "(unknown endian)", @@ -86,4 +87,4 @@ _airEndian = { const airEnum *const airEndian = &_airEndian; - +/* clang-format on */ diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/endianNrrd.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/endianNrrd.c index 914df2e3659..e4defcd4444 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/endianNrrd.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/endianNrrd.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -34,11 +34,12 @@ _nrrdSwap16Endian(void *_data, size_t N) { return; } data = AIR_CAST(unsigned short *, _data); - mask = AIR_CAST(unsigned short, 0x00FFu); - for (I=0; I>= 0x08; - fix = (dd & mask) | AIR_CAST(unsigned short, fix << 0x08); + fix = (dd & mask); + dd >>= 0x08; + fix = (dd & mask) | AIR_USHORT(fix << 0x08); data[I] = fix; } } @@ -53,12 +54,14 @@ _nrrdSwap32Endian(void *_data, size_t N) { } data = AIR_CAST(unsigned int *, _data); mask = 0x000000FFu; - for (I=0; I>= 0x08; fix = (dd & mask) | (fix << 0x08); dd >>= 0x08; fix = (dd & mask) | (fix << 0x08); dd >>= 0x08; fix = (dd & mask) | (fix << 0x08); + /* clang-format on */ data[I] = fix; } } @@ -73,8 +76,9 @@ _nrrdSwap64Endian(void *_data, size_t N) { } data = AIR_CAST(airULLong *, _data); mask = AIR_ULLONG(0x00000000000000FF); - for (I=0; I>= 0x08; fix = (dd & mask) | (fix << 0x08); dd >>= 0x08; fix = (dd & mask) | (fix << 0x08); dd >>= 0x08; @@ -83,6 +87,7 @@ _nrrdSwap64Endian(void *_data, size_t N) { fix = (dd & mask) | (fix << 0x08); dd >>= 0x08; fix = (dd & mask) | (fix << 0x08); dd >>= 0x08; fix = (dd & mask) | (fix << 0x08); + /* clang-format on */ data[I] = fix; } } @@ -96,7 +101,7 @@ _nrrdNoopEndian(void *data, size_t N) { static void _nrrdBlockEndian(void *data, size_t N) { - char me[]="_nrrdBlockEndian"; + static const char me[] = "_nrrdBlockEndian"; AIR_UNUSED(data); AIR_UNUSED(N); @@ -104,28 +109,25 @@ _nrrdBlockEndian(void *data, size_t N) { airEnumStr(nrrdType, nrrdTypeBlock)); } -static void -(*_nrrdSwapEndian[])(void *, size_t) = { - _nrrdNoopEndian, /* 0: nobody knows! */ - _nrrdNoopEndian, /* 1: signed 1-byte integer */ - _nrrdNoopEndian, /* 2: unsigned 1-byte integer */ - _nrrdSwap16Endian, /* 3: signed 2-byte integer */ - _nrrdSwap16Endian, /* 4: unsigned 2-byte integer */ - _nrrdSwap32Endian, /* 5: signed 4-byte integer */ - _nrrdSwap32Endian, /* 6: unsigned 4-byte integer */ - _nrrdSwap64Endian, /* 7: signed 8-byte integer */ - _nrrdSwap64Endian, /* 8: unsigned 8-byte integer */ - _nrrdSwap32Endian, /* 9: 4-byte floating point */ - _nrrdSwap64Endian, /* 10: 8-byte floating point */ - _nrrdBlockEndian /* 11: size user defined at run time */ +static void (*_nrrdSwapEndian[])(void *, size_t) = { + _nrrdNoopEndian, /* 0: nobody knows! */ + _nrrdNoopEndian, /* 1: signed 1-byte integer */ + _nrrdNoopEndian, /* 2: unsigned 1-byte integer */ + _nrrdSwap16Endian, /* 3: signed 2-byte integer */ + _nrrdSwap16Endian, /* 4: unsigned 2-byte integer */ + _nrrdSwap32Endian, /* 5: signed 4-byte integer */ + _nrrdSwap32Endian, /* 6: unsigned 4-byte integer */ + _nrrdSwap64Endian, /* 7: signed 8-byte integer */ + _nrrdSwap64Endian, /* 8: unsigned 8-byte integer */ + _nrrdSwap32Endian, /* 9: 4-byte floating point */ + _nrrdSwap64Endian, /* 10: 8-byte floating point */ + _nrrdBlockEndian /* 11: size user defined at run time */ }; void nrrdSwapEndian(Nrrd *nrrd) { - if (nrrd - && nrrd->data - && !airEnumValCheck(nrrdType, nrrd->type)) { + if (nrrd && nrrd->data && !airEnumValCheck(nrrdType, nrrd->type)) { _nrrdSwapEndian[nrrd->type](nrrd->data, nrrdElementNumber(nrrd)); } return; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/enum.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/enum.c index 50ee847fa42..d6a76f8b281 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/enum.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/enum.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -61,7 +61,7 @@ _airEnumIndex(const airEnum *enm, int val) { ret = 0; if (enm->val) { - for (ii=1; ii<=enm->M; ii++) { + for (ii = 1; ii <= enm->M; ii++) { if (val == enm->val[ii]) { ret = ii; break; @@ -103,7 +103,7 @@ airEnumDesc(const airEnum *enm, int val) { int airEnumVal(const airEnum *enm, const char *str) { - char *strCpy, test[AIR_STRLEN_SMALL]; + char *strCpy, test[AIR_STRLEN_SMALL + 1]; unsigned int ii; if (!str) { @@ -118,8 +118,8 @@ airEnumVal(const airEnum *enm, const char *str) { if (enm->strEqv) { /* want strlen and not airStrlen here because the strEqv array should be terminated by a non-null empty string */ - for (ii=0; strlen(enm->strEqv[ii]); ii++) { - airStrcpy(test, AIR_STRLEN_SMALL, enm->strEqv[ii]); + for (ii = 0; strlen(enm->strEqv[ii]); ii++) { + airStrcpy(test, AIR_STRLEN_SMALL + 1, enm->strEqv[ii]); if (!enm->sense) { airToLower(test); } @@ -130,8 +130,8 @@ airEnumVal(const airEnum *enm, const char *str) { } } else { /* enm->strEqv NULL */ - for (ii=1; ii<=enm->M; ii++) { - airStrcpy(test, AIR_STRLEN_SMALL, enm->str[ii]); + for (ii = 1; ii <= enm->M; ii++) { + airStrcpy(test, AIR_STRLEN_SMALL + 1, enm->str[ii]); if (!enm->sense) { airToLower(test); } @@ -148,25 +148,24 @@ airEnumVal(const airEnum *enm, const char *str) { } /* -******** airEnumFmtDesc() -** -** Formats a description line for one element "val" of airEnum "enm", -** and puts the result in a NEWLY ALLOCATED string which is the return -** of this function. The formatting is done via sprintf(), as governed -** by "fmt", which should contain to "%s" conversion sequences, the -** first for the string version "val", and the second for the -** description If "canon", then the canonical string representation -** will be used (the one in enm->str[]), otherwise the shortest string -** representation will be used (which differs from the canonical one -** when there is a strEqv[]/valEqv[] pair defining a shorter string) -*/ + ******* airEnumFmtDesc() + * + * Formats a description line for one element `val` of airEnum `enm`, and puts the result + * in a NEWLY ALLOCATED string which is the return of this function. The formatting is + * done via snprintf(), as governed by `fmt`, which should contain two `%s` conversion + * sequences, the first for the string version `val`, and the second for the description. + * If `canon`, then the canonical string representation will be used (the one in + * enm->str[]), otherwise the shortest string representation will be used (which differs + * from the canonical one when there is a strEqv[]/valEqv[] pair defining a shorter + * string) + */ char * airEnumFmtDesc(const airEnum *enm, int val, int canon, const char *fmt) { const char *desc; - char *buff, ident[AIR_STRLEN_SMALL]; + char *buff, ident[AIR_STRLEN_SMALL + 1]; const char *_ident; int i; - size_t len; + size_t bsize, len; if (!(enm && enm->desc && fmt)) { return airStrdup("(airEnumDesc: invalid args)"); @@ -177,7 +176,7 @@ airEnumFmtDesc(const airEnum *enm, int val, int canon, const char *fmt) { _ident = airEnumStr(enm, val); if (!canon && enm->strEqv) { len = airStrlen(_ident); - for (i=0; airStrlen(enm->strEqv[i]); i++) { + for (i = 0; airStrlen(enm->strEqv[i]); i++) { if (val != enm->valEqv[i]) { /* this isn't a string representing the value we care about */ continue; @@ -189,15 +188,16 @@ airEnumFmtDesc(const airEnum *enm, int val, int canon, const char *fmt) { } } } - airStrcpy(ident, AIR_STRLEN_SMALL, _ident); + airStrcpy(ident, AIR_STRLEN_SMALL + 1, _ident); if (!enm->sense) { airToLower(ident); } desc = enm->desc[_airEnumIndex(enm, val)]; - buff = AIR_CALLOC(airStrlen(fmt) + airStrlen(ident) + - airStrlen(desc) + 1, char); + bsize = airStrlen(fmt) + airStrlen(ident) + airStrlen(desc) + 1; + buff = AIR_CALLOC(bsize, char); if (buff) { - sprintf(buff, fmt, ident, desc); + /* snprintf just in case our math is wrong */ + snprintf(buff, bsize, fmt, ident, desc); } return buff; } @@ -210,12 +210,11 @@ _enumPrintVal(FILE *file, const airEnum *enm, int ii) { } if (enm->strEqv) { unsigned int jj; - fprintf(file, "eqv:"); fflush(file); + fprintf(file, "eqv:"); + fflush(file); jj = 0; while (airStrlen(enm->strEqv[jj])) { - if (enm->valEqv[jj] == (enm->val - ? enm->val[ii] - : ii)) { + if (enm->valEqv[jj] == (enm->val ? enm->val[ii] : ii)) { fprintf(file, " \"%s\"", enm->strEqv[jj]); } jj++; @@ -243,9 +242,8 @@ airEnumPrint(FILE *file, const airEnum *enm) { if (enm->val) { fprintf(file, "Values (%u valid) given explicitly\n", enm->M); fprintf(file, "--- (0) %d: \"%s\"\n", enm->val[0], enm->str[0]); - for (ii=1; ii<=AIR_CAST(int, enm->M); ii++) { - fprintf(file, "--- (%d) %d: \"%s\" == \"%s\"\n", ii, - enm->val[ii], enm->str[ii], + for (ii = 1; ii <= AIR_INT(enm->M); ii++) { + fprintf(file, "--- (%d) %d: \"%s\" == \"%s\"\n", ii, enm->val[ii], enm->str[ii], airEnumStr(enm, enm->val[ii])); _enumPrintVal(file, enm, ii); } @@ -253,9 +251,8 @@ airEnumPrint(FILE *file, const airEnum *enm) { /* enm->val NULL */ fprintf(file, "Values implicit; [1,%u] valid\n", enm->M); fprintf(file, "--- 0: \"%s\"\n", enm->str[0]); - for (ii=1; ii<=AIR_CAST(int, enm->M); ii++) { - fprintf(file, "--- %d: %s == %s\n", ii, enm->str[ii], - airEnumStr(enm, ii)); + for (ii = 1; ii <= AIR_INT(enm->M); ii++) { + fprintf(file, "--- %d: %s == %s\n", ii, enm->str[ii], airEnumStr(enm, ii)); _enumPrintVal(file, enm, ii); } } diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/enumsNrrd.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/enumsNrrd.c index 987be14d014..dcafdf10713 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/enumsNrrd.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/enumsNrrd.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -24,7 +24,7 @@ */ #include "NrrdIO.h" - +/* clang-format off */ /* ** Rules of thumb for editing these things. The airEnum definitions are ** unfortunately EXTREMELY sensitive to small typo errors, and there is @@ -92,7 +92,7 @@ _nrrdFormatTypeValEqv[] = { nrrdFormatTypeEPS, }; -airEnum +static const airEnum _nrrdFormatType = { "format", NRRD_FORMAT_TYPE_MAX, @@ -183,7 +183,7 @@ _nrrdTypeValEqv[] = { ntBL, }; -airEnum +static const airEnum _nrrdType = { "type", NRRD_TYPE_MAX, @@ -205,6 +205,7 @@ _nrrdEncodingTypeStr[NRRD_ENCODING_TYPE_MAX+1] = { "hex", "gz", "bz2", + "zrl" }; static const char * @@ -215,6 +216,7 @@ _nrrdEncodingTypeDesc[NRRD_ENCODING_TYPE_MAX+1] = { "case-insenstive hexadecimal encoding (2 chars / byte)", "gzip compression of binary encoding", "bzip2 compression of binary encoding", + "simple compression by encoding run-length of zeros", }; static const char * @@ -224,6 +226,7 @@ _nrrdEncodingTypeStrEqv[] = { "hex", "gz", "gzip", "bz2", "bzip2", + "zrl", "" }; @@ -234,9 +237,10 @@ _nrrdEncodingTypeValEqv[] = { nrrdEncodingTypeHex, nrrdEncodingTypeGzip, nrrdEncodingTypeGzip, nrrdEncodingTypeBzip2, nrrdEncodingTypeBzip2, + nrrdEncodingTypeZRL }; -airEnum +static const airEnum _nrrdEncodingType = { "encoding", NRRD_ENCODING_TYPE_MAX, @@ -657,24 +661,30 @@ nrrdField = &_nrrdField; /* nrrdSpaceUnknown, - nrrdSpaceRightAnteriorSuperior, * 1: NIFTI-1 (right-handed) * - nrrdSpaceLeftAnteriorSuperior, * 2: standard Analyze (left-handed) * - nrrdSpaceLeftPosteriorSuperior, * 3: DICOM 3.0 (right-handed) * - nrrdSpaceRightAnteriorSuperiorTime, * 4: * - nrrdSpaceLeftAnteriorSuperiorTime, * 5: * - nrrdSpaceLeftPosteriorSuperiorTime, * 6: * - nrrdSpaceScannerXYZ, * 7: ACR/NEMA 2.0 (pre-DICOM 3.0) * - nrrdSpaceScannerXYZTime, * 8: * - nrrdSpace3DRightHanded, * 9: * - nrrdSpace3DLeftHanded, * 10: * - nrrdSpace3DRightHandedTime, * 11: * - nrrdSpace3DLeftHandedTime, * 12: * + nrrdSpaceRightUp, * 1: 2-D, oriented like upper right + Cartesian quadrant, number I * + nrrdSpaceRightDown, * 2: 2-D, oriented like raster + coordinates * + nrrdSpaceRightAnteriorSuperior, * 3: NIFTI-1 (right-handed) * + nrrdSpaceLeftAnteriorSuperior, * 4: standard Analyze (left-handed) * + nrrdSpaceLeftPosteriorSuperior, * 5: DICOM 3.0 (right-handed) * + nrrdSpaceRightAnteriorSuperiorTime, * 6: * + nrrdSpaceLeftAnteriorSuperiorTime, * 7: * + nrrdSpaceLeftPosteriorSuperiorTime, * 8: * + nrrdSpaceScannerXYZ, * 9: ACR/NEMA 2.0 (pre-DICOM 3.0) * + nrrdSpaceScannerXYZTime, * 10: * + nrrdSpace3DRightHanded, * 11: * + nrrdSpace3DLeftHanded, * 12: * + nrrdSpace3DRightHandedTime, * 13: * + nrrdSpace3DLeftHandedTime, * 14: * nrrdSpaceLast */ static const char * _nrrdSpaceStr[NRRD_SPACE_MAX+1] = { "(unknown_space)", + "right-up", + "right-down", "right-anterior-superior", "left-anterior-superior", "left-posterior-superior", @@ -692,6 +702,8 @@ _nrrdSpaceStr[NRRD_SPACE_MAX+1] = { static const char * _nrrdSpaceDesc[NRRD_SPACE_MAX+1] = { "unknown space", + "right-up (like Cartesian quadrant I)", + "right-down (like raster coordinates)", "right-anterior-superior (used in NIFTI-1 and SPL's 3D Slicer)", "left-anterior-superior (used in Analyze 7.5)", "left-posterior-superior (used in DICOM 3)", @@ -708,6 +720,8 @@ _nrrdSpaceDesc[NRRD_SPACE_MAX+1] = { static const char * _nrrdSpaceStrEqv[] = { + "right-up", "right up", + "right-down", "right down", "right-anterior-superior", "right anterior superior", "rightanteriorsuperior", "RAS", "left-anterior-superior", "left anterior superior", @@ -733,6 +747,8 @@ _nrrdSpaceStrEqv[] = { static const int _nrrdSpaceValEqv[] = { + nrrdSpaceRightUp, nrrdSpaceRightUp, + nrrdSpaceRightDown, nrrdSpaceRightDown, nrrdSpaceRightAnteriorSuperior, nrrdSpaceRightAnteriorSuperior, nrrdSpaceRightAnteriorSuperior, nrrdSpaceRightAnteriorSuperior, nrrdSpaceLeftAnteriorSuperior, nrrdSpaceLeftAnteriorSuperior, @@ -779,7 +795,7 @@ _nrrdSpacingStatusStr[NRRD_SPACING_STATUS_MAX+1] = { }; static const char * -_nrrdSpacingStatusDesc[NRRD_BOUNDARY_MAX+1] = { +_nrrdSpacingStatusDesc[NRRD_SPACING_STATUS_MAX+1] = { "unknown spacing status behavior", "neither axis->spacing nor axis->spaceDirection set", "axis->spacing set normally", @@ -798,4 +814,3 @@ _nrrdSpacingStatus = { }; const airEnum *const nrrdSpacingStatus = &_nrrdSpacingStatus; - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/format.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/format.c index 2d40a430f2c..bc8c804134e 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/format.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/format.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -62,14 +62,14 @@ _nrrdFormatUnknown_nameLooksLike(const char *filename) { return AIR_FALSE; } -static int +static int /* Biff: maybe:3:AIR_FALSE */ _nrrdFormatUnknown_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, int useBiff) { - static const char me[]="_nrrdFormatUnknown_fitsInto"; + static const char me[] = "_nrrdFormatUnknown_fitsInto"; if (!(nrrd && encoding)) { - biffMaybeAddf(useBiff, NRRD, "%s: got NULL nrrd (%p) or encoding (%p)", - me, AIR_CVOIDP(nrrd), AIR_CVOIDP(encoding)); + biffMaybeAddf(useBiff, NRRD, "%s: got NULL nrrd (%p) or encoding (%p)", me, + AIR_CVOIDP(nrrd), AIR_CVOIDP(encoding)); return AIR_FALSE; } @@ -87,10 +87,9 @@ _nrrdFormatUnknown_contentStartsLike(NrrdIoState *nio) { return AIR_FALSE; } -static int -_nrrdFormatUnknown_read(FILE *file, Nrrd *nrrd, - NrrdIoState *nio) { - static const char me[]="_nrrdFormatUnknown_read"; +static int /* Biff: 1 */ +_nrrdFormatUnknown_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { + static const char me[] = "_nrrdFormatUnknown_read"; /* insert code here, and remove error handling below */ AIR_UNUSED(file); @@ -101,10 +100,9 @@ _nrrdFormatUnknown_read(FILE *file, Nrrd *nrrd, return 1; } -static int -_nrrdFormatUnknown_write(FILE *file, const Nrrd *nrrd, - NrrdIoState *nio) { - static const char me[]="_nrrdFormatUnknown_write"; +static int /* Biff: 1 */ +_nrrdFormatUnknown_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { + static const char me[] = "_nrrdFormatUnknown_write"; /* insert code here, and remove error handling below */ AIR_UNUSED(file); @@ -115,30 +113,24 @@ _nrrdFormatUnknown_write(FILE *file, const Nrrd *nrrd, return 1; } -static const NrrdFormat -_nrrdFormatUnknown = { - "unknown", - AIR_FALSE, /* isImage */ - AIR_TRUE, /* readable */ - AIR_FALSE, /* usesDIO */ - _nrrdFormatUnknown_available, - _nrrdFormatUnknown_nameLooksLike, - _nrrdFormatUnknown_fitsInto, - _nrrdFormatUnknown_contentStartsLike, - _nrrdFormatUnknown_read, - _nrrdFormatUnknown_write -}; - -const NrrdFormat *const -nrrdFormatUnknown = &_nrrdFormatUnknown; - -const NrrdFormat *const -nrrdFormatArray[NRRD_FORMAT_TYPE_MAX+1] = { - &_nrrdFormatUnknown, - &_nrrdFormatNRRD, - &_nrrdFormatPNM, - &_nrrdFormatPNG, - &_nrrdFormatVTK, - &_nrrdFormatText, - &_nrrdFormatEPS +static const NrrdFormat _nrrdFormatUnknown = {"unknown", + AIR_FALSE, /* isImage */ + AIR_TRUE, /* readable */ + _nrrdFormatUnknown_available, + _nrrdFormatUnknown_nameLooksLike, + _nrrdFormatUnknown_fitsInto, + _nrrdFormatUnknown_contentStartsLike, + _nrrdFormatUnknown_read, + _nrrdFormatUnknown_write}; + +const NrrdFormat *const nrrdFormatUnknown = &_nrrdFormatUnknown; + +const NrrdFormat *const nrrdFormatArray[NRRD_FORMAT_TYPE_MAX + 1] = { + &_nrrdFormatUnknown, /* */ + &_nrrdFormatNRRD, /* */ + &_nrrdFormatPNM, /* */ + &_nrrdFormatPNG, /* */ + &_nrrdFormatVTK, /* */ + &_nrrdFormatText, /* */ + &_nrrdFormatEPS /* */ }; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatEPS.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatEPS.c index c2e5fa84ebf..f8c0ea0bb91 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatEPS.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatEPS.c @@ -1,8 +1,8 @@ /* NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,80 +26,73 @@ #include "NrrdIO.h" #include "privateNrrd.h" -int +static int _nrrdFormatEPS_available(void) { return AIR_FALSE; } -int +static int _nrrdFormatEPS_nameLooksLike(const char *filename) { return airEndsWith(filename, NRRD_EXT_EPS); } -int -_nrrdFormatEPS_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, - int useBiff) { - char me[]="_nrrdFormatEPS_fitsInto", err[AIR_STRLEN_MED]; +static int /* Biff: maybe:3:AIR_FALSE */ +_nrrdFormatEPS_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, int useBiff) { + static const char me[] = "_nrrdFormatEPS_fitsInto"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(nrrd); AIR_UNUSED(encoding); AIR_UNUSED(useBiff); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatEPS->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatEPS->name); biffMaybeAdd(NRRD, err, useBiff); return AIR_FALSE; - } -int +static int _nrrdFormatEPS_contentStartsLike(NrrdIoState *nio) { AIR_UNUSED(nio); + /* this is a write-only format */ return AIR_FALSE; - } -int +static int /* Biff: 1 */ _nrrdFormatEPS_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdReadEPS", err[AIR_STRLEN_MED]; + static const char me[] = "_nrrdFormatEPS_read"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatEPS->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatEPS->name); biffAdd(NRRD, err); return 1; } -int -_nrrdFormatEPS_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdFormatEPS_write", err[AIR_STRLEN_MED]; +static int /* Biff: 1 */ +_nrrdFormatEPS_write(FILE *file, const Nrrd *_nrrd, NrrdIoState *nio) { + static const char me[] = "_nrrdFormatEPS_write"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); - AIR_UNUSED(nrrd); + AIR_UNUSED(_nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatEPS->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatEPS->name); biffAdd(NRRD, err); return 1; } -const NrrdFormat -_nrrdFormatEPS = { - "EPS", - AIR_FALSE, /* isImage */ - AIR_FALSE, /* readable */ - AIR_FALSE, /* usesDIO */ - _nrrdFormatEPS_available, - _nrrdFormatEPS_nameLooksLike, - _nrrdFormatEPS_fitsInto, - _nrrdFormatEPS_contentStartsLike, - _nrrdFormatEPS_read, - _nrrdFormatEPS_write -}; - -const NrrdFormat *const -nrrdFormatEPS = &_nrrdFormatEPS; +const NrrdFormat _nrrdFormatEPS = {"EPS", + AIR_FALSE, /* isImage */ + AIR_FALSE, /* readable */ + _nrrdFormatEPS_available, + _nrrdFormatEPS_nameLooksLike, + _nrrdFormatEPS_fitsInto, + _nrrdFormatEPS_contentStartsLike, + _nrrdFormatEPS_read, + _nrrdFormatEPS_write}; + +const NrrdFormat *const nrrdFormatEPS = &_nrrdFormatEPS; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatNRRD.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatNRRD.c index 8818ab29d11..3012be7eae5 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatNRRD.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatNRRD.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -137,20 +137,19 @@ On output: **** ***/ -#define MAGIC "NRRD" +#define MGIC "NRRD" #define MAGIC0 "NRRD00.01" #define MAGIC1 "NRRD0001" #define MAGIC2 "NRRD0002" #define MAGIC3 "NRRD0003" #define MAGIC4 "NRRD0004" #define MAGIC5 "NRRD0005" +#define MAGIC6 "NRRD0006" -const char * -_nrrdFormatURLLine0 = "Complete NRRD file format specification at:"; -const char * -_nrrdFormatURLLine1 = "http://teem.sourceforge.net/nrrd/format.html"; +const char *const _nrrdFormatURLLine0 = "Complete NRRD file format specification at:"; +const char *const _nrrdFormatURLLine1 = "http://teem.sourceforge.net/nrrd/format.html"; -void +static void nrrdIoStateDataFileIterBegin(NrrdIoState *nio) { nio->dataFNIndex = 0; @@ -164,9 +163,7 @@ nrrdIoStateDataFileIterBegin(NrrdIoState *nio) { ** else str[1] != ':' ** if str[0] = '/', its a normal full path, return false */ -#define _NEED_PATH(str) (strcmp("-", (str)) \ - && ':' != (str)[1] \ - && '/' != (str)[0]) +#define _NEED_PATH(str) (strcmp("-", (str)) && ':' != (str)[1] && '/' != (str)[0]) /* ** this is responsible for the header-relative path processing @@ -176,25 +173,27 @@ nrrdIoStateDataFileIterBegin(NrrdIoState *nio) { ** ** NOTE: this should work okay with nio->headerStringRead, I think ... */ -int +static int /* Biff: 1 */ nrrdIoStateDataFileIterNext(FILE **fileP, NrrdIoState *nio, int reading) { - static const char me[]="nrrdIoStateDataFileIterNext"; - char *fname=NULL; + static const char me[] = "nrrdIoStateDataFileIterNext"; + char *fname = NULL; int ii, needPath; unsigned int num, fi; size_t maxl; airArray *mop; mop = airMopNew(); - airMopAdd(mop, (void*)fileP, (airMopper)airSetNull, airMopOnError); + airMopAdd(mop, (void *)fileP, (airMopper)airSetNull, airMopOnError); if (!fileP) { biffAddf(NRRD, "%s: got NULL pointer", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } if (!_nrrdDataFNNumber(nio)) { biffAddf(NRRD, "%s: there appear to be zero datafiles!", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } if (nio->dataFNIndex >= _nrrdDataFNNumber(nio)) { @@ -216,19 +215,21 @@ nrrdIoStateDataFileIterNext(FILE **fileP, NrrdIoState *nio, int reading) { /* assuming 10-digit integers is plenty big */ maxl = 10 + strlen(nio->dataFNFormat); } else { - for (fi=0; fidataFNArr->len; fi++) { + for (fi = 0; fi < nio->dataFNArr->len; fi++) { needPath |= _NEED_PATH(nio->dataFN[fi]); maxl = AIR_MAX(maxl, strlen(nio->dataFN[fi])); } } if (needPath && !airStrlen(nio->path)) { biffAddf(NRRD, "%s: need nio->path for header-relative datafiles", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } - fname = (char*)malloc(airStrlen(nio->path) + strlen("/") + maxl + 1); + fname = (char *)malloc(airStrlen(nio->path) + strlen("/") + maxl + 1); if (!fname) { biffAddf(NRRD, "%s: couldn't allocate filename buffer", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } airMopAdd(mop, fname, airFree, airMopAlways); } @@ -238,9 +239,8 @@ nrrdIoStateDataFileIterNext(FILE **fileP, NrrdIoState *nio, int reading) { /* --------- base.%d [] ------------- */ /* ---------------------------------------------------------- */ num = 0; - for (ii = nio->dataFNMin; - ((nio->dataFNStep > 0 && ii <= nio->dataFNMax) - || (nio->dataFNStep < 0 && ii >= nio->dataFNMax)); + for (ii = nio->dataFNMin; ((nio->dataFNStep > 0 && ii <= nio->dataFNMax) + || (nio->dataFNStep < 0 && ii >= nio->dataFNMax)); ii += nio->dataFNStep) { if (num == nio->dataFNIndex) { break; @@ -269,10 +269,11 @@ nrrdIoStateDataFileIterNext(FILE **fileP, NrrdIoState *nio, int reading) { if (nio->dataFNFormat || nio->dataFNArr->len) { *fileP = airFopen(fname, reading ? stdin : stdout, reading ? "rb" : "wb"); if (!(*fileP)) { - biffAddf(NRRD, "%s: couldn't open \"%s\" (data file %u of %u) for %s", - me, fname, nio->dataFNIndex+1, _nrrdDataFNNumber(nio), + biffAddf(NRRD, "%s: couldn't open \"%s\" (data file %u of %u) for %s", me, fname, + nio->dataFNIndex + 1, _nrrdDataFNNumber(nio), reading ? "reading" : "writing"); - airMopError(mop); return 1; + airMopError(mop); + return 1; } } else { /* data file is attached */ @@ -291,13 +292,18 @@ nrrdIoStateDataFileIterNext(FILE **fileP, NrrdIoState *nio, int reading) { } /* -** we try to use the oldest format that will hold the nrrd +** we try to use the oldest format that will hold the nrrd; this +** function will determine which NRRD00XX magic gets used for the +** output file */ -int +int /* Biff: (private) nope */ _nrrdFormatNRRD_whichVersion(const Nrrd *nrrd, NrrdIoState *nio) { int ret; - if (_nrrdFieldInteresting(nrrd, nio, nrrdField_measurement_frame)) { + if (nrrdEncodingZRL == nio->encoding || nrrdSpaceRightUp == nrrd->space + || nrrdSpaceRightDown == nrrd->space) { + ret = 6; + } else if (_nrrdFieldInteresting(nrrd, nio, nrrdField_measurement_frame)) { ret = 5; } else if (_nrrdFieldInteresting(nrrd, nio, nrrdField_thicknesses) || _nrrdFieldInteresting(nrrd, nio, nrrdField_space) @@ -324,18 +330,16 @@ _nrrdFormatNRRD_available(void) { static int _nrrdFormatNRRD_nameLooksLike(const char *filename) { - return (airEndsWith(filename, NRRD_EXT_NRRD) - || airEndsWith(filename, NRRD_EXT_NHDR)); + return (airEndsWith(filename, NRRD_EXT_NRRD) || airEndsWith(filename, NRRD_EXT_NHDR)); } -static int -_nrrdFormatNRRD_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, - int useBiff) { - static const char me[]="_nrrdFormatNRRD_fitsInto"; +static int /* Biff: maybe:3:AIR_FALSE */ +_nrrdFormatNRRD_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, int useBiff) { + static const char me[] = "_nrrdFormatNRRD_fitsInto"; - if (!( nrrd && encoding )) { - biffMaybeAddf(useBiff, NRRD, "%s: got NULL nrrd (%p) or encoding (%p)", - me, AIR_CVOIDP(nrrd), AIR_CVOIDP(encoding)); + if (!(nrrd && encoding)) { + biffMaybeAddf(useBiff, NRRD, "%s: got NULL nrrd (%p) or encoding (%p)", me, + AIR_CVOIDP(nrrd), AIR_CVOIDP(encoding)); return AIR_FALSE; } @@ -346,13 +350,10 @@ _nrrdFormatNRRD_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, static int _nrrdFormatNRRD_contentStartsLike(NrrdIoState *nio) { - return (!strcmp(MAGIC0, nio->line) - || !strcmp(MAGIC1, nio->line) - || !strcmp(MAGIC2, nio->line) - || !strcmp(MAGIC3, nio->line) - || !strcmp(MAGIC4, nio->line) - || !strcmp(MAGIC5, nio->line) - ); + return (!strcmp(MAGIC0, nio->line) || !strcmp(MAGIC1, nio->line) + || !strcmp(MAGIC2, nio->line) || !strcmp(MAGIC3, nio->line) + || !strcmp(MAGIC4, nio->line) || !strcmp(MAGIC5, nio->line) + || !strcmp(MAGIC6, nio->line)); } /* @@ -367,16 +368,16 @@ _nrrdFormatNRRD_contentStartsLike(NrrdIoState *nio) { ** nrrdCheck(), because it includes I/O-specific stuff ** */ -int +int /* Biff: (private) 1 */ _nrrdHeaderCheck(Nrrd *nrrd, NrrdIoState *nio, int checkSeen) { - static const char me[]="_nrrdHeaderCheck"; + static const char me[] = "_nrrdHeaderCheck"; int i; if (checkSeen) { - for (i=1; i<=NRRD_FIELD_MAX; i++) { + for (i = 1; i <= NRRD_FIELD_MAX; i++) { if (_nrrdFieldRequired[i] && !nio->seen[i]) { - biffAddf(NRRD, "%s: didn't see required field: %s", - me, airEnumStr(nrrdField, i)); + biffAddf(NRRD, "%s: didn't see required field: %s", me, + airEnumStr(nrrdField, i)); return 1; } } @@ -393,12 +394,10 @@ _nrrdHeaderCheck(Nrrd *nrrd, NrrdIoState *nio, int checkSeen) { } /* _nrrdReadNrrdParse_sizes() checks axis[i].size, which completely determines the return of nrrdElementNumber() */ - if (airEndianUnknown == nio->endian - && nio->encoding->endianMatters + if (airEndianUnknown == nio->endian && nio->encoding->endianMatters && 1 != nrrdElementSize(nrrd)) { biffAddf(NRRD, "%s: type (%s) and encoding (%s) require %s info", me, - airEnumStr(nrrdType, nrrd->type), - nio->encoding->name, + airEnumStr(nrrdType, nrrd->type), nio->encoding->name, airEnumStr(nrrdField, nrrdField_endian)); return 1; } @@ -421,16 +420,15 @@ _nrrdHeaderCheck(Nrrd *nrrd, NrrdIoState *nio, int checkSeen) { ** NOTE: by giving a NULL "file", you can make this function basically ** do the work of reading in datafiles, without any header parsing */ -static int +static int /* Biff: 1 */ _nrrdFormatNRRD_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="_nrrdFormatNRRD_read"; + static const char me[] = "_nrrdFormatNRRD_read"; /* Dynamically allocated for space reasons. */ - /* MWC: These strlen usages look really unsafe. */ int ret; unsigned int llen; size_t valsPerPiece; char *data; - FILE *dataFile=NULL; + FILE *dataFile = NULL; /* record where the header is being read from for the sake of nrrdIoStateDataFileIterNext() */ @@ -441,45 +439,97 @@ _nrrdFormatNRRD_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { /* nio->headerStringRead is NULL whenever IO from string is not being done */ if (file || nio->headerStringRead) { if (!_nrrdFormatNRRD_contentStartsLike(nio)) { - biffAddf(NRRD, "%s: this doesn't look like a %s file", me, - nrrdFormatNRRD->name); + biffAddf(NRRD, "%s: this doesn't look like a %s file", me, nrrdFormatNRRD->name); return 1; } /* parse all the header lines */ do { nio->pos = 0; - if (_nrrdOneLine(&llen, nio, file)) { + if (nrrdOneLine(&llen, nio, file)) { biffAddf(NRRD, "%s: trouble getting line of header", me); return 1; } + if (nio && nio->verbose > 3) { + printf("%s: got line |%s|@%p len %u\n", me, nio->line, AIR_VOIDP(nio->line), + llen); + } if (llen > 1) { + char *nioLineSave = NULL; ret = _nrrdReadNrrdParseField(nio, AIR_TRUE); + if (nio && nio->verbose > 3) { + printf("%s: parsed field %d = %s\n", me, ret, airEnumStr(nrrdField, ret)); + } if (!ret) { - biffAddf(NRRD, "%s: trouble parsing NRRD field identifier from " - "in \"%s\"", me, nio->line); + biffAddf(NRRD, + "%s: trouble parsing NRRD field identifier from " + "in \"%s\"", + me, nio->line); return 1; } /* comments and key/values are allowed multiple times */ - if (nio->seen[ret] - && !(ret == nrrdField_comment || ret == nrrdField_keyvalue)) { - biffAddf(NRRD, "%s: already set field %s", me, - airEnumStr(nrrdField, ret)); + if (nio->seen[ret] && !(ret == nrrdField_comment || ret == nrrdField_keyvalue)) { + biffAddf(NRRD, "%s: already set field %s", me, airEnumStr(nrrdField, ret)); return 1; } + /* belated TeemV2 2025 fix: Format spec says: + (end of 2nd paragraph of Section 1.2 Basic header structure) + ... Extra whitespace after the field descriptor and before the line + termination is ignored. + (One nitpick: this can't mean all " \t\n\r\v\f" whitespace; + so probably it just just means " \t" aka _nrrdFieldSep) + BUT WOW the code does not actually done this (at least not the code as it + arrives to us in 2025). So what to do. Rather than do the right-trim within every + nrrdFieldInfoParse[field]() function, we do it here. But, should we do it on + every possible field, or do we avoid doing it on those that might care about the + full content of the line, even the trailing whitespace? We opt for the latter + (the more cautious approach). */ + if (ret /* */ + && ret != nrrdField_comment /* */ + && ret != nrrdField_content /* */ + && ret != nrrdField_keyvalue /* */ + && ret != nrrdField_data_file) { + char *info = nio->line + nio->pos; + char *last = info + strlen(info) - 1; + while (last > info && _nrrdCharIsFieldSep(last[0])) { + last--; + } + /* stopped when `last` hit non-fieldsep char; back off */ + last++; + if (last[0]) { /* if not at the original '\0' termination of `info` */ + if (nio && nio->verbose > 3) { + printf("%s: removing trailing |%s| from %s info |%s|\n", me, last, + airEnumStr(nrrdField, ret), info); + } + last[0] = '\0'; + } + } + /* We need this nioLineSave because *IF* the field ret is nrrdField_data_file, + then parseNrrd.c/_nrrdReadNrrdParse_data_file() is going to re-use nio->line, + which means that the error message below will print garbage */ + if (nrrdField_data_file == ret) { + nioLineSave = airStrdup(nio->line + nio->pos); + } else { + nioLineSave = NULL; + } + if (nio && nio->verbose > 3) { + printf("%s: about to parse %s info |%s|\n", me, airEnumStr(nrrdField, ret), + nio->line + nio->pos); + } if (nrrdFieldInfoParse[ret](file, nrrd, nio, AIR_TRUE)) { biffAddf(NRRD, "%s: trouble parsing %s info |%s|", me, - airEnumStr(nrrdField, ret), nio->line + nio->pos); + airEnumStr(nrrdField, ret), + nioLineSave ? nioLineSave : nio->line + nio->pos); + airFree(nioLineSave); return 1; } + airFree(nioLineSave); nio->seen[ret] = AIR_TRUE; } } while (llen > 1); /* either 0 == llen: we're at EOF (or end of nio->headerStringRead), or 1 == llen: we just read the empty line separating header from data */ - if (0 == llen - && !nio->headerStringRead - && !nio->dataFNFormat + if (0 == llen && !nio->headerStringRead && !nio->dataFNFormat && 0 == nio->dataFNArr->len) { /* we're at EOF, we're not reading from a string, but there's apparently no separate data file */ @@ -491,7 +541,7 @@ _nrrdFormatNRRD_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { if (_nrrdHeaderCheck(nrrd, nio, !!file)) { biffAddf(NRRD, "%s: %s", me, (llen ? "finished reading header, but there were problems" - : "hit EOF before seeing a complete valid header")); + : "hit EOF before seeing a complete valid header")); return 1; } @@ -507,18 +557,18 @@ _nrrdFormatNRRD_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { nrrd->data = NULL; data = NULL; } else { - if (_nrrdCalloc(nrrd, nio, dataFile)) { + if (_nrrdCalloc(nrrd, nio)) { biffAddf(NRRD, "%s: couldn't allocate memory for data", me); return 1; } - data = (char*)nrrd->data; + data = (char *)nrrd->data; } /* iterate through datafiles and read them in */ /* NOTE: you have to open dataFile even in the case of skipData, because caller might have set keepNrrdDataFileOpen, in which case you need to do any line or byte skipping if it is specified */ - valsPerPiece = nrrdElementNumber(nrrd)/_nrrdDataFNNumber(nio); + valsPerPiece = nrrdElementNumber(nrrd) / _nrrdDataFNNumber(nio); while (dataFile) { /* ---------------- skip, if need be */ if (nrrdLineSkip(dataFile, nio)) { @@ -528,26 +578,45 @@ _nrrdFormatNRRD_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { if (!nio->encoding->isCompression) { /* bytes are skipped here for non-compression encodings, but are skipped within the decompressed stream for compression encodings */ - if (nrrdByteSkip(dataFile, nrrd, nio)) { - biffAddf(NRRD, "%s: couldn't skip bytes", me); - return 1; + if (nio->dataFSkip) { + /* this error checking is clearly done unnecessarily repeated, + but it was logically the simplest place to add it */ + if (nio->byteSkip) { + biffAddf(NRRD, + "%s: using per-list-line skip, " + "but also set global byte skip %ld", + me, nio->byteSkip); + return 1; + } + /* wow, the meaning of nio->dataFNIndex is a little confusing */ + if (_nrrdByteSkipSkip(dataFile, nrrd, nio, + nio->dataFSkip[nio->dataFNIndex - 1])) { + biffAddf(NRRD, "%s: couldn't skip %ld bytes on for list line %u", me, + nio->dataFSkip[nio->dataFNIndex - 1], nio->dataFNIndex - 1); + return 1; + } + } else { + if (nrrdByteSkip(dataFile, nrrd, nio)) { + biffAddf(NRRD, "%s: couldn't skip bytes", me); + return 1; + } } } /* ---------------- read the data itself */ - if (2 <= nrrdStateVerboseIO) { + if (nio && nio->verbose >= 2) { fprintf(stderr, "(%s: reading %s data ... ", me, nio->encoding->name); fflush(stderr); } if (!nio->skipData) { if (nio->encoding->read(dataFile, data, valsPerPiece, nrrd, nio)) { - if (2 <= nrrdStateVerboseIO) { + if (nio && nio->verbose >= 2) { fprintf(stderr, "error!\n"); } biffAddf(NRRD, "%s:", me); return 1; } } - if (2 <= nrrdStateVerboseIO) { + if (nio && nio->verbose >= 2) { fprintf(stderr, "done)\n"); } /* ---------------- go to next data file */ @@ -558,7 +627,7 @@ _nrrdFormatNRRD_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { dataFile = airFclose(dataFile); } } - data += valsPerPiece*nrrdElementSize(nrrd); + data += valsPerPiece * nrrdElementSize(nrrd); if (nrrdIoStateDataFileIterNext(&dataFile, nio, AIR_TRUE)) { biffAddf(NRRD, "%s: couldn't get the next datafile", me); return 1; @@ -567,16 +636,15 @@ _nrrdFormatNRRD_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { if (airEndianUnknown != nio->endian && nrrd->data) { /* we positively know the endianness of data just read */ - if (1 < nrrdElementSize(nrrd) - && nio->encoding->endianMatters + if (1 < nrrdElementSize(nrrd) && nio->encoding->endianMatters && nio->endian != airMyEndian()) { /* endianness exposed in encoding, and its wrong */ - if (2 <= nrrdStateVerboseIO) { + if (nio && nio->verbose >= 2) { fprintf(stderr, "(%s: fixing endianness ... ", me); fflush(stderr); } nrrdSwapEndian(nrrd); - if (2 <= nrrdStateVerboseIO) { + if (nio && nio->verbose >= 2) { fprintf(stderr, "done)\n"); fflush(stderr); } @@ -586,31 +654,32 @@ _nrrdFormatNRRD_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { return 0; } -static int +static int /* Biff: 1 */ _nrrdFormatNRRD_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="_nrrdFormatNRRD_write"; - char strbuf[AIR_STRLEN_MED], *strptr, *tmp; + static const char me[] = "_nrrdFormatNRRD_write"; + char strbuf[AIR_STRLEN_MED + 1], *strptr, *tmp; int ii; unsigned int jj; airArray *mop; - FILE *dataFile=NULL; + FILE *dataFile = NULL; size_t valsPerPiece; char *data; mop = airMopNew(); - if (!(file - || nio->headerStringWrite - || nio->learningHeaderStrlen)) { - biffAddf(NRRD, "%s: have no file or string to write to, nor are " - "learning header string length", me); - airMopError(mop); return 1; + if (!(file || nio->headerStringWrite || nio->learningHeaderStrlen)) { + biffAddf(NRRD, + "%s: have no file or string to write to, nor are " + "learning header string length", + me); + airMopError(mop); + return 1; } if (nrrdTypeBlock == nrrd->type && nrrdEncodingAscii == nio->encoding) { biffAddf(NRRD, "%s: can't write nrrd type %s with %s encoding", me, - airEnumStr(nrrdType, nrrdTypeBlock), - nrrdEncodingAscii->name); - airMopError(mop); return 1; + airEnumStr(nrrdType, nrrdTypeBlock), nrrdEncodingAscii->name); + airMopError(mop); + return 1; } /* record where the header is being written to for the sake of @@ -620,9 +689,7 @@ _nrrdFormatNRRD_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { /* we have to make sure that the data filename information is set (if needed), so that it can be printed by _nrrdFprintFieldInfo */ - if (nio->detachedHeader - && !nio->dataFNFormat - && 0 == nio->dataFNArr->len) { + if (nio->detachedHeader && !nio->dataFNFormat && 0 == nio->dataFNArr->len) { /* NOTE: this means someone requested a detached header, but we don't already have implicit (via dataFNFormat) or explicit (via dataFN[]) information about the data file */ @@ -634,36 +701,40 @@ _nrrdFormatNRRD_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { a name in dataFN[0] will trump the name implied by nio->{path,base}, which is a useful way for the user to explicitly set the output data filename (as with unu make -od) */ - if (!( !!airStrlen(nio->path) && !!airStrlen(nio->base) )) { - biffAddf(NRRD, "%s: can't create data file name: nio's " - "path and base empty", me); - airMopError(mop); return 1; + if (!(!!airStrlen(nio->path) && !!airStrlen(nio->base))) { + biffAddf(NRRD, + "%s: can't create data file name: nio's " + "path and base empty", + me); + airMopError(mop); + return 1; } - tmp = (char*)malloc(strlen(nio->base) - + strlen(".") - + strlen(nio->encoding->suffix) + 1); + tmp = (char *)malloc(strlen(nio->base) + strlen(".") + strlen(nio->encoding->suffix) + + 1); if (!tmp) { biffAddf(NRRD, "%s: couldn't allocate data filename", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } airMopAdd(mop, tmp, airFree, airMopOnError); sprintf(tmp, "%s.%s", nio->base, nio->encoding->suffix); jj = airArrayLenIncr(nio->dataFNArr, 1); if (!nio->dataFNArr->data) { biffAddf(NRRD, "%s: can't increase dataFNArr storage", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } nio->dataFN[jj] = tmp; } /* the magic is in fact the first thing to be written */ if (file) { - fprintf(file, "%s%04d\n", MAGIC, _nrrdFormatNRRD_whichVersion(nrrd, nio)); + fprintf(file, "%s%04d\n", MGIC, _nrrdFormatNRRD_whichVersion(nrrd, nio)); } else if (nio->headerStringWrite) { - sprintf(nio->headerStringWrite, "%s%04d\n", - MAGIC, _nrrdFormatNRRD_whichVersion(nrrd, nio)); + sprintf(nio->headerStringWrite, "%s%04d\n", MGIC, + _nrrdFormatNRRD_whichVersion(nrrd, nio)); } else { - nio->headerStrlen = AIR_CAST(unsigned int, strlen(MAGIC) + strlen("0000")) + 1; + nio->headerStrlen = AIR_UINT(strlen(MGIC) + strlen("0000")) + 1; } /* write the advertisement about where to get the file format */ @@ -683,12 +754,12 @@ _nrrdFormatNRRD_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { } /* this is where the majority of the header printing happens */ - for (ii=1; ii<=NRRD_FIELD_MAX; ii++) { + for (ii = 1; ii <= NRRD_FIELD_MAX; ii++) { if (_nrrdFieldInteresting(nrrd, nio, ii)) { if (file) { - _nrrdFprintFieldInfo(file, "", nrrd, nio, ii); + _nrrdFprintFieldInfo(file, "", nrrd, nio, ii, AIR_FALSE); } else if (nio->headerStringWrite) { - _nrrdSprintFieldInfo(&strptr, "", nrrd, nio, ii); + _nrrdSprintFieldInfo(&strptr, "", nrrd, nio, ii, AIR_FALSE); if (strptr) { strcat(nio->headerStringWrite, strptr); strcat(nio->headerStringWrite, "\n"); @@ -696,10 +767,10 @@ _nrrdFormatNRRD_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { strptr = NULL; } } else { - _nrrdSprintFieldInfo(&strptr, "", nrrd, nio, ii); + _nrrdSprintFieldInfo(&strptr, "", nrrd, nio, ii, AIR_FALSE); if (strptr) { - nio->headerStrlen += AIR_CAST(unsigned int, strlen(strptr)); - nio->headerStrlen += AIR_CAST(unsigned int, strlen("\n")); + nio->headerStrlen += AIR_UINT(strlen(strptr)); + nio->headerStrlen += AIR_UINT(strlen("\n")); free(strptr); strptr = NULL; } @@ -708,42 +779,39 @@ _nrrdFormatNRRD_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { } /* comments and key/value pairs handled differently */ - for (jj=0; jjcmtArr->len; jj++) { + for (jj = 0; jj < nrrd->cmtArr->len; jj++) { char *strtmp; strtmp = airOneLinify(airStrdup(nrrd->cmt[jj])); if (file) { fprintf(file, "%c %s\n", NRRD_COMMENT_CHAR, strtmp); } else if (nio->headerStringWrite) { - strptr = (char*)malloc(1 + strlen(" ") - + strlen(strtmp) + strlen("\n") + 1); + strptr = (char *)malloc(1 + strlen(" ") + strlen(strtmp) + strlen("\n") + 1); sprintf(strptr, "%c %s\n", NRRD_COMMENT_CHAR, strtmp); strcat(nio->headerStringWrite, strptr); free(strptr); strptr = NULL; } else { - nio->headerStrlen += (1 + AIR_CAST(unsigned int, strlen(" ") - + strlen(strtmp) - + strlen("\n")) + 1); + nio->headerStrlen += (1 + AIR_UINT(strlen(" ") + strlen(strtmp) + strlen("\n")) + + 1); } airFree(strtmp); } - for (jj=0; jjkvpArr->len; jj++) { + for (jj = 0; jj < nrrd->kvpArr->len; jj++) { if (file) { - _nrrdKeyValueWrite(file, NULL, - NULL, nrrd->kvp[0 + 2*jj], nrrd->kvp[1 + 2*jj]); + _nrrdKeyValueWrite(file, NULL, NULL, nrrd->kvp[0 + 2 * jj], nrrd->kvp[1 + 2 * jj]); } else if (nio->headerStringWrite) { - _nrrdKeyValueWrite(NULL, &strptr, - NULL, nrrd->kvp[0 + 2*jj], nrrd->kvp[1 + 2*jj]); + _nrrdKeyValueWrite(NULL, &strptr, NULL, nrrd->kvp[0 + 2 * jj], + nrrd->kvp[1 + 2 * jj]); if (strptr) { strcat(nio->headerStringWrite, strptr); free(strptr); strptr = NULL; } } else { - _nrrdKeyValueWrite(NULL, &strptr, - NULL, nrrd->kvp[0 + 2*jj], nrrd->kvp[1 + 2*jj]); + _nrrdKeyValueWrite(NULL, &strptr, NULL, nrrd->kvp[0 + 2 * jj], + nrrd->kvp[1 + 2 * jj]); if (strptr) { - nio->headerStrlen += AIR_CAST(unsigned int, strlen(strptr)); + nio->headerStrlen += AIR_UINT(strlen(strptr)); free(strptr); strptr = NULL; } @@ -751,7 +819,7 @@ _nrrdFormatNRRD_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { } if (file) { - if (!( nio->detachedHeader || _nrrdDataFNNumber(nio) > 1 )) { + if (!(nio->detachedHeader || _nrrdDataFNNumber(nio) > 1)) { fprintf(file, "\n"); } } @@ -760,35 +828,38 @@ _nrrdFormatNRRD_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { nrrdIoStateDataFileIterBegin(nio); if (nrrdIoStateDataFileIterNext(&dataFile, nio, AIR_FALSE)) { biffAddf(NRRD, "%s: couldn't write the first datafile", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } - valsPerPiece = nrrdElementNumber(nrrd)/_nrrdDataFNNumber(nio); - data = (char*)nrrd->data; + valsPerPiece = nrrdElementNumber(nrrd) / _nrrdDataFNNumber(nio); + data = (char *)nrrd->data; do { /* ---------------- write data */ - if (2 <= nrrdStateVerboseIO) { + if (nio && nio->verbose >= 2) { fprintf(stderr, "(%s: writing %s data ", me, nio->encoding->name); fflush(stderr); } if (nio->encoding->write(dataFile, data, valsPerPiece, nrrd, nio)) { - if (2 <= nrrdStateVerboseIO) { + if (nio && nio->verbose >= 2) { fprintf(stderr, "error!\n"); } biffAddf(NRRD, "%s: couldn't write %s data", me, nio->encoding->name); - airMopError(mop); return 1; + airMopError(mop); + return 1; } - if (2 <= nrrdStateVerboseIO) { + if (nio && nio->verbose >= 2) { fprintf(stderr, "done)\n"); } /* ---------------- go to next data file */ if (dataFile != nio->headerFile) { dataFile = airFclose(dataFile); } - data += valsPerPiece*nrrdElementSize(nrrd); + data += valsPerPiece * nrrdElementSize(nrrd); if (nrrdIoStateDataFileIterNext(&dataFile, nio, AIR_TRUE)) { biffAddf(NRRD, "%s: couldn't get the next datafile", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } } while (dataFile); } @@ -797,19 +868,14 @@ _nrrdFormatNRRD_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { return 0; } -const NrrdFormat -_nrrdFormatNRRD = { - "NRRD", - AIR_FALSE, /* isImage */ - AIR_TRUE, /* readable */ - AIR_TRUE, /* usesDIO */ - _nrrdFormatNRRD_available, - _nrrdFormatNRRD_nameLooksLike, - _nrrdFormatNRRD_fitsInto, - _nrrdFormatNRRD_contentStartsLike, - _nrrdFormatNRRD_read, - _nrrdFormatNRRD_write -}; - -const NrrdFormat *const -nrrdFormatNRRD = &_nrrdFormatNRRD; +const NrrdFormat _nrrdFormatNRRD = {"NRRD", + AIR_FALSE, /* isImage */ + AIR_TRUE, /* readable */ + _nrrdFormatNRRD_available, + _nrrdFormatNRRD_nameLooksLike, + _nrrdFormatNRRD_fitsInto, + _nrrdFormatNRRD_contentStartsLike, + _nrrdFormatNRRD_read, + _nrrdFormatNRRD_write}; + +const NrrdFormat *const nrrdFormatNRRD = &_nrrdFormatNRRD; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatPNG.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatPNG.c index 2c72cede641..9ea36160a27 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatPNG.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatPNG.c @@ -1,8 +1,8 @@ /* NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,80 +26,72 @@ #include "NrrdIO.h" #include "privateNrrd.h" -int +static int _nrrdFormatPNG_available(void) { return AIR_FALSE; } -int +static int _nrrdFormatPNG_nameLooksLike(const char *filename) { return airEndsWith(filename, NRRD_EXT_PNG); } -int -_nrrdFormatPNG_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, - int useBiff) { - char me[]="_nrrdFormatPNG_fitsInto", err[AIR_STRLEN_MED]; +static int /* Biff: maybe:3:AIR_FALSE */ +_nrrdFormatPNG_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, int useBiff) { + static const char me[] = "_nrrdFormatPNG_fitsInto"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(nrrd); AIR_UNUSED(encoding); AIR_UNUSED(useBiff); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatPNG->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatPNG->name); biffMaybeAdd(NRRD, err, useBiff); return AIR_FALSE; - } -int +static int _nrrdFormatPNG_contentStartsLike(NrrdIoState *nio) { AIR_UNUSED(nio); return AIR_FALSE; - } -int +static int /* Biff: 1 */ _nrrdFormatPNG_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdReadPNG", err[AIR_STRLEN_MED]; + static const char me[] = "_nrrdFormatPNG_read"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatPNG->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatPNG->name); biffAdd(NRRD, err); return 1; } -int +static int /* Biff: 1 */ _nrrdFormatPNG_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdFormatPNG_write", err[AIR_STRLEN_MED]; + static const char me[] = "_nrrdFormatPNG_write"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatPNG->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatPNG->name); biffAdd(NRRD, err); return 1; } -const NrrdFormat -_nrrdFormatPNG = { - "PNG", - AIR_FALSE, /* isImage */ - AIR_FALSE, /* readable */ - AIR_FALSE, /* usesDIO */ - _nrrdFormatPNG_available, - _nrrdFormatPNG_nameLooksLike, - _nrrdFormatPNG_fitsInto, - _nrrdFormatPNG_contentStartsLike, - _nrrdFormatPNG_read, - _nrrdFormatPNG_write -}; - -const NrrdFormat *const -nrrdFormatPNG = &_nrrdFormatPNG; +const NrrdFormat _nrrdFormatPNG = {"PNG", + AIR_FALSE, /* isImage */ + AIR_FALSE, /* readable */ + _nrrdFormatPNG_available, + _nrrdFormatPNG_nameLooksLike, + _nrrdFormatPNG_fitsInto, + _nrrdFormatPNG_contentStartsLike, + _nrrdFormatPNG_read, + _nrrdFormatPNG_write}; + +const NrrdFormat *const nrrdFormatPNG = &_nrrdFormatPNG; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatPNM.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatPNM.c index 1761fe1694f..60cda61712b 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatPNM.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatPNM.c @@ -1,8 +1,8 @@ /* NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,81 +26,72 @@ #include "NrrdIO.h" #include "privateNrrd.h" -int +static int _nrrdFormatPNM_available(void) { return AIR_FALSE; } -int +static int _nrrdFormatPNM_nameLooksLike(const char *filename) { - return (airEndsWith(filename, NRRD_EXT_PGM) - || airEndsWith(filename, NRRD_EXT_PPM)); + return (airEndsWith(filename, NRRD_EXT_PGM) || airEndsWith(filename, NRRD_EXT_PPM)); } -int -_nrrdFormatPNM_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, - int useBiff) { - char me[]="_nrrdFormatPNM_fitsInto", err[AIR_STRLEN_MED]; +static int /* Biff: maybe:3:AIR_FALSE */ +_nrrdFormatPNM_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, int useBiff) { + static const char me[] = "_nrrdFormatPNM_fitsInto"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(nrrd); AIR_UNUSED(encoding); AIR_UNUSED(useBiff); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatPNM->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatPNM->name); biffMaybeAdd(NRRD, err, useBiff); return AIR_FALSE; - } -int +static int _nrrdFormatPNM_contentStartsLike(NrrdIoState *nio) { AIR_UNUSED(nio); return AIR_FALSE; - } -int +static int /* Biff: 1 */ _nrrdFormatPNM_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdReadPNM", err[AIR_STRLEN_MED]; + static const char me[] = "_nrrdReadPNM"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatPNM->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatPNM->name); biffAdd(NRRD, err); return 1; } -int -_nrrdFormatPNM_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdFormatPNM_write", err[AIR_STRLEN_MED]; +static int /* Biff: 1 */ +_nrrdFormatPNM_write(FILE *file, const Nrrd *_nrrd, NrrdIoState *nio) { + static const char me[] = "_nrrdFormatPNM_write"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); - AIR_UNUSED(nrrd); + AIR_UNUSED(_nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatPNM->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatPNM->name); biffAdd(NRRD, err); return 1; } -const NrrdFormat -_nrrdFormatPNM = { - "PNM", - AIR_FALSE, /* isImage */ - AIR_FALSE, /* readable */ - AIR_FALSE, /* usesDIO */ - _nrrdFormatPNM_available, - _nrrdFormatPNM_nameLooksLike, - _nrrdFormatPNM_fitsInto, - _nrrdFormatPNM_contentStartsLike, - _nrrdFormatPNM_read, - _nrrdFormatPNM_write -}; - -const NrrdFormat *const -nrrdFormatPNM = &_nrrdFormatPNM; +const NrrdFormat _nrrdFormatPNM = {"PNM", + AIR_FALSE, /* isImage */ + AIR_FALSE, /* readable */ + _nrrdFormatPNM_available, + _nrrdFormatPNM_nameLooksLike, + _nrrdFormatPNM_fitsInto, + _nrrdFormatPNM_contentStartsLike, + _nrrdFormatPNM_read, + _nrrdFormatPNM_write}; + +const NrrdFormat *const nrrdFormatPNM = &_nrrdFormatPNM; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatText.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatText.c index 7c22202a8ee..0ae930a3193 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatText.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatText.c @@ -1,8 +1,8 @@ /* NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,82 +26,72 @@ #include "NrrdIO.h" #include "privateNrrd.h" -int +static int _nrrdFormatText_available(void) { - return AIR_FALSE; } -int +static int _nrrdFormatText_nameLooksLike(const char *fname) { - return (airEndsWith(fname, NRRD_EXT_TEXT) - || airEndsWith(fname, ".text") + return (airEndsWith(fname, NRRD_EXT_TEXT) || airEndsWith(fname, ".text") || airEndsWith(fname, ".ascii")); } -int -_nrrdFormatText_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, - int useBiff) { - char me[]="_nrrdFormatText_fitsInto", err[AIR_STRLEN_MED]; +static int /* Biff: maybe:3:AIR_FALSE */ +_nrrdFormatText_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, int useBiff) { + static const char me[] = "_nrrdFormatText_fitsInto"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(nrrd); AIR_UNUSED(encoding); AIR_UNUSED(useBiff); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatText->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatText->name); biffMaybeAdd(NRRD, err, useBiff); return AIR_FALSE; - } -int +static int _nrrdFormatText_contentStartsLike(NrrdIoState *nio) { AIR_UNUSED(nio); return AIR_FALSE; - } -int +static int /* Biff: 1 */ _nrrdFormatText_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdReadText", err[AIR_STRLEN_MED]; + static const char me[] = "_nrrdFormatText_read"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatText->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatText->name); biffAdd(NRRD, err); return 1; } -int +static int _nrrdFormatText_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdFormatText_write", err[AIR_STRLEN_MED]; + static const char me[] = "_nrrdFormatText_write"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatText->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatText->name); biffAdd(NRRD, err); return 1; } -const NrrdFormat -_nrrdFormatText = { - "text", - AIR_FALSE, /* isImage */ - AIR_FALSE, /* readable */ - AIR_FALSE, /* usesDIO */ - _nrrdFormatText_available, - _nrrdFormatText_nameLooksLike, - _nrrdFormatText_fitsInto, - _nrrdFormatText_contentStartsLike, - _nrrdFormatText_read, - _nrrdFormatText_write -}; - -const NrrdFormat *const -nrrdFormatText = &_nrrdFormatText; +const NrrdFormat _nrrdFormatText = {"text", + AIR_FALSE, /* isImage */ + AIR_FALSE, /* readable */ + _nrrdFormatText_available, + _nrrdFormatText_nameLooksLike, + _nrrdFormatText_fitsInto, + _nrrdFormatText_contentStartsLike, + _nrrdFormatText_read, + _nrrdFormatText_write}; + +const NrrdFormat *const nrrdFormatText = &_nrrdFormatText; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatVTK.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatVTK.c index 403e0a542b8..a64a9b70487 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatVTK.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/formatVTK.c @@ -1,8 +1,8 @@ /* NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,81 +26,73 @@ #include "NrrdIO.h" #include "privateNrrd.h" -int +static int _nrrdFormatVTK_available(void) { return AIR_FALSE; } -int +static int _nrrdFormatVTK_nameLooksLike(const char *fname) { return airEndsWith(fname, NRRD_EXT_VTK); } -int -_nrrdFormatVTK_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, - int useBiff) { - char me[]="_nrrdFormatVTK_fitsInto", err[AIR_STRLEN_MED]; +static int /* Biff: maybe:3:AIR_FALSE */ +_nrrdFormatVTK_fitsInto(const Nrrd *nrrd, const NrrdEncoding *encoding, int useBiff) { + static const char me[] = "_nrrdFormatVTK_fitsInto"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(nrrd); AIR_UNUSED(encoding); AIR_UNUSED(useBiff); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatVTK->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatVTK->name); biffMaybeAdd(NRRD, err, useBiff); return AIR_FALSE; - } -int +static int _nrrdFormatVTK_contentStartsLike(NrrdIoState *nio) { AIR_UNUSED(nio); return AIR_FALSE; - } -int +static int /* Biff: 1 */ _nrrdFormatVTK_read(FILE *file, Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdReadVTK", err[AIR_STRLEN_MED]; + static const char me[] = "_nrrdFormatVTK_read"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); AIR_UNUSED(nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatVTK->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatVTK->name); biffAdd(NRRD, err); return 1; } /* this strongly assumes that nrrdFitsInFormat() was true */ -int -_nrrdFormatVTK_write(FILE *file, const Nrrd *nrrd, NrrdIoState *nio) { - char me[]="_nrrdFormatVTK_write", err[AIR_STRLEN_MED]; +static int /* Biff: 1 */ +_nrrdFormatVTK_write(FILE *file, const Nrrd *_nrrd, NrrdIoState *nio) { + static const char me[] = "_nrrdFormatVTK_write"; + char err[AIR_STRLEN_MED]; AIR_UNUSED(file); - AIR_UNUSED(nrrd); + AIR_UNUSED(_nrrd); AIR_UNUSED(nio); - sprintf(err, "%s: Sorry, %s format not available in NrrdIO", - me, nrrdFormatVTK->name); + sprintf(err, "%s: Sorry, %s format not available in NrrdIO", me, nrrdFormatVTK->name); biffAdd(NRRD, err); return 1; } -const NrrdFormat -_nrrdFormatVTK = { - "VTK", - AIR_FALSE, /* isImage */ - AIR_FALSE, /* readable */ - AIR_FALSE, /* usesDIO */ - _nrrdFormatVTK_available, - _nrrdFormatVTK_nameLooksLike, - _nrrdFormatVTK_fitsInto, - _nrrdFormatVTK_contentStartsLike, - _nrrdFormatVTK_read, - _nrrdFormatVTK_write -}; - -const NrrdFormat *const -nrrdFormatVTK = &_nrrdFormatVTK; +const NrrdFormat _nrrdFormatVTK = {"VTK", + AIR_FALSE, /* isImage */ + AIR_FALSE, /* readable */ + _nrrdFormatVTK_available, + _nrrdFormatVTK_nameLooksLike, + _nrrdFormatVTK_fitsInto, + _nrrdFormatVTK_contentStartsLike, + _nrrdFormatVTK_read, + _nrrdFormatVTK_write}; + +const NrrdFormat *const nrrdFormatVTK = &_nrrdFormatVTK; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/gzio.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/gzio.c index 792d16bf4ed..4835e4b4993 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/gzio.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/gzio.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -57,69 +57,69 @@ #if TEEM_ZLIB -#include "NrrdIO.h" -#include "privateNrrd.h" +# include "NrrdIO.h" +# include "privateNrrd.h" -#ifdef _WIN32 /* Window 95 & Windows NT */ -# define _NRRD_OS_CODE 0x0b -#endif +# ifdef _WIN32 /* Window 95 & Windows NT */ +# define _NRRD_OS_CODE 0x0b +# endif -#if defined(MACOS) || defined(TARGET_OS_MAC) || defined(__APPLE_CC__) -# define _NRRD_OS_CODE 0x07 -#endif +# if defined(MACOS) || defined(TARGET_OS_MAC) || defined(__APPLE_CC__) +# define _NRRD_OS_CODE 0x07 +# endif -#ifndef _NRRD_OS_CODE -# define _NRRD_OS_CODE 0x03 /* assume Unix */ -#endif +# ifndef _NRRD_OS_CODE +# define _NRRD_OS_CODE 0x03 /* assume Unix */ +# endif /* default memLevel */ -#if MAX_MEM_LEVEL >= 8 -# define _NRRD_DEF_MEM_LEVEL 8 -#else -# define _NRRD_DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif +# if MAX_MEM_LEVEL >= 8 +# define _NRRD_DEF_MEM_LEVEL 8 +# else +# define _NRRD_DEF_MEM_LEVEL MAX_MEM_LEVEL +# endif /* stream buffer size */ -#define _NRRD_Z_BUFSIZE 16 * 1024 +# define _NRRD_Z_BUFSIZE 16 * 1024 /* gzip flag byte */ -#define _NRRD_ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ -#define _NRRD_HEAD_CRC 0x02 /* bit 1 set: header CRC present */ -#define _NRRD_EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ -#define _NRRD_ORIG_NAME 0x08 /* bit 3 set: original file name present */ -#define _NRRD_COMMENT 0x10 /* bit 4 set: file comment present */ -#define _NRRD_RESERVED 0xE0 /* bits 5..7: reserved */ +# define _NRRD_ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ +# define _NRRD_HEAD_CRC 0x02 /* bit 1 set: header CRC present */ +# define _NRRD_EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ +# define _NRRD_ORIG_NAME 0x08 /* bit 3 set: original file name present */ +# define _NRRD_COMMENT 0x10 /* bit 4 set: file comment present */ +# define _NRRD_RESERVED 0xE0 /* bits 5..7: reserved */ typedef struct _NrrdGzStream { z_stream stream; - int z_err; /* error code for last stream operation */ - int z_eof; /* set if end of input file */ - FILE *file; /* .gz file */ - Byte *inbuf; /* input buffer */ - Byte *outbuf; /* output buffer */ - uLong crc; /* crc32 of uncompressed data */ - char *msg; /* error message */ - int transparent; /* 1 if input file is not a .gz file */ - char mode; /* 'w' or 'r' */ - long startpos; /* start of compressed data in file (header skipped) */ + int z_err; /* error code for last stream operation */ + int z_eof; /* set if end of input file */ + FILE *file; /* .gz file */ + Byte *inbuf; /* input buffer */ + Byte *outbuf; /* output buffer */ + uLong crc; /* crc32 of uncompressed data */ + char *msg; /* error message */ + int transparent; /* 1 if input file is not a .gz file */ + char mode; /* 'w' or 'r' */ + long startpos; /* start of compressed data in file (header skipped) */ } _NrrdGzStream; static int _nrrdGzMagic[2] = {0x1f, 0x8b}; /* gzip magic header */ /* zlib error messages */ -static const char *_nrrdGzErrMsg[10] = { - "need dictionary", /* Z_NEED_DICT 2 */ - "stream end", /* Z_STREAM_END 1 */ - "", /* Z_OK 0 */ - "file error", /* Z_ERRNO (-1) */ - "stream error", /* Z_STREAM_ERROR (-2) */ - "data error", /* Z_DATA_ERROR (-3) */ - "insufficient memory", /* Z_MEM_ERROR (-4) */ - "buffer error", /* Z_BUF_ERROR (-5) */ - "incompatible version",/* Z_VERSION_ERROR (-6) */ - ""}; - -#define _NRRD_GZ_ERR_MSG(err) _nrrdGzErrMsg[Z_NEED_DICT-(err)] +static const char *_nrrdGzErrMsg[10] + = {"need dictionary", /* Z_NEED_DICT 2 */ + "stream end", /* Z_STREAM_END 1 */ + "", /* Z_OK 0 */ + "file error", /* Z_ERRNO (-1) */ + "stream error", /* Z_STREAM_ERROR (-2) */ + "data error", /* Z_DATA_ERROR (-3) */ + "insufficient memory", /* Z_MEM_ERROR (-4) */ + "buffer error", /* Z_BUF_ERROR (-5) */ + "incompatible version", /* Z_VERSION_ERROR (-6) */ + ""}; + +# define _NRRD_GZ_ERR_MSG(err) _nrrdGzErrMsg[Z_NEED_DICT - (err)] /* some forward declarations for things in this file */ static void _nrrdGzCheckHeader(_NrrdGzStream *s); @@ -157,26 +157,26 @@ static uLong _nrrdGzGetLong(_NrrdGzStream *s); ** can be checked to distinguish the two cases (if errno is zero, the ** zlib error is Z_MEM_ERROR). */ -gzFile -_nrrdGzOpen(FILE* fd, const char* mode) { - static const char me[]="_nrrdGzOpen"; +gzFile /* Biff: (private) (gzFile)Z_NULL */ +_nrrdGzOpen(FILE *fd, const char *mode) { + static const char me[] = "_nrrdGzOpen"; int error; int level = Z_DEFAULT_COMPRESSION; /* compression level */ int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */ const char *p = mode; _NrrdGzStream *s; - char fmode[AIR_STRLEN_MED]; /* copy of mode, without the compression level */ + char fmode[AIR_STRLEN_MED + 1]; /* copy of mode, without the compression level */ char *m = fmode; if (!mode) { biffAddf(NRRD, "%s: no file mode specified", me); - return Z_NULL; + return (gzFile)Z_NULL; } /* allocate stream struct */ s = (_NrrdGzStream *)calloc(1, sizeof(_NrrdGzStream)); if (!s) { biffAddf(NRRD, "%s: failed to allocate stream buffer", me); - return Z_NULL; + return (gzFile)Z_NULL; } /* initialize stream struct */ s->stream.zalloc = (alloc_func)0; @@ -208,22 +208,23 @@ _nrrdGzOpen(FILE* fd, const char* mode) { } while (*p++ && m != fmode + sizeof(fmode)); if (s->mode == '\0') { biffAddf(NRRD, "%s: invalid file mode", me); - return _nrrdGzDestroy(s), (gzFile)Z_NULL; + _nrrdGzDestroy(s); + return (gzFile)Z_NULL; } if (s->mode == 'w') { - error = deflateInit2(&(s->stream), level, - Z_DEFLATED, -MAX_WBITS, _NRRD_DEF_MEM_LEVEL, - strategy); + error = deflateInit2(&(s->stream), level, Z_DEFLATED, -MAX_WBITS, + _NRRD_DEF_MEM_LEVEL, strategy); /* windowBits is passed < 0 to suppress zlib header */ - s->stream.next_out = s->outbuf = (Byte*)calloc(1, _NRRD_Z_BUFSIZE); + s->stream.next_out = s->outbuf = (Byte *)calloc(1, _NRRD_Z_BUFSIZE); if (error != Z_OK || s->outbuf == Z_NULL) { biffAddf(NRRD, "%s: stream init failed", me); - return _nrrdGzDestroy(s), (gzFile)Z_NULL; + _nrrdGzDestroy(s); + return (gzFile)Z_NULL; } } else { - s->stream.next_in = s->inbuf = (Byte*)calloc(1, _NRRD_Z_BUFSIZE); + s->stream.next_in = s->inbuf = (Byte *)calloc(1, _NRRD_Z_BUFSIZE); error = inflateInit2(&(s->stream), -MAX_WBITS); /* windowBits is passed < 0 to tell that there is no zlib header. @@ -234,7 +235,8 @@ _nrrdGzOpen(FILE* fd, const char* mode) { */ if (error != Z_OK || s->inbuf == Z_NULL) { biffAddf(NRRD, "%s: stream init failed", me); - return _nrrdGzDestroy(s), (gzFile)Z_NULL; + _nrrdGzDestroy(s); + return (gzFile)Z_NULL; } } s->stream.avail_out = _NRRD_Z_BUFSIZE; @@ -242,16 +244,13 @@ _nrrdGzOpen(FILE* fd, const char* mode) { s->file = fd; if (s->file == NULL) { biffAddf(NRRD, "%s: null file pointer", me); - return _nrrdGzDestroy(s), (gzFile)Z_NULL; + _nrrdGzDestroy(s); + return (gzFile)Z_NULL; } if (s->mode == 'w') { /* Write a very simple .gz header: */ fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", _nrrdGzMagic[0], _nrrdGzMagic[1], - Z_DEFLATED, - 0 /*flags*/, - 0,0,0,0 /*time*/, - 0 /*xflags*/, - _NRRD_OS_CODE); + Z_DEFLATED, 0 /*flags*/, 0, 0, 0, 0 /*time*/, 0 /*xflags*/, _NRRD_OS_CODE); s->startpos = 10L; /* We use 10L instead of ftell(s->file) to because ftell causes an * fflush on some systems. This version of the library doesn't use @@ -271,11 +270,11 @@ _nrrdGzOpen(FILE* fd, const char* mode) { ** Flushes all pending output if necessary, closes the compressed file ** and deallocates the (de)compression state. */ -int -_nrrdGzClose (gzFile file) { - static const char me[]="_nrrdGzClose"; +int /* Biff: (private) 1 */ +_nrrdGzClose(gzFile file) { + static const char me[] = "_nrrdGzClose"; int error; - _NrrdGzStream *s = (_NrrdGzStream*)file; + _NrrdGzStream *s = (_NrrdGzStream *)file; if (s == NULL) { biffAddf(NRRD, "%s: invalid stream", me); @@ -285,12 +284,17 @@ _nrrdGzClose (gzFile file) { error = _nrrdGzDoFlush(file, Z_FINISH); if (error != Z_OK) { biffAddf(NRRD, "%s: failed to flush pending data", me); - return _nrrdGzDestroy((_NrrdGzStream*)file); + _nrrdGzDestroy((_NrrdGzStream *)file); + return 1; /* _nrrdGzDestroy's return does not communicate our known error */ } _nrrdGzPutLong(s->file, s->crc); _nrrdGzPutLong(s->file, s->stream.total_in); } - return _nrrdGzDestroy((_NrrdGzStream*)file); + if (_nrrdGzDestroy((_NrrdGzStream *)file)) { + biffAddf(NRRD, "%s: failed to clean up", me); + return 1; + } + return 0; } /* @@ -299,12 +303,12 @@ _nrrdGzClose (gzFile file) { ** Reads the given number of uncompressed bytes from the compressed file. ** Returns the number of bytes actually read (0 for end of file). */ -int -_nrrdGzRead(gzFile file, void* buf, unsigned int len, unsigned int* didread) { - static const char me[]="_nrrdGzRead"; - _NrrdGzStream *s = (_NrrdGzStream*)file; - Bytef *start = (Bytef*)buf; /* starting point for crc computation */ - Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ +int /* Biff: (private) 1 */ +_nrrdGzRead(gzFile file, void *buf, unsigned int len, unsigned int *didread) { + static const char me[] = "_nrrdGzRead"; + _NrrdGzStream *s = (_NrrdGzStream *)file; + Bytef *start = (Bytef *)buf; /* starting point for crc computation */ + Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ if (s == NULL || s->mode != 'r') { biffAddf(NRRD, "%s: invalid stream or file mode", me); @@ -320,11 +324,11 @@ _nrrdGzRead(gzFile file, void* buf, unsigned int len, unsigned int* didread) { if (s->z_err == Z_STREAM_END) { *didread = 0; - return 0; /* EOF */ + return 0; /* EOF */ } - next_out = (Byte*)buf; - s->stream.next_out = (Bytef*)buf; + next_out = (Byte *)buf; + s->stream.next_out = (Bytef *)buf; s->stream.avail_out = len; while (s->stream.avail_out != 0) { @@ -337,16 +341,15 @@ _nrrdGzRead(gzFile file, void* buf, unsigned int len, unsigned int* didread) { memcpy(s->stream.next_out, s->stream.next_in, n); next_out += n; s->stream.next_out = next_out; - s->stream.next_in += n; + s->stream.next_in += n; s->stream.avail_out -= n; - s->stream.avail_in -= n; + s->stream.avail_in -= n; } if (s->stream.avail_out > 0) { - s->stream.avail_out -= (uInt)fread(next_out, 1, s->stream.avail_out, - s->file); + s->stream.avail_out -= (uInt)fread(next_out, 1, s->stream.avail_out, s->file); } len -= s->stream.avail_out; - s->stream.total_in += len; + s->stream.total_in += len; s->stream.total_out += len; if (len == 0) s->z_eof = 1; *didread = len; @@ -406,11 +409,10 @@ _nrrdGzRead(gzFile file, void* buf, unsigned int len, unsigned int* didread) { ** Writes the given number of uncompressed bytes into the compressed file. ** Returns the number of bytes actually written (0 in case of error). */ -int -_nrrdGzWrite(gzFile file, const void* buf, unsigned int len, - unsigned int* written) { - static const char me[]="_nrrdGzWrite"; - _NrrdGzStream *s = (_NrrdGzStream*)file; +int /* Biff: (private) 1 */ +_nrrdGzWrite(gzFile file, const void *buf, unsigned int len, unsigned int *written) { + static const char me[] = "_nrrdGzWrite"; + _NrrdGzStream *s = (_NrrdGzStream *)file; void *nonconstbuf; if (s == NULL || s->mode != 'w') { @@ -424,8 +426,8 @@ _nrrdGzWrite(gzFile file, const void* buf, unsigned int len, zlib doesn't have all the consts that it should, and various code examples of using multiple casts to hide the problem. Here's a slow way that doesn't use mere casting to make the const go away */ - memcpy(&nonconstbuf, &buf, sizeof(void*)); - s->stream.next_in = (Bytef*)nonconstbuf; + memcpy(&nonconstbuf, &buf, sizeof(void *)); + s->stream.next_in = (Bytef *)nonconstbuf; s->stream.avail_in = len; while (s->stream.avail_in != 0) { @@ -433,13 +435,23 @@ _nrrdGzWrite(gzFile file, const void* buf, unsigned int len, s->stream.next_out = s->outbuf; if (fwrite(s->outbuf, 1, _NRRD_Z_BUFSIZE, s->file) != _NRRD_Z_BUFSIZE) { s->z_err = Z_ERRNO; - biffAddf(NRRD, "%s: failed to write to file", me); - break; + biffAddf(NRRD, "%s: failed to fwrite to file", me); + /* earlier code had a "break" here instead of return, which seemed to + permit the function returning 0 instead of 1; so doing the return here + and not trying to record any additional state in s */ + return 1; } s->stream.avail_out = _NRRD_Z_BUFSIZE; } s->z_err = deflate(&(s->stream), Z_NO_FLUSH); - if (s->z_err != Z_OK) break; + if (s->z_err != Z_OK) { + /* earlier code had a mere "break" here, which definitely meant that + the error was not reflected in the final return (always returned 0), + so adding info to biff (and also not trying to record anything in s) + */ + biffAddf(NRRD, "%s: s->z_err (%d) != Z_OK (%d)", me, s->z_err, Z_OK); + return 1; + } } s->crc = crc32(s->crc, (const Bytef *)buf, len); @@ -454,9 +466,9 @@ _nrrdGzWrite(gzFile file, const void* buf, unsigned int len, ** Returns EOF for end of file. ** IN assertion: the stream s has been sucessfully opened for reading. */ -static int +static int /* Biff: EOF */ _nrrdGzGetByte(_NrrdGzStream *s) { - static const char me[]="_nrrdGzGetByte"; + static const char me[] = "_nrrdGzGetByte"; if (s->z_eof) return EOF; if (s->stream.avail_in == 0) { @@ -489,7 +501,7 @@ _nrrdGzGetByte(_NrrdGzStream *s) { */ static void _nrrdGzCheckHeader(_NrrdGzStream *s) { - static const char me[]="_nrrdGzCheckHeader"; + /* static const char me[] = "_nrrdGzCheckHeader"; */ int method; /* method byte */ int flags; /* flags byte */ uInt len; @@ -511,30 +523,37 @@ _nrrdGzCheckHeader(_NrrdGzStream *s) { method = _nrrdGzGetByte(s); flags = _nrrdGzGetByte(s); if (method != Z_DEFLATED || (flags & _NRRD_RESERVED) != 0) { - biffAddf(NRRD, "%s: gzip compression method is not deflate", me); + /* (GLK) this (long-standing) biff usage is not acted on by any callers */ + /* biffAddf(NRRD, "%s: gzip compression method is not deflate", me); */ s->z_err = Z_DATA_ERROR; return; } /* Discard time, xflags and OS code: */ - for (len = 0; len < 6; len++) (void)_nrrdGzGetByte(s); + for (len = 0; len < 6; len++) + (void)_nrrdGzGetByte(s); if ((flags & _NRRD_EXTRA_FIELD) != 0) { /* skip the extra field */ - len = (uInt)_nrrdGzGetByte(s); - len += ((uInt)_nrrdGzGetByte(s))<<8; + len = (uInt)_nrrdGzGetByte(s); + len += ((uInt)_nrrdGzGetByte(s)) << 8; /* len is garbage if EOF but the loop below will quit anyway */ - while (len-- != 0 && _nrrdGzGetByte(s) != EOF) ; + while (len-- != 0 && _nrrdGzGetByte(s) != EOF) + ; } if ((flags & _NRRD_ORIG_NAME) != 0) { /* skip the original file name */ - while ((c = _nrrdGzGetByte(s)) != 0 && c != EOF) ; + while ((c = _nrrdGzGetByte(s)) != 0 && c != EOF) + ; } - if ((flags & _NRRD_COMMENT) != 0) { /* skip the .gz file comment */ - while ((c = _nrrdGzGetByte(s)) != 0 && c != EOF) ; + if ((flags & _NRRD_COMMENT) != 0) { /* skip the .gz file comment */ + while ((c = _nrrdGzGetByte(s)) != 0 && c != EOF) + ; } - if ((flags & _NRRD_HEAD_CRC) != 0) { /* skip the header crc */ - for (len = 0; len < 2; len++) (void)_nrrdGzGetByte(s); + if ((flags & _NRRD_HEAD_CRC) != 0) { /* skip the header crc */ + for (len = 0; len < 2; len++) + (void)_nrrdGzGetByte(s); } s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK; + return; } /* @@ -543,10 +562,12 @@ _nrrdGzCheckHeader(_NrrdGzStream *s) { ** Cleans up then free the given _NrrdGzStream. Returns a zlib error code. ** Try freeing in the reverse order of allocations. FILE* s->file is not ** closed. Because we didn't allocate it, we shouldn't delete it. +** +** Returns 1 (not an zlib error code) in case of error */ -static int +static int /* Biff: 1 */ _nrrdGzDestroy(_NrrdGzStream *s) { - static const char me[]="_nrrdGzDestroy"; + static const char me[] = "_nrrdGzDestroy"; int error = Z_OK; if (s == NULL) { @@ -562,16 +583,18 @@ _nrrdGzDestroy(_NrrdGzStream *s) { } } if (error != Z_OK) { - biffAddf(NRRD, "%s: %s", me, _NRRD_GZ_ERR_MSG(error)); + biffAddf(NRRD, "%s: %s (%d)", me, _NRRD_GZ_ERR_MSG(error), error); + return 1; } - if (s->z_err < 0) error = s->z_err; + if (s->z_err < 0) error = s->z_err; /* GLK is curious why */ if (error != Z_OK) { - biffAddf(NRRD, "%s: %s", me, _NRRD_GZ_ERR_MSG(error)); + biffAddf(NRRD, "%s: %s (%d)", me, _NRRD_GZ_ERR_MSG(error), error); + return 1; } s->inbuf = (Byte *)airFree(s->inbuf); s->outbuf = (Byte *)airFree(s->outbuf); - airFree(s); /* avoiding unused value warnings, no NULL set */ - return error != Z_OK; + airFree(s); + return 0; } /* @@ -580,12 +603,12 @@ _nrrdGzDestroy(_NrrdGzStream *s) { ** Flushes all pending output into the compressed file. The parameter ** flush is the same as in the deflate() function. */ -static int +static int /* Biff: Z_STREAM_ERROR */ _nrrdGzDoFlush(gzFile file, int flush) { - static const char me[]="_nrrdGzDoFlush"; + static const char me[] = "_nrrdGzDoFlush"; uInt len; int done = 0; - _NrrdGzStream *s = (_NrrdGzStream*)file; + _NrrdGzStream *s = (_NrrdGzStream *)file; if (s == NULL || s->mode != 'w') { biffAddf(NRRD, "%s: invalid stream or file mode", me); @@ -618,7 +641,7 @@ _nrrdGzDoFlush(gzFile file, int flush) { if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; } - return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; + return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; } /* @@ -627,7 +650,7 @@ _nrrdGzDoFlush(gzFile file, int flush) { ** Outputs a long in LSB order to the given file. */ static void -_nrrdGzPutLong(FILE* file, uLong x) { +_nrrdGzPutLong(FILE *file, uLong x) { int n; for (n = 0; n < 4; n++) { fputc((int)(x & 0xff), file); @@ -646,11 +669,11 @@ _nrrdGzGetLong(_NrrdGzStream *s) { uLong x = (uLong)_nrrdGzGetByte(s); int c; - x += ((uLong)_nrrdGzGetByte(s))<<8; - x += ((uLong)_nrrdGzGetByte(s))<<16; + x += ((uLong)_nrrdGzGetByte(s)) << 8; + x += ((uLong)_nrrdGzGetByte(s)) << 16; c = _nrrdGzGetByte(s); if (c == EOF) s->z_err = Z_DATA_ERROR; - x += ((uLong)c)<<24; + x += ((uLong)c) << 24; return x; } @@ -659,8 +682,7 @@ _nrrdGzGetLong(_NrrdGzStream *s) { /* ** random symbol to have in object file, even when Zlib not enabled */ -int +int /* Biff: (private) nope */ _nrrdGzDummySymbol(void) { return 42; } - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/itk_NrrdIO_mangle.h.in b/Modules/ThirdParty/NrrdIO/src/NrrdIO/itk_NrrdIO_mangle.h.in index 41a09eff2ac..09d896ad139 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/itk_NrrdIO_mangle.h.in +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/itk_NrrdIO_mangle.h.in @@ -1,26 +1,28 @@ -#ifndef itk_NrrdIO_mangle_h -#define itk_NrrdIO_mangle_h +#ifndef __@MANGLE_PREFIX@_NrrdIO_mangle_h__ +#define __@MANGLE_PREFIX@_NrrdIO_mangle_h__ /* -This header file mangles all symbols exported from the -NrrdIO library. It is included in all files while building -the NrrdIO library. Due to namespace pollution, no NrrdIO -headers should be included in .h files in ITK. +This header file mangles all symbols exported from the NrrdIO library, +to be included in all .c files while building NrrdIO in settings that +require symbol renaming. -This file was created via the mangle.pl script in the -NrrdIO distribution: +This file was made by the mangle.py script in the NrrdIO distribution: - perl mangle.pl @MANGLE_PREFIX@ > itk_NrrdIO_mangle.h + python mangle.py @MANGLE_PREFIX@ itk -This uses nm to list all text (T), data (D) symbols, as well -read-only (R) things (seen on Linux) and "other" (S) things -(seen on Mac). On Macs, the preceeding underscore is removed. +and then > redirecting that to the current file, via the "0-gen.sh itk" +script in the NrrdIO distribution. +This uses nm to list all text (T), data (D) symbols, as well as +read-only (R) things (on Linux) and "other" (S) things (on Mac). +On Macs, the preceding underscore is removed. -Also ensures that a few others starting with nrrd are included, and -prevents variables ending with .N* where N is some number, from inclusion. +This also ensures that a few others things starting with nrrd are +included, and prevents variables ending with .N* where N is some +number, from inclusion. */ #define airExists @MANGLE_PREFIX@_airExists +#define airFPClass_ae @MANGLE_PREFIX@_airFPClass_ae #define airFPClass_d @MANGLE_PREFIX@_airFPClass_d #define airFPClass_f @MANGLE_PREFIX@_airFPClass_f #define airFPFprintf_d @MANGLE_PREFIX@_airFPFprintf_d @@ -31,14 +33,12 @@ prevents variables ending with .N* where N is some number, from inclusion. #define airFPPartsToVal_f @MANGLE_PREFIX@_airFPPartsToVal_f #define airFPValToParts_d @MANGLE_PREFIX@_airFPValToParts_d #define airFPValToParts_f @MANGLE_PREFIX@_airFPValToParts_f +#define airFloatNaN @MANGLE_PREFIX@_airFloatNaN #define airFloatNegInf @MANGLE_PREFIX@_airFloatNegInf #define airFloatPosInf @MANGLE_PREFIX@_airFloatPosInf -#define airFloatQNaN @MANGLE_PREFIX@_airFloatQNaN -#define airFloatSNaN @MANGLE_PREFIX@_airFloatSNaN #define airIsInf_d @MANGLE_PREFIX@_airIsInf_d #define airIsInf_f @MANGLE_PREFIX@_airIsInf_f #define airIsNaN @MANGLE_PREFIX@_airIsNaN -#define airMyQNaNHiBit @MANGLE_PREFIX@_airMyQNaNHiBit #define airNaN @MANGLE_PREFIX@_airNaN #define airMopAdd @MANGLE_PREFIX@_airMopAdd #define airMopDebug @MANGLE_PREFIX@_airMopDebug @@ -59,27 +59,20 @@ prevents variables ending with .N* where N is some number, from inclusion. #define airArrayStructCB @MANGLE_PREFIX@_airArrayStructCB #define airAtod @MANGLE_PREFIX@_airAtod #define airBool @MANGLE_PREFIX@_airBool -#define airParseStr @MANGLE_PREFIX@_airParseStr #define airParseStrB @MANGLE_PREFIX@_airParseStrB #define airParseStrC @MANGLE_PREFIX@_airParseStrC #define airParseStrD @MANGLE_PREFIX@_airParseStrD #define airParseStrE @MANGLE_PREFIX@_airParseStrE #define airParseStrF @MANGLE_PREFIX@_airParseStrF +#define airParseStrH @MANGLE_PREFIX@_airParseStrH #define airParseStrI @MANGLE_PREFIX@_airParseStrI -#define airParseStrLI @MANGLE_PREFIX@_airParseStrLI +#define airParseStrL @MANGLE_PREFIX@_airParseStrL #define airParseStrS @MANGLE_PREFIX@_airParseStrS +#define airParseStrUH @MANGLE_PREFIX@_airParseStrUH #define airParseStrUI @MANGLE_PREFIX@_airParseStrUI -#define airParseStrULI @MANGLE_PREFIX@_airParseStrULI +#define airParseStrUL @MANGLE_PREFIX@_airParseStrUL #define airParseStrZ @MANGLE_PREFIX@_airParseStrZ #define airSingleSscanf @MANGLE_PREFIX@_airSingleSscanf -#define airDioInfo @MANGLE_PREFIX@_airDioInfo -#define airDioMalloc @MANGLE_PREFIX@_airDioMalloc -#define airDioRead @MANGLE_PREFIX@_airDioRead -#define airDioTest @MANGLE_PREFIX@_airDioTest -#define airDioWrite @MANGLE_PREFIX@_airDioWrite -#define airDisableDio @MANGLE_PREFIX@_airDisableDio -#define airMyDio @MANGLE_PREFIX@_airMyDio -#define airNoDioErr @MANGLE_PREFIX@_airNoDioErr #define airInsaneErr @MANGLE_PREFIX@_airInsaneErr #define airSanity @MANGLE_PREFIX@_airSanity #define airEndian @MANGLE_PREFIX@_airEndian @@ -92,7 +85,6 @@ prevents variables ending with .N* where N is some number, from inclusion. #define airStrlen @MANGLE_PREFIX@_airStrlen #define airStrntok @MANGLE_PREFIX@_airStrntok #define airStrtok @MANGLE_PREFIX@_airStrtok -#define airStrtokQuoting @MANGLE_PREFIX@_airStrtokQuoting #define airStrtrans @MANGLE_PREFIX@_airStrtrans #define airToLower @MANGLE_PREFIX@_airToLower #define airToUpper @MANGLE_PREFIX@_airToUpper @@ -114,7 +106,9 @@ prevents variables ending with .N* where N is some number, from inclusion. #define airSprintPtrdiff_t @MANGLE_PREFIX@_airSprintPtrdiff_t #define airSprintSize_t @MANGLE_PREFIX@_airSprintSize_t #define airTeemReleaseDate @MANGLE_PREFIX@_airTeemReleaseDate +#define airTeemReleaseDone @MANGLE_PREFIX@_airTeemReleaseDone #define airTeemVersion @MANGLE_PREFIX@_airTeemVersion +#define airTeemVersionSprint @MANGLE_PREFIX@_airTeemVersionSprint #define biffAdd @MANGLE_PREFIX@_biffAdd #define biffAddf @MANGLE_PREFIX@_biffAddf #define biffCheck @MANGLE_PREFIX@_biffCheck @@ -129,17 +123,13 @@ prevents variables ending with .N* where N is some number, from inclusion. #define biffSetStr @MANGLE_PREFIX@_biffSetStr #define _biffMsgAddVL @MANGLE_PREFIX@__biffMsgAddVL #define _biffMsgMoveVL @MANGLE_PREFIX@__biffMsgMoveVL -#define _biffMsgNoop @MANGLE_PREFIX@__biffMsgNoop #define biffMsgAdd @MANGLE_PREFIX@_biffMsgAdd #define biffMsgClear @MANGLE_PREFIX@_biffMsgClear #define biffMsgErrNum @MANGLE_PREFIX@_biffMsgErrNum -#define biffMsgLineLenMax @MANGLE_PREFIX@_biffMsgLineLenMax #define biffMsgMove @MANGLE_PREFIX@_biffMsgMove #define biffMsgMovef @MANGLE_PREFIX@_biffMsgMovef #define biffMsgNew @MANGLE_PREFIX@_biffMsgNew #define biffMsgNix @MANGLE_PREFIX@_biffMsgNix -#define biffMsgNoop @MANGLE_PREFIX@_biffMsgNoop -#define biffMsgStrAlloc @MANGLE_PREFIX@_biffMsgStrAlloc #define biffMsgStrGet @MANGLE_PREFIX@_biffMsgStrGet #define biffMsgStrSet @MANGLE_PREFIX@_biffMsgStrSet #define biffMsgStrlen @MANGLE_PREFIX@_biffMsgStrlen @@ -164,10 +154,11 @@ prevents variables ending with .N* where N is some number, from inclusion. #define _nrrdLLongMinHelp @MANGLE_PREFIX@__nrrdLLongMinHelp #define _nrrdULLongMaxHelp @MANGLE_PREFIX@__nrrdULLongMaxHelp #define nrrdDefaultCenter @MANGLE_PREFIX@_nrrdDefaultCenter -#define nrrdDefaultSpacing @MANGLE_PREFIX@_nrrdDefaultSpacing +#define nrrdDefaultVerboseIO @MANGLE_PREFIX@_nrrdDefaultVerboseIO #define nrrdDefaultWriteBareText @MANGLE_PREFIX@_nrrdDefaultWriteBareText #define nrrdDefaultWriteCharsPerLine @MANGLE_PREFIX@_nrrdDefaultWriteCharsPerLine #define nrrdDefaultWriteEncodingType @MANGLE_PREFIX@_nrrdDefaultWriteEncodingType +#define nrrdDefaultWriteMoreThanFloatInText @MANGLE_PREFIX@_nrrdDefaultWriteMoreThanFloatInText #define nrrdDefaultWriteValsPerLine @MANGLE_PREFIX@_nrrdDefaultWriteValsPerLine #define nrrdStateAlwaysSetContent @MANGLE_PREFIX@_nrrdStateAlwaysSetContent #define nrrdStateDisableContent @MANGLE_PREFIX@_nrrdStateDisableContent @@ -176,10 +167,6 @@ prevents variables ending with .N* where N is some number, from inclusion. #define nrrdStateKeyValueReturnInternalPointers @MANGLE_PREFIX@_nrrdStateKeyValueReturnInternalPointers #define nrrdStateKindNoop @MANGLE_PREFIX@_nrrdStateKindNoop #define nrrdStateUnknownContent @MANGLE_PREFIX@_nrrdStateUnknownContent -#define nrrdStateVerboseIO @MANGLE_PREFIX@_nrrdStateVerboseIO -#define _nrrdEncodingType @MANGLE_PREFIX@__nrrdEncodingType -#define _nrrdFormatType @MANGLE_PREFIX@__nrrdFormatType -#define _nrrdType @MANGLE_PREFIX@__nrrdType #define nrrdCenter @MANGLE_PREFIX@_nrrdCenter #define nrrdEncodingType @MANGLE_PREFIX@_nrrdEncodingType #define nrrdField @MANGLE_PREFIX@_nrrdField @@ -228,18 +215,13 @@ prevents variables ending with .N* where N is some number, from inclusion. #define _nrrdCenter @MANGLE_PREFIX@__nrrdCenter #define _nrrdCenter2 @MANGLE_PREFIX@__nrrdCenter2 #define _nrrdKindAltered @MANGLE_PREFIX@__nrrdKindAltered -#define _nrrdSpaceVecExists @MANGLE_PREFIX@__nrrdSpaceVecExists #define nrrdAxisInfoCopy @MANGLE_PREFIX@_nrrdAxisInfoCopy #define nrrdAxisInfoGet_nva @MANGLE_PREFIX@_nrrdAxisInfoGet_nva #define nrrdAxisInfoGet_va @MANGLE_PREFIX@_nrrdAxisInfoGet_va -#define nrrdAxisInfoIdx @MANGLE_PREFIX@_nrrdAxisInfoIdx -#define nrrdAxisInfoIdxRange @MANGLE_PREFIX@_nrrdAxisInfoIdxRange -#define nrrdAxisInfoMinMaxSet @MANGLE_PREFIX@_nrrdAxisInfoMinMaxSet #define nrrdAxisInfoPos @MANGLE_PREFIX@_nrrdAxisInfoPos #define nrrdAxisInfoPosRange @MANGLE_PREFIX@_nrrdAxisInfoPosRange #define nrrdAxisInfoSet_nva @MANGLE_PREFIX@_nrrdAxisInfoSet_nva #define nrrdAxisInfoSet_va @MANGLE_PREFIX@_nrrdAxisInfoSet_va -#define nrrdAxisInfoSpacingSet @MANGLE_PREFIX@_nrrdAxisInfoSpacingSet #define nrrdDomainAxesGet @MANGLE_PREFIX@_nrrdDomainAxesGet #define nrrdKindIsDomain @MANGLE_PREFIX@_nrrdKindIsDomain #define nrrdKindSize @MANGLE_PREFIX@_nrrdKindSize @@ -258,6 +240,7 @@ prevents variables ending with .N* where N is some number, from inclusion. #define nrrdCheck @MANGLE_PREFIX@_nrrdCheck #define nrrdContentSet_va @MANGLE_PREFIX@_nrrdContentSet_va #define nrrdDescribe @MANGLE_PREFIX@_nrrdDescribe +#define nrrdDescribeMore @MANGLE_PREFIX@_nrrdDescribeMore #define nrrdElementNumber @MANGLE_PREFIX@_nrrdElementNumber #define nrrdElementSize @MANGLE_PREFIX@_nrrdElementSize #define nrrdOriginCalculate @MANGLE_PREFIX@_nrrdOriginCalculate @@ -287,42 +270,34 @@ prevents variables ending with .N* where N is some number, from inclusion. #define nrrdKeyValueIndex @MANGLE_PREFIX@_nrrdKeyValueIndex #define nrrdKeyValueSize @MANGLE_PREFIX@_nrrdKeyValueSize #define nrrdSwapEndian @MANGLE_PREFIX@_nrrdSwapEndian -#define _nrrdContainsPercentThisAndMore @MANGLE_PREFIX@__nrrdContainsPercentThisAndMore #define _nrrdDataFNCheck @MANGLE_PREFIX@__nrrdDataFNCheck #define _nrrdDataFNNumber @MANGLE_PREFIX@__nrrdDataFNNumber #define _nrrdReadNrrdParseField @MANGLE_PREFIX@__nrrdReadNrrdParseField -#define _nrrdSpaceVectorParse @MANGLE_PREFIX@__nrrdSpaceVectorParse +#define nrrdContainsPercentThisAndMore @MANGLE_PREFIX@_nrrdContainsPercentThisAndMore #define nrrdFieldInfoParse @MANGLE_PREFIX@_nrrdFieldInfoParse +#define nrrdStringValsParse @MANGLE_PREFIX@_nrrdStringValsParse #define _nrrdGzClose @MANGLE_PREFIX@__nrrdGzClose #define _nrrdGzDummySymbol @MANGLE_PREFIX@__nrrdGzDummySymbol #define _nrrdGzOpen @MANGLE_PREFIX@__nrrdGzOpen #define _nrrdGzRead @MANGLE_PREFIX@__nrrdGzRead #define _nrrdGzWrite @MANGLE_PREFIX@__nrrdGzWrite +#define _nrrdByteSkipSkip @MANGLE_PREFIX@__nrrdByteSkipSkip #define _nrrdCalloc @MANGLE_PREFIX@__nrrdCalloc +#define _nrrdCharIsFieldSep @MANGLE_PREFIX@__nrrdCharIsFieldSep #define _nrrdFieldSep @MANGLE_PREFIX@__nrrdFieldSep -#define _nrrdHeaderStringOneLine @MANGLE_PREFIX@__nrrdHeaderStringOneLine -#define _nrrdHeaderStringOneLineStrlen @MANGLE_PREFIX@__nrrdHeaderStringOneLineStrlen -#define _nrrdLineSep @MANGLE_PREFIX@__nrrdLineSep #define _nrrdNoSpaceVector @MANGLE_PREFIX@__nrrdNoSpaceVector -#define _nrrdOneLine @MANGLE_PREFIX@__nrrdOneLine -#define _nrrdRead @MANGLE_PREFIX@__nrrdRead -#define _nrrdRelativePathFlag @MANGLE_PREFIX@__nrrdRelativePathFlag #define _nrrdSplitName @MANGLE_PREFIX@__nrrdSplitName #define _nrrdTextSep @MANGLE_PREFIX@__nrrdTextSep #define nrrdByteSkip @MANGLE_PREFIX@_nrrdByteSkip #define nrrdLineSkip @MANGLE_PREFIX@_nrrdLineSkip #define nrrdLoad @MANGLE_PREFIX@_nrrdLoad #define nrrdLoadMulti @MANGLE_PREFIX@_nrrdLoadMulti +#define nrrdOneLine @MANGLE_PREFIX@_nrrdOneLine #define nrrdRead @MANGLE_PREFIX@_nrrdRead #define nrrdStringRead @MANGLE_PREFIX@_nrrdStringRead -#define _nrrdEncodingMaybeSet @MANGLE_PREFIX@__nrrdEncodingMaybeSet #define _nrrdFieldInteresting @MANGLE_PREFIX@__nrrdFieldInteresting -#define _nrrdFormatMaybeGuess @MANGLE_PREFIX@__nrrdFormatMaybeGuess -#define _nrrdFormatMaybeSet @MANGLE_PREFIX@__nrrdFormatMaybeSet #define _nrrdFprintFieldInfo @MANGLE_PREFIX@__nrrdFprintFieldInfo #define _nrrdSprintFieldInfo @MANGLE_PREFIX@__nrrdSprintFieldInfo -#define _nrrdStrcatSpaceVector @MANGLE_PREFIX@__nrrdStrcatSpaceVector -#define _nrrdWrite @MANGLE_PREFIX@__nrrdWrite #define nrrdIoStateEncodingGet @MANGLE_PREFIX@_nrrdIoStateEncodingGet #define nrrdIoStateEncodingSet @MANGLE_PREFIX@_nrrdIoStateEncodingSet #define nrrdIoStateFormatGet @MANGLE_PREFIX@_nrrdIoStateFormatGet @@ -341,11 +316,6 @@ prevents variables ending with .N* where N is some number, from inclusion. #define _nrrdFormatURLLine1 @MANGLE_PREFIX@__nrrdFormatURLLine1 #define _nrrdHeaderCheck @MANGLE_PREFIX@__nrrdHeaderCheck #define nrrdFormatNRRD @MANGLE_PREFIX@_nrrdFormatNRRD -#define nrrdIoStateDataFileIterBegin @MANGLE_PREFIX@_nrrdIoStateDataFileIterBegin -#define nrrdIoStateDataFileIterNext @MANGLE_PREFIX@_nrrdIoStateDataFileIterNext -#define _nrrdEncodingUnknown @MANGLE_PREFIX@__nrrdEncodingUnknown -#define nrrdEncodingArray @MANGLE_PREFIX@_nrrdEncodingArray -#define nrrdEncodingUnknown @MANGLE_PREFIX@_nrrdEncodingUnknown #define _nrrdEncodingRaw @MANGLE_PREFIX@__nrrdEncodingRaw #define nrrdEncodingRaw @MANGLE_PREFIX@_nrrdEncodingRaw #define _nrrdEncodingAscii @MANGLE_PREFIX@__nrrdEncodingAscii @@ -354,51 +324,22 @@ prevents variables ending with .N* where N is some number, from inclusion. #define nrrdEncodingHex @MANGLE_PREFIX@_nrrdEncodingHex #define _nrrdEncodingGzip @MANGLE_PREFIX@__nrrdEncodingGzip #define nrrdEncodingGzip @MANGLE_PREFIX@_nrrdEncodingGzip -#define nrrdCrop @MANGLE_PREFIX@_nrrdCrop -#define nrrdSlice @MANGLE_PREFIX@_nrrdSlice +#define _nrrdEncodingZRL @MANGLE_PREFIX@__nrrdEncodingZRL +#define nrrdEncodingZRL @MANGLE_PREFIX@_nrrdEncodingZRL #define _nrrdEncodingBzip2 @MANGLE_PREFIX@__nrrdEncodingBzip2 -#define _nrrdEncodingBzip2_available @MANGLE_PREFIX@__nrrdEncodingBzip2_available -#define _nrrdEncodingBzip2_read @MANGLE_PREFIX@__nrrdEncodingBzip2_read -#define _nrrdEncodingBzip2_write @MANGLE_PREFIX@__nrrdEncodingBzip2_write #define nrrdEncodingBzip2 @MANGLE_PREFIX@_nrrdEncodingBzip2 +#define nrrdEncodingArray @MANGLE_PREFIX@_nrrdEncodingArray +#define nrrdEncodingUnknown @MANGLE_PREFIX@_nrrdEncodingUnknown +#define nrrdCrop @MANGLE_PREFIX@_nrrdCrop +#define nrrdSlice @MANGLE_PREFIX@_nrrdSlice #define _nrrdFormatEPS @MANGLE_PREFIX@__nrrdFormatEPS -#define _nrrdFormatEPS_available @MANGLE_PREFIX@__nrrdFormatEPS_available -#define _nrrdFormatEPS_contentStartsLike @MANGLE_PREFIX@__nrrdFormatEPS_contentStartsLike -#define _nrrdFormatEPS_fitsInto @MANGLE_PREFIX@__nrrdFormatEPS_fitsInto -#define _nrrdFormatEPS_nameLooksLike @MANGLE_PREFIX@__nrrdFormatEPS_nameLooksLike -#define _nrrdFormatEPS_read @MANGLE_PREFIX@__nrrdFormatEPS_read -#define _nrrdFormatEPS_write @MANGLE_PREFIX@__nrrdFormatEPS_write #define nrrdFormatEPS @MANGLE_PREFIX@_nrrdFormatEPS #define _nrrdFormatPNG @MANGLE_PREFIX@__nrrdFormatPNG -#define _nrrdFormatPNG_available @MANGLE_PREFIX@__nrrdFormatPNG_available -#define _nrrdFormatPNG_contentStartsLike @MANGLE_PREFIX@__nrrdFormatPNG_contentStartsLike -#define _nrrdFormatPNG_fitsInto @MANGLE_PREFIX@__nrrdFormatPNG_fitsInto -#define _nrrdFormatPNG_nameLooksLike @MANGLE_PREFIX@__nrrdFormatPNG_nameLooksLike -#define _nrrdFormatPNG_read @MANGLE_PREFIX@__nrrdFormatPNG_read -#define _nrrdFormatPNG_write @MANGLE_PREFIX@__nrrdFormatPNG_write #define nrrdFormatPNG @MANGLE_PREFIX@_nrrdFormatPNG #define _nrrdFormatPNM @MANGLE_PREFIX@__nrrdFormatPNM -#define _nrrdFormatPNM_available @MANGLE_PREFIX@__nrrdFormatPNM_available -#define _nrrdFormatPNM_contentStartsLike @MANGLE_PREFIX@__nrrdFormatPNM_contentStartsLike -#define _nrrdFormatPNM_fitsInto @MANGLE_PREFIX@__nrrdFormatPNM_fitsInto -#define _nrrdFormatPNM_nameLooksLike @MANGLE_PREFIX@__nrrdFormatPNM_nameLooksLike -#define _nrrdFormatPNM_read @MANGLE_PREFIX@__nrrdFormatPNM_read -#define _nrrdFormatPNM_write @MANGLE_PREFIX@__nrrdFormatPNM_write #define nrrdFormatPNM @MANGLE_PREFIX@_nrrdFormatPNM #define _nrrdFormatText @MANGLE_PREFIX@__nrrdFormatText -#define _nrrdFormatText_available @MANGLE_PREFIX@__nrrdFormatText_available -#define _nrrdFormatText_contentStartsLike @MANGLE_PREFIX@__nrrdFormatText_contentStartsLike -#define _nrrdFormatText_fitsInto @MANGLE_PREFIX@__nrrdFormatText_fitsInto -#define _nrrdFormatText_nameLooksLike @MANGLE_PREFIX@__nrrdFormatText_nameLooksLike -#define _nrrdFormatText_read @MANGLE_PREFIX@__nrrdFormatText_read -#define _nrrdFormatText_write @MANGLE_PREFIX@__nrrdFormatText_write #define nrrdFormatText @MANGLE_PREFIX@_nrrdFormatText #define _nrrdFormatVTK @MANGLE_PREFIX@__nrrdFormatVTK -#define _nrrdFormatVTK_available @MANGLE_PREFIX@__nrrdFormatVTK_available -#define _nrrdFormatVTK_contentStartsLike @MANGLE_PREFIX@__nrrdFormatVTK_contentStartsLike -#define _nrrdFormatVTK_fitsInto @MANGLE_PREFIX@__nrrdFormatVTK_fitsInto -#define _nrrdFormatVTK_nameLooksLike @MANGLE_PREFIX@__nrrdFormatVTK_nameLooksLike -#define _nrrdFormatVTK_read @MANGLE_PREFIX@__nrrdFormatVTK_read -#define _nrrdFormatVTK_write @MANGLE_PREFIX@__nrrdFormatVTK_write #define nrrdFormatVTK @MANGLE_PREFIX@_nrrdFormatVTK -#endif /* itk_NrrdIO_mangle_h */ +#endif /* __@MANGLE_PREFIX@_NrrdIO_mangle_h__ */ diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/keyvalue.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/keyvalue.c index 5f86f84e54d..9930f217600 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/keyvalue.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/keyvalue.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -37,7 +37,7 @@ ** ** returns the number of key/value pairs in a nrrd */ -unsigned int +unsigned int /* Biff: nope */ nrrdKeyValueSize(const Nrrd *nrrd) { if (!nrrd) { @@ -58,10 +58,9 @@ nrrdKeyValueSize(const Nrrd *nrrd) { ** to AIR_FALSE */ void -nrrdKeyValueIndex(const Nrrd *nrrd, char **keyP, char **valueP, - unsigned int ki) { +nrrdKeyValueIndex(const Nrrd *nrrd, char **keyP, char **valueP, unsigned int ki) { - if (!( nrrd && keyP && valueP && ki < nrrd->kvpArr->len )) { + if (!(nrrd && keyP && valueP && ki < nrrd->kvpArr->len)) { if (keyP) { *keyP = NULL; } @@ -71,11 +70,11 @@ nrrdKeyValueIndex(const Nrrd *nrrd, char **keyP, char **valueP, return; } if (nrrdStateKeyValueReturnInternalPointers) { - *keyP = nrrd->kvp[0 + 2*ki]; - *valueP = nrrd->kvp[1 + 2*ki]; + *keyP = nrrd->kvp[0 + 2 * ki]; + *valueP = nrrd->kvp[1 + 2 * ki]; } else { - *keyP = airStrdup(nrrd->kvp[0 + 2*ki]); - *valueP = airStrdup(nrrd->kvp[1 + 2*ki]); + *keyP = airStrdup(nrrd->kvp[0 + 2 * ki]); + *valueP = airStrdup(nrrd->kvp[1 + 2 * ki]); } return; } @@ -85,12 +84,12 @@ _kvpIdxFind(const Nrrd *nrrd, const char *key, int *found) { unsigned int nk, ki, ret; nk = nrrd->kvpArr->len; - for (ki=0; kikvp[0 + 2*ki], key)) { + for (ki = 0; ki < nk; ki++) { + if (!strcmp(nrrd->kvp[0 + 2 * ki], key)) { break; } } - if (kikvpArr->len; - for (ki=0; kikvp[0 + 2*ki] = (char *)airFree(nrrd->kvp[0 + 2*ki]); - nrrd->kvp[1 + 2*ki] = (char *)airFree(nrrd->kvp[1 + 2*ki]); + for (ki = 0; ki < nk; ki++) { + nrrd->kvp[0 + 2 * ki] = (char *)airFree(nrrd->kvp[0 + 2 * ki]); + nrrd->kvp[1 + 2 * ki] = (char *)airFree(nrrd->kvp[1 + 2 * ki]); } airArrayLenSet(nrrd->kvpArr, 0); return; } -int +int /* Biff: nope */ nrrdKeyValueErase(Nrrd *nrrd, const char *key) { unsigned int nk, ki; int found; - if (!( nrrd && key )) { + if (!(nrrd && key)) { /* got NULL pointer */ return 1; } @@ -131,12 +130,12 @@ nrrdKeyValueErase(Nrrd *nrrd, const char *key) { if (!found) { return 0; } - nrrd->kvp[0 + 2*ki] = (char *)airFree(nrrd->kvp[0 + 2*ki]); - nrrd->kvp[1 + 2*ki] = (char *)airFree(nrrd->kvp[1 + 2*ki]); + nrrd->kvp[0 + 2 * ki] = (char *)airFree(nrrd->kvp[0 + 2 * ki]); + nrrd->kvp[1 + 2 * ki] = (char *)airFree(nrrd->kvp[1 + 2 * ki]); nk = nrrd->kvpArr->len; - for (; kikvp[0 + 2*ki] = nrrd->kvp[0 + 2*(ki+1)]; - nrrd->kvp[1 + 2*ki] = nrrd->kvp[1 + 2*(ki+1)]; + for (; ki < nk - 1; ki++) { + nrrd->kvp[0 + 2 * ki] = nrrd->kvp[0 + 2 * (ki + 1)]; + nrrd->kvp[1 + 2 * ki] = nrrd->kvp[1 + 2 * (ki + 1)]; } airArrayLenIncr(nrrd->kvpArr, -1); @@ -152,15 +151,13 @@ nrrdKeyValueErase(Nrrd *nrrd, const char *key) { ** NOTE: Despite what might be most logical, there is no effort made ** here to cleanup key or value, including any escaping or filtering ** that might be warranted for white space other than \n -** -** does NOT use BIFF */ -int +int /* Biff: nope */ nrrdKeyValueAdd(Nrrd *nrrd, const char *key, const char *value) { unsigned int ki; int found; - if (!( nrrd && key && value )) { + if (!(nrrd && key && value)) { /* got NULL pointer */ return 1; } @@ -171,13 +168,13 @@ nrrdKeyValueAdd(Nrrd *nrrd, const char *key, const char *value) { ki = _kvpIdxFind(nrrd, key, &found); if (found) { /* over-writing value for an existing key, so have to free old value */ - airFree(nrrd->kvp[1 + 2*ki]); - nrrd->kvp[1 + 2*ki] = airStrdup(value); + airFree(nrrd->kvp[1 + 2 * ki]); + nrrd->kvp[1 + 2 * ki] = airStrdup(value); } else { /* adding value for a new key */ ki = airArrayLenIncr(nrrd->kvpArr, 1); - nrrd->kvp[0 + 2*ki] = airStrdup(key); - nrrd->kvp[1 + 2*ki] = airStrdup(value); + nrrd->kvp[0 + 2 * ki] = airStrdup(key); + nrrd->kvp[1 + 2 * ki] = airStrdup(value); } return 0; } @@ -189,25 +186,23 @@ nrrdKeyValueAdd(Nrrd *nrrd, const char *key, const char *value) { ** "inside" the nrrd struct (pointers which you had better not free()!) ** is controlled by nrrdStateKeyValueReturnInternalPointers, which defaults ** to AIR_FALSE -** -** does NOT use BIFF */ -char * +char * /* Biff: nope */ nrrdKeyValueGet(const Nrrd *nrrd, const char *key) { char *ret; unsigned int ki; int found; - if (!( nrrd && key )) { + if (!(nrrd && key)) { /* got NULL pointer */ return NULL; } ki = _kvpIdxFind(nrrd, key, &found); if (found) { if (nrrdStateKeyValueReturnInternalPointers) { - ret = nrrd->kvp[1 + 2*ki]; + ret = nrrd->kvp[1 + 2 * ki]; } else { - ret = airStrdup(nrrd->kvp[1 + 2*ki]); + ret = airStrdup(nrrd->kvp[1 + 2 * ki]); } } else { ret = NULL; @@ -228,17 +223,17 @@ nrrdKeyValueGet(const Nrrd *nrrd, const char *key) { ** accident of history that this function is in this file */ void -_nrrdWriteEscaped(FILE *file, char *dst, const char *str, - const char *toescape, const char *tospace) { - /* static const char me[]="_nrrdWriteEscaped"; */ +_nrrdWriteEscaped(FILE *file, char *dst, const char *str, const char *toescape, + const char *tospace) { + /* static const char me[] = "_nrrdWriteEscaped"; */ size_t ci, gslen; /* given strlen */ gslen = strlen(str); - for (ci=0; cikvpArr->len; ki++) { - key = nin->kvp[0 + 2*ki]; - value = nin->kvp[1 + 2*ki]; + for (ki = 0; ki < nin->kvpArr->len; ki++) { + key = nin->kvp[0 + 2 * ki]; + value = nin->kvp[1 + 2 * ki]; if (nrrdKeyValueAdd(nout, key, value)) { return 3; } diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/mangle.pl b/Modules/ThirdParty/NrrdIO/src/NrrdIO/mangle.pl deleted file mode 100644 index 5cca884a30f..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/mangle.pl +++ /dev/null @@ -1,86 +0,0 @@ -# -# NrrdIO: stand-alone code for basic nrrd functionality -# Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago -# Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann -# Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah -# -# This software is provided 'as-is', without any express or implied -# warranty. In no event will the authors be held liable for any -# damages arising from the use of this software. -# -# Permission is granted to anyone to use this software for any -# purpose, including commercial applications, and to alter it and -# redistribute it freely, subject to the following restrictions: -# -# 1. The origin of this software must not be misrepresented; you must -# not claim that you wrote the original software. If you use this -# software in a product, an acknowledgment in the product -# documentation would be appreciated but is not required. -# -# 2. Altered source versions must be plainly marked as such, and must -# not be misrepresented as being the original software. -# -# 3. This notice may not be removed or altered from any source distribution. -# -# -# generates (to stdout) a header file intended to be included into -# source files where there is a concern of name-space collision induced -# by linking to two different version of NrrdIO -# - -if (0 != $#ARGV) { - die "usage: perl mangle.pl \n"; -} -$prefix = $ARGV[0]; - -# there's probably a proper way to detect if the compiler is putting -# an underscore in front of all the symbols, but this works to detect -# what happens on macs -if (exists $ENV{OSTYPE} and "darwin" eq $ENV{OSTYPE}) { - $mac = 1; -} else { - $mac = 0; -} - -print "#ifndef __${prefix}_NrrdIO_mangle_h\n"; -print "#define __${prefix}_NrrdIO_mangle_h\n"; -print "\n"; -print "/*\n"; -print "This header file mangles all symbols exported from the\n"; -print "NrrdIO library. It is included in all files while building\n"; -print "the NrrdIO library. Due to namespace pollution, no NrrdIO\n"; -print "headers should be included in .h files in ITK.\n"; -print "\n"; -print "This file was created via the mangle.pl script in the\n"; -print "NrrdIO distribution:\n"; -print "\n"; -print " perl mangle.pl ${prefix} > ${prefix}_NrrdIO_mangle.h\n"; -print "\n"; -print "This uses nm to list all text (T), data (D) symbols, as well\n"; -print "read-only (R) things (seen on Linux) and \"other\" (S) things\n"; -print "(seen on Mac). On Macs, the preceeding underscore is removed.\n"; -print "\n"; -print "Also ensures that a few others starting with nrrd are included, and\n"; -print "prevents variables ending with .N* where N is some number, from inclusion.\n"; -print "*/\n"; -print "\n"; -open(NM, "nm libNrrdIO.a |"); -while () { - if (m/.* .* .*\.[0-9]/) { - next; - } - if (m/.*\.eh$/) { - next; - } - if (m/ [TBDRS] /) { - s|.* [TBDRS] (.*)|$1|g; - if ($mac) { - s|^_||g; - } - chop; - $sym = $_; - print "#define ${sym} ${prefix}_${sym}\n"; - } -} -close(NM); -print "#endif /* __${prefix}_NrrdIO_mangle_h */ \n"; diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/methodsNrrd.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/methodsNrrd.c index 77515e77135..8204ebf45d2 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/methodsNrrd.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/methodsNrrd.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -28,8 +28,7 @@ /* Wed Sep 14 05:55:40 EDT 2005: these are no longer used -void -nrrdPeripheralInit(Nrrd *nrrd) { +void nrrdPeripheralInit(Nrrd *nrrd) { nrrdBasicInfoInit(nrrd, NRRD_BASIC_INFO_DATA_BIT @@ -42,8 +41,7 @@ nrrdPeripheralInit(Nrrd *nrrd) { return; } -int -nrrdPeripheralCopy(Nrrd *nout, const Nrrd *nin) { +int nrrdPeripheralCopy(Nrrd *nout, const Nrrd *nin) { nrrdBasicInfoCopy(nout, nin, NRRD_BASIC_INFO_DATA_BIT @@ -57,13 +55,13 @@ nrrdPeripheralCopy(Nrrd *nout, const Nrrd *nin) { } */ - /* ------------------------------------------------------------ */ void nrrdIoStateInit(NrrdIoState *nio) { if (nio) { + nio->verbose = nrrdDefaultVerboseIO; nio->path = (char *)airFree(nio->path); nio->base = (char *)airFree(nio->base); nio->line = (char *)airFree(nio->line); @@ -72,6 +70,7 @@ nrrdIoStateInit(NrrdIoState *nio) { nio->headerStringRead = NULL; nio->headerStringWrite = NULL; airArrayLenSet(nio->dataFNArr, 0); + airArrayLenSet(nio->dataFSkipArr, 0); /* closing this is always someone else's responsibility */ nio->headerFile = NULL; nio->dataFile = NULL; @@ -87,9 +86,10 @@ nrrdIoStateInit(NrrdIoState *nio) { nio->headerStrlen = 0; nio->headerStrpos = 0; nio->byteSkip = 0; - memset(nio->seen, 0, (NRRD_FIELD_MAX+1)*sizeof(int)); + memset(nio->seen, 0, (NRRD_FIELD_MAX + 1) * sizeof(int)); nio->detachedHeader = AIR_FALSE; nio->bareText = nrrdDefaultWriteBareText; + nio->moreThanFloatInText = nrrdDefaultWriteMoreThanFloatInText; nio->charsPerLine = nrrdDefaultWriteCharsPerLine; nio->valsPerLine = nrrdDefaultWriteValsPerLine; nio->skipData = AIR_FALSE; @@ -107,14 +107,14 @@ nrrdIoStateInit(NrrdIoState *nio) { return; } -NrrdIoState * +NrrdIoState * /* Biff: nope */ nrrdIoStateNew(void) { NrrdIoState *nio; nio = (NrrdIoState *)calloc(1, sizeof(NrrdIoState)); if (nio) { airPtrPtrUnion appu; - + nio->verbose = nrrdDefaultVerboseIO; nio->path = NULL; nio->base = NULL; nio->line = NULL; @@ -123,9 +123,11 @@ nrrdIoStateNew(void) { nio->headerStringRead = NULL; nio->headerStringWrite = NULL; appu.cp = &(nio->dataFN); - nio->dataFNArr = airArrayNew(appu.v, NULL, - sizeof(char *), NRRD_FILENAME_INCR); + nio->dataFNArr = airArrayNew(appu.v, NULL, sizeof(char *), NRRD_FILENAME_INCR); airArrayPointerCB(nio->dataFNArr, airNull, airFree); + nio->dataFSkip = NULL; + appu.li = &(nio->dataFSkip); + nio->dataFSkipArr = airArrayNew(appu.v, NULL, sizeof(long int), NRRD_FILENAME_INCR); nio->format = nrrdFormatUnknown; nio->encoding = nrrdEncodingUnknown; nrrdIoStateInit(nio); @@ -133,7 +135,7 @@ nrrdIoStateNew(void) { return nio; } -NrrdIoState * +NrrdIoState * /* Biff: nope */ nrrdIoStateNix(NrrdIoState *nio) { nio->path = (char *)airFree(nio->path); @@ -141,12 +143,12 @@ nrrdIoStateNix(NrrdIoState *nio) { nio->line = (char *)airFree(nio->line); nio->dataFNFormat = (char *)airFree(nio->dataFNFormat); nio->dataFNArr = airArrayNuke(nio->dataFNArr); + nio->dataFSkipArr = airArrayNuke(nio->dataFSkipArr); /* the NrrdIoState never owned nio->oldData; we don't free it */ - airFree(nio); /* no NULL assignment, else compile warnings */ + airFree(nio); /* no NULL assignment, else compile warnings */ return NULL; } - /* ------------------------------------------------------------ */ /* see axis.c for axis-specific "methods" */ @@ -196,18 +198,18 @@ nrrdBasicInfoInit(Nrrd *nrrd, int bitflag) { nrrd->spaceDim = 0; } if (!(NRRD_BASIC_INFO_SPACEUNITS_BIT & bitflag)) { - for (dd=0; ddspaceUnits[dd] = (char *)airFree(nrrd->spaceUnits[dd]); } } if (!(NRRD_BASIC_INFO_SPACEORIGIN_BIT & bitflag)) { - for (dd=0; ddspaceOrigin[dd] = AIR_NAN; } } if (!(NRRD_BASIC_INFO_MEASUREMENTFRAME_BIT & bitflag)) { - for (dd=0; ddmeasurementFrame[dd][ee] = AIR_NAN; } } @@ -235,13 +237,12 @@ nrrdBasicInfoInit(Nrrd *nrrd, int bitflag) { ** ** the bitflag communicates which fields should *not* be copied */ -int +int /* Biff: 1 */ nrrdBasicInfoCopy(Nrrd *dest, const Nrrd *src, int bitflag) { - static const char me[]="nrrdBasicInfoCopy"; + static const char me[] = "nrrdBasicInfoCopy"; unsigned int dd, ee; - if (!( dest && src )) - return 0; + if (!(dest && src)) return 0; if (dest == src) { /* nothing to do */ return 0; @@ -282,7 +283,7 @@ nrrdBasicInfoCopy(Nrrd *dest, const Nrrd *src, int bitflag) { dest->spaceDim = src->spaceDim; } if (!(NRRD_BASIC_INFO_SPACEUNITS_BIT & bitflag)) { - for (dd=0; ddspaceDim; dd++) { + for (dd = 0; dd < src->spaceDim; dd++) { dest->spaceUnits[dd] = (char *)airFree(dest->spaceUnits[dd]); dest->spaceUnits[dd] = airStrdup(src->spaceUnits[dd]); if (src->spaceUnits[dd] && !dest->spaceUnits[dd]) { @@ -290,13 +291,13 @@ nrrdBasicInfoCopy(Nrrd *dest, const Nrrd *src, int bitflag) { return 1; } } - for (dd=src->spaceDim; ddspaceDim; dd < NRRD_SPACE_DIM_MAX; dd++) { dest->spaceUnits[dd] = (char *)airFree(dest->spaceUnits[dd]); } } if (!(NRRD_BASIC_INFO_SPACEORIGIN_BIT & bitflag)) { - for (dd=0; ddspaceDim-1) { + for (dd = 0; dd < NRRD_SPACE_DIM_MAX; dd++) { + if (dd <= src->spaceDim - 1) { dest->spaceOrigin[dd] = src->spaceOrigin[dd]; } else { dest->spaceOrigin[dd] = AIR_NAN; @@ -304,16 +305,16 @@ nrrdBasicInfoCopy(Nrrd *dest, const Nrrd *src, int bitflag) { } } if (!(NRRD_BASIC_INFO_MEASUREMENTFRAME_BIT & bitflag)) { - for (dd=0; ddspaceDim-1 && ee <= src->spaceDim-1) { + for (dd = 0; dd < NRRD_SPACE_DIM_MAX; dd++) { + for (ee = 0; ee < NRRD_SPACE_DIM_MAX; ee++) { + if (dd <= src->spaceDim - 1 && ee <= src->spaceDim - 1) { dest->measurementFrame[dd][ee] = src->measurementFrame[dd][ee]; } else { dest->measurementFrame[dd][ee] = AIR_NAN; } } } - for (dd=src->spaceDim; ddspaceDim; dd < NRRD_SPACE_DIM_MAX; dd++) { dest->spaceOrigin[dd] = AIR_NAN; } } @@ -351,7 +352,7 @@ nrrdInit(Nrrd *nrrd) { if (nrrd) { nrrdBasicInfoInit(nrrd, NRRD_BASIC_INFO_NONE); - for (ii=0; iiaxis + ii); } } @@ -362,16 +363,14 @@ nrrdInit(Nrrd *nrrd) { ******** nrrdNew() ** ** creates and initializes a Nrrd -** -** this does NOT use biff */ -Nrrd * +Nrrd * /* Biff: nope */ nrrdNew(void) { int ii; Nrrd *nrrd; airPtrPtrUnion appu; - nrrd = (Nrrd*)(calloc(1, sizeof(Nrrd))); + nrrd = (Nrrd *)(calloc(1, sizeof(Nrrd))); if (!nrrd) { return NULL; } @@ -379,10 +378,10 @@ nrrdNew(void) { /* explicitly set pointers to NULL, since calloc isn't officially guaranteed to do that. */ nrrd->data = NULL; - for (ii=0; iiaxis + ii); } - for (ii=0; iispaceUnits[ii] = NULL; } nrrd->content = NULL; @@ -400,8 +399,7 @@ nrrdNew(void) { /* create key/value airArray (even thought it starts empty) */ nrrd->kvp = NULL; appu.cp = &(nrrd->kvp); - nrrd->kvpArr = airArrayNew(appu.v, NULL, - 2*sizeof(char *), NRRD_KEYVALUE_INCR); + nrrd->kvpArr = airArrayNew(appu.v, NULL, 2 * sizeof(char *), NRRD_KEYVALUE_INCR); if (!nrrd->kvpArr) { return NULL; } @@ -420,18 +418,16 @@ nrrdNew(void) { ** to free the nrrd itself ** ** returns NULL -** -** this does NOT use biff */ -Nrrd * +Nrrd * /* Biff: nope */ nrrdNix(Nrrd *nrrd) { int ii; if (nrrd) { - for (ii=0; iiaxis[ii])); } - for (ii=0; iispaceUnits[ii] = (char *)airFree(nrrd->spaceUnits[ii]); } nrrd->content = (char *)airFree(nrrd->content); @@ -452,7 +448,7 @@ nrrdNix(Nrrd *nrrd) { ** same as what comes from nrrdNew(). This includes free()ing ** any comments. */ -Nrrd * +Nrrd * /* Biff: nope */ nrrdEmpty(Nrrd *nrrd) { if (nrrd) { @@ -469,7 +465,7 @@ nrrdEmpty(Nrrd *nrrd) { ** ** always returns NULL */ -Nrrd * +Nrrd * /* Biff: nope */ nrrdNuke(Nrrd *nrrd) { if (nrrd) { @@ -481,23 +477,24 @@ nrrdNuke(Nrrd *nrrd) { /* ------------------------------------------------------------ */ -int +int /* Biff: (private) maybe:3:1 */ _nrrdSizeCheck(const size_t *size, unsigned int dim, int useBiff) { - static const char me[]="_nrrdSizeCheck"; + static const char me[] = "_nrrdSizeCheck"; size_t num, pre; unsigned int ai; pre = num = 1; - for (ai=0; aiblockSize at some other time. */ -int -nrrdWrap_nva(Nrrd *nrrd, void *data, int type, - unsigned int dim, const size_t *size) { - static const char me[]="nrrdWrap_nva"; +int /* Biff: 1 */ +nrrdWrap_nva(Nrrd *nrrd, void *data, int type, unsigned int dim, const size_t *size) { + static const char me[] = "nrrdWrap_nva"; if (!(nrrd && size)) { biffAddf(NRRD, "%s: got NULL pointer", me); @@ -548,9 +544,9 @@ nrrdWrap_nva(Nrrd *nrrd, void *data, int type, ** If successful, returns 0, otherwise, 1. ** This does use biff. */ -int +int /* Biff: 1 */ nrrdWrap_va(Nrrd *nrrd, void *data, int type, unsigned int dim, ...) { - static const char me[]="nrrdWrap_va"; + static const char me[] = "nrrdWrap_va"; va_list ap; size_t size[NRRD_DIM_MAX]; unsigned int ai; @@ -560,7 +556,7 @@ nrrdWrap_va(Nrrd *nrrd, void *data, int type, unsigned int dim, ...) { return 1; } va_start(ap, dim); - for (ai=0; aidata, nin->data, - nrrdElementNumber(nin)*nrrdElementSize(nin)); + memcpy(nout->data, nin->data, nrrdElementNumber(nin) * nrrdElementSize(nin)); } else { /* someone is trying to copy structs without data, fine fine fine */ if (nrrdWrap_nva(nout, NULL, nin->type, nin->dim, size)) { - biffAddf(NRRD, "%s: couldn't allocate data", me); + biffAddf(NRRD, "%s: couldn't wrap NULL data", me); return 1; } } @@ -640,9 +635,9 @@ _nrrdCopy(Nrrd *nout, const Nrrd *nin, int bitflag) { ** Comments from old are added to comments for new, so these are also ** newly allocated. nout->ptr is not set, nin->ptr is not read. */ -int +int /* Biff: 1 */ nrrdCopy(Nrrd *nout, const Nrrd *nin) { - static const char me[]="nrrdCopy"; + static const char me[] = "nrrdCopy"; if (_nrrdCopy(nout, nin, NRRD_BASIC_INFO_NONE)) { biffAddf(NRRD, "%s:", me); @@ -670,11 +665,11 @@ nrrdCopy(Nrrd *nout, const Nrrd *nin) { ** ** Note: This function DOES use biff */ -int +int /* Biff: 1 */ nrrdAlloc_nva(Nrrd *nrrd, int type, unsigned int dim, const size_t *size) { - static const char me[]="nrrdAlloc_nva"; + static const char me[] = "nrrdAlloc_nva"; size_t num, esize; - char stmp[2][AIR_STRLEN_SMALL]; + char stmp[2][AIR_STRLEN_SMALL + 1]; if (!(nrrd && size)) { biffAddf(NRRD, "%s: got NULL pointer", me); @@ -692,24 +687,22 @@ nrrdAlloc_nva(Nrrd *nrrd, int type, unsigned int dim, const size_t *size) { } } if (!AIR_IN_CL(1, dim, NRRD_DIM_MAX)) { - biffAddf(NRRD, "%s: dim (%d) not in valid range [1,%d]", - me, dim, NRRD_DIM_MAX); + biffAddf(NRRD, "%s: dim (%d) not in valid range [1,%d]", me, dim, NRRD_DIM_MAX); return 1; } nrrd->data = airFree(nrrd->data); if (nrrdWrap_nva(nrrd, NULL, type, dim, size)) { biffAddf(NRRD, "%s:", me); - return 1 ; + return 1; } num = nrrdElementNumber(nrrd); esize = nrrdElementSize(nrrd); nrrd->data = calloc(num, esize); if (!(nrrd->data)) { - biffAddf(NRRD, "%s: calloc(%s,%s) failed", me, - airSprintSize_t(stmp[0], num), + biffAddf(NRRD, "%s: calloc(%s,%s) failed", me, airSprintSize_t(stmp[0], num), airSprintSize_t(stmp[1], esize)); - return 1 ; + return 1; } return 0; @@ -721,9 +714,9 @@ nrrdAlloc_nva(Nrrd *nrrd, int type, unsigned int dim, const size_t *size) { ** Handy wrapper around nrrdAlloc_nva, which takes, as its vararg list, ** all the axes sizes. */ -int +int /* Biff: 1 */ nrrdAlloc_va(Nrrd *nrrd, int type, unsigned int dim, ...) { - static const char me[]="nrrdAlloc_va"; + static const char me[] = "nrrdAlloc_va"; size_t size[NRRD_DIM_MAX]; unsigned int ai; va_list ap; @@ -733,7 +726,7 @@ nrrdAlloc_va(Nrrd *nrrd, int type, unsigned int dim, ...) { return 1; } va_start(ap, dim); - for (ai=0; aiblockSize)) { - char stmp[AIR_STRLEN_SMALL]; + char stmp[AIR_STRLEN_SMALL + 1]; biffAddf(NRRD, "%s: given nrrd->blockSize %s invalid", me, airSprintSize_t(stmp, nrrd->blockSize)); return 1; @@ -795,7 +786,7 @@ _nrrdMaybeAllocMaybeZero_nva(Nrrd *nrrd, int type, need = 1; } else { numWant = 1; - for (ai=0; aidata, 0, nrrdElementNumber(nrrd)*nrrdElementSize(nrrd)); + memset(nrrd->data, 0, nrrdElementNumber(nrrd) * nrrdElementSize(nrrd)); } } @@ -844,17 +835,15 @@ _nrrdMaybeAllocMaybeZero_nva(Nrrd *nrrd, int type, ** ** also subscribes to the "don't mess with peripheral information" philosophy */ -int -nrrdMaybeAlloc_nva(Nrrd *nrrd, int type, - unsigned int dim, const size_t *size) { - static const char me[]="nrrdMaybeAlloc_nva"; - int ret; - ret = _nrrdMaybeAllocMaybeZero_nva(nrrd, type, dim, size, - AIR_TRUE); - if (ret) { +int /* Biff: 1 */ +nrrdMaybeAlloc_nva(Nrrd *nrrd, int type, unsigned int dim, const size_t *size) { + static const char me[] = "nrrdMaybeAlloc_nva"; + + if (_nrrdMaybeAllocMaybeZero_nva(nrrd, type, dim, size, AIR_TRUE)) { biffAddf(NRRD, "%s: trouble", me); + return 1; } - return ret; + return 0; } /* @@ -863,9 +852,9 @@ nrrdMaybeAlloc_nva(Nrrd *nrrd, int type, ** Handy wrapper around nrrdAlloc, which takes, as its vararg list ** all the axes sizes, thereby calculating the total number. */ -int +int /* Biff: 1 */ nrrdMaybeAlloc_va(Nrrd *nrrd, int type, unsigned int dim, ...) { - static const char me[]="nrrdMaybeAlloc_va"; + static const char me[] = "nrrdMaybeAlloc_va"; size_t size[NRRD_DIM_MAX]; unsigned int ai; va_list ap; @@ -875,7 +864,7 @@ nrrdMaybeAlloc_va(Nrrd *nrrd, int type, unsigned int dim, ...) { return 1; } va_start(ap, dim); - for (ai=0; ai -#include -#include +# include +# include +# include #else -#include +# include #endif /* ******** airTeemVersion +******** airTeemReleaseDone ******** airTeemReleaseDate ** ** updated with each release to contain a string representation of ** the Teem version number and release date. Originated in version 1.5; ** use of TEEM_VERSION #defines started in 1.9 */ -const char * -airTeemVersion = TEEM_VERSION_STRING; -const char * -airTeemReleaseDate = "8 August 2013"; +const char *const airTeemVersion = TEEM_VERSION_STRING; +const int airTeemReleaseDone = AIR_FALSE; +const char *const airTeemReleaseDate = "hopefully 2025"; + +/* +******** airTeemVersionSprint +** +** uniform way of printing information about the Teem version +*/ +void +airTeemVersionSprint(char buff[AIR_STRLEN_LARGE + 1]) { + snprintf(buff, AIR_STRLEN_LARGE + 1, "Teem version %s, %s%s%s", airTeemVersion, + airTeemReleaseDone ? "released on " : "", airTeemReleaseDate, + airTeemReleaseDone ? "" : " (not yet released)"); + return; +} double _airSanityHelper(double val) { - return val*val*val; + return val * val * val; } /* @@ -95,10 +108,14 @@ airFree(void *ptr) { /* ******** airFopen() ** -** encapsulates that idea that "-" is either standard in or stardard -** out, and does McRosopht stuff required to make piping work +** encapsulates that idea that "-" OR "-=" is either standard in or standard +** out, and does McRosopht stuff required to make piping work. Handling "-=" +** is a convenience for implementing NrrdIoState->declineStdioOnTTY, with +** the semantics (not handled here) that "-=" means "read/write from stdin/ +** stdout, even when it IS a terminal". But this is currently only supported +** in full Teem, not the minimal NrrdIO library. ** -** Does not error checking. If fopen fails, then C' errno and strerror are +** Does no error checking. If fopen fails, then C' errno and strerror are ** left untouched for the caller to access. */ FILE * @@ -129,7 +146,7 @@ FILE * airFclose(FILE *file) { if (file) { - if (!( stdin == file || stdout == file || stderr == file )) { + if (!(stdin == file || stdout == file || stderr == file)) { fclose(file); } } @@ -137,29 +154,31 @@ airFclose(FILE *file) { } /* -******** airSinglePrintf -** -** a complete stand-in for {f|s}printf(), as long as the given format -** string contains exactly one conversion sequence. The utility of -** this is to standardize the printing of IEEE 754 special values: -** QNAN, SNAN -> "NaN" -** POS_INF -> "+inf" -** NEG_INF -> "-inf" -** The format string can contain other things besides just the -** conversion sequence: airSingleFprintf(f, " (%f)\n", AIR_NAN) -** will be the same as fprintf(f, " (%s)\n", "NaN"); -** -** To get fprintf behavior, pass "str" as NULL -** to get sprintf bahavior, pass "file" as NULL -** -** Finding a complete {f|s|}printf replacement is a priority for Teem 2.0 -*/ + ******* airSinglePrintf + * + * a complete stand-in for {f|s}printf(), as long as the given format string contains + * exactly one conversion sequence, and does use any precision modifiers. The utility of + * this is to standardize the printing of IEEE 754 special values: + * NAN (any kind) -> "NaN" + * POS_INF -> "+inf" + * NEG_INF -> "-inf" + * The format string can contain other things besides just the conversion sequence: + * airSinglePrintf(f, NULL, " (%f)\n", AIR_NAN) will be the same as: + * fprintf(f, " (%s)\n", "NaN"); + * + * To get fprintf behavior, pass "str" as NULL + * to get sprintf bahavior, pass "file" as NULL. AND NOTE THAT THIS DOES USE sprintf + * and not snprintf because we're not in a position to know what the buffer size is. + * + * Finding a complete {f|s|}printf replacement would be great, but finding one compatible + * with our LGPL+linking exception is hard. + */ int airSinglePrintf(FILE *file, char *str, const char *_fmt, ...) { - char *fmt, buff[AIR_STRLEN_LARGE]; - double val=0, gVal, fVal; + char *fmt, buff[AIR_STRLEN_LARGE + 1]; + double val = 0, gVal, fVal; int ret, isF, isD, cls; - char *conv=NULL, *p0, *p1, *p2, *p3, *p4, *p5; + char *conv = NULL, *p0, *p1, *p2, *p3, *p4, *p5; va_list ap; va_start(ap, _fmt); @@ -189,8 +208,7 @@ airSinglePrintf(FILE *file, char *str, const char *_fmt, ...) { val = va_arg(ap, double); cls = airFPClass_d(val); switch (cls) { - case airFP_SNAN: - case airFP_QNAN: + case airFP_NAN: case airFP_POS_INF: case airFP_NEG_INF: if (isF) { @@ -203,10 +221,9 @@ airSinglePrintf(FILE *file, char *str, const char *_fmt, ...) { } break; } -#define PRINT(F, S, C, V) ((F) ? fprintf((F),(C),(V)) : sprintf((S),(C),(V))) +#define PRINT(F, S, C, V) ((F) ? fprintf((F), (C), (V)) : sprintf((S), (C), (V))) switch (cls) { - case airFP_SNAN: - case airFP_QNAN: + case airFP_NAN: ret = PRINT(file, str, fmt, "NaN"); break; case airFP_POS_INF: @@ -251,14 +268,14 @@ airSinglePrintf(FILE *file, char *str, const char *_fmt, ...) { ** non-standardized format specifier confusion with printf */ char * -airSprintSize_t(char _str[AIR_STRLEN_SMALL], size_t val) { - char str[AIR_STRLEN_SMALL]; +airSprintSize_t(char _str[AIR_STRLEN_SMALL + 1], size_t val) { + char str[AIR_STRLEN_SMALL + 1]; unsigned int si; if (!_str) { return NULL; } - si = AIR_STRLEN_SMALL-1; + si = AIR_STRLEN_SMALL; str[si] = '\0'; do { str[--si] = AIR_CAST(char, (val % 10) + '0'); @@ -275,15 +292,15 @@ airSprintSize_t(char _str[AIR_STRLEN_SMALL], size_t val) { ** non-standardized format specifier confusion with printf */ char * -airSprintPtrdiff_t(char _str[AIR_STRLEN_SMALL], ptrdiff_t val) { - char str[AIR_STRLEN_SMALL]; +airSprintPtrdiff_t(char _str[AIR_STRLEN_SMALL + 1], ptrdiff_t val) { + char str[AIR_STRLEN_SMALL + 1]; unsigned int si; int sign; if (!_str) { return NULL; } - si = AIR_STRLEN_SMALL-1; + si = AIR_STRLEN_SMALL; str[si] = '\0'; sign = (val < 0 ? -1 : 1); do { @@ -298,4 +315,3 @@ airSprintPtrdiff_t(char _str[AIR_STRLEN_SMALL], ptrdiff_t val) { strcpy(_str, str + si); return _str; } - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/mop.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/mop.c index 51d1edd6420..06db9a114e6 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/mop.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/mop.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -61,7 +61,7 @@ airMopSub() and airMopUnMem were created #define AIR_MOP_INCR 10 airArray * -airMopNew() { +airMopNew(void) { return airArrayNew(NULL, NULL, sizeof(airMop), AIR_MOP_INCR); } @@ -81,7 +81,7 @@ airMopNew() { */ int airMopAdd(airArray *arr, void *ptr, airMopper mop, int when) { - static const char me[]="airMopAdd"; + static const char me[] = "airMopAdd"; airMop *mops; unsigned int ii; @@ -91,7 +91,7 @@ airMopAdd(airArray *arr, void *ptr, airMopper mop, int when) { mops = (airMop *)arr->data; /* first see if this is something we already set a callback for */ - for (ii=0; iilen; ii++) { + for (ii = 0; ii < arr->len; ii++) { if (mops[ii].ptr == ptr && mops[ii].mop == mop) { mops[ii].when = when; /* we're done */ @@ -122,7 +122,7 @@ airMopSub(airArray *arr, void *ptr, airMopper mop) { mops = (airMop *)arr->data; /* first see if this is something we already set a callback for */ - for (ii=0; iilen; ii++) { + for (ii = 0; ii < arr->len; ii++) { if (mops[ii].ptr == ptr && mops[ii].mop == mop) { mops[ii].ptr = NULL; mops[ii].mop = NULL; @@ -183,17 +183,15 @@ void airMopPrint(airArray *arr, const void *_str, int when) { char *copy; - if (!(arr && _str)) - return; + if (!(arr && _str)) return; - copy = airStrdup(AIR_CAST(const char*, _str)); + copy = airStrdup(AIR_CAST(const char *, _str)); airMopAdd(arr, copy, airFree, airMopAlways); airMopAdd(arr, copy, _airMopPrint, when); return; } -static const char -_airMopWhenStr[4][128] = { +static const char _airMopWhenStr[4][128] = { " never", " error", " okay", @@ -216,19 +214,16 @@ airMopDebug(airArray *arr) { unsigned int ii; mvunion mvu; - if (!arr) - return; + if (!arr) return; mops = (airMop *)arr->data; - printf("airMopDebug: _________________________ mop stack for 0x%p:\n", - AIR_VOIDP(arr)); + printf("airMopDebug: _________________________ mop stack for 0x%p:\n", AIR_VOIDP(arr)); if (arr->len) { ii = arr->len; do { ii--; printf("%4u: ", ii); - if (NULL == mops[ii].mop && NULL == mops[ii].ptr - && airMopNever == mops[ii].when) { + if (NULL == mops[ii].mop && NULL == mops[ii].ptr && airMopNever == mops[ii].when) { printf("no-op\n"); continue; } @@ -243,8 +238,8 @@ airMopDebug(airArray *arr) { continue; } if (_airMopPrint == mops[ii].mop) { - printf("_airMopPrint(\"%s\" == 0x%p)\n", - AIR_CAST(char*, mops[ii].ptr), AIR_VOIDP(mops[ii].ptr)); + printf("_airMopPrint(\"%s\" == 0x%p)\n", AIR_CAST(char *, mops[ii].ptr), + AIR_VOIDP(mops[ii].ptr)); continue; } if ((airMopper)airFclose == mops[ii].mop) { @@ -259,7 +254,7 @@ airMopDebug(airArray *arr) { printf("airMopDebug: ^^^^^^^^^^^^^^^^^^^^^^^^^\n"); } -void +airArray * airMopDone(airArray *arr, int error) { airMop *mops; unsigned int ii; @@ -286,18 +281,17 @@ airMopDone(airArray *arr, int error) { printf("airMopDone(%p): done!\n", (void*)arr); */ } - return; + return NULL; } -void +airArray * airMopError(airArray *arr) { - airMopDone(arr, AIR_TRUE); + return airMopDone(arr, AIR_TRUE); } -void +airArray * airMopOkay(airArray *arr) { - airMopDone(arr, AIR_FALSE); + return airMopDone(arr, AIR_FALSE); } - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/parseAir.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/parseAir.c index a14baeb1e61..24cc95f6a26 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/parseAir.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/parseAir.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -25,6 +25,7 @@ #include "NrrdIO.h" +/* clang-format off */ static const char * _airBoolStr[] = { "(unknown bool)", @@ -73,6 +74,7 @@ _airBool = { const airEnum *const airBool = &_airBool; +/* clang-format on */ double airAtod(const char *str) { @@ -82,6 +84,8 @@ airAtod(const char *str) { return val; } +/* NOTE: see info n air.h about TeemV2 changes to all things airType and airParse */ + int airSingleSscanf(const char *str, const char *fmt, void *ptr) { char *tmp; @@ -96,17 +100,16 @@ airSingleSscanf(const char *str, const char *fmt, void *ptr) { } airToLower(tmp); if (strstr(tmp, "nan")) { - val = AIR_NAN; - } - else if (strstr(tmp, "-inf")) { - val = AIR_NEG_INF; - } - else if (strstr(tmp, "inf")) { - val = AIR_POS_INF; - } - else { + val = (double)AIR_NAN; + } else if (strstr(tmp, "-inf")) { + val = (double)AIR_NEG_INF; + } else if (strstr(tmp, "inf")) { + val = (double)AIR_POS_INF; + } else { /* nothing special matched; pass it off to sscanf() */ + /* (save setlocale here) */ ret = sscanf(str, fmt, ptr); + /* (return setlocale here) */ free(tmp); return ret; } @@ -114,22 +117,21 @@ airSingleSscanf(const char *str, const char *fmt, void *ptr) { if (!strncmp(fmt, "%l", 2)) { /* we were given a double pointer */ *((double *)(ptr)) = val; - } - else { + } else { /* we were given a float pointer */ - *((float *)(ptr)) = AIR_CAST(float, val); + *((float *)(ptr)) = AIR_FLOAT(val); } free(tmp); return 1; } else if (!strcmp(fmt, "%z")) { /* its a size_t */ - size_t tsz = 0; /* tmp size_t */ + size_t tsz = 0; /* tmp size_t */ const char *chh = str; /* char here */ while (chh) { int dig; - dig = AIR_CAST(int, *chh - '0'); + dig = AIR_INT(*chh - '0'); if (AIR_IN_CL(0, dig, 9)) { - tsz = 10*tsz + AIR_CAST(size_t, dig); + tsz = 10 * tsz + AIR_CAST(size_t, dig); } else { break; } @@ -143,86 +145,19 @@ airSingleSscanf(const char *str, const char *fmt, void *ptr) { } } -#define _PARSE_STR_ARGS(type) type *out, const char *_s, \ - const char *ct, unsigned int n, ... -#define _PARSE_STR_BODY(format) \ - unsigned int i; \ - char *tmp, *s, *last; \ - \ - /* if we got NULL, there's nothing to do */ \ - if (!(out && _s && ct)) \ - return 0; \ - \ - /* copy the input so that we don't change it */ \ - s = airStrdup(_s); \ - \ - /* keep calling airStrtok() until we have everything */ \ - for (i=0; i 1 || !greedy) { + for (i = 0; i < n; i++) { + if (n > 1) { tmp = airStrtok(i ? NULL : s, ct, &last); - } - else { + } else { tmp = s; } if (!tmp) { @@ -305,24 +312,21 @@ airParseStrS(char **out, const char *_s, const char *ct, unsigned int n, ...) { airMopError(mop); return i; } - airMopMem(mop, out+i, airMopOnError); + airMopMem(mop, out + i, airMopOnError); } airMopOkay(mop); return n; } unsigned int -airParseStrE(int *out, const char *_s, const char *ct, unsigned int n, ...) { +airParseStrE(int *out, + const char *_s, + const char *ct, + unsigned int n, + const airEnum *enm) { unsigned int i; char *tmp, *s, *last; airArray *mop; - va_list ap; - airEnum *enm; - - /* grab the enum every time, prior to error checking */ - va_start(ap, n); - enm = va_arg(ap, airEnum *); - va_end(ap); /* if we got NULL, there's nothing to do */ if (!(out && _s && ct)) { @@ -346,7 +350,7 @@ airParseStrE(int *out, const char *_s, const char *ct, unsigned int n, ...) { } } else { /* keep calling airStrtok() until we have everything */ - for (i=0; iline + nio->pos; @@ -44,7 +44,7 @@ _nrrdReadNrrdParseField(NrrdIoState *nio, int useBiff) { return nrrdField_comment; } - if (!( buff = airStrdup(next) )) { + if (!(buff = airStrdup(next))) { biffMaybeAddf(useBiff, NRRD, "%s: couldn't allocate buffer!", me); return nrrdField_unknown; } @@ -61,21 +61,19 @@ _nrrdReadNrrdParseField(NrrdIoState *nio, int useBiff) { noField = !colon; if (colon) { *colon = '\0'; - badField = ( nrrdField_unknown == (fld = airEnumVal(nrrdField, buff)) ); + badField = (nrrdField_unknown == (fld = airEnumVal(nrrdField, buff))); } if (noField || badField) { keysep = strstr(buff, ":="); if (!keysep) { if (noField) { - biffMaybeAddf(useBiff, NRRD, - "%s: didn't see \": \" or \":=\" in line", - me); + biffMaybeAddf(useBiff, NRRD, "%s: didn't see \": \" or \":=\" in line", me); } else { - biffMaybeAddf(useBiff, NRRD, - "%s: failed to parse \"%s\" as field identifier", + biffMaybeAddf(useBiff, NRRD, "%s: failed to parse \"%s\" as field identifier", me, buff); } - free(buff); return nrrdField_unknown; + free(buff); + return nrrdField_unknown; } free(buff); @@ -89,7 +87,7 @@ _nrrdReadNrrdParseField(NrrdIoState *nio, int useBiff) { /* skip whitespace prior to start of first field descriptor */ next += strspn(next, _nrrdFieldSep); - nio->pos = AIR_CAST(int, next - nio->line); + nio->pos = AIR_INT(next - nio->line); ret = fld; } @@ -105,8 +103,7 @@ _nrrdReadNrrdParseField(NrrdIoState *nio, int useBiff) { */ static int -_nrrdReadNrrdParse_nonfield(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { +_nrrdReadNrrdParse_nonfield(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { AIR_UNUSED(file); AIR_UNUSED(nrrd); AIR_UNUSED(nio); @@ -123,10 +120,9 @@ _nrrdReadNrrdParse_nonfield(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_comment(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_comment"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_comment(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_comment"; char *info; AIR_UNUSED(file); @@ -139,10 +135,9 @@ _nrrdReadNrrdParse_comment(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_content(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_content"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_content(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_content"; char *info; AIR_UNUSED(file); @@ -154,19 +149,18 @@ _nrrdReadNrrdParse_content(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_number(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { +static int /* Biff: nope # unlike other parsers, for reasons described below */ +_nrrdReadNrrdParse_number(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { /* - static const char me[]="_nrrdReadNrrdParse_number"; - char *info; - - info = nio->line + nio->pos; - if (1 != sscanf(info, NRRD_BIG_INT_PRINTF, &(nrrd->num))) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't parse number \"%s\"", me, info); return 1; - } - */ + *static const char me[] = "_nrrdReadNrrdParse_number"; + *char *info; + * + *info = nio->line + nio->pos; + *if (1 != sscanf(info, NRRD_BIG_INT_PRINTF, &(nrrd->num))) { + * biffMaybeAddf(useBiff, NRRD, + * "%s: couldn't parse number \"%s\"", me, info); return 1; + *} + */ AIR_UNUSED(file); AIR_UNUSED(nrrd); @@ -186,10 +180,9 @@ _nrrdReadNrrdParse_number(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_type(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_type"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_type(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_type"; char *info; AIR_UNUSED(file); @@ -205,34 +198,36 @@ _nrrdReadNrrdParse_type(FILE *file, Nrrd *nrrd, return 0; } -#define _PARSE_ONE_VAL(FIELD, CONV, TYPE) \ - if (1 != sscanf(info, CONV, &(FIELD))) { \ - biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse " TYPE \ - " from \"%s\"", me, info); \ - return 1; \ +#define _PARSE_ONE_VAL(FIELD, CONV, TYPE) \ + if (1 != airSingleSscanf(info, CONV, &(FIELD))) { \ + biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse " TYPE " from \"%s\"", me, info); \ + return 1; \ } -static int -_nrrdReadNrrdParse_block_size(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_block_size"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_block_size(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_block_size"; char *info; AIR_UNUSED(file); info = nio->line + nio->pos; if (1 != airSingleSscanf(info, "%z", &(nrrd->blockSize))) { - biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse size_t" - " from \"%s\"", me, info); + biffMaybeAddf(useBiff, NRRD, + "%s: couldn't parse size_t" + " from \"%s\"", + me, info); + /* For >15 years this return was missing; highlighting that it was missing was thanks + * to the biff auto-scan in teem/src/_util/scan-symbols.py */ + return 1; } /* because blockSize and type fields may appear in any order, we can't use _nrrdFieldCheck[] */ return 0; } -static int -_nrrdReadNrrdParse_dimension(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_dimension"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_dimension(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_dimension"; char *info; AIR_UNUSED(file); @@ -250,32 +245,28 @@ _nrrdReadNrrdParse_dimension(FILE *file, Nrrd *nrrd, ** to zero, and, _nrrdReadNrrdParse_dimension() won't allow it to be ** set to anything outside the range [1, NRRD_DIM_MAX] */ -#define _CHECK_HAVE_DIM \ - if (0 == nrrd->dim) { \ - biffMaybeAddf(useBiff, NRRD, \ - "%s: don't yet have a valid dimension", me); \ - return 1; \ +#define _CHECK_HAVE_DIM \ + if (0 == nrrd->dim) { \ + biffMaybeAddf(useBiff, NRRD, "%s: don't yet have a valid dimension", me); \ + return 1; \ } -#define _CHECK_HAVE_SPACE_DIM \ - if (0 == nrrd->spaceDim) { \ - biffMaybeAddf(useBiff, NRRD, \ - "%s: don't yet have a valid space dimension", me); \ - return 1; \ +#define _CHECK_HAVE_SPACE_DIM \ + if (0 == nrrd->spaceDim) { \ + biffMaybeAddf(useBiff, NRRD, "%s: don't yet have a valid space dimension", me); \ + return 1; \ } -#define _CHECK_GOT_ALL_VALUES \ - if (nrrd->dim != ret) { \ - biffMaybeAddf(useBiff, NRRD, \ - "%s: parsed %d values, but dimension is %d", \ - me, ret, nrrd->dim); \ - return 1; \ +#define _CHECK_GOT_ALL_VALUES \ + if (nrrd->dim != ret) { \ + biffMaybeAddf(useBiff, NRRD, "%s: parsed %d values, but dimension is %d", me, ret, \ + nrrd->dim); \ + return 1; \ } -static int -_nrrdReadNrrdParse_sizes(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_sizes"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_sizes(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_sizes"; unsigned int ret; size_t val[NRRD_DIM_MAX]; char *info; @@ -287,10 +278,9 @@ _nrrdReadNrrdParse_sizes(FILE *file, Nrrd *nrrd, _CHECK_GOT_ALL_VALUES; nrrdAxisInfoSet_nva(nrrd, nrrdAxisInfoSize, val); /* HEY: this is a very imperfect check of excess info */ - if (nrrd->dim+1 == airParseStrZ(val, info, _nrrdFieldSep, nrrd->dim+1)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d sizes", - me, nrrd->dim); + if (nrrd->dim + 1 == airParseStrZ(val, info, _nrrdFieldSep, nrrd->dim + 1)) { + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d sizes", me, + nrrd->dim); return 1; } if (_nrrdFieldCheck[nrrdField_sizes](nrrd, useBiff)) { @@ -300,10 +290,9 @@ _nrrdReadNrrdParse_sizes(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_spacings(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_spacings"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_spacings(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_spacings"; unsigned int ret; double val[NRRD_DIM_MAX]; char *info; @@ -315,10 +304,9 @@ _nrrdReadNrrdParse_spacings(FILE *file, Nrrd *nrrd, _CHECK_GOT_ALL_VALUES; nrrdAxisInfoSet_nva(nrrd, nrrdAxisInfoSpacing, val); /* HEY: this is a very imperfect check of excess info */ - if (nrrd->dim+1 == airParseStrD(val, info, _nrrdFieldSep, nrrd->dim+1)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d spacings", - me, nrrd->dim); + if (nrrd->dim + 1 == airParseStrD(val, info, _nrrdFieldSep, nrrd->dim + 1)) { + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d spacings", me, + nrrd->dim); return 1; } if (_nrrdFieldCheck[nrrdField_spacings](nrrd, useBiff)) { @@ -328,10 +316,9 @@ _nrrdReadNrrdParse_spacings(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_thicknesses(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_thicknesses"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_thicknesses(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_thicknesses"; unsigned int ret; double val[NRRD_DIM_MAX]; char *info; @@ -343,9 +330,8 @@ _nrrdReadNrrdParse_thicknesses(FILE *file, Nrrd *nrrd, _CHECK_GOT_ALL_VALUES; nrrdAxisInfoSet_nva(nrrd, nrrdAxisInfoThickness, val); /* HEY: this is a very imperfect check of excess info */ - if (nrrd->dim+1 == airParseStrD(val, info, _nrrdFieldSep, nrrd->dim+1)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d thicknesses", + if (nrrd->dim + 1 == airParseStrD(val, info, _nrrdFieldSep, nrrd->dim + 1)) { + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d thicknesses", me, nrrd->dim); return 1; } @@ -356,10 +342,9 @@ _nrrdReadNrrdParse_thicknesses(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_axis_mins(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_axis_mins"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_axis_mins(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_axis_mins"; unsigned int ret; double val[NRRD_DIM_MAX]; char *info; @@ -371,10 +356,9 @@ _nrrdReadNrrdParse_axis_mins(FILE *file, Nrrd *nrrd, _CHECK_GOT_ALL_VALUES; nrrdAxisInfoSet_nva(nrrd, nrrdAxisInfoMin, val); /* HEY: this is a very imperfect check of excess info */ - if (nrrd->dim+1 == airParseStrD(val, info, _nrrdFieldSep, nrrd->dim+1)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d axis mins", - me, nrrd->dim); + if (nrrd->dim + 1 == airParseStrD(val, info, _nrrdFieldSep, nrrd->dim + 1)) { + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d axis mins", me, + nrrd->dim); return 1; } if (_nrrdFieldCheck[nrrdField_axis_mins](nrrd, useBiff)) { @@ -384,10 +368,9 @@ _nrrdReadNrrdParse_axis_mins(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_axis_maxs(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_axis_maxs"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_axis_maxs(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_axis_maxs"; unsigned int ret; double val[NRRD_DIM_MAX]; char *info; @@ -399,10 +382,9 @@ _nrrdReadNrrdParse_axis_maxs(FILE *file, Nrrd *nrrd, _CHECK_GOT_ALL_VALUES; nrrdAxisInfoSet_nva(nrrd, nrrdAxisInfoMax, val); /* HEY: this is a very imperfect check of excess info */ - if (nrrd->dim+1 == airParseStrD(val, info, _nrrdFieldSep, nrrd->dim+1)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d axis maxs", - me, nrrd->dim); + if (nrrd->dim + 1 == airParseStrD(val, info, _nrrdFieldSep, nrrd->dim + 1)) { + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d axis maxs", me, + nrrd->dim); return 1; } if (_nrrdFieldCheck[nrrdField_axis_maxs](nrrd, useBiff)) { @@ -412,11 +394,11 @@ _nrrdReadNrrdParse_axis_maxs(FILE *file, Nrrd *nrrd, return 0; } -int -_nrrdSpaceVectorParse(double val[NRRD_SPACE_DIM_MAX], - char **hhP, unsigned int spaceDim, int useBiff) { - static const char me[]="_nrrdSpaceVectorParse"; - char *hh, *buff, sep[]=",)"; +static int /* Biff: maybe:4:1 */ +_nrrdSpaceVectorParse(double val[NRRD_SPACE_DIM_MAX], char **hhP, unsigned int spaceDim, + int useBiff) { + static const char me[] = "_nrrdSpaceVectorParse"; + char *hh, *buff, sep[] = ",)"; airArray *mop; unsigned int ret, dd; size_t length; @@ -430,43 +412,43 @@ _nrrdSpaceVectorParse(double val[NRRD_SPACE_DIM_MAX], /* make sure we have something */ if (!*hh) { - biffMaybeAddf(useBiff, NRRD, - "%s: hit end of string before seeing (", me); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: hit end of string before seeing (", me); + airMopError(mop); + return 1; } /* first, see if we're getting the non-vector */ - if ( (strstr(hh, _nrrdNoSpaceVector) == hh) ) { + if ((strstr(hh, _nrrdNoSpaceVector) == hh)) { if (!hh[strlen(_nrrdNoSpaceVector)] || strchr(_nrrdFieldSep, hh[strlen(_nrrdNoSpaceVector)])) { /* yes, we got the non-vector */ - for (dd=0; dd spaceDim) { biffMaybeAddf(useBiff, NRRD, "%s: space dimension is %d, but seem to have %d " - "coefficients", me, spaceDim, ret); - airMopError(mop); return 1; + "coefficients", + me, spaceDim, ret); + airMopError(mop); + return 1; } /* try to parse the values */ - ret = airParseStrD(val, buff+1, ",", spaceDim); + ret = airParseStrD(val, buff + 1, ",", spaceDim); if (spaceDim != ret) { - biffMaybeAddf(useBiff, NRRD, - "%s: parsed %d values, but space dimension is %d", - me, ret, spaceDim); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: parsed %d values, but space dimension is %d", me, + ret, spaceDim); + airMopError(mop); + return 1; } } /* probably not useful */ - for (dd=spaceDim; dddim; dd++) { - if (_nrrdSpaceVectorParse(nrrd->axis[dd].spaceDirection, - &info, nrrd->spaceDim, useBiff)) { - biffMaybeAddf(useBiff, NRRD, - "%s: trouble getting space vector %d of %d", - me, dd+1, nrrd->dim); + for (dd = 0; dd < nrrd->dim; dd++) { + if (_nrrdSpaceVectorParse(nrrd->axis[dd].spaceDirection, &info, nrrd->spaceDim, + useBiff)) { + biffMaybeAddf(useBiff, NRRD, "%s: trouble getting space vector %d of %d", me, + dd + 1, nrrd->dim); return 1; } } if (strlen(info) != strspn(info, _nrrdFieldSep)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d directions", - me, nrrd->dim); + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d directions", me, + nrrd->dim); return 1; } if (_nrrdFieldCheck[nrrdField_space_directions](nrrd, useBiff)) { @@ -560,10 +545,9 @@ _nrrdReadNrrdParse_space_directions(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_centers(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_centers"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_centers(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_centers"; unsigned int ai; char *tok, *info, *last; airArray *mop; @@ -573,13 +557,13 @@ _nrrdReadNrrdParse_centers(FILE *file, Nrrd *nrrd, info = airStrdup(nio->line + nio->pos); airMopAdd(mop, info, airFree, airMopAlways); _CHECK_HAVE_DIM; - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { tok = airStrtok(!ai ? info : NULL, _nrrdFieldSep, &last); if (!tok) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't extract string for center %d of %d", - me, ai+1, nrrd->dim); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: couldn't extract string for center %d of %d", me, + ai + 1, nrrd->dim); + airMopError(mop); + return 1; } if (!strcmp(tok, NRRD_UNKNOWN)) { nrrd->axis[ai].center = nrrdCenterUnknown; @@ -590,30 +574,30 @@ _nrrdReadNrrdParse_centers(FILE *file, Nrrd *nrrd, continue; } if (!(nrrd->axis[ai].center = airEnumVal(nrrdCenter, tok))) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't parse center \"%s\" for axis %d", - me, tok, ai); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse center \"%s\" for axis %d", me, + tok, ai); + airMopError(mop); + return 1; } } if (airStrtok(!ai ? info : NULL, _nrrdFieldSep, &last)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d centers", - me, nrrd->dim); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d centers", me, + nrrd->dim); + airMopError(mop); + return 1; } if (_nrrdFieldCheck[nrrdField_centers](nrrd, useBiff)) { biffMaybeAddf(useBiff, NRRD, "%s: trouble", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } airMopOkay(mop); return 0; } -static int -_nrrdReadNrrdParse_kinds(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_kinds"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_kinds(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_kinds"; unsigned int ai; char *info, *tok, *last; airArray *mop; @@ -623,13 +607,13 @@ _nrrdReadNrrdParse_kinds(FILE *file, Nrrd *nrrd, info = airStrdup(nio->line + nio->pos); airMopAdd(mop, info, airFree, airMopAlways); _CHECK_HAVE_DIM; - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { tok = airStrtok(!ai ? info : NULL, _nrrdFieldSep, &last); if (!tok) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't extract string for kind %d of %d", - me, ai+1, nrrd->dim); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: couldn't extract string for kind %d of %d", me, + ai + 1, nrrd->dim); + airMopError(mop); + return 1; } if (!strcmp(tok, NRRD_UNKNOWN)) { nrrd->axis[ai].kind = nrrdKindUnknown; @@ -640,33 +624,38 @@ _nrrdReadNrrdParse_kinds(FILE *file, Nrrd *nrrd, continue; } if (!(nrrd->axis[ai].kind = airEnumVal(nrrdKind, tok))) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't parse \"%s\" kind %d of %d", - me, tok, ai+1, nrrd->dim); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse \"%s\" kind %d of %d", me, tok, + ai + 1, nrrd->dim); + airMopError(mop); + return 1; } } if (airStrtok(!ai ? info : NULL, _nrrdFieldSep, &last)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d kinds", - me, nrrd->dim); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d kinds", me, + nrrd->dim); + airMopError(mop); + return 1; } /* can't run this now because kinds can come before sizes, in which - case the kind/size check in _nrrdFieldCheck_kinds will incorrectly - flag an error ... - if (_nrrdFieldCheck[nrrdField_kinds](nrrd, useBiff)) { - biffMaybeAddf(useBiff, NRRD, "%s: trouble", me); - airMopError(mop); return 1; - } - */ + * case the kind/size check in _nrrdFieldCheck_kinds will incorrectly + * flag an error ... + * if (_nrrdFieldCheck[nrrdField_kinds](nrrd, useBiff)) { + * biffMaybeAddf(useBiff, NRRD, "%s: trouble", me); + * airMopError(mop); return 1; + * } + */ airMopOkay(mop); return 0; } -static char * +/* + * The kind of double-quoted string extraction used for NRRD units, space units, and + * labels: get the string within the "", with only one kind of escaping supported: + * \" means " + */ +static char * /* Biff: maybe:2:NULL */ _nrrdGetQuotedString(char **hP, int useBiff) { - static const char me[]="_nrrdGetQuotedString"; + static const char me[] = "_nrrdGetQuotedString"; char *h, *buff, *ret; airArray *buffArr; unsigned int pos; @@ -680,8 +669,7 @@ _nrrdGetQuotedString(char **hP, int useBiff) { /* make sure we have something */ if (!*h) { - biffMaybeAddf(useBiff, NRRD, - "%s: hit end of string before seeing opening \"", me); + biffMaybeAddf(useBiff, NRRD, "%s: hit end of string before seeing opening \"", me); return NULL; } /* make sure we have a starting quote */ @@ -699,13 +687,13 @@ _nrrdGetQuotedString(char **hP, int useBiff) { biffMaybeAddf(useBiff, NRRD, "%s: couldn't create airArray", me); return NULL; } - pos = airArrayLenIncr(buffArr, 1); /* pos should get 0 */ + pos = airArrayLenIncr(buffArr, 1); /* pos should get 0 */ while (h[pos]) { /* printf("!%s: h+%d |%s|\n", me, pos, h+pos); */ if ('\"' == h[pos]) { break; } - if ('\\' == h[pos] && '\"' == h[pos+1]) { + if ('\\' == h[pos] && '\"' == h[pos + 1]) { h += 1; } buff[pos] = h[pos]; @@ -725,12 +713,11 @@ _nrrdGetQuotedString(char **hP, int useBiff) { return ret; } -static int -_nrrdReadNrrdParse_labels(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_labels"; - char *h; /* this is the "here" pointer which gradually progresses - through all the labels (for all axes) */ +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_labels(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_labels"; + char *h; /* this is the "here" pointer which gradually progresses + through all the labels (for all axes) */ unsigned int ai; char *info; @@ -741,17 +728,16 @@ _nrrdReadNrrdParse_labels(FILE *file, Nrrd *nrrd, /* printf("!%s: info |%s|\n", me, info); */ _CHECK_HAVE_DIM; h = info; - for (ai=0; aidim; ai++) { - if (!( nrrd->axis[ai].label = _nrrdGetQuotedString(&h, useBiff) )) { - biffMaybeAddf(useBiff, NRRD, "%s: couldn't get get label %d of %d\n", - me, ai+1, nrrd->dim); + for (ai = 0; ai < nrrd->dim; ai++) { + if (!(nrrd->axis[ai].label = _nrrdGetQuotedString(&h, useBiff))) { + biffMaybeAddf(useBiff, NRRD, "%s: couldn't get get label %d of %d\n", me, ai + 1, + nrrd->dim); return 1; } } if (strlen(h) != strspn(h, _nrrdFieldSep)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d labels", - me, nrrd->dim); + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d labels", me, + nrrd->dim); return 1; } if (_nrrdFieldCheck[nrrdField_labels](nrrd, useBiff)) { @@ -761,12 +747,11 @@ _nrrdReadNrrdParse_labels(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_units(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_units"; - char *h; /* this is the "here" pointer which gradually progresses - through all the units (for all axes) */ +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_units(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_units"; + char *h; /* this is the "here" pointer which gradually progresses + through all the units (for all axes) */ unsigned int ai; char *info; @@ -777,17 +762,16 @@ _nrrdReadNrrdParse_units(FILE *file, Nrrd *nrrd, /* printf("!%s: info |%s|\n", me, info); */ _CHECK_HAVE_DIM; h = info; - for (ai=0; aidim; ai++) { - if (!( nrrd->axis[ai].units = _nrrdGetQuotedString(&h, useBiff) )) { - biffMaybeAddf(useBiff, NRRD, "%s: couldn't get get unit %d of %d\n", - me, ai+1, nrrd->dim); + for (ai = 0; ai < nrrd->dim; ai++) { + if (!(nrrd->axis[ai].units = _nrrdGetQuotedString(&h, useBiff))) { + biffMaybeAddf(useBiff, NRRD, "%s: couldn't get get unit %d of %d\n", me, ai + 1, + nrrd->dim); return 1; } } if (strlen(h) != strspn(h, _nrrdFieldSep)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d units", - me, nrrd->dim); + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d units", me, + nrrd->dim); return 1; } if (_nrrdFieldCheck[nrrdField_units](nrrd, useBiff)) { @@ -798,8 +782,7 @@ _nrrdReadNrrdParse_units(FILE *file, Nrrd *nrrd, } static int -_nrrdReadNrrdParse_min(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { +_nrrdReadNrrdParse_min(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { AIR_UNUSED(file); AIR_UNUSED(nrrd); @@ -815,8 +798,7 @@ _nrrdReadNrrdParse_min(FILE *file, Nrrd *nrrd, } static int -_nrrdReadNrrdParse_max(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { +_nrrdReadNrrdParse_max(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { AIR_UNUSED(file); AIR_UNUSED(nrrd); @@ -828,10 +810,9 @@ _nrrdReadNrrdParse_max(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_old_min(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_old_min"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_old_min(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_old_min"; char *info; AIR_UNUSED(file); @@ -844,10 +825,9 @@ _nrrdReadNrrdParse_old_min(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_old_max(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_old_max"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_old_max(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_old_max"; char *info; AIR_UNUSED(file); @@ -860,27 +840,24 @@ _nrrdReadNrrdParse_old_max(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_endian(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_endian"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_endian(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_endian"; char *info; AIR_UNUSED(file); AIR_UNUSED(nrrd); info = nio->line + nio->pos; if (!(nio->endian = airEnumVal(airEndian, info))) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't parse endian \"%s\"", me, info); + biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse endian \"%s\"", me, info); return 1; } return 0; } -static int -_nrrdReadNrrdParse_encoding(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_encoding"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_encoding(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_encoding"; char *info; int etype; @@ -888,8 +865,7 @@ _nrrdReadNrrdParse_encoding(FILE *file, Nrrd *nrrd, AIR_UNUSED(nrrd); info = nio->line + nio->pos; if (!(etype = airEnumVal(nrrdEncodingType, info))) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't parse encoding \"%s\"", me, info); + biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse encoding \"%s\"", me, info); return 1; } @@ -897,10 +873,9 @@ _nrrdReadNrrdParse_encoding(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_line_skip(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_line_skip"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_line_skip(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_line_skip"; char *info; AIR_UNUSED(file); @@ -918,9 +893,8 @@ _nrrdReadNrrdParse_line_skip(FILE *file, Nrrd *nrrd, } static int -_nrrdReadNrrdParse_byte_skip(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_byte_skip"; +_nrrdReadNrrdParse_byte_skip(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_byte_skip"; char *info; AIR_UNUSED(file); @@ -939,10 +913,9 @@ _nrrdReadNrrdParse_byte_skip(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_keyvalue(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_keyvalue"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_keyvalue(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_keyvalue"; char *keysep, *line, *key, *value; AIR_UNUSED(file); @@ -954,15 +927,15 @@ _nrrdReadNrrdParse_keyvalue(FILE *file, Nrrd *nrrd, } keysep = strstr(line, ":="); if (!keysep) { - biffMaybeAddf(useBiff, NRRD, - "%s: didn't see \":=\" key/value delimiter in \"%s\"", + biffMaybeAddf(useBiff, NRRD, "%s: didn't see \":=\" key/value delimiter in \"%s\"", me, line); - free(line); return 1; + free(line); + return 1; } keysep[0] = 0; keysep[1] = 0; key = line; - value = keysep+2; + value = keysep + 2; /* convert escape sequences */ airUnescape(key); @@ -974,18 +947,16 @@ _nrrdReadNrrdParse_keyvalue(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_sample_units(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_sample_units"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_sample_units(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_sample_units"; char *info; AIR_UNUSED(file); info = nio->line + nio->pos; if (strlen(info) && !(nrrd->sampleUnits = airStrdup(info))) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't strdup() sampleUnits", me); + biffMaybeAddf(useBiff, NRRD, "%s: couldn't strdup() sampleUnits", me); return 1; } if (_nrrdFieldCheck[nrrdField_sample_units](nrrd, useBiff)) { @@ -995,10 +966,9 @@ _nrrdReadNrrdParse_sample_units(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_space(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_space"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_space(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_space"; char *info; int space; @@ -1007,12 +977,12 @@ _nrrdReadNrrdParse_space(FILE *file, Nrrd *nrrd, if (nio->seen[nrrdField_space_dimension]) { biffMaybeAddf(useBiff, NRRD, "%s: can't specify space after specifying " - "space dimension (%d)", me, nrrd->spaceDim); + "space dimension (%d)", + me, nrrd->spaceDim); return 1; } if (!(space = airEnumVal(nrrdSpace, info))) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't parse space \"%s\"", me, info); + biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse space \"%s\"", me, info); return 1; } if (nrrdSpaceSet(nrrd, space)) { @@ -1026,10 +996,10 @@ _nrrdReadNrrdParse_space(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_space_dimension(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_space_dimension"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_space_dimension(FILE *file, Nrrd *nrrd, NrrdIoState *nio, + int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_space_dimension"; char *info; AIR_UNUSED(file); @@ -1037,7 +1007,8 @@ _nrrdReadNrrdParse_space_dimension(FILE *file, Nrrd *nrrd, if (nio->seen[nrrdField_space]) { biffMaybeAddf(useBiff, NRRD, "%s: can't specify space dimension after specifying " - "space (%s)", me, airEnumStr(nrrdSpace, nrrd->space)); + "space (%s)", + me, airEnumStr(nrrdSpace, nrrd->space)); return 1; } _PARSE_ONE_VAL(nrrd->spaceDim, "%u", "unsigned int"); @@ -1048,12 +1019,11 @@ _nrrdReadNrrdParse_space_dimension(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_space_units(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_space_units"; - char *h; /* this is the "here" pointer which gradually progresses - through all the units (for all axes) */ +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_space_units(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_space_units"; + char *h; /* this is the "here" pointer which gradually progresses + through all the units (for all axes) */ unsigned int ai; char *info; @@ -1064,16 +1034,15 @@ _nrrdReadNrrdParse_space_units(FILE *file, Nrrd *nrrd, /* printf("!%s: info |%s|\n", me, info); */ _CHECK_HAVE_SPACE_DIM; h = info; - for (ai=0; aispaceDim; ai++) { - if (!( nrrd->spaceUnits[ai] = _nrrdGetQuotedString(&h, useBiff) )) { - biffMaybeAddf(useBiff, NRRD, "%s: couldn't get get space unit %d of %d", - me, ai+1, nrrd->spaceDim); + for (ai = 0; ai < nrrd->spaceDim; ai++) { + if (!(nrrd->spaceUnits[ai] = _nrrdGetQuotedString(&h, useBiff))) { + biffMaybeAddf(useBiff, NRRD, "%s: couldn't get get space unit %d of %d", me, + ai + 1, nrrd->spaceDim); return 1; } } if (_nrrdGetQuotedString(&h, AIR_FALSE)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seemed to have more than expected %d space units", + biffMaybeAddf(useBiff, NRRD, "%s: seemed to have more than expected %d space units", me, nrrd->spaceDim); return 1; } @@ -1084,10 +1053,9 @@ _nrrdReadNrrdParse_space_units(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_space_origin(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_space_origin"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_space_origin(FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_space_origin"; char *info; AIR_UNUSED(file); @@ -1095,10 +1063,8 @@ _nrrdReadNrrdParse_space_origin(FILE *file, Nrrd *nrrd, _CHECK_HAVE_SPACE_DIM; - if (_nrrdSpaceVectorParse(nrrd->spaceOrigin, &info, - nrrd->spaceDim, useBiff)) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't parse origin \"%s\"", me, info); + if (_nrrdSpaceVectorParse(nrrd->spaceOrigin, &info, nrrd->spaceDim, useBiff)) { + biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse origin \"%s\"", me, info); return 1; } if (_nrrdFieldCheck[nrrdField_space_origin](nrrd, useBiff)) { @@ -1108,10 +1074,10 @@ _nrrdReadNrrdParse_space_origin(FILE *file, Nrrd *nrrd, return 0; } -static int -_nrrdReadNrrdParse_measurement_frame(FILE *file, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_measurement_frame"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_measurement_frame(FILE *file, Nrrd *nrrd, NrrdIoState *nio, + int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_measurement_frame"; double colvec[NRRD_SPACE_DIM_MAX]; unsigned int dd, ii; char *info; @@ -1121,28 +1087,24 @@ _nrrdReadNrrdParse_measurement_frame(FILE *file, Nrrd *nrrd, _CHECK_HAVE_SPACE_DIM; - for (dd=0; ddspaceDim; dd++) { + for (dd = 0; dd < nrrd->spaceDim; dd++) { /* we are going through the *columns* of the mf matrix */ if (_nrrdSpaceVectorParse(colvec, &info, nrrd->spaceDim, useBiff)) { - biffMaybeAddf(useBiff, NRRD, - "%s: trouble getting space vector %d of %d", - me, dd+1, nrrd->spaceDim); + biffMaybeAddf(useBiff, NRRD, "%s: trouble getting space vector %d of %d", me, + dd + 1, nrrd->spaceDim); return 1; } - for (ii=0; iimeasurementFrame[dd][ii] = (ii < nrrd->spaceDim - ? colvec[ii] - : AIR_NAN); + for (ii = 0; ii < NRRD_SPACE_DIM_MAX; ii++) { + nrrd->measurementFrame[dd][ii] = (ii < nrrd->spaceDim ? colvec[ii] : AIR_NAN); } } if (strlen(info) != strspn(info, _nrrdFieldSep)) { - biffMaybeAddf(useBiff, NRRD, - "%s: seem to have more than expected %d directions", - me, nrrd->spaceDim); + biffMaybeAddf(useBiff, NRRD, "%s: seem to have more than expected %d directions", me, + nrrd->spaceDim); return 1; } - for (dd=nrrd->spaceDim; ddspaceDim; dd < NRRD_SPACE_DIM_MAX; dd++) { + for (ii = 0; ii < NRRD_SPACE_DIM_MAX; ii++) { nrrd->measurementFrame[dd][ii] = AIR_NAN; } } @@ -1153,14 +1115,14 @@ _nrrdReadNrrdParse_measurement_frame(FILE *file, Nrrd *nrrd, return 0; } -int -_nrrdContainsPercentThisAndMore(const char *str, char thss) { +int /* Biff: nope */ +nrrdContainsPercentThisAndMore(const char *str, char thss) { const char *hh, *tmp; tmp = str; do { hh = strchr(tmp, '%'); - if (!( hh && hh[1] )) { + if (!(hh && hh[1])) { return 0; } if ('%' == hh[1]) { @@ -1172,14 +1134,14 @@ _nrrdContainsPercentThisAndMore(const char *str, char thss) { } while (tmp[0]); hh++; hh += strspn(hh, "0123456789"); - if (!( hh[0] == thss )) { + if (!(hh[0] == thss)) { return 0; } hh += strcspn(hh, _nrrdFieldSep); return !!hh; } -unsigned int +unsigned int /* Biff: nope */ _nrrdDataFNNumber(NrrdIoState *nio) { unsigned int ret; int ii; @@ -1187,9 +1149,8 @@ _nrrdDataFNNumber(NrrdIoState *nio) { if (nio->dataFNFormat) { /* datafiles given in iterator form; count number of values */ ret = 0; - for (ii = nio->dataFNMin; - ((nio->dataFNStep > 0 && ii <= nio->dataFNMax) - || (nio->dataFNStep < 0 && ii >= nio->dataFNMax)); + for (ii = nio->dataFNMin; ((nio->dataFNStep > 0 && ii <= nio->dataFNMax) + || (nio->dataFNStep < 0 && ii >= nio->dataFNMax)); ii += nio->dataFNStep) { ret += 1; } @@ -1208,14 +1169,15 @@ _nrrdDataFNNumber(NrrdIoState *nio) { /* ** this always requires that the per-axis size fields have been set */ -int +int /* Biff: maybe:3:1 */ _nrrdDataFNCheck(NrrdIoState *nio, Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdDataFNCheck"; + static const char me[] = "_nrrdDataFNCheck"; size_t pieceSize, pieceNum; - char stmp[AIR_STRLEN_SMALL]; + char stmp[AIR_STRLEN_SMALL + 1]; if (!nio->seen[nrrdField_sizes]) { - biffMaybeAddf(useBiff, NRRD, "%s: sorry, currently can't handle " + biffMaybeAddf(useBiff, NRRD, + "%s: sorry, currently can't handle " "multiple detached data files without first knowing " "the \"%s\" field", me, airEnumStr(nrrdField, nrrdField_sizes)); @@ -1227,32 +1189,30 @@ _nrrdDataFNCheck(NrrdIoState *nio, Nrrd *nrrd, int useBiff) { if (pieceNum != _nrrdDataFNNumber(nio)) { biffMaybeAddf(useBiff, NRRD, "%s: expected %s filenames (of %u-D pieces) " - "but got %u", me, - airSprintSize_t(stmp, pieceNum), nio->dataFileDim, + "but got %u", + me, airSprintSize_t(stmp, pieceNum), nio->dataFileDim, _nrrdDataFNNumber(nio)); return 1; } } else { /* we're getting data in "slabs" with the same dimension as the nrrd, so for simplicity we assume that they're all equal size */ - if (_nrrdDataFNNumber(nio) > nrrd->axis[nrrd->dim-1].size) { + if (_nrrdDataFNNumber(nio) > nrrd->axis[nrrd->dim - 1].size) { biffMaybeAddf(useBiff, NRRD, "%s: can't have more pieces (%u) than axis %u " "slices (%s) when nrrd dimension and " - "datafile dimension are both %u", me, - _nrrdDataFNNumber(nio), - nrrd->dim-1, - airSprintSize_t(stmp, nrrd->axis[nrrd->dim-1].size), - nrrd->dim); + "datafile dimension are both %u", + me, _nrrdDataFNNumber(nio), nrrd->dim - 1, + airSprintSize_t(stmp, nrrd->axis[nrrd->dim - 1].size), nrrd->dim); return 1; } - if ((double)nrrd->axis[nrrd->dim-1].size/_nrrdDataFNNumber(nio) - != nrrd->axis[nrrd->dim-1].size/_nrrdDataFNNumber(nio)) { + if ((double)nrrd->axis[nrrd->dim - 1].size / _nrrdDataFNNumber(nio) + != nrrd->axis[nrrd->dim - 1].size / _nrrdDataFNNumber(nio)) { biffMaybeAddf(useBiff, NRRD, "%s: number of datafiles (%d) doesn't divide into " - "number of axis %u slices (%s)", me, - (int)_nrrdDataFNNumber(nio), nrrd->dim-1, - airSprintSize_t(stmp, nrrd->axis[nrrd->dim-1].size)); + "number of axis %u slices (%s)", + me, (int)_nrrdDataFNNumber(nio), nrrd->dim - 1, + airSprintSize_t(stmp, nrrd->axis[nrrd->dim - 1].size)); return 1; } } @@ -1270,10 +1230,9 @@ _nrrdDataFNCheck(NrrdIoState *nio, Nrrd *nrrd, int useBiff) { ** identifying multiple data files, and possibly prefixing them with ** nio->path. */ -static int -_nrrdReadNrrdParse_data_file(FILE *ffile, Nrrd *nrrd, - NrrdIoState *nio, int useBiff) { - static const char me[]="_nrrdReadNrrdParse_data_file"; +static int /* Biff: maybe:4:1 */ +_nrrdReadNrrdParse_data_file(FILE *ffile, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { + static const char me[] = "_nrrdReadNrrdParse_data_file"; char *info, *nums; unsigned int linelen, tmp; airArray *mop; @@ -1287,9 +1246,9 @@ _nrrdReadNrrdParse_data_file(FILE *ffile, Nrrd *nrrd, airMopAdd(mop, info, airFree, airMopAlways); /* HEY: this change should be made someday - if (_nrrdContainsPercentThisAndMore(info, 'd') - || _nrrdContainsPercentThisAndMore(info, 'u')) { */ - if (_nrrdContainsPercentThisAndMore(info, 'd')) { + if (nrrdContainsPercentThisAndMore(info, 'd') + || nrrdContainsPercentThisAndMore(info, 'u')) { */ + if (nrrdContainsPercentThisAndMore(info, 'd')) { /* ---------------------------------------------------------- */ /* --------- format.%d [] ----------- */ /* ---------------------------------------------------------- */ @@ -1297,96 +1256,151 @@ _nrrdReadNrrdParse_data_file(FILE *ffile, Nrrd *nrrd, _CHECK_HAVE_DIM; nums = info + strcspn(info, _nrrdFieldSep); sspn = strspn(nums, _nrrdFieldSep); - nums[0] = 0; /* terminate so that format is now in info */ + nums[0] = 0; /* terminate so that format is now in info */ nums += sspn; - if (!( 3 == sscanf(nums, "%d %d %d",&(nio->dataFNMin), - &(nio->dataFNMax), &(nio->dataFNStep)) )) { + if (!(3 + == sscanf(nums, "%d %d %d", &(nio->dataFNMin), &(nio->dataFNMax), + &(nio->dataFNStep)))) { biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse three ints (min, max, step) after " - "data filename template", me); - airMopError(mop); return 1; + "data filename template", + me); + airMopError(mop); + return 1; } - if ( 4 == sscanf(nums, "%d %d %d %u", &(nio->dataFNMin), - &(nio->dataFNMax), &(nio->dataFNStep), - &(nio->dataFileDim)) ) { + if (4 + == sscanf(nums, "%d %d %d %u", &(nio->dataFNMin), &(nio->dataFNMax), + &(nio->dataFNStep), &(nio->dataFileDim))) { if (!AIR_IN_CL(1, nio->dataFileDim, nrrd->dim)) { biffMaybeAddf(useBiff, NRRD, - "%s: datafile dimension %u outside valid range [1,%u]", - me, nio->dataFileDim, nrrd->dim); - airMopError(mop); return 1; + "%s: datafile dimension %u outside valid range [1,%u]", me, + nio->dataFileDim, nrrd->dim); + airMopError(mop); + return 1; } } else { - nio->dataFileDim = nrrd->dim-1; + nio->dataFileDim = nrrd->dim - 1; } if (0 == nio->dataFNStep) { - biffMaybeAddf(useBiff, NRRD, - "%s: file number step must be non-zero", me); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: file number step must be non-zero", me); + airMopError(mop); + return 1; } - if ((nio->dataFNMax - nio->dataFNMin)*(nio->dataFNStep) < 0) { + if ((nio->dataFNMax - nio->dataFNMin) * (nio->dataFNStep) < 0) { biffMaybeAddf(useBiff, NRRD, "%s: file number max %d not approached from min %d " - "by step %d", me, - nio->dataFNMax, nio->dataFNMin, nio->dataFNStep); - airMopError(mop); return 1; + "by step %d", + me, nio->dataFNMax, nio->dataFNMin, nio->dataFNStep); + airMopError(mop); + return 1; } - if (!( nio->dataFNFormat = airStrdup(info) )) { - biffMaybeAddf(useBiff, NRRD, - "%s: couldn't copy data filename format", me); - airMopError(mop); return 1; + if (!(nio->dataFNFormat = airStrdup(info))) { + biffMaybeAddf(useBiff, NRRD, "%s: couldn't copy data filename format", me); + airMopError(mop); + return 1; } if (_nrrdDataFNCheck(nio, nrrd, useBiff)) { - biffMaybeAddf(useBiff, NRRD, - "%s: trouble with number of datafiles", me); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: trouble with number of datafiles", me); + airMopError(mop); + return 1; } - } else if (!strncmp(info, NRRD_LIST_FLAG, strlen(NRRD_LIST_FLAG))) { + } else if (!strncmp(info, NRRD_LIST_FLAG, strlen(NRRD_LIST_FLAG)) + || !strncmp(info, NRRD_SKIPLIST_FLAG, strlen(NRRD_SKIPLIST_FLAG))) { + int skiplist; + unsigned int lineidx; /* ---------------------------------------------------------- */ - /* ------------------------- LIST --------------------------- */ + /* -------------------- LIST or SKIPLIST -------------------- */ /* ---------------------------------------------------------- */ _CHECK_HAVE_DIM; + skiplist = !strncmp(info, NRRD_SKIPLIST_FLAG, strlen(NRRD_SKIPLIST_FLAG)); if (_nrrdHeaderCheck(nrrd, nio, AIR_TRUE)) { - biffMaybeAddf(useBiff, NRRD, "%s: NRRD header is incomplete. \"" - NRRD_LIST_FLAG "\" data file specification must be " - "contiguous with end of header!", me); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, + "%s: NRRD header is incomplete. " + "\"%s\" data file specification must be " + "contiguous with end of header!", + me, skiplist ? NRRD_SKIPLIST_FLAG : NRRD_LIST_FLAG); + airMopError(mop); + return 1; } - info += strlen(NRRD_LIST_FLAG); + info += strlen(skiplist ? NRRD_SKIPLIST_FLAG : NRRD_LIST_FLAG); if (info[0]) { if (1 == sscanf(info, "%u", &(nio->dataFileDim))) { if (!AIR_IN_CL(1, nio->dataFileDim, nrrd->dim)) { - biffMaybeAddf(useBiff, NRRD, "%s: datafile dimension %u outside " + biffMaybeAddf(useBiff, NRRD, + "%s: datafile dimension %u outside " "valid range [1,%u]", me, nio->dataFileDim, nrrd->dim); - airMopError(mop); return 1; + airMopError(mop); + return 1; } } else { - biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse info after \"" - NRRD_LIST_FLAG "\" as an int", me); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, + "%s: couldn't parse info after " + "\"%s\" as an int", + me, skiplist ? NRRD_SKIPLIST_FLAG : NRRD_LIST_FLAG); + airMopError(mop); + return 1; } } else { - /* nothing after NRRD_LIST_FLAG, so dataFileDim is implicit */ - nio->dataFileDim = nrrd->dim-1; + /* nothing after NRRD_LIST_FLAG or NRRD_SKIPLIST_FLAG, + so dataFileDim is implicit */ + nio->dataFileDim = nrrd->dim - 1; } /* read in all the datafile names */ + lineidx = 0; do { - /* yes, nio->line is re-used/over-written here, but I don't - think that's a problem */ - if (_nrrdOneLine(&linelen, nio, ffile)) { - biffMaybeAddf(useBiff, NRRD, - "%s: trouble getting file name line", me); - airMopError(mop); return 1; + /* yes, nio->line is re-used/over-written here, but I don't think that's a problem + (2025 ha ha can I point out nioLineSave in formatNRRD.c/_nrrdFormatNRRD_read) */ + if (nrrdOneLine(&linelen, nio, ffile)) { + biffMaybeAddf(useBiff, NRRD, "%s: trouble getting file name line %u", me, + lineidx); + airMopError(mop); + return 1; } if (linelen > 0) { - tmp = airArrayLenIncr(nio->dataFNArr, 1); - nio->dataFN[tmp] = airStrdup(nio->line); + /* we got a non-empty line */ + if (skiplist) { + char *lhere; + long int oneskip; + if (1 != airSingleSscanf(nio->line, "%ld", &oneskip)) { + biffMaybeAddf(useBiff, NRRD, "%s: couldn't parse skip on list line %u", me, + lineidx); + airMopError(mop); + return 1; + } + lhere = strchr(nio->line, ' '); + if (!lhere) { + biffMaybeAddf(useBiff, NRRD, + "%s: didn't see space after " + "skip on list line %u", + me, lineidx); + airMopError(mop); + return 1; + } + lhere++; + if (!(lhere[0])) { + biffMaybeAddf(useBiff, NRRD, + "%s: didn't see filename after " + "skip and space on list line %u", + me, lineidx); + airMopError(mop); + return 1; + } + airArrayLenIncr(nio->dataFSkipArr, 1); + nio->dataFSkip[lineidx] = oneskip; + airArrayLenIncr(nio->dataFNArr, 1); + nio->dataFN[lineidx] = airStrdup(lhere); + } else { + airArrayLenIncr(nio->dataFNArr, 1); + nio->dataFN[lineidx] = airStrdup(nio->line); + } } + ++lineidx; } while (linelen > 0); if (_nrrdDataFNCheck(nio, nrrd, useBiff)) { - biffMaybeAddf(useBiff, NRRD, - "%s: trouble with number of datafiles", me); - airMopError(mop); return 1; + biffMaybeAddf(useBiff, NRRD, "%s: trouble with number of datafiles", me); + airMopError(mop); + return 1; } } else { /* ---------------------------------------------------------- */ @@ -1407,43 +1421,111 @@ _nrrdReadNrrdParse_data_file(FILE *ffile, Nrrd *nrrd, ** ** These are all for parsing the stuff AFTER the colon */ -int -(*nrrdFieldInfoParse[NRRD_FIELD_MAX+1])(FILE *, Nrrd *, - NrrdIoState *, int) = { - _nrrdReadNrrdParse_nonfield, - _nrrdReadNrrdParse_comment, - _nrrdReadNrrdParse_content, - _nrrdReadNrrdParse_number, - _nrrdReadNrrdParse_type, - _nrrdReadNrrdParse_block_size, - _nrrdReadNrrdParse_dimension, - _nrrdReadNrrdParse_space, - _nrrdReadNrrdParse_space_dimension, - _nrrdReadNrrdParse_sizes, - _nrrdReadNrrdParse_spacings, - _nrrdReadNrrdParse_thicknesses, - _nrrdReadNrrdParse_axis_mins, - _nrrdReadNrrdParse_axis_maxs, - _nrrdReadNrrdParse_space_directions, - _nrrdReadNrrdParse_centers, - _nrrdReadNrrdParse_kinds, - _nrrdReadNrrdParse_labels, - _nrrdReadNrrdParse_units, - _nrrdReadNrrdParse_min, - _nrrdReadNrrdParse_max, - _nrrdReadNrrdParse_old_min, - _nrrdReadNrrdParse_old_max, - _nrrdReadNrrdParse_endian, - _nrrdReadNrrdParse_encoding, - _nrrdReadNrrdParse_line_skip, - _nrrdReadNrrdParse_byte_skip, - _nrrdReadNrrdParse_keyvalue, - _nrrdReadNrrdParse_sample_units, - _nrrdReadNrrdParse_space_units, - _nrrdReadNrrdParse_space_origin, - _nrrdReadNrrdParse_measurement_frame, - _nrrdReadNrrdParse_data_file -}; +int (*const nrrdFieldInfoParse[NRRD_FIELD_MAX + 1])(FILE *, Nrrd *, NrrdIoState *, int) + = {_nrrdReadNrrdParse_nonfield, + _nrrdReadNrrdParse_comment, + _nrrdReadNrrdParse_content, + _nrrdReadNrrdParse_number, + _nrrdReadNrrdParse_type, + _nrrdReadNrrdParse_block_size, + _nrrdReadNrrdParse_dimension, + _nrrdReadNrrdParse_space, + _nrrdReadNrrdParse_space_dimension, + _nrrdReadNrrdParse_sizes, + _nrrdReadNrrdParse_spacings, + _nrrdReadNrrdParse_thicknesses, + _nrrdReadNrrdParse_axis_mins, + _nrrdReadNrrdParse_axis_maxs, + _nrrdReadNrrdParse_space_directions, + _nrrdReadNrrdParse_centers, + _nrrdReadNrrdParse_kinds, + _nrrdReadNrrdParse_labels, + _nrrdReadNrrdParse_units, + _nrrdReadNrrdParse_min, + _nrrdReadNrrdParse_max, + _nrrdReadNrrdParse_old_min, + _nrrdReadNrrdParse_old_max, + _nrrdReadNrrdParse_endian, + _nrrdReadNrrdParse_encoding, + _nrrdReadNrrdParse_line_skip, + _nrrdReadNrrdParse_byte_skip, + _nrrdReadNrrdParse_keyvalue, + _nrrdReadNrrdParse_sample_units, + _nrrdReadNrrdParse_space_units, + _nrrdReadNrrdParse_space_origin, + _nrrdReadNrrdParse_measurement_frame, + _nrrdReadNrrdParse_data_file}; /* kernel parsing is all in kernel.c */ +/* nrrdStringValsParse[]: parse N values of given type from string + NB: based on air/parseAir.c +*/ +#define P_ARGS (void *_out, const char *_s, const char *sep, size_t n) +#define P_BODY(type, ntype) \ + size_t i; \ + char *tmp, *s, *last; \ + const char *format; \ + type *out; \ + \ + /* if we got NULL, there's nothing to do */ \ + if (!(_out && _s && sep)) return 0; \ + format = nrrdTypePrintfStr[ntype]; \ + out = (type *)_out; \ + /* copy the input so that we don't change it */ \ + s = airStrdup(_s); \ + \ + /* keep calling airStrtok() until we have everything */ \ + for (i = 0; i < n; i++) { \ + tmp = airStrtok(i ? NULL : s, sep, &last); \ + if (!tmp) { \ + free(s); \ + return i; \ + } \ + if (1 != airSingleSscanf(tmp, format, out + i)) { \ + free(s); \ + return i; \ + } \ + } \ + free(s); \ + return n + +/* clang-format off */ +static size_t _parseChar P_ARGS { P_BODY( char, nrrdTypeChar); } +static size_t _parseUChar P_ARGS { P_BODY( unsigned char, nrrdTypeUChar); } +static size_t _parseShort P_ARGS { P_BODY( short, nrrdTypeShort); } +static size_t _parseUShort P_ARGS { P_BODY(unsigned short, nrrdTypeUShort); } +static size_t _parseInt P_ARGS { P_BODY( int, nrrdTypeInt); } +static size_t _parseUInt P_ARGS { P_BODY( unsigned int, nrrdTypeUInt); } +static size_t _parseLLong P_ARGS { P_BODY( airLLong, nrrdTypeLLong); } +static size_t _parseULLong P_ARGS { P_BODY( airULLong, nrrdTypeULLong); } +static size_t _parseFloat P_ARGS { P_BODY( float, nrrdTypeFloat); } +static size_t _parseDouble P_ARGS { P_BODY( double, nrrdTypeDouble); } +static size_t _parseNoop(void *out, const char *s, const char *sep, size_t n) { + AIR_UNUSED(out); + AIR_UNUSED(s); + AIR_UNUSED(sep); + AIR_UNUSED(n); + return 0; +} +#undef P_ARGS +#undef P_BODY + +size_t +(*const nrrdStringValsParse[NRRD_TYPE_MAX+1])(void *out, const char *s, + const char *sep, size_t n) += { + _parseNoop, /* 0 = unknown */ + _parseChar, + _parseUChar, + _parseShort, + _parseUShort, + _parseInt, + _parseUInt, + _parseLLong, + _parseULLong, + _parseFloat, + _parseDouble, + _parseNoop /* block */ +}; +/* clang-format on */ diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/pre-GNUmakefile b/Modules/ThirdParty/NrrdIO/src/NrrdIO/pre-GNUmakefile index 22238896db1..62d0bba1275 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/pre-GNUmakefile +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/pre-GNUmakefile @@ -1,8 +1,8 @@ # -# NrrdIO: stand-alone code for basic nrrd functionality -# Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago -# Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann -# Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah +# NrrdIO: C library for NRRD file IO (with optional compression) +# Copyright (C) 2009--2025 University of Chicago +# Copyright (C) 2005--2008 Gordon Kindlmann +# Copyright (C) 1998--2004 University of Utah # # This software is provided 'as-is', without any express or implied # warranty. In no event will the authors be held liable for any @@ -23,36 +23,22 @@ # 3. This notice may not be removed or altered from any source distribution. # -### The process of creating the NrrdIO source distribution from a Teem -### source distribution is automated, and is controlled by this GNU -### makefile: +### The process of creating the NrrdIO source distribution from a Teem source +### distribution is automated, and is controlled by this GNUmakefile. ### -### for the NrrdIO in ITK: +### First, set environment variable TEEM_SRC_ROOT to root of Teem source: the +### full path to the directory containing `src` (with `src/air`, `src/biff`, +### `src/nrrd` subidrectories). Then run: ### -### svn update -### rm -f itk_NrrdIO_mangle.h -### touch itk_NrrdIO_mangle.h -### make -f pre-GNUmakefile clean -### setenv ITK_NRRDIO -### make -f pre-GNUmakefile -### unsetenv ITK_NRRDIO -### make -f sample-GNUmakefile -### perl mangle.pl itk >! itk_NrrdIO_mangle.h -### make -f sample-GNUmakefile clean +### ./0-gen.sh # for generating regular NrrdIO ### -### for a NrrdIO in any other application +### or: ### -### svn update -### make -f pre-GNUmakefile clean -### make -f pre-GNUmakefile -### make -f sample-GNUmakefile -### make -f sample-GNUmakefile clean +### ./0-gen.sh itk # for generating NrrdIO for ITK ### -### This file is the single place where the required Teem source files -### are listed. Once the NrrdIO source distribution is created, this -### GNU makefile is completely moot. TEEM_SRC_ROOT must be set in order -### to locate the Teem source. We use this instead of TEEM_ROOT to avoid -### conflict with Teem's own make system +### This pre-GNUmakefile file is the single place where the required Teem source +### files are listed, and this file is only used for creating the NrrdIO source +### distribution (not for compiling it) $(if $(TEEM_SRC_ROOT),,\ $(warning *)\ @@ -63,38 +49,38 @@ $(warning * distribution (rather than a Teem installation))\ $(warning *)\ $(error Make quitting)) +### Like Teem, we rely on clang-format for auto-formatting sources +### (The .clang-format is copied from Teem) +CLANG_FORMAT = clang-format --style=file --assume-filename=foo.c + ### The following sources are pretty much stubs, to create the symbols, ### but not the functionality of different formats and the bzip2 encoding. ### As such, they are NOT copied from Teem but are made for NrrdIO. ### -NEED_NOT = encodingBzip2.c formatEPS.c formatPNG.c formatPNM.c \ +NEED_NOT = formatEPS.c formatPNG.c formatPNM.c \ formatText.c formatVTK.c -### These are still needed for exact same functionality as in Teem -### -TEEM_HDRS = $(addprefix teem/, \ - teemDio.h teemPng.h teemQnanhibit.h) +# Gone in TeemV2: TEEM_HDRS = $(addprefix teem/, teemDio.h teemPng.h teemQnanhibit.h) ### NEED_{AIR,BIFF,NRRD}: the source files from teem that we need ### NEED_HDRS: the headers that we need ### NEED_AIR = $(addprefix air/, \ - 754.c mop.c array.c parseAir.c dio.c \ + 754.c mop.c array.c parseAir.c \ sane.c endianAir.c string.c enum.c miscAir.c) NEED_BIFF = $(addprefix biff/, biffbiff.c biffmsg.c) NEED_NRRD = $(addprefix nrrd/, \ accessors.c defaultsNrrd.c enumsNrrd.c arraysNrrd.c methodsNrrd.c \ reorder.c axis.c simple.c comment.c keyvalue.c endianNrrd.c \ parseNrrd.c gzio.c read.c write.c format.c formatNRRD.c \ - encoding.c encodingRaw.c encodingAscii.c encodingHex.c encodingGzip.c \ - subset.c) + encodingRaw.c encodingAscii.c encodingHex.c encodingGzip.c encodingZRL.c \ + encodingBzip2.c encoding.c subset.c) NEED_SRCS = $(NEED_AIR) $(NEED_BIFF) $(NEED_NRRD) NEED_PUB_HDRS = air/air.h biff/biff.h \ $(addprefix nrrd/, nrrdDefines.h nrrdEnums.h nrrdMacros.h nrrd.h) NEED_PRIV_HDRS = air/privateAir.h biff/privateBiff.h nrrd/privateNrrd.h -### Building NrrdIO requires the teem*.h headers, and the processed sources -### from air, biff, and nrrd +### Building NrrdIO requires processed sources from air, biff, and nrrd ### .PHONY: all ifeq (undefined,$(origin ITK_NRRDIO)) @@ -102,31 +88,34 @@ ifeq (undefined,$(origin ITK_NRRDIO)) else NRRDIO_H = NrrdIO.h.in endif -all: $(TEEM_HDRS) $(NEED_SRCS) $(NEED_PRIV_HDRS) $(NRRDIO_H) NrrdIO_Srcs.txt +all: $(NEED_SRCS) $(NEED_PRIV_HDRS) $(NRRDIO_H) NrrdIO_Srcs.txt ### NrrdIO.h is basically the result of cat'ing together all the ### teem headers in $(NEED_HDRS), but we do need to "unteem" them. ### In the case of ITK, we have to put this into NrrdIO.h.in, so -### that ITK's CMake to process the #cmakedefine line. But we still -### a NrrdIO.h to build the library here, in order to run nm to get +### that ITK's CMake can process the #cmakedefine line. But we still +### need a NrrdIO.h to build the library here, in order to run nm to get ### all the symbols for name mangling ### $(NEED_PUB_HDRS): - perl tail.pl < $(TEEM_SRC_ROOT)/src/$@ \ - | perl unteem.pl \ - | grep -v HAS_BEEN_INCLUDED > $(notdir $@) + ./tail.py < $(TEEM_SRC_ROOT)/src/$@ \ + | ./unteem.py \ + | grep -v HAS_BEEN_INCLUDED > $(notdir $@) $(NEED_PRIV_HDRS): - perl tail.pl < $(TEEM_SRC_ROOT)/src/$@ \ - | cat preamble.c - \ - | perl unteem.pl \ - | grep -v HAS_BEEN_INCLUDED > $(notdir $@) + ./tail.py < $(TEEM_SRC_ROOT)/src/$@ \ + | cat preamble.c - \ + | ./unteem.py \ + | grep -v HAS_BEEN_INCLUDED \ + | $(CLANG_FORMAT) > $(notdir $@) ifeq (undefined,$(origin ITK_NRRDIO)) $(NRRDIO_H): $(NEED_PUB_HDRS) - cat preamble.c $(notdir $(NEED_PUB_HDRS)) > $(NRRDIO_H) + cat preamble.c $(notdir $(NEED_PUB_HDRS)) \ + | $(CLANG_FORMAT) > $(NRRDIO_H) rm -f $(notdir $(NEED_PUB_HDRS)) else $(NRRDIO_H): $(NEED_PUB_HDRS) - cat preamble.c $(notdir $(NEED_PUB_HDRS)) > $(NRRDIO_H) + cat preamble.c $(notdir $(NEED_PUB_HDRS)) \ + | $(CLANG_FORMAT) > $(NRRDIO_H) grep -v cmakedefine NrrdIO.h.in > NrrdIO.h rm -f $(notdir $(NEED_PUB_HDRS)) endif @@ -137,26 +126,20 @@ endif NrrdIO_Srcs.txt: echo $(notdir $(NEED_SRCS)) $(NEED_NOT) > $@ -### The teem*.h headers: we need only change the pre-amble here -### -teem/%.h: - perl tail.pl < $(TEEM_SRC_ROOT)/include/$(notdir $@) \ - | cat preamble.c - > $(notdir $@) - ### The rest: by design, these targets have the library names as part ### of the name (e.g. nrrd/simple.c) and that allows us to locate the ### source file without any VPATH games ### %.h %.c: - perl tail.pl < $(TEEM_SRC_ROOT)/src/$@ \ + ./tail.py < $(TEEM_SRC_ROOT)/src/$@ \ | cat preamble.c - \ - | perl unteem.pl \ - | grep -v HAS_BEEN_INCLUDED > $(notdir $@) - + | ./unteem.py \ + | grep -v HAS_BEEN_INCLUDED \ + | $(CLANG_FORMAT) > $(notdir $@) ### To start from scratch ### clean: - rm -f $(notdir $(TEEM_HDRS) $(NEED_SRCS) \ + rm -f $(notdir $(NEED_SRCS) \ $(NEED_PUB_HDRS) $(NEED_PRIV_HDRS)) \ NrrdIO.in.h NrrdIO.h NrrdIO_Srcs.txt \ *.o libNrrdIO.a sampleIO diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/preamble.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/preamble.c index 5744ee5b072..952b32bd9fd 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/preamble.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/preamble.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateAir.h b/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateAir.h index 67deda1da74..e8fadd52704 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateAir.h +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateAir.h @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -23,6 +23,13 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifdef __cplusplus +extern "C" { +#endif + /* miscAir.c */ extern double _airSanityHelper(double val); +#ifdef __cplusplus +} +#endif diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateBiff.h b/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateBiff.h index d2b8e99d6da..a493b2ec6a7 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateBiff.h +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateBiff.h @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -23,24 +23,34 @@ 3. This notice may not be removed or altered from any source distribution. */ - #ifdef __cplusplus extern "C" { #endif /* -** This private header exists because these functions are used in -** the biff sources, but no where else. Also, they take a va_list, -** which is unusual, and (currently) used for no other public functions -** in Teem. Use of va_list args complicates python wrapping (at least -** with the current ctypeslib mechanism), so these functions are being -** taken out of the public API. +** This private header was created because the following two "VL" functions are used +** only within in the biff sources. They take a va_list, which is unusual, and +** (currently) used for no other public functions in Teem. +** +** Furthermore, pre-1.13 release it became apparent that nothing else in Teem (outside +** of biff) was using any biffMsg anything, so these were also all moved to here, +** though out of laziness no _ prefix was added (as is expected of "private" text +** symbols in the library) */ /* biffmsg.c */ extern void _biffMsgAddVL(biffMsg *msg, const char *errfmt, va_list args); -extern void _biffMsgMoveVL(biffMsg *dest, biffMsg *src, - const char *errfmt, va_list args); +extern void _biffMsgMoveVL(biffMsg *dest, biffMsg *src, const char *errfmt, + va_list args); + +extern biffMsg *biffMsgNew(const char *key); +extern biffMsg *biffMsgNix(biffMsg *msg); +extern void biffMsgAdd(biffMsg *msg, const char *err); +extern void biffMsgClear(biffMsg *msg); +extern void biffMsgMove(biffMsg *dest, biffMsg *src, const char *err); +extern unsigned int biffMsgErrNum(const biffMsg *msg); +extern unsigned int biffMsgStrlen(const biffMsg *msg); +extern void biffMsgStrSet(char *ret, const biffMsg *msg); #ifdef __cplusplus } diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateNrrd.h b/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateNrrd.h index 766ab723d77..f4427178d7e 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateNrrd.h +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/privateNrrd.h @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -23,22 +23,20 @@ 3. This notice may not be removed or altered from any source distribution. */ - #ifdef _WIN32 -#include -#include +# include +# include #endif #ifdef __cplusplus extern "C" { #endif -#define _NRRD_TEXT_INCR 1024 +#define _NRRD_TEXT_INCR 1024 #define _NRRD_LLONG_MAX_HELP AIR_LLONG(2305843009213693951) #define _NRRD_LLONG_MIN_HELP AIR_LLONG(-2305843009213693952) -#define _NRRD_WHITESPACE_NOTAB " \n\r\v\f" /* K+R pg. 157 */ - +#define _NRRD_WHITESPACE_NOTAB " \n\r\v\f" /* K+R pg. 157 */ /* ** _NRRD_SPACING @@ -46,7 +44,7 @@ extern "C" { ** returns nrrdDefSpacing if the argument doesn't exist, otherwise ** returns the argument */ -#define _NRRD_SPACING(spc) (AIR_EXISTS(spc) ? spc: nrrdDefSpacing) +#define _NRRD_SPACING(spc) (AIR_EXISTS(spc) ? spc : nrrdDefSpacing) typedef union { char **CP; @@ -80,8 +78,8 @@ extern int _nrrdKeyValueWrite(FILE *file, char **stringP, const char *prefix, const char *key, const char *value); /* formatXXX.c */ -extern const char *_nrrdFormatURLLine0; -extern const char *_nrrdFormatURLLine1; +extern const char *const _nrrdFormatURLLine0; +extern const char *const _nrrdFormatURLLine1; extern const NrrdFormat _nrrdFormatNRRD; extern const NrrdFormat _nrrdFormatPNM; extern const NrrdFormat _nrrdFormatPNG; @@ -97,86 +95,78 @@ extern const NrrdEncoding _nrrdEncodingAscii; extern const NrrdEncoding _nrrdEncodingHex; extern const NrrdEncoding _nrrdEncodingGzip; extern const NrrdEncoding _nrrdEncodingBzip2; - -/* read.c */ -extern int _nrrdCalloc(Nrrd *nrrd, NrrdIoState *nio, FILE *file); -extern char _nrrdFieldSep[]; +extern const NrrdEncoding _nrrdEncodingZRL; /* arrays.c */ -extern const int _nrrdFieldValidInImage[NRRD_FIELD_MAX+1]; -extern const int _nrrdFieldValidInText[NRRD_FIELD_MAX+1]; -extern const int _nrrdFieldOnePerAxis[NRRD_FIELD_MAX+1]; -extern const char _nrrdEnumFieldStr[NRRD_FIELD_MAX+1][AIR_STRLEN_SMALL]; -extern const int _nrrdFieldRequired[NRRD_FIELD_MAX+1]; +extern const int _nrrdFieldValidInImage[NRRD_FIELD_MAX + 1]; +extern const int _nrrdFieldValidInText[NRRD_FIELD_MAX + 1]; +extern const int _nrrdFieldOnePerAxis[NRRD_FIELD_MAX + 1]; +extern const int _nrrdFieldRequired[NRRD_FIELD_MAX + 1]; /* simple.c */ extern char *_nrrdContentGet(const Nrrd *nin); -extern int _nrrdContentSet_nva(Nrrd *nout, const char *func, - char *content, const char *format, - va_list arg); -extern int _nrrdContentSet_va(Nrrd *nout, const char *func, - char *content, const char *format, ...); -extern int (*_nrrdFieldCheck[NRRD_FIELD_MAX+1])(const Nrrd *nrrd, int useBiff); -extern void _nrrdSplitSizes(size_t *pieceSize, size_t *pieceNum, - Nrrd *nrrd, unsigned int listDim); +extern int _nrrdContentSet_nva(Nrrd *nout, const char *func, char *content, + const char *format, va_list arg); +extern int _nrrdContentSet_va(Nrrd *nout, const char *func, char *content, + const char *format, ...); +extern int (*const _nrrdFieldCheck[NRRD_FIELD_MAX + 1])(const Nrrd *nrrd, int useBiff); +extern void _nrrdSplitSizes(size_t *pieceSize, size_t *pieceNum, Nrrd *nrrd, + unsigned int listDim); /* axis.c */ extern int _nrrdKindAltered(int kindIn, int resampling); -extern void _nrrdAxisInfoCopy(NrrdAxisInfo *dest, const NrrdAxisInfo *src, - int bitflag); +extern void _nrrdAxisInfoCopy(NrrdAxisInfo *dest, const NrrdAxisInfo *src, int bitflag); extern void _nrrdAxisInfoInit(NrrdAxisInfo *axis); extern void _nrrdAxisInfoNewInit(NrrdAxisInfo *axis); extern int _nrrdCenter(int center); extern int _nrrdCenter2(int center, int def); /* read.c */ -extern char _nrrdFieldStr[NRRD_FIELD_MAX+1][AIR_STRLEN_SMALL]; -extern char _nrrdRelativePathFlag[]; -extern char _nrrdFieldSep[]; -extern char _nrrdNoSpaceVector[]; -extern char _nrrdTextSep[]; +extern const char *const _nrrdFieldSep; +extern const char *const _nrrdTextSep; +extern const char *const _nrrdNoSpaceVector; +extern int _nrrdCharIsFieldSep(char cc); +extern int _nrrdByteSkipSkip(FILE *dataFile, Nrrd *nrrd, NrrdIoState *nio, + long int byteSkip); +extern int _nrrdCalloc(Nrrd *nrrd, NrrdIoState *nio); extern void _nrrdSplitName(char **dirP, char **baseP, const char *name); /* write.c */ -extern int _nrrdFieldInteresting(const Nrrd *nrrd, NrrdIoState *nio, - int field); -extern void _nrrdSprintFieldInfo(char **strP, const char *prefix, - const Nrrd *nrrd, NrrdIoState *nio, - int field); -extern void _nrrdFprintFieldInfo(FILE *file, const char *prefix, - const Nrrd *nrrd, NrrdIoState *nio, - int field); +extern int _nrrdFieldInteresting(const Nrrd *nrrd, NrrdIoState *nio, int field); +extern void _nrrdSprintFieldInfo(char **strP, const char *prefix, const Nrrd *nrrd, + NrrdIoState *nio, int field, int dropAxis0); +extern void _nrrdFprintFieldInfo(FILE *file, const char *prefix, const Nrrd *nrrd, + NrrdIoState *nio, int field, int dropAxis0); /* parseNrrd.c */ extern int _nrrdReadNrrdParseField(NrrdIoState *nio, int useBiff); /* methodsNrrd.c */ -extern void nrrdPeripheralInit(Nrrd *nrrd); -extern int nrrdPeripheralCopy(Nrrd *nout, const Nrrd *nin); extern int _nrrdCopy(Nrrd *nout, const Nrrd *nin, int bitflag); extern int _nrrdSizeCheck(const size_t *size, unsigned int dim, int useBiff); -extern void _nrrdTraverse(Nrrd *nrrd); -extern int _nrrdMaybeAllocMaybeZero_nva(Nrrd *nrrd, int type, - unsigned int dim, const size_t *size, - int zeroWhenNoAlloc); +extern int _nrrdMaybeAllocMaybeZero_nva(Nrrd *nrrd, int type, unsigned int dim, + const size_t *size, int zeroWhenNoAlloc); #if TEEM_ZLIB -#if TEEM_VTK_MANGLE -#include "vtk_zlib_mangle.h" -#endif -#include "itk_zlib.h" +# if TEEM_VTK_MANGLE +# include "vtk_zlib_mangle.h" +# endif +# if TEEM_ITK_MANGLE +# include "itk_zlib.h" +# else +# include "zlib.h" +# endif /* gzio.c */ -extern gzFile _nrrdGzOpen(FILE* fd, const char *mode); +extern gzFile _nrrdGzOpen(FILE *fd, const char *mode); extern int _nrrdGzClose(gzFile file); -extern int _nrrdGzRead(gzFile file, void* buf, unsigned int len, - unsigned int* read); -extern int _nrrdGzWrite(gzFile file, const void* buf, unsigned int len, - unsigned int* written); +extern int _nrrdGzRead(gzFile file, void *buf, unsigned int len, unsigned int *read); +extern int _nrrdGzWrite(gzFile file, const void *buf, unsigned int len, + unsigned int *written); +#else +extern int _nrrdGzDummySymbol(void); #endif - #ifdef __cplusplus } #endif - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/qnanhibit.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/qnanhibit.c deleted file mode 100644 index 348af682178..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/qnanhibit.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include -#include - -int -main(int argc, char *argv[]) -{ - char *me; - float pinf, qnan; - int i; - - me = argv[0]; - if (sizeof(float) != sizeof(int)) - { - fprintf(stderr, "%s: MADNESS: sizeof(float)=%d != sizeof(int)=%d\n", - me, (int)sizeof(float), (int)sizeof(int)); - return -1; - } - pinf = FLT_MAX; - pinf = pinf*pinf; - qnan = pinf/pinf; - i = *(int*)(&qnan); - printf("-DTEEM_QNANHIBIT=%d\n", (i >> 22) & 1); - return (int)((i >> 22) & 1); -} diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/read.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/read.c index 7ea4e635e39..0630899b9f9 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/read.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/read.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -27,31 +27,42 @@ #include "privateNrrd.h" #if TEEM_BZIP2 -#include +# include #endif -/* The "/ *Teem:" (without space) comments in here are an experiment */ +/* (not apparently used) const char *const _nrrdRelativePathFlag = "./"; */ +const char *const _nrrdFieldSep = " \t"; +static const char *const _nrrdLineSep = "\r\n"; +const char *const _nrrdTextSep = " ,\t"; +const char *const _nrrdNoSpaceVector = "none"; -char _nrrdRelativePathFlag[] = "./"; -char _nrrdFieldSep[] = " \t"; -char _nrrdLineSep[] = "\r\n"; -char _nrrdNoSpaceVector[] = "none"; -char _nrrdTextSep[] = " ,\t"; +/* returns non-zero if given char `cc` is in _nrrdFieldSep */ +int +_nrrdCharIsFieldSep(char cc) { + unsigned int ii, fslen = (unsigned int)strlen(_nrrdFieldSep); + int ret = 0; + for (ii = 0; ii < fslen; ii++) { + if (cc == _nrrdFieldSep[ii]) { + ret = 1; + break; + } + } + return ret; +} /* ** return length of next "line" in nio->headerStringRead */ -unsigned int +static unsigned int _nrrdHeaderStringOneLineStrlen(NrrdIoState *nio) { - return AIR_CAST(unsigned int, - strcspn(nio->headerStringRead + nio->headerStrpos, _nrrdLineSep)); + return AIR_UINT(strcspn(nio->headerStringRead + nio->headerStrpos, _nrrdLineSep)); } /* ** read next "line" in nio->headerStringRead */ -unsigned int +static unsigned int _nrrdHeaderStringOneLine(NrrdIoState *nio) { unsigned int len1, len2; @@ -59,14 +70,13 @@ _nrrdHeaderStringOneLine(NrrdIoState *nio) { strncpy(nio->line, nio->headerStringRead + nio->headerStrpos, len1); nio->line[len1] = '\0'; nio->headerStrpos += len1; - len2 = AIR_CAST(unsigned int, - strspn(nio->headerStringRead + nio->headerStrpos, _nrrdLineSep)); + len2 = AIR_UINT(strspn(nio->headerStringRead + nio->headerStrpos, _nrrdLineSep)); nio->headerStrpos += len2; return len1; } /* -** _nrrdOneLine +** nrrdOneLine ** ** wrapper around airOneLine; does re-allocation of line buffer ** ("line") in the NrrdIoState if needed. The return value semantics @@ -75,30 +85,28 @@ _nrrdHeaderStringOneLine(NrrdIoState *nio) { ** something couldn't be allocated), *lenP is set to 0, and ** we return 1. HITTING EOF IS NOT ACTUALLY AN ERROR, see code ** below. Otherwise we return 0. -** -** Does use biff */ -int -_nrrdOneLine(unsigned int *lenP, NrrdIoState *nio, FILE *file) { - static const char me[]="_nrrdOneLine"; +int /* Biff: 1 */ +nrrdOneLine(unsigned int *lenP, NrrdIoState *nio, FILE *file) { + static const char me[] = "nrrdOneLine"; char **line; airArray *mop, *lineArr; airPtrPtrUnion appu; unsigned int lineIdx, len, needLen; - if (!( lenP && nio && (file || nio->headerStringRead))) { - biffAddf(NRRD, "%s: got NULL pointer (%p, %p, %p/%p)", me, - AIR_CAST(void*, lenP), AIR_CAST(void*, nio), - AIR_CAST(void*, file), nio->headerStringRead); + if (!(lenP && nio && (file || nio->headerStringRead))) { + biffAddf(NRRD, "%s: got NULL pointer (%p, %p, %p/%p)", me, AIR_VOIDP(lenP), + AIR_VOIDP(nio), AIR_VOIDP(file), AIR_CVOIDP(nio->headerStringRead)); return 1; } if (0 == nio->lineLen) { /* nio->line hasn't been allocated for anything */ nio->lineLen = 3; - nio->line = (char*)malloc(nio->lineLen); + nio->line = (char *)malloc(nio->lineLen); if (!nio->line) { biffAddf(NRRD, "%s: couldn't alloc %d-char line\n", me, nio->lineLen); - *lenP = 0; return 1; + *lenP = 0; + return 1; } } if (file) { @@ -106,14 +114,14 @@ _nrrdOneLine(unsigned int *lenP, NrrdIoState *nio, FILE *file) { } else { /* NOTE: NULL-ity error check above makes this safe */ needLen = _nrrdHeaderStringOneLineStrlen(nio); - if (needLen+1 > nio->lineLen) { - nio->lineLen = needLen+1; - airFree(nio->line); /* lose previous allocated line */ - nio->line = (char*)malloc(nio->lineLen); + if (needLen + 1 > nio->lineLen) { + nio->lineLen = needLen + 1; + airFree(nio->line); /* lose previous allocated line */ + nio->line = (char *)malloc(nio->lineLen); if (!nio->line) { - biffAddf(NRRD, "%s: couldn't alloc %d-char line\n", - me, nio->lineLen); - *lenP = 0; return 1; + biffAddf(NRRD, "%s: couldn't alloc %d-char line\n", me, nio->lineLen); + *lenP = 0; + return 1; } } len = _nrrdHeaderStringOneLine(nio); @@ -131,24 +139,28 @@ _nrrdOneLine(unsigned int *lenP, NrrdIoState *nio, FILE *file) { lineArr = airArrayNew(appu.v, NULL, sizeof(char *), 1); if (!lineArr) { biffAddf(NRRD, "%s: couldn't allocate airArray", me); - *lenP = 0; return 1; + *lenP = 0; + return 1; } airArrayPointerCB(lineArr, airNull, airFree); mop = airMopNew(); airMopAdd(mop, lineArr, (airMopper)airArrayNuke, airMopAlways); - while (len == nio->lineLen+1) { + while (len == nio->lineLen + 1) { lineIdx = airArrayLenIncr(lineArr, 1); if (!lineArr->data) { biffAddf(NRRD, "%s: couldn't increment line buffer array", me); - *lenP = 0; airMopError(mop); return 1; + *lenP = 0; + airMopError(mop); + return 1; } line[lineIdx] = nio->line; nio->lineLen *= 2; - nio->line = (char*)malloc(nio->lineLen); + nio->line = (char *)malloc(nio->lineLen); if (!nio->line) { - biffAddf(NRRD, "%s: couldn't alloc %d-char line\n", - me, nio->lineLen); - *lenP = 0; airMopError(mop); return 1; + biffAddf(NRRD, "%s: couldn't alloc %d-char line\n", me, nio->lineLen); + *lenP = 0; + airMopError(mop); + return 1; } len = airOneLine(file, nio->line, nio->lineLen); } @@ -156,18 +168,22 @@ _nrrdOneLine(unsigned int *lenP, NrrdIoState *nio, FILE *file) { lineIdx = airArrayLenIncr(lineArr, 1); if (!lineArr->data) { biffAddf(NRRD, "%s: couldn't increment line buffer array", me); - *lenP = 0; airMopError(mop); return 1; + *lenP = 0; + airMopError(mop); + return 1; } line[lineIdx] = nio->line; - nio->lineLen *= 3; /* for good measure */ - nio->line = (char*)malloc(nio->lineLen); + nio->lineLen *= 3; /* for good measure */ + nio->line = (char *)malloc(nio->lineLen); if (!nio->line) { biffAddf(NRRD, "%s: couldn't alloc %d-char line\n", me, nio->lineLen); - *lenP = 0; airMopError(mop); return 1; + *lenP = 0; + airMopError(mop); + return 1; } /* now concatenate everything into a new nio->line */ strcpy(nio->line, ""); - for (lineIdx=0; lineIdxlen; lineIdx++) { + for (lineIdx = 0; lineIdx < lineArr->len; lineIdx++) { strcat(nio->line, line[lineIdx]); } /* HEY: API is bad: *lenP should be a size_t pointer! */ @@ -183,44 +199,30 @@ _nrrdOneLine(unsigned int *lenP, NrrdIoState *nio, FILE *file) { ** allocates the data for the array, but only if necessary (as informed by ** nio->oldData and nio->oldDataSize). ** -** as a recent feature, this will handle the extra work of allocating -** memory in the special way required for direct IO, if possible. For -** this to work, though, the FILE *file has to be passed. Since file -** is not otherwise needed, it can be passed as NULL for non-direct-IO -** situations. In any case, if the directIO-compatible allocation fails -** its not error, and we revert to regular allocation. -** ** NOTE: this assumes the checking that is done by _nrrdHeaderCheck */ -int -_nrrdCalloc(Nrrd *nrrd, NrrdIoState *nio, FILE *file) { - static const char me[]="_nrrdCalloc"; +int /* Biff: (private) 1 */ +_nrrdCalloc(Nrrd *nrrd, NrrdIoState *nio) { + static const char me[] = "_nrrdCalloc"; size_t needDataSize; - int fd; - needDataSize = nrrdElementNumber(nrrd)*nrrdElementSize(nrrd); - if (nio->oldData && needDataSize == nio->oldDataSize) { + needDataSize = nrrdElementNumber(nrrd) * nrrdElementSize(nrrd); + if (nio->oldData && needDataSize == nio->oldDataSize) { /* re-use old data */ nrrd->data = nio->oldData; /* its not an error to have a directIO-incompatible pointer, so there's no other error checking to do here */ } else { nrrd->data = airFree(nrrd->data); - fd = file ? fileno(file) : -1; - if (nrrdEncodingRaw == nio->encoding - && -1 != fd - && airNoDio_okay == airDioTest(fd, NULL, needDataSize)) { - nrrd->data = airDioMalloc(needDataSize, fd); - } if (!nrrd->data) { - /* directIO-compatible allocation wasn't tried, or it failed */ + /* allocate data if needed */ nrrd->data = malloc(needDataSize); } if (!nrrd->data) { - char stmp1[AIR_STRLEN_SMALL], stmp2[AIR_STRLEN_SMALL]; + char stmp[2][AIR_STRLEN_SMALL + 1]; biffAddf(NRRD, "%s: couldn't allocate %s things of size %s", me, - airSprintSize_t(stmp1, nrrdElementNumber(nrrd)), - airSprintSize_t(stmp2, nrrdElementSize(nrrd))); + airSprintSize_t(stmp[0], nrrdElementNumber(nrrd)), + airSprintSize_t(stmp[1], nrrdElementSize(nrrd))); return 1; } } @@ -233,97 +235,89 @@ _nrrdCalloc(Nrrd *nrrd, NrrdIoState *nio, FILE *file) { ******** nrrdLineSkip ** ** public for the sake of things like "unu make" -** uses the NrrdIoState for its line buffer (used by _nrrdOneLine) +** uses the NrrdIoState for its line buffer (used by nrrdOneLine) */ -int +int /* Biff: 1 */ nrrdLineSkip(FILE *dataFile, NrrdIoState *nio) { - static const char me[]="nrrdLineSkip"; + static const char me[] = "nrrdLineSkip"; unsigned int lsi, skipRet; /* For compressed data: If you don't actually have ascii headers on top of your gzipped data then you will potentially huge lines - while _nrrdOneLine looks for line terminations. Quoting Gordon: + while nrrdOneLine looks for line terminations. Quoting Gordon: "Garbage in, Garbage out." */ - if (!( dataFile && nio )) { + if (!(dataFile && nio)) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } - for (lsi=0; lsilineSkip; lsi++) { - if (_nrrdOneLine(&skipRet, nio, dataFile)) { - biffAddf(NRRD, "%s: error skipping line %u of %u", - me, lsi+1, nio->lineSkip); + for (lsi = 0; lsi < nio->lineSkip; lsi++) { + if (nrrdOneLine(&skipRet, nio, dataFile)) { + biffAddf(NRRD, "%s: error skipping line %u of %u", me, lsi + 1, nio->lineSkip); return 1; } if (!skipRet) { - biffAddf(NRRD, "%s: hit EOF skipping line %u of %u", - me, lsi+1, nio->lineSkip); + biffAddf(NRRD, "%s: hit EOF skipping line %u of %u", me, lsi + 1, nio->lineSkip); return 1; } } return 0; } -/* -******** nrrdByteSkip -** -** public for the sake of things like "unu make" -** uses nio for information about how much data should actually be skipped -** with negative byteSkip -*/ -int -nrrdByteSkip(FILE *dataFile, Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="nrrdByteSkip"; +int /* Biff: (private) 1 */ +_nrrdByteSkipSkip(FILE *dataFile, Nrrd *nrrd, NrrdIoState *nio, long int byteSkip) { + static const char me[] = "_nrrdByteSkipSkip"; int skipRet; size_t bsize; - if (!( dataFile && nrrd && nio )) { + if (!(dataFile && nrrd && nio)) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } if (nio->encoding->isCompression) { - biffAddf(NRRD, "%s: this function can't work with compressed " - "encoding %s", me, nio->encoding->name); + biffAddf(NRRD, + "%s: this function can't work with compressed " + "encoding %s", + me, nio->encoding->name); return 1; } - if (nio->byteSkip < 0) { + if (byteSkip < 0) { long backwards; if (nrrdEncodingRaw != nio->encoding) { - biffAddf(NRRD, "%s: this function can do backwards byte skip only " - "in %s encoding, not %s", me, - nrrdEncodingRaw->name, nio->encoding->name); + biffAddf(NRRD, + "%s: this function can do backwards byte skip only " + "in %s encoding, not %s", + me, nrrdEncodingRaw->name, nio->encoding->name); return 1; } if (stdin == dataFile) { biffAddf(NRRD, "%s: can't fseek on stdin", me); return 1; } - bsize = nrrdElementNumber(nrrd)/_nrrdDataFNNumber(nio); + bsize = nrrdElementNumber(nrrd) / _nrrdDataFNNumber(nio); bsize *= nrrdElementSize(nrrd); /* backwards is (positive) number of bytes AFTER data that we ignore */ - backwards = -nio->byteSkip - 1; + backwards = -byteSkip - 1; /* HEY what if bsize fits in size_t but not in (signed) long? */ if (fseek(dataFile, -AIR_CAST(long, bsize) - backwards, SEEK_END)) { - char stmp[AIR_STRLEN_SMALL]; + char stmp[AIR_STRLEN_SMALL + 1]; biffAddf(NRRD, "%s: failed to fseek(dataFile, %s, SEEK_END)", me, airSprintSize_t(stmp, bsize)); return 1; } - if (nrrdStateVerboseIO >= 2) { - fprintf(stderr, "(%s: actually skipped %d bytes)\n", - me, (int)ftell(dataFile)); + if (nio && nio->verbose >= 2) { + fprintf(stderr, "(%s: actually skipped %d bytes)\n", me, (int)ftell(dataFile)); } } else { - if ((stdin == dataFile) || (-1==fseek(dataFile, nio->byteSkip, SEEK_CUR))) { + if ((stdin == dataFile) || (-1 == fseek(dataFile, byteSkip, SEEK_CUR))) { long skipi; /* fseek failed, perhaps because we're reading stdin, so we revert to consuming the input one byte at a time */ - for (skipi=0; skipibyteSkip; skipi++) { + for (skipi = 0; skipi < byteSkip; skipi++) { skipRet = fgetc(dataFile); if (EOF == skipRet) { - biffAddf(NRRD, "%s: hit EOF skipping byte %ld of %ld", - me, skipi, nio->byteSkip); + biffAddf(NRRD, "%s: hit EOF skipping byte %ld of %ld", me, skipi, byteSkip); return 1; } } @@ -332,6 +326,31 @@ nrrdByteSkip(FILE *dataFile, Nrrd *nrrd, NrrdIoState *nio) { return 0; } +/* +******** nrrdByteSkip +** +** public for the sake of things like "unu make" +** uses nio for information about how much data should actually be skipped +** with negative byteSkip +*/ +int /* Biff: 1 */ +nrrdByteSkip(FILE *dataFile, Nrrd *nrrd, NrrdIoState *nio) { + static const char me[] = "nrrdByteSkip"; + + if (!(dataFile && nrrd && nio)) { + biffAddf(NRRD, "%s: got NULL pointer", me); + return 1; + } + /* HEY: with the advent of NRRD0006 per-file skips, maybe this is + the function that should be public */ + if (_nrrdByteSkipSkip(dataFile, nrrd, nio, nio->byteSkip)) { + biffAddf(NRRD, "%s: trouble", me); + return 1; + } + + return 0; +} + /* ** _nrrdRead() ** @@ -346,9 +365,9 @@ nrrdByteSkip(FILE *dataFile, Nrrd *nrrd, NrrdIoState *nio) { ** found. If (string), the headerStr-related fields in the _nio will ** be set/used */ -int +static int /* Biff: 1 */ _nrrdRead(Nrrd *nrrd, FILE *file, const char *string, NrrdIoState *_nio) { - static const char me[]="_nrrdRead"; + static const char me[] = "_nrrdRead"; unsigned int llen; NrrdIoState *nio; int nfi; @@ -356,8 +375,7 @@ _nrrdRead(Nrrd *nrrd, FILE *file, const char *string, NrrdIoState *_nio) { /* sanity check, for good measure */ if (!nrrdSanity()) { - biffAddf(NRRD, "%s: sanity check FAILED: have to fix and re-compile", - me); + biffAddf(NRRD, "%s: sanity check FAILED: have to fix and re-compile", me); return 1; } @@ -384,9 +402,8 @@ _nrrdRead(Nrrd *nrrd, FILE *file, const char *string, NrrdIoState *_nio) { /* remember old data pointer and allocated size. Whether or not to free() this memory will be decided later */ nio->oldData = nrrd->data; - nio->oldDataSize = (nio->oldData - ? nrrdElementNumber(nrrd)*nrrdElementSize(nrrd) - : 0); + nio->oldDataSize = (nio->oldData ? nrrdElementNumber(nrrd) * nrrdElementSize(nrrd) + : 0); /* fprintf(stderr, "!%s: nio->oldData = %p, oldDataSize = %d\n", me, nio->oldData, (int)(nio->oldDataSize)); @@ -399,48 +416,53 @@ _nrrdRead(Nrrd *nrrd, FILE *file, const char *string, NrrdIoState *_nio) { /* tell the nio where to find the string to read from */ nio->headerStringRead = string; - if (_nrrdOneLine(&llen, nio, file)) { - biffAddf(NRRD, "%s: error getting first line (containing \"magic\")", - me); - airMopError(mop); return 1; + if (nrrdOneLine(&llen, nio, file)) { + biffAddf(NRRD, "%s: error getting first line (containing \"magic\")", me); + airMopError(mop); + return 1; } if (!llen) { - biffAddf(NRRD, "%s: immediately hit EOF", me); - airMopError(mop); return 1; + biffAddf(NRRD, "%s: immediately hit EOF", me); + airMopError(mop); + return 1; } nio->format = nrrdFormatUnknown; - for (nfi = nrrdFormatTypeUnknown+1; - nfi < nrrdFormatTypeLast; - nfi++) { + for (nfi = nrrdFormatTypeUnknown + 1; nfi < nrrdFormatTypeLast; nfi++) { if (nrrdFormatArray[nfi]->contentStartsLike(nio)) { nio->format = nrrdFormatArray[nfi]; break; } } if (nrrdFormatUnknown == nio->format) { - char linestart[AIR_STRLEN_SMALL], stmp[AIR_STRLEN_SMALL]; - airStrcpy(linestart, AIR_STRLEN_SMALL, nio->line); + char linestart[AIR_STRLEN_SMALL + 1], stmp[AIR_STRLEN_SMALL + 1]; + airStrcpy(linestart, AIR_STRLEN_SMALL + 1, nio->line); if (strlen(linestart) != strlen(nio->line)) { - biffAddf(NRRD, "%s: couldn't parse (length %s) line starting " + biffAddf(NRRD, + "%s: couldn't parse (length %s) line starting " "with \"%s\" as magic or beginning of any recognized format", me, airSprintSize_t(stmp, strlen(nio->line)), linestart); } else { - biffAddf(NRRD, "%s: couldn't parse \"%s\" as magic or beginning " - "of any recognized format", me, nio->line); + biffAddf(NRRD, + "%s: couldn't parse \"%s\" as magic or beginning " + "of any recognized format", + me, nio->line); } - airMopError(mop); return 1; + airMopError(mop); + return 1; } if (string && nrrdFormatNRRD != nio->format) { - biffAddf(NRRD, "%s: sorry, can only read %s files from strings (not %s)", - me, nrrdFormatNRRD->name, nio->format->name); - airMopError(mop); return 1; + biffAddf(NRRD, "%s: sorry, can only read %s files from strings (not %s)", me, + nrrdFormatNRRD->name, nio->format->name); + airMopError(mop); + return 1; } /* try to read the file */ if (nio->format->read(file, nrrd, nio)) { biffAddf(NRRD, "%s: trouble reading %s file", me, nio->format->name); - airMopError(mop); return 1; + airMopError(mop); + return 1; } /* reshape up grayscale images, if desired */ @@ -475,9 +497,9 @@ _nrrdRead(Nrrd *nrrd, FILE *file, const char *string, NrrdIoState *_nio) { ** ** now just a wrapper around _nrrdRead(); reads a NRRD from a FILE * */ -int +int /* Biff: 1 */ nrrdRead(Nrrd *nrrd, FILE *file, NrrdIoState *_nio) { - static const char me[]="nrrdRead"; + static const char me[] = "nrrdRead"; if (_nrrdRead(nrrd, file, NULL, _nio)) { biffAddf(NRRD, "%s: trouble", me); @@ -495,9 +517,9 @@ nrrdRead(Nrrd *nrrd, FILE *file, NrrdIoState *_nio) { ** about using existing nrrd->data when possible applies, as does the ** action of nrrdStateGrayscaleImage3D */ -int +int /* Biff: 1 */ nrrdStringRead(Nrrd *nrrd, const char *string, NrrdIoState *_nio) { - static const char me[]="nrrdRead"; + static const char me[] = "nrrdStringRead"; if (_nrrdRead(nrrd, NULL, string, _nio)) { biffAddf(NRRD, "%s: trouble", me); @@ -521,7 +543,7 @@ nrrdStringRead(Nrrd *nrrd, const char *string, NrrdIoState *_nio) { */ void _nrrdSplitName(char **dirP, char **baseP, const char *name) { - char *where; + const char *where; if (dirP) { *dirP = (char *)airFree(*dirP); @@ -532,7 +554,7 @@ _nrrdSplitName(char **dirP, char **baseP, const char *name) { where = strrchr(name, '/'); #ifdef _WIN32 /* Deal with Windows "\" path separators; thanks to Torsten Rohlfing */ - if ( !where || (strrchr(name, '\\') > where) ) { + if (!where || (strrchr(name, '\\') > where)) { where = strrchr(name, '\\'); } #endif @@ -572,7 +594,7 @@ _nrrdSplitName(char **dirP, char **baseP, const char *name) { ** | read.c/nrrdRead ** | nio->format->read ** = formatNRRD.c/_nrrdFormatNRRD_read: -** | read.c/_nrrdOneLine +** | read.c/nrrdOneLine ** | parseNrrd.c/_nrrdReadNrrdParseField ** | parseNrrd.c/nrrdFieldInfoParse[] ** = parseNrrd.c/_nrrdReadNrrdParse_data_file @@ -591,9 +613,9 @@ _nrrdSplitName(char **dirP, char **baseP, const char *name) { ** sneakiness: returns 2 if the reason for problem was a failed fopen(). ** */ -int /*Teem: biff if (ret) */ +int /* Biff: 1|2 */ nrrdLoad(Nrrd *nrrd, const char *filename, NrrdIoState *nio) { - static const char me[]="nrrdLoad"; + static const char me[] = "nrrdLoad"; FILE *file; airArray *mop; @@ -617,22 +639,22 @@ nrrdLoad(Nrrd *nrrd, const char *filename, NrrdIoState *nio) { _nrrdSplitName(&(nio->path), NULL, filename); /* printf("!%s: |%s|%s|\n", me, nio->dir, nio->base); */ - if (!( file = airFopen(filename, stdin, "rb") )) { - biffAddf(NRRD, "%s: fopen(\"%s\",\"rb\") failed: %s", - me, filename, strerror(errno)); - airMopError(mop); return 2; + if (!(file = airFopen(filename, stdin, "rb"))) { + biffAddf(NRRD, "%s: fopen(\"%s\",\"rb\") failed: %s", me, filename, strerror(errno)); + airMopError(mop); + return 2; } airMopAdd(mop, file, (airMopper)airFclose, airMopOnError); /* non-error exiting is handled below */ if (nrrdRead(nrrd, file, nio)) { biffAddf(NRRD, "%s: trouble reading \"%s\"", me, filename); - airMopError(mop); return 1; + airMopError(mop); + return 1; } - if (nrrdFormatNRRD == nio->format - && nio->keepNrrdDataFileOpen - && file == nio->dataFile ) { + if (nrrdFormatNRRD == nio->format && nio->keepNrrdDataFileOpen + && file == nio->dataFile) { /* we have to keep the datafile open. If was attached, we can't close file, because that is the datafile. If was detached, file != nio->dataFile, so we can close file. */ @@ -645,11 +667,10 @@ nrrdLoad(Nrrd *nrrd, const char *filename, NrrdIoState *nio) { return 0; } -int -nrrdLoadMulti(Nrrd *const *nin, unsigned int ninLen, - const char *fnameFormat, +int /* Biff: 1 */ +nrrdLoadMulti(Nrrd *const *nin, unsigned int ninLen, const char *fnameFormat, unsigned int numStart, NrrdIoState *nio) { - static const char me[]="nrrdLoadMulti"; + static const char me[] = "nrrdLoadMulti"; char *fname; airArray *mop; unsigned int nii; @@ -658,10 +679,12 @@ nrrdLoadMulti(Nrrd *const *nin, unsigned int ninLen, biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } - if (!( _nrrdContainsPercentThisAndMore(fnameFormat, 'u') )) { - biffAddf(NRRD, "%s: given format \"%s\" doesn't seem to " + if (!(nrrdContainsPercentThisAndMore(fnameFormat, 'u'))) { + biffAddf(NRRD, + "%s: given format \"%s\" doesn't seem to " "have the \"%%u\" conversion specification to sprintf " - "an unsigned int\n", me, fnameFormat); + "an unsigned int\n", + me, fnameFormat); return 1; } @@ -670,17 +693,19 @@ nrrdLoadMulti(Nrrd *const *nin, unsigned int ninLen, fname = AIR_CAST(char *, malloc(strlen(fnameFormat) + 128)); if (!(fname)) { biffAddf(NRRD, "%s: couldn't allocate local fname buffer", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } airMopAdd(mop, fname, airFree, airMopAlways); - for (nii=0; niidim )) { - biffAddf(NRRD, "%s: given axis (%d) outside valid range [0, %d]", - me, axis, nin->dim); + if (!(axis <= nin->dim)) { + biffAddf(NRRD, "%s: given axis (%d) outside valid range [0, %d]", me, axis, + nin->dim); return 1; } if (NRRD_DIM_MAX == nin->dim) { - biffAddf(NRRD, "%s: given nrrd already at NRRD_DIM_MAX (%d)", - me, NRRD_DIM_MAX); + biffAddf(NRRD, "%s: given nrrd already at NRRD_DIM_MAX (%d)", me, NRRD_DIM_MAX); return 1; } if (nout != nin) { - if (_nrrdCopy(nout, nin, (NRRD_BASIC_INFO_COMMENTS_BIT - | (nrrdStateKeyValuePairsPropagate - ? 0 - : NRRD_BASIC_INFO_KEYVALUEPAIRS_BIT)))) { + if (_nrrdCopy(nout, nin, + (NRRD_BASIC_INFO_COMMENTS_BIT + | (nrrdStateKeyValuePairsPropagate + ? 0 + : NRRD_BASIC_INFO_KEYVALUEPAIRS_BIT)))) { biffAddf(NRRD, "%s:", me); return 1; } } nout->dim = 1 + nin->dim; - for (ai=nin->dim; ai>axis; ai--) { - _nrrdAxisInfoCopy(&(nout->axis[ai]), &(nin->axis[ai-1]), - NRRD_AXIS_INFO_NONE); + for (ai = nin->dim; ai > axis; ai--) { + _nrrdAxisInfoCopy(&(nout->axis[ai]), &(nin->axis[ai - 1]), NRRD_AXIS_INFO_NONE); } /* the ONLY thing we can say about the new axis is its size */ _nrrdAxisInfoInit(&(nout->axis[axis])); @@ -155,47 +152,47 @@ nrrdAxesInsert(Nrrd *nout, const Nrrd *nin, unsigned int axis) { ** (axis[i] answers: "what do I put here", from the standpoint of the output, ** not "where do I put this", from the standpoint of the input) */ -int +int /* Biff: 1 */ nrrdAxesPermute(Nrrd *nout, const Nrrd *nin, const unsigned int *axes) { - static const char me[]="nrrdAxesPermute", func[]="permute"; - char buff1[NRRD_DIM_MAX*30], buff2[AIR_STRLEN_SMALL]; - size_t idxOut, idxInA=0, /* indices for input and output scanlines */ + static const char me[] = "nrrdAxesPermute", func[] = "permute"; + char buff1[NRRD_DIM_MAX * 30], buff2[AIR_STRLEN_SMALL + 1]; + size_t idxOut, idxInA = 0, /* indices for input and output scanlines */ lineSize, /* size of block of memory which can be moved contiguously from input to output, thought of as a "scanline" */ numLines, /* how many "scanlines" there are to permute */ - szIn[NRRD_DIM_MAX], *lszIn, - szOut[NRRD_DIM_MAX], *lszOut, - cIn[NRRD_DIM_MAX], - cOut[NRRD_DIM_MAX]; + szIn[NRRD_DIM_MAX], *lszIn, szOut[NRRD_DIM_MAX], *lszOut, cIn[NRRD_DIM_MAX], + cOut[NRRD_DIM_MAX]; char *dataIn, *dataOut; int axmap[NRRD_DIM_MAX]; - unsigned int - ai, /* running index along dimensions */ + unsigned int ai, /* running index along dimensions */ lowPax, /* lowest axis which is "p"ermutated */ ldim, /* nin->dim - lowPax */ - ip[NRRD_DIM_MAX+1], /* inverse of permutation in "axes" */ - laxes[NRRD_DIM_MAX+1]; /* copy of axes[], but shifted down by lowPax + ip[NRRD_DIM_MAX + 1], /* inverse of permutation in "axes" */ + laxes[NRRD_DIM_MAX + 1]; /* copy of axes[], but shifted down by lowPax elements, to remove i such that i == axes[i] */ airArray *mop; mop = airMopNew(); if (!(nin && nout && axes)) { biffAddf(NRRD, "%s: got NULL pointer", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } /* we don't actually need ip[], computing it is for error checking */ if (nrrdInvertPerm(ip, axes, nin->dim)) { biffAddf(NRRD, "%s: couldn't compute axis permutation inverse", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } /* this shouldn't actually be necessary .. */ if (!nrrdElementSize(nin)) { biffAddf(NRRD, "%s: nrrd reports zero element size!", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } - for (ai=0; aidim && axes[ai] == ai; ai++) + for (ai = 0; ai < nin->dim && axes[ai] == ai; ai++) ; lowPax = ai; @@ -203,83 +200,87 @@ nrrdAxesPermute(Nrrd *nout, const Nrrd *nin, const unsigned int *axes) { if (nout != nin) { if (nrrdCopy(nout, nin)) { biffAddf(NRRD, "%s: trouble copying input", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } - dataIn = (char*)nin->data; + dataIn = (char *)nin->data; } else { - dataIn = (char*)calloc(nrrdElementNumber(nin), nrrdElementSize(nin)); + dataIn = (char *)calloc(nrrdElementNumber(nin), nrrdElementSize(nin)); if (!dataIn) { biffAddf(NRRD, "%s: couldn't create local copy of data", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } airMopAdd(mop, dataIn, airFree, airMopAlways); - memcpy(dataIn, nin->data, nrrdElementNumber(nin)*nrrdElementSize(nin)); + memcpy(dataIn, nin->data, nrrdElementNumber(nin) * nrrdElementSize(nin)); } if (lowPax < nin->dim) { /* if lowPax == nin->dim, then we were given the identity permutation, so there's nothing to do other than the copy already done. Otherwise, here we are (actually, lowPax < nin->dim-1) */ - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nin->dim; ai++) { axmap[ai] = AIR_INT(axes[ai]); } nrrdAxisInfoGet_nva(nin, nrrdAxisInfoSize, szIn); if (nrrdAxisInfoCopy(nout, nin, axmap, NRRD_AXIS_INFO_NONE)) { biffAddf(NRRD, "%s:", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } nrrdAxisInfoGet_nva(nout, nrrdAxisInfoSize, szOut); /* the skinny */ lineSize = 1; - for (ai=0; aidim - lowPax; memset(laxes, 0, sizeof(laxes)); - for (ai=0; aidata); memset(cIn, 0, sizeof(cIn)); memset(cOut, 0, sizeof(cOut)); - for (idxOut=0; idxOutdim; ai++) { + for (ai = 0; ai < nin->dim; ai++) { sprintf(buff2, "%s%d", (ai ? "," : ""), axes[ai]); strcat(buff1, buff2); } if (nrrdContentSet_va(nout, func, nin, "%s", buff1)) { biffAddf(NRRD, "%s:", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } if (nout != nin) { if (nrrdBasicInfoCopy(nout, nin, - NRRD_BASIC_INFO_DATA_BIT - | NRRD_BASIC_INFO_TYPE_BIT - | NRRD_BASIC_INFO_BLOCKSIZE_BIT - | NRRD_BASIC_INFO_DIMENSION_BIT - | NRRD_BASIC_INFO_CONTENT_BIT - | NRRD_BASIC_INFO_COMMENTS_BIT - | (nrrdStateKeyValuePairsPropagate - ? 0 - : NRRD_BASIC_INFO_KEYVALUEPAIRS_BIT))) { + NRRD_BASIC_INFO_DATA_BIT /* */ + | NRRD_BASIC_INFO_TYPE_BIT | NRRD_BASIC_INFO_BLOCKSIZE_BIT + | NRRD_BASIC_INFO_DIMENSION_BIT + | NRRD_BASIC_INFO_CONTENT_BIT + | NRRD_BASIC_INFO_COMMENTS_BIT + | (nrrdStateKeyValuePairsPropagate + ? 0 + : NRRD_BASIC_INFO_KEYVALUEPAIRS_BIT))) { biffAddf(NRRD, "%s:", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } } } @@ -305,11 +306,10 @@ nrrdAxesPermute(Nrrd *nout, const Nrrd *nin, const unsigned int *axes) { ** insures that there is an source for all positions along the new ** array. */ -int -nrrdShuffle(Nrrd *nout, const Nrrd *nin, unsigned int axis, - const size_t *perm) { - static const char me[]="nrrdShuffle", func[]="shuffle"; - char buff2[AIR_STRLEN_SMALL]; +int /* Biff: 1 */ +nrrdShuffle(Nrrd *nout, const Nrrd *nin, unsigned int axis, const size_t *perm) { + static const char me[] = "nrrdShuffle", func[] = "shuffle"; + char buff2[AIR_STRLEN_SMALL + 1]; /* Sun Feb 8 13:13:58 CST 2009: There was a memory bug here caused by using the same buff1[NRRD_DIM_MAX*30] declaration that had worked fine for nrrdAxesPermute and nrrdReshape, but does NOT @@ -324,10 +324,10 @@ nrrdShuffle(Nrrd *nout, const Nrrd *nin, unsigned int axis, probably do *not* need the shuffle (the sample reversal) to be documented for long axes */ #define LONGEST_INTERESTING_AXIS 42 - char buff1[LONGEST_INTERESTING_AXIS*30]; + char buff1[LONGEST_INTERESTING_AXIS * 30]; unsigned int ai, ldim, len; - size_t idxInB=0, idxOut, lineSize, numLines, size[NRRD_DIM_MAX], *lsize, - cIn[NRRD_DIM_MAX+1], cOut[NRRD_DIM_MAX+1]; + size_t idxInB = 0, idxOut, lineSize, numLines, size[NRRD_DIM_MAX], *lsize, + cIn[NRRD_DIM_MAX + 1], cOut[NRRD_DIM_MAX + 1]; char *dataIn, *dataOut; if (!(nin && nout && perm)) { @@ -338,17 +338,16 @@ nrrdShuffle(Nrrd *nout, const Nrrd *nin, unsigned int axis, biffAddf(NRRD, "%s: nout==nin disallowed", me); return 1; } - if (!( axis < nin->dim )) { - biffAddf(NRRD, "%s: axis %d outside valid range [0,%d]", - me, axis, nin->dim-1); + if (!(axis < nin->dim)) { + biffAddf(NRRD, "%s: axis %d outside valid range [0,%d]", me, axis, nin->dim - 1); return 1; } - len = AIR_CAST(unsigned int, nin->axis[axis].size); - for (ai=0; aiaxis[axis].size); + for (ai = 0; ai < len; ai++) { + if (!(perm[ai] < len)) { + char stmp[AIR_STRLEN_SMALL + 1]; biffAddf(NRRD, "%s: perm[%d] (%s) outside valid range [0,%d]", me, ai, - airSprintSize_t(stmp, perm[ai]), len-1); + airSprintSize_t(stmp, perm[ai]), len - 1); return 1; } } @@ -374,8 +373,7 @@ nrrdShuffle(Nrrd *nout, const Nrrd *nin, unsigned int axis, nout->axis[axis].kind = _nrrdKindAltered(nin->axis[axis].kind, AIR_FALSE); /* try cleverness */ if (!nrrdStateKindNoop) { - if (0 == nrrdKindSize(nin->axis[axis].kind) - || nrrdKindStub == nin->axis[axis].kind + if (0 == nrrdKindSize(nin->axis[axis].kind) || nrrdKindStub == nin->axis[axis].kind || nrrdKindScalar == nin->axis[axis].kind || nrrdKind2Vector == nin->axis[axis].kind || nrrdKind3Color == nin->axis[axis].kind @@ -390,10 +388,10 @@ nrrdShuffle(Nrrd *nout, const Nrrd *nin, unsigned int axis, } /* the skinny */ lineSize = 1; - for (ai=0; aiaxis[ai].size; } - numLines = nrrdElementNumber(nin)/lineSize; + numLines = nrrdElementNumber(nin) / lineSize; lineSize *= nrrdElementSize(nin); lsize = size + axis; ldim = nin->dim - axis; @@ -401,20 +399,20 @@ nrrdShuffle(Nrrd *nout, const Nrrd *nin, unsigned int axis, dataOut = AIR_CAST(char *, nout->data); memset(cIn, 0, sizeof(cIn)); memset(cOut, 0, sizeof(cOut)); - for (idxOut=0; idxOutdim, nin->type, - airEnumStr(nrrdType, nin->type)); - printf("%s: the array contains %d elements, each %d bytes in size\n", - me, (int)nrrdElementNumber(nin), (int)nrrdElementSize(nin)); - - /* print out the key/value pairs present */ - kvn = nrrdKeyValueSize(nin); - if (kvn) { - for (kvi=0; kvidata (nrrdNix() frees the struct but not the data, nrrdEmpty() frees the data but not the struct) */ @@ -79,13 +74,13 @@ demoIO(char *filename) { } int -main(int argc, char **argv) { - char *err, *me; +main(int argc, const char **argv) { + const char *me; + char *err; int enc, form, miss; me = argv[0]; - fprintf(stderr, "(from Teem %s, %s)\n", - airTeemVersion, airTeemReleaseDate); + fprintf(stderr, "(from Teem %s, %s)\n", airTeemVersion, airTeemReleaseDate); if (!nrrdSanity()) { fprintf(stderr, "\n"); @@ -98,7 +93,7 @@ main(int argc, char **argv) { fprintf(stderr, "(nrrdSanity check passed)\n"); fprintf(stderr, " Formats available:"); miss = AIR_FALSE; - for (form=nrrdFormatTypeUnknown+1; formavailable()) { fprintf(stderr, " %s", airEnumStr(nrrdFormatType, form)); } else { @@ -108,7 +103,7 @@ main(int argc, char **argv) { fprintf(stderr, "\n"); if (miss) { fprintf(stderr, " (not available:"); - for (enc=nrrdFormatTypeUnknown+1; encavailable()) { fprintf(stderr, " %s", airEnumStr(nrrdFormatType, enc)); } @@ -118,7 +113,7 @@ main(int argc, char **argv) { fprintf(stderr, " Nrrd data encodings available:"); miss = AIR_FALSE; - for (enc=nrrdEncodingTypeUnknown+1; encavailable()) { fprintf(stderr, " %s", airEnumStr(nrrdEncodingType, enc)); } else { @@ -128,7 +123,7 @@ main(int argc, char **argv) { fprintf(stderr, "\n"); if (miss) { fprintf(stderr, " (not available:"); - for (enc=nrrdEncodingTypeUnknown+1; encavailable()) { fprintf(stderr, " %s", airEnumStr(nrrdEncodingType, enc)); } @@ -137,12 +132,12 @@ main(int argc, char **argv) { } fprintf(stderr, "\n"); - if (2 != argc) { - fprintf(stderr, "usage: %s \n", me); + if (!(2 == argc || 3 == argc)) { + fprintf(stderr, "usage: %s []\n", me); return 1; } - demoIO(argv[1]); + demoIO(argv[1], 3 == argc ? argv[2] : NULL); return 0; } diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/sane.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/sane.c index 8912b21cc8b..706d2b00238 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/sane.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/sane.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -37,22 +37,26 @@ int airSanity(void) { double nanValue, pinf, ninf; float nanF, pinfF, ninfF; - unsigned int sign, expvalue, mant; - int tmpI; - char endian; + unsigned int sign, expvalue, mant, tmpI; + unsigned char endian; unsigned char uc0, uc1; - static int _airSanity=0; - + /* for Teem v1.13 GLK decided to remove this optimization, which meant that this + function could only run through its tests once. Global state, especially if hidden + like this, is fishy (and flagged by teem/src/_util/scan-symbols.py). Things like + floating point rounding mode can be changed at run-time, which makes it more + reasonable to re-run the FP-related tests. The non-FP tests are simple and should be + fast to do. If profiling reveals this to be a bottleneck we can reconsider. + static int _airSanity = 0; if (_airSanity) { return airInsane_not; } + */ - /* now that there is no more compile-time endian info, this is - merely double checking that airMyEndian() works, and returns - the constants (either 1234, pronounced "little endian", or - 4321, "big endian") that are defined in air.h */ + /* now that there is no more compile-time endian info, this is merely double checking + that airMyEndian() works, and returns the constants (either 1234, pronounced + "little endian", or 4321, "big endian") that are defined in air.h */ tmpI = 1; - endian = !(*((char*)(&tmpI))); + endian = !(*((unsigned char *)(&tmpI))); if (endian) { /* big endian */ if (4321 != airMyEndian()) { @@ -63,70 +67,98 @@ airSanity(void) { return airInsane_endian; } } - /* checks on sizes of uchar, float, int, double, airLLong */ uc0 = 255; - uc1 = AIR_CAST(unsigned char, AIR_INT(uc0) + 1); /* want to overflow */ - if (!( 255 == uc0 && 0 == uc1 )) { + uc1 = AIR_UCHAR(AIR_INT(uc0) + 1); /* want to overflow */ + if (!(255 == uc0 && 0 == uc1)) { return airInsane_UCSize; } - /* these justify the AIR_EXISTS_F and AIR_EXISTS_D macros */ - if (!( (sizeof(float) == sizeof(int)) && (4 == sizeof(int)) )) { + /* 2002 GLK: "these justify the AIR_EXISTS_F and AIR_EXISTS_D macros" + well, probably: those macros depend on knowing which bits are for exponent + vs significand, which is not revealed by sizeof(). But IEEE 754 Table 3.2 + gives those bit allocations for 32- and 64-bit floats. But the value of + this sanity check is much larger than those macros. */ + if (!((sizeof(float) == sizeof(int)) && (4 == sizeof(int)))) { return airInsane_FISize; } - if (!( (sizeof(double) == sizeof(airLLong)) && (8 == sizeof(airLLong)) )) { + if (!((sizeof(double) == sizeof(airLLong)) && (8 == sizeof(airLLong)))) { return airInsane_DLSize; } /* run-time NaN checks */ - pinf = DBL_MAX; + ninf = -1e+300; /* pretty close to -DBL_MAX */ + ninf = _airSanityHelper(ninf); + ninf = _airSanityHelper(ninf); + ninf = _airSanityHelper(ninf); + if (AIR_EXISTS(ninf)) { + return airInsane_nInfExists; + } + pinf = 1e+300; /* pretty close to DBL_MAX */ pinf = _airSanityHelper(pinf); pinf = _airSanityHelper(pinf); pinf = _airSanityHelper(pinf); if (AIR_EXISTS(pinf)) { return airInsane_pInfExists; } - ninf = -pinf; - if (AIR_EXISTS(ninf)) { - return airInsane_nInfExists; - } + /* (commenting out until this FP rounding-mode-dependent surprise can be replicated) + if (0 && AIR_EXISTS(pinf)) { + / * on at least one computer GLK used, if fesetround(FE_DOWNWARD) has been + called, then the above run-time generation of positive infinity fails; + it instead rounds down to DBL_MAX. We err on the side of + permissiveness, and opt not to try to detect the current rounding mode + (because doing so in a C89-compliant way would be a pain), and thus + flag AIR_EXISTS(pinf) as a problem only if pinf != DBL_MAX. On that + one computer, fesetround(FE_UPWARD) did not hamper the above run-time + negative infinity generation * / + if (pinf != DBL_MAX) { + return airInsane_pInfExists; + } else { + / * as best we can tell, pinf would have been +inf if it + weren't for fesetround(FE_DOWNWARD), so fix pinf so that + later tests can use it. * / + pinf = -ninf; + } + } */ nanValue = pinf / pinf; if (AIR_EXISTS(nanValue)) { return airInsane_NaNExists; } + if (!(AIR_EXISTS(0.0) && AIR_EXISTS(-0.0) && AIR_EXISTS(1.0) + && AIR_EXISTS(-1.0) /* */ + /* not using AIR_PI because NrrdIO doesn't need or define that */ + && AIR_EXISTS(42.42) && AIR_EXISTS(3.14159265358979323846))) { + return airInsane_ExistsBad; + } nanF = (float)nanValue; pinfF = (float)pinf; ninfF = (float)ninf; airFPValToParts_f(&sign, &expvalue, &mant, nanF); mant >>= 22; - if (AIR_QNANHIBIT != (int)mant) { - return airInsane_QNaNHiBit; - } - if (!( airFP_QNAN == airFPClass_f(AIR_NAN) - && airFP_QNAN == airFPClass_f(AIR_QNAN) - /* - As of July 4 2012 GLK decides that the signalling NaN tests are - more trouble than they're worth: the signal-ness of the NaN is not - preserved in double-float conversion for some platforms (so - airFP_SNAN == airFPClass_d(AIR_SNAN) has never been enforced), and - there are more platforms for which (apparently) passing AIR_SNAN to - airFPClass_d changes it to a quiet NaN, which defeats the purpose - of the test. To summarize, given that: - ** AIR_NAN and AIR_QNAN are checked here to be quiet NaN, after - casting to both float and double, - ** quiet NaN "hi bit" is tested above, and that - ** quiet and signalling NaN are mutually exclusive, - skipping the signalling NaN tests is unlikely to undermine knowing - the correctness of the compile-time representation of NaNs. So the - following line is now commented out for all platforms. - */ - /* && airFP_SNAN == airFPClass_f(AIR_SNAN) */ - && airFP_QNAN == airFPClass_d(AIR_NAN) - && airFP_QNAN == airFPClass_d(AIR_QNAN) )) { + if (!(airFP_NAN == airFPClass_f(AIR_NAN) + /* + As of July 4 2012 GLK decides that the signalling NaN tests are + more trouble than they're worth: the signal-ness of the NaN is not + preserved in double-float conversion for some platforms (so + airFP_SNAN == airFPClass_d(AIR_SNAN) has never been enforced), and + there are more platforms for which (apparently) passing AIR_SNAN to + airFPClass_d changes it to a quiet NaN, which defeats the purpose + of the test. To summarize, given that: + ** AIR_NAN checked here to be quiet NaN, after + casting to both float and double, + ** quiet NaN "hi bit" is tested above, and that + ** quiet and signalling NaN are mutually exclusive, + skipping the signalling NaN tests is unlikely to undermine knowing + the correctness of the compile-time representation of NaNs. So the + following line is now commented out for all platforms. + */ + /* && airFP_SNAN == airFPClass_f((double)AIR_SNAN) */ + /* (and on August 15 2025 GLK decides to totally drop QNAN-vs-SNAN, + along with all handling of "qnanhibit") */ + && airFP_NAN == airFPClass_d((double)AIR_NAN))) { return airInsane_AIR_NAN; } - if (!(airFP_QNAN == airFPClass_f(nanF) + if (!(airFP_NAN == airFPClass_f(nanF) /* */ && airFP_POS_INF == airFPClass_f(pinfF) && airFP_NEG_INF == airFPClass_f(ninfF))) { /* really, this is verifying that assigning from a double to a @@ -134,33 +166,22 @@ airSanity(void) { return airInsane_FltDblFPClass; } - /* just make sure AIR_DIO is reasonably set - (actually, this should be done by include/teemDio.h) */ - switch (AIR_DIO) { - case 0: break; - case 1: break; - default: - return airInsane_dio; - } - - _airSanity = 1; + /* _airSanity = 1; (see above) */ return airInsane_not; } -static const char -_airInsaneErr[AIR_INSANE_MAX+1][AIR_STRLEN_MED] = { - "sanity checked PASSED!", - "airMyEndian() is wrong", - "AIR_EXISTS(+inf) was true", - "AIR_EXISTS(-inf) was true", - "AIR_EXISTS(NaN) was true", - "air_FPClass_f() wrong after double->float assignment", - "TEEM_QNANHIBIT is wrong", - "airFPClass(AIR_QNAN) wrong", - "TEEM_DIO has invalid value", - "unsigned char isn't 8 bits", - "sizeof(float), sizeof(int) not both == 4", - "sizeof(double), sizeof(airLLong) not both == 8", +static const char _airInsaneErr[AIR_INSANE_MAX + 1][AIR_STRLEN_MED + 1] = { + "sanity checked PASSED!", /* 0: airInsane_not */ + "airMyEndian() is wrong", /* 1: airInsane_endian */ + "AIR_EXISTS(+inf) was true", /* 2: airInsane_pInfExists */ + "AIR_EXISTS(-inf) was true", /* 3: airInsane_nInfExists */ + "AIR_EXISTS(NaN) was true", /* 4: airInsane_NaNExists */ + "AIR_EXISTS() was false for some finite values", /* 5: airInsane_ExistsBad */ + "air_FPClass_f() wrong after double->float assign", /* 6: airInsane_FltDblFPClass */ + "airFPClass(AIR_NAN) wrong", /* 7: airInsane_AIR_NAN */ + "unsigned char isn't 8 bits", /* 8: airInsane_UCSize */ + "sizeof(float), sizeof(int) not both == 4", /* 9: airInsane_FISize */ + "sizeof(double), sizeof(airLLong) not both == 8", /* 10: airInsane_DLSize */ }; static const char _airBadInsane[] = "(invalid insane value)"; @@ -170,9 +191,7 @@ airInsaneErr(int insane) { if (AIR_IN_CL(0, insane, AIR_INSANE_MAX)) { return _airInsaneErr[insane]; - } - else { + } else { return _airBadInsane; } } - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/simple.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/simple.c index eeb43dcc646..e86e411164e 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/simple.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/simple.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -28,10 +28,7 @@ #include -/* The "/ *Teem:" (without space) comments in here are an experiment */ - -const char * -nrrdBiffKey = "nrrd"; +const char *const nrrdBiffKey = "nrrd"; /* ******** nrrdSpaceDimension @@ -42,16 +39,20 @@ nrrdBiffKey = "nrrd"; ** The expected behavior here is to return 0 for nrrdSpaceUnknown, because ** that is the right answer, not because its an error of any kind. */ -unsigned int +unsigned int /* Biff: nope */ nrrdSpaceDimension(int space) { - static const char me[]="nrrdSpaceDimension"; + static const char me[] = "nrrdSpaceDimension"; unsigned int ret; - if (!( AIR_IN_OP(nrrdSpaceUnknown, space, nrrdSpaceLast) )) { + if (!(AIR_IN_OP(nrrdSpaceUnknown, space, nrrdSpaceLast))) { /* they gave us invalid or unknown space */ return 0; } switch (space) { + case nrrdSpaceRightUp: + case nrrdSpaceRightDown: + ret = 2; + break; case nrrdSpaceRightAnteriorSuperior: case nrrdSpaceLeftAnteriorSuperior: case nrrdSpaceLeftPosteriorSuperior: @@ -82,9 +83,9 @@ nrrdSpaceDimension(int space) { ** What to use to set space, when a value from nrrdSpace enum is known, ** or, to nullify all space-related information when passed nrrdSpaceUnknown */ -int +int /* Biff: 1 */ nrrdSpaceSet(Nrrd *nrrd, int space) { - static const char me[]="nrrdSpaceSet"; + static const char me[] = "nrrdSpaceSet"; unsigned axi, saxi; if (!nrrd) { @@ -94,10 +95,10 @@ nrrdSpaceSet(Nrrd *nrrd, int space) { if (nrrdSpaceUnknown == space) { nrrd->space = nrrdSpaceUnknown; nrrd->spaceDim = 0; - for (axi=0; axiaxis[axi].spaceDirection); } - for (saxi=0; saxispaceUnits[saxi]); nrrd->spaceUnits[saxi] = NULL; } @@ -119,15 +120,15 @@ nrrdSpaceSet(Nrrd *nrrd, int space) { ** What to use to set space, based on spaceDim alone (nrrd->space set to ** nrrdSpaceUnknown) */ -int +int /* Biff: 1 */ nrrdSpaceDimensionSet(Nrrd *nrrd, unsigned int spaceDim) { - static const char me[]="nrrdSpaceDimensionSet"; + static const char me[] = "nrrdSpaceDimensionSet"; if (!nrrd) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } - if (!( spaceDim <= NRRD_SPACE_DIM_MAX )) { + if (!(spaceDim <= NRRD_SPACE_DIM_MAX)) { biffAddf(NRRD, "%s: given spaceDim (%u) not valid", me, spaceDim); return 1; } @@ -144,16 +145,15 @@ nrrdSpaceDimensionSet(Nrrd *nrrd, unsigned int spaceDim) { ** of space origin, and all further indices are set to NaN. That is, ** this really does write to all NRRD_SPACE_DIM_MAX elements of vector[] */ -unsigned int -nrrdSpaceOriginGet(const Nrrd *nrrd, - double vector[NRRD_SPACE_DIM_MAX]) { +unsigned int /* Biff: nope */ +nrrdSpaceOriginGet(const Nrrd *nrrd, double vector[NRRD_SPACE_DIM_MAX]) { unsigned int sdi, ret; if (nrrd && vector) { - for (sdi=0; sdispaceDim; sdi++) { + for (sdi = 0; sdi < nrrd->spaceDim; sdi++) { vector[sdi] = nrrd->spaceOrigin[sdi]; } - for (sdi=nrrd->spaceDim; sdispaceDim; sdi < NRRD_SPACE_DIM_MAX; sdi++) { vector[sdi] = AIR_NAN; } ret = nrrd->spaceDim; @@ -172,24 +172,24 @@ nrrdSpaceOriginGet(const Nrrd *nrrd, ** ** returns 1 if there were problems, 0 otherwise */ -int +int /* Biff: 1 */ nrrdSpaceOriginSet(Nrrd *nrrd, const double *vector) { - static const char me[]="nrrdSpaceOriginSet"; + static const char me[] = "nrrdSpaceOriginSet"; unsigned int sdi; - if (!( nrrd && vector )) { + if (!(nrrd && vector)) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } - if (!( 0 < nrrd->spaceDim && nrrd->spaceDim <= NRRD_SPACE_DIM_MAX )) { + if (!(0 < nrrd->spaceDim && nrrd->spaceDim <= NRRD_SPACE_DIM_MAX)) { biffAddf(NRRD, "%s: set spaceDim %d not valid", me, nrrd->spaceDim); return 1; } - for (sdi=0; sdispaceDim; sdi++) { + for (sdi = 0; sdi < nrrd->spaceDim; sdi++) { nrrd->spaceOrigin[sdi] = vector[sdi]; } - for (sdi=nrrd->spaceDim; sdispaceDim; sdi < NRRD_SPACE_DIM_MAX; sdi++) { nrrd->spaceOrigin[sdi] = AIR_NAN; } return 0; @@ -225,32 +225,29 @@ nrrdSpaceOriginSet(Nrrd *nrrd, const double *vector) { ** ** nrrdOriginStatusOkay: all is well */ -int -nrrdOriginCalculate(const Nrrd *nrrd, - unsigned int *axisIdx, unsigned int axisIdxNum, +int /* Biff: nope */ +nrrdOriginCalculate(const Nrrd *nrrd, unsigned int *axisIdx, unsigned int axisIdxNum, int defaultCenter, double *origin) { const NrrdAxisInfo *axis[NRRD_SPACE_DIM_MAX]; int center, okay, gotSpace, gotMin, gotMaxOrSpacing; unsigned int ai; double min, spacing; -#define ERROR \ - if (origin) { \ - for (ai=0; aidim; } if (!okay) { @@ -259,12 +256,12 @@ nrrdOriginCalculate(const Nrrd *nrrd, } /* learn axisInfo pointers */ - for (ai=0; aiaxis + axisIdx[ai]; } gotSpace = AIR_FALSE; - for (ai=0; aispaceDirection[0]); } if (nrrd->spaceDim > 0 && gotSpace) { @@ -273,7 +270,7 @@ nrrdOriginCalculate(const Nrrd *nrrd, } gotMin = AIR_TRUE; - for (ai=0; aimin); } if (!gotMin) { @@ -282,38 +279,33 @@ nrrdOriginCalculate(const Nrrd *nrrd, } gotMaxOrSpacing = AIR_TRUE; - for (ai=0; aimax) - || AIR_EXISTS(axis[ai]->spacing)); + for (ai = 0; ai < axisIdxNum; ai++) { + gotMaxOrSpacing &= (AIR_EXISTS(axis[ai]->max) || AIR_EXISTS(axis[ai]->spacing)); } if (!gotMaxOrSpacing) { ERROR; return nrrdOriginStatusNoMaxOrSpacing; } - for (ai=0; aisize; min = axis[ai]->min; - center = (nrrdCenterUnknown != axis[ai]->center - ? axis[ai]->center - : defaultCenter); - denom = AIR_CAST(double, nrrdCenterCell == center ? size : size-1); - spacing = (AIR_EXISTS(axis[ai]->spacing) - ? axis[ai]->spacing - : (axis[ai]->max - min)/denom); - origin[ai] = min + (nrrdCenterCell == center ? spacing/2 : 0); + center = (nrrdCenterUnknown != axis[ai]->center ? axis[ai]->center : defaultCenter); + denom = AIR_CAST(double, nrrdCenterCell == center ? size : size - 1); + spacing = (AIR_EXISTS(axis[ai]->spacing) ? axis[ai]->spacing + : (axis[ai]->max - min) / denom); + origin[ai] = min + (nrrdCenterCell == center ? spacing / 2 : 0); } return nrrdOriginStatusOkay; } void -nrrdSpaceVecCopy(double dst[NRRD_SPACE_DIM_MAX], - const double src[NRRD_SPACE_DIM_MAX]) { +nrrdSpaceVecCopy(double dst[NRRD_SPACE_DIM_MAX], const double src[NRRD_SPACE_DIM_MAX]) { unsigned int ii; - for (ii=0; iicontent) - ? airStrdup(nin->content) - : airStrdup(nrrdStateUnknownContent)); + ret = ((nin && nin->content) ? airStrdup(nin->content) + : airStrdup(nrrdStateUnknownContent)); if (!ret) { fprintf(stderr, "%s: PANIC: content strdup failed!\n", me); return NULL; @@ -403,10 +393,10 @@ _nrrdContentGet(const Nrrd *nin) { return ret; } -int -_nrrdContentSet_nva(Nrrd *nout, const char *func, - char *content, const char *format, va_list arg) { - static const char me[]="_nrrdContentSet_nva"; +int /* Biff: (private) 1 */ +_nrrdContentSet_nva(Nrrd *nout, const char *func, char *content, const char *format, + va_list arg) { + static const char me[] = "_nrrdContentSet_nva"; char *buff; if (nrrdStateDisableContent) { @@ -414,7 +404,7 @@ _nrrdContentSet_nva(Nrrd *nout, const char *func, nout->content = (char *)airFree(nout->content); return 0; } - buff = (char *)malloc(128*AIR_STRLEN_HUGE); + buff = (char *)malloc(128 * AIR_STRLEN_HUGE + 1); if (!buff) { biffAddf(NRRD, "%s: couln't alloc buffer!", me); return 1; @@ -425,34 +415,32 @@ _nrrdContentSet_nva(Nrrd *nout, const char *func, /* HEY: replace with vsnprintf or whatever when its available */ vsprintf(buff, format, arg); - nout->content = (char *)calloc(strlen("(,)") - + airStrlen(func) - + 1 /* '(' */ - + airStrlen(content) - + 1 /* ',' */ - + airStrlen(buff) - + 1 /* ')' */ - + 1, sizeof(char)); /* '\0' */ + nout->content = (char *)calloc(strlen("(,)") + airStrlen(func) + 1 /* '(' */ + + airStrlen(content) + 1 /* ',' */ + + airStrlen(buff) + 1 /* ')' */ + + 1, + sizeof(char)); /* '\0' */ if (!nout->content) { biffAddf(NRRD, "%s: couln't alloc output content!", me); - airFree(buff); return 1; + airFree(buff); + return 1; } - sprintf(nout->content, "%s(%s%s%s)", func, content, - airStrlen(buff) ? "," : "", buff); - airFree(buff); /* no NULL assignment, else compile warnings */ + sprintf(nout->content, "%s(%s%s%s)", func, content, airStrlen(buff) ? "," : "", buff); + airFree(buff); /* no NULL assignment, else compile warnings */ return 0; } -int -_nrrdContentSet_va(Nrrd *nout, const char *func, - char *content, const char *format, ...) { - static const char me[]="_nrrdContentSet_va"; +int /* Biff: (private) 1 */ +_nrrdContentSet_va(Nrrd *nout, const char *func, char *content, const char *format, + ...) { + static const char me[] = "_nrrdContentSet_va"; va_list ap; va_start(ap, format); if (_nrrdContentSet_nva(nout, func, content, format, ap)) { biffAddf(NRRD, "%s:", me); - free(content); return 1; + free(content); + return 1; } va_end(ap); @@ -472,10 +460,10 @@ _nrrdContentSet_va(Nrrd *nout, const char *func, ** Does the string allocation and some attempts at error detection. ** Does allow nout==nin, which requires some care. */ -int -nrrdContentSet_va(Nrrd *nout, const char *func, - const Nrrd *nin, const char *format, ...) { - static const char me[]="nrrdContentSet_va"; +int /* Biff: 1 */ +nrrdContentSet_va(Nrrd *nout, const char *func, const Nrrd *nin, const char *format, + ...) { + static const char me[] = "nrrdContentSet_va"; va_list ap; char *content; @@ -500,7 +488,9 @@ nrrdContentSet_va(Nrrd *nout, const char *func, va_start(ap, format); if (_nrrdContentSet_nva(nout, func, content, format, ap)) { biffAddf(NRRD, "%s:", me); - va_end(ap); free(content); return 1; + va_end(ap); + free(content); + return 1; } va_end(ap); free(content); @@ -508,15 +498,233 @@ nrrdContentSet_va(Nrrd *nout, const char *func, return 0; } +static void +printDescSep(FILE *file, const char *pfx, const char *sepStr, unsigned int sepWidth, + const char *label) { + unsigned int printWidth, slen; + slen = airStrlen(sepStr); + if (!(file && slen && sepWidth)) { + /* nothing to do */ + return; + } + printWidth = 0; + if (pfx) { + fprintf(file, "%s", pfx); + printWidth += strlen(pfx); + } + do { + fprintf(file, "%s", sepStr); + printWidth += slen; + } while (printWidth < sepWidth); + if (airStrlen(label)) { + fprintf(file, " %s", label); + } + fprintf(file, "\n"); + return; +} + +/* + ******** nrrdDescribeMore + * + * new (for TeemV2) version of nrrdDescribe, printing more information, and having more + * more controls. Relative to nrrdDescribe, which has been left as is, there are many + * many changes, all in the interest of completeness and consistency. + */ +void +nrrdDescribeMore(FILE *file, const Nrrd *nrrd, const char *pfx, int showPtrs, + int elideNonExist, int elideUnknown, const char *sepStr, + unsigned int sepWidth) { + unsigned int ii, jj, sdim, sulen; + char stmp[AIR_STRLEN_SMALL + 1]; + + if (!file) { + /* nothing to do! */ + return; + } +#define PFX (pfx ? pfx : "") +#define INDENT " " +#define DESC_STRING(PTR, IND, DLIT, DSTR) \ + if ((PTR)) { \ + fprintf(file, "%s" IND DLIT "%s=|%s|", PFX, (DSTR), (PTR)); \ + if (showPtrs) { \ + fprintf(file, "@%p", AIR_VOIDP(PTR)); \ + } \ + fprintf(file, "\n"); \ + } else if (showPtrs) { \ + fprintf(file, "%s" IND DLIT "%s=NULL\n", PFX, (DSTR)); \ + } + if (!nrrd) { + fprintf(file, "%sgot NULL Nrrd\n", PFX); + return; + } + printDescSep(file, PFX, sepStr, sepWidth, "begin"); /* ---------------- */ + if (showPtrs) { + fprintf(file, "%sNrrd@%p\n", PFX, AIR_CVOIDP(nrrd)); + fprintf(file, "%sdata@%p\n", PFX, nrrd->data); + } + DESC_STRING(nrrd->content, "", "content", ""); + DESC_STRING(nrrd->sampleUnits, "", "sampleUnits", ""); + sdim = nrrd->spaceDim; + if (sdim) { + int mfex = 0; + printDescSep(file, PFX, sepStr, sepWidth, "space"); /* ---------------- */ + if (nrrd->space) { + fprintf(file, "%sSpace=%s (%u-dimensional)\n", PFX, + airEnumStr(nrrdSpace, nrrd->space), sdim); + } else { + fprintf(file, "%sSpace Dim=%u\n", PFX, sdim); + } + if (!elideNonExist || nrrdSpaceVecExists(sdim, nrrd->spaceOrigin)) { + fprintf(file, "%sSpace Origin=(", PFX); + for (jj = 0; jj < sdim; jj++) { + if (jj) fprintf(file, ","); + airSinglePrintf(file, NULL, "%lg", nrrd->spaceOrigin[jj]); + } + fprintf(file, ")\n"); + } + for (jj = 0; jj < sdim; jj++) { + mfex |= nrrdSpaceVecExists(sdim, nrrd->measurementFrame[jj]); + } + if (!elideNonExist || mfex) { + unsigned mmlen = 0; + char buff[AIR_STRLEN_SMALL + 1], fmt[AIR_STRLEN_SMALL + 1]; + fprintf(file, "%sMeasurement Frame=\n", PFX); + /* figure out longest string for on component */ + for (ii = 0; ii < sdim; ii++) { + for (jj = 0; jj < sdim; jj++) { + unsigned int ml; + airSinglePrintf(NULL, buff, "%lg", nrrd->measurementFrame[jj][ii]); + ml = strlen(buff); + mmlen = AIR_MAX(ml, mmlen); + } + } + /* print the formatting string for one component */ + sprintf(fmt, " %%%us", mmlen); + for (ii = 0; ii < sdim; ii++) { + fprintf(file, "%s ", PFX); + for (jj = 0; jj < sdim; jj++) { + /* inner loop is looping over columns */ + airSinglePrintf(NULL, buff, "%lg", nrrd->measurementFrame[jj][ii]); + fprintf(file, fmt, buff); + } + fprintf(file, "\n"); + } + } + sulen = 0; + for (jj = 0; jj < sdim; jj++) { + sulen += airStrlen(nrrd->spaceUnits[jj]); + } + if (showPtrs || sulen) { + fprintf(file, "%sSpace Units=\n", PFX); + for (jj = 0; jj < sdim; jj++) { + sprintf(stmp, "[%u]", jj); + DESC_STRING(nrrd->spaceUnits[jj], "", "", stmp); + } + } + } + printDescSep(file, PFX, sepStr, sepWidth, "basic"); /* ---------------- */ + if (!elideNonExist || AIR_EXISTS(nrrd->oldMin) || AIR_EXISTS(nrrd->oldMax)) { + fprintf(file, "%s", PFX); + airSinglePrintf(file, NULL, "The old min, old max values are %lg", nrrd->oldMin); + airSinglePrintf(file, NULL, ", %lg\n", nrrd->oldMax); + } + fprintf(file, "%selementNumber=%s\n", PFX, + airSprintSize_t(stmp, nrrdElementNumber(nrrd))); + fprintf(file, "%stype=%s\n", PFX, airEnumStr(nrrdType, nrrd->type)); + if (nrrdTypeBlock == nrrd->type) { + fprintf(file, "%sblockSize=%s\n", PFX, airSprintSize_t(stmp, nrrd->blockSize)); + } else { + fprintf(file, "%selementSize=%u\n", PFX, (unsigned int)nrrdElementSize(nrrd)); + } + printDescSep(file, PFX, sepStr, sepWidth, "axes"); /* ---------------- */ + fprintf(file, "%s%u-dimensional array, with axes:\n", PFX, nrrd->dim); + for (ii = 0; ii < nrrd->dim; ii++) { + fprintf(file, "%s[%u] size=%s\n", PFX, ii, + airSprintSize_t(stmp, nrrd->axis[ii].size)); + if (!elideNonExist || AIR_EXISTS(nrrd->axis[ii].spacing)) { + fprintf(file, "%s", PFX); + airSinglePrintf(file, NULL, INDENT "spacing=%lg\n", nrrd->axis[ii].spacing); + } + if (!elideNonExist || AIR_EXISTS(nrrd->axis[ii].thickness)) { + fprintf(file, "%s", PFX); + airSinglePrintf(file, NULL, INDENT "thickness=%lg\n", nrrd->axis[ii].thickness); + } + if (!elideNonExist || AIR_EXISTS(nrrd->axis[ii].min) + || AIR_EXISTS(nrrd->axis[ii].max)) { + fprintf(file, "%s", PFX); + airSinglePrintf(file, NULL, INDENT "axis min, max = %lg, ", nrrd->axis[ii].min); + airSinglePrintf(file, NULL, "%lg\n", nrrd->axis[ii].max); + } + if (sdim) { + if (!elideNonExist || nrrdSpaceVecExists(sdim, nrrd->axis[ii].spaceDirection)) { + fprintf(file, "%s" INDENT "spaceDirection=(", PFX); + for (jj = 0; jj < sdim; jj++) { + if (jj) fprintf(file, ","); + airSinglePrintf(file, NULL, "%lg", nrrd->axis[ii].spaceDirection[jj]); + } + fprintf(file, ")\n"); + } + } + if (!elideUnknown || nrrd->axis[ii].center) { + fprintf(file, "%s" INDENT "center=%s\n", PFX, + airEnumStr(nrrdCenter, nrrd->axis[ii].center)); + } + if (!elideUnknown || nrrd->axis[ii].kind) { + fprintf(file, "%s" INDENT "kind=%s\n", PFX, + airEnumStr(nrrdKind, nrrd->axis[ii].kind)); + } + DESC_STRING(nrrd->axis[ii].label, INDENT, "label", ""); + DESC_STRING(nrrd->axis[ii].units, INDENT, "units", ""); + } + if (nrrd->cmtArr->len) { + printDescSep(file, PFX, sepStr, sepWidth, "comments"); /* ---------------- */ + fprintf(file, "%scomments (%u):\n", PFX, nrrd->cmtArr->len); + for (ii = 0; ii < nrrd->cmtArr->len; ii++) { + sprintf(stmp, "[%u]", ii); + DESC_STRING(nrrd->cmt[ii], "", "", stmp); + } + } + if (nrrd->kvpArr->len) { + printDescSep(file, PFX, sepStr, sepWidth, "key/value"); /* ---------------- */ + fprintf(file, "%skey/value pairs (%u):\n", PFX, nrrd->kvpArr->len); + if (showPtrs) { + for (ii = 0; ii < nrrd->kvpArr->len; ii++) { + fprintf(file, "%s[%u]=|%s|@%p:=|%s|@%p\n", PFX, ii, /* */ + nrrd->kvp[0 + 2 * ii], AIR_VOIDP(nrrd->kvp[0 + 2 * ii]), /* */ + nrrd->kvp[1 + 2 * ii], AIR_VOIDP(nrrd->kvp[1 + 2 * ii])); + } + } else { + for (ii = 0; ii < nrrd->kvpArr->len; ii++) { + fprintf(file, "%s[%u]=|%s|:=|%s|\n", PFX, ii, nrrd->kvp[0 + 2 * ii], + nrrd->kvp[1 + 2 * ii]); + } + } + } + printDescSep(file, PFX, sepStr, sepWidth, "end"); /* ---------------- */ + +#undef DESC_STRING +#undef INDENT +#undef PFX +} + /* ******** nrrdDescribe ** ** writes verbose description of nrrd to given file + +2025 note: this is *old* function, written early in Nrrd development. You can tell its +age from the commented-out code referring to nrrd->min,max,hasNonExist, fields that +were in the Nrrd a long time ago but are now in NrrdRange. Also, it is not printing +anything about space and orientation. To implement "unu describe" GLK opted to write a +new different function nrrdDescribeMore (above), and keep this living fossil as is, +rather than try to make its output be generated by one particular parameterization of +nrrdDescribeMore. + */ void nrrdDescribe(FILE *file, const Nrrd *nrrd) { unsigned int ai; - char stmp[AIR_STRLEN_SMALL]; + char stmp[AIR_STRLEN_SMALL + 1]; if (file && nrrd) { fprintf(file, "Nrrd at 0x%p:\n", AIR_CVOIDP(nrrd)); @@ -524,14 +732,13 @@ nrrdDescribe(FILE *file, const Nrrd *nrrd) { airSprintSize_t(stmp, nrrdElementNumber(nrrd)), airEnumStr(nrrdType, nrrd->type)); if (nrrdTypeBlock == nrrd->type) { - fprintf(file, "The blocks have size %s\n", - airSprintSize_t(stmp, nrrd->blockSize)); + fprintf(file, "The blocks have size %s\n", airSprintSize_t(stmp, nrrd->blockSize)); } if (airStrlen(nrrd->content)) { fprintf(file, "Content = \"%s\"\n", nrrd->content); } fprintf(file, "%d-dimensional array, with axes:\n", nrrd->dim); - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { if (airStrlen(nrrd->axis[ai].label)) { fprintf(file, "%d: (\"%s\") ", ai, nrrd->axis[ai].label); } else { @@ -541,10 +748,8 @@ nrrdDescribe(FILE *file, const Nrrd *nrrd) { airEnumStr(nrrdCenter, nrrd->axis[ai].center), airSprintSize_t(stmp, nrrd->axis[ai].size)); airSinglePrintf(file, NULL, "spacing=%lg, \n", nrrd->axis[ai].spacing); - airSinglePrintf(file, NULL, "thickness=%lg, \n", - nrrd->axis[ai].thickness); - airSinglePrintf(file, NULL, " axis(Min,Max) = (%lg,", - nrrd->axis[ai].min); + airSinglePrintf(file, NULL, "thickness=%lg, \n", nrrd->axis[ai].thickness); + airSinglePrintf(file, NULL, " axis(Min,Max) = (%lg,", nrrd->axis[ai].min); airSinglePrintf(file, NULL, "%lg)\n", nrrd->axis[ai].max); if (airStrlen(nrrd->axis[ai].units)) { fprintf(file, "units=%s, \n", nrrd->axis[ai].units); @@ -555,13 +760,12 @@ nrrdDescribe(FILE *file, const Nrrd *nrrd) { nrrd->min); airSinglePrintf(file, NULL, ", %lg\n", nrrd->max); */ - airSinglePrintf(file, NULL, "The old min, old max values are %lg", - nrrd->oldMin); + airSinglePrintf(file, NULL, "The old min, old max values are %lg", nrrd->oldMin); airSinglePrintf(file, NULL, ", %lg\n", nrrd->oldMax); /* fprintf(file, "hasNonExist = %d\n", nrrd->hasNonExist); */ if (nrrd->cmtArr->len) { fprintf(file, "Comments:\n"); - for (ai=0; aicmtArr->len; ai++) { + for (ai = 0; ai < nrrd->cmtArr->len; ai++) { fprintf(file, "%s\n", nrrd->cmt[ai]); } } @@ -569,13 +773,13 @@ nrrdDescribe(FILE *file, const Nrrd *nrrd) { } } -int -nrrdSpaceVecExists(unsigned int sdim, double vec[NRRD_SPACE_DIM_MAX]) { +int /* Biff: nope */ +nrrdSpaceVecExists(unsigned int sdim, const double vec[NRRD_SPACE_DIM_MAX]) { int exists; unsigned int ii; exists = AIR_EXISTS(vec[0]); - for (ii=1; iispace || !airEnumValCheck(nrrdSpace, nrrd->space) )) { - biffMaybeAddf(useBiff, NRRD, "%s: space %d invalid", - me, nrrd->space); + if (!(!nrrd->space || !airEnumValCheck(nrrdSpace, nrrd->space))) { + biffMaybeAddf(useBiff, NRRD, "%s: space %d invalid", me, nrrd->space); return 1; } - if (!( nrrd->spaceDim <= NRRD_SPACE_DIM_MAX )) { - biffMaybeAddf(useBiff, NRRD, "%s: space dimension %d is outside " + if (!(nrrd->spaceDim <= NRRD_SPACE_DIM_MAX)) { + biffMaybeAddf(useBiff, NRRD, + "%s: space dimension %d is outside " "valid range [0,NRRD_SPACE_DIM_MAX] = [0,%d]", me, nrrd->dim, NRRD_SPACE_DIM_MAX); return 1; @@ -607,8 +811,7 @@ _nrrdFieldCheckSpaceInfo(const Nrrd *nrrd, int useBiff) { if (nrrd->spaceDim) { if (nrrd->space) { if (nrrdSpaceDimension(nrrd->space) != nrrd->spaceDim) { - biffMaybeAddf(useBiff, NRRD, - "%s: space %s has dimension %d but spaceDim is %d", + biffMaybeAddf(useBiff, NRRD, "%s: space %s has dimension %d but spaceDim is %d", me, airEnumStr(nrrdSpace, nrrd->space), nrrdSpaceDimension(nrrd->space), nrrd->spaceDim); return 1; @@ -616,46 +819,48 @@ _nrrdFieldCheckSpaceInfo(const Nrrd *nrrd, int useBiff) { } /* check that all coeffs of spaceOrigin have consistent existance */ exists = AIR_EXISTS(nrrd->spaceOrigin[0]); - for (ii=0; iispaceDim; ii++) { + for (ii = 0; ii < nrrd->spaceDim; ii++) { if (exists ^ AIR_EXISTS(nrrd->spaceOrigin[ii])) { biffMaybeAddf(useBiff, NRRD, "%s: existance of space origin coefficients must " - "be consistent (val[0] not like val[%d])", me, ii); + "be consistent (val[0] not like val[%d])", + me, ii); return 1; } } /* check that all coeffs of measurementFrame have consistent existance */ exists = AIR_EXISTS(nrrd->measurementFrame[0][0]); - for (dd=0; ddspaceDim; dd++) { - for (ii=0; iispaceDim; ii++) { + for (dd = 0; dd < nrrd->spaceDim; dd++) { + for (ii = 0; ii < nrrd->spaceDim; ii++) { if (exists ^ AIR_EXISTS(nrrd->measurementFrame[dd][ii])) { biffMaybeAddf(useBiff, NRRD, "%s: existance of measurement frame coefficients " "must be consistent: [col][row] [%d][%d] not " - "like [0][0])", me, dd, ii); + "like [0][0])", + me, dd, ii); return 1; } } } /* check on space directions */ - for (dd=0; dddim; dd++) { + for (dd = 0; dd < nrrd->dim; dd++) { exists = AIR_EXISTS(nrrd->axis[dd].spaceDirection[0]); - for (ii=1; iispaceDim; ii++) { + for (ii = 1; ii < nrrd->spaceDim; ii++) { if (exists ^ AIR_EXISTS(nrrd->axis[dd].spaceDirection[ii])) { biffMaybeAddf(useBiff, NRRD, "%s: existance of space direction %d coefficients " - "must be consistent (val[0] not like val[%d])", me, - dd, ii); return 1; + "must be consistent (val[0] not like val[%d])", + me, dd, ii); + return 1; } } if (exists) { - if (AIR_EXISTS(nrrd->axis[dd].min) - || AIR_EXISTS(nrrd->axis[dd].max) - || AIR_EXISTS(nrrd->axis[dd].spacing) - || !!airStrlen(nrrd->axis[dd].units)) { + if (AIR_EXISTS(nrrd->axis[dd].min) || AIR_EXISTS(nrrd->axis[dd].max) + || AIR_EXISTS(nrrd->axis[dd].spacing) || !!airStrlen(nrrd->axis[dd].units)) { biffMaybeAddf(useBiff, NRRD, "%s: axis[%d] has a direction vector, and so can't " - "have min, max, spacing, or units set", me, dd); + "have min, max, spacing, or units set", + me, dd); return 1; } } @@ -663,42 +868,38 @@ _nrrdFieldCheckSpaceInfo(const Nrrd *nrrd, int useBiff) { } else { /* else there's not supposed to be anything in "space" */ if (nrrd->space) { - biffMaybeAddf(useBiff, NRRD, - "%s: space %s can't be set with spaceDim %d", - me, airEnumStr(nrrdSpace, nrrd->space), - nrrd->spaceDim); + biffMaybeAddf(useBiff, NRRD, "%s: space %s can't be set with spaceDim %d", me, + airEnumStr(nrrdSpace, nrrd->space), nrrd->spaceDim); return 1; } /* -------- */ exists = AIR_FALSE; - for (dd=0; ddspaceUnits[dd]); } if (exists) { - biffMaybeAddf(useBiff, NRRD, - "%s: spaceDim is 0, but space units is set", me); + biffMaybeAddf(useBiff, NRRD, "%s: spaceDim is 0, but space units is set", me); return 1; } /* -------- */ exists = AIR_FALSE; - for (dd=0; ddspaceOrigin[dd]); } if (exists) { - biffMaybeAddf(useBiff, NRRD, - "%s: spaceDim is 0, but space origin is set", me); + biffMaybeAddf(useBiff, NRRD, "%s: spaceDim is 0, but space origin is set", me); return 1; } /* -------- */ exists = AIR_FALSE; - for (dd=0; ddaxis[ii].spaceDirection[dd]); } } if (exists) { - biffMaybeAddf(useBiff, NRRD, - "%s: spaceDim is 0, but space directions are set", me); + biffMaybeAddf(useBiff, NRRD, "%s: spaceDim is 0, but space directions are set", + me); return 1; } } @@ -724,32 +925,30 @@ _nrrdFieldCheck_noop(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_type(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_type"; + static const char me[] = "_nrrdFieldCheck_type"; if (airEnumValCheck(nrrdType, nrrd->type)) { - biffMaybeAddf(useBiff, NRRD, - "%s: type (%d) is not valid", me, nrrd->type); + biffMaybeAddf(useBiff, NRRD, "%s: type (%d) is not valid", me, nrrd->type); return 1; } return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_block_size(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_block_size"; - char stmp[AIR_STRLEN_SMALL]; + static const char me[] = "_nrrdFieldCheck_block_size"; + char stmp[AIR_STRLEN_SMALL + 1]; - if (nrrdTypeBlock == nrrd->type && (!(0 < nrrd->blockSize)) ) { - biffMaybeAddf(useBiff, NRRD, - "%s: type is %s but nrrd->blockSize (%s) invalid", me, + if (nrrdTypeBlock == nrrd->type && (!(0 < nrrd->blockSize))) { + biffMaybeAddf(useBiff, NRRD, "%s: type is %s but nrrd->blockSize (%s) invalid", me, airEnumStr(nrrdType, nrrdTypeBlock), - airSprintSize_t(stmp, nrrd->blockSize)); return 1; + airSprintSize_t(stmp, nrrd->blockSize)); + return 1; } if (nrrdTypeBlock != nrrd->type && (0 < nrrd->blockSize)) { - biffMaybeAddf(useBiff, NRRD, - "%s: type is %s (not block) but blockSize is %s", me, + biffMaybeAddf(useBiff, NRRD, "%s: type is %s (not block) but blockSize is %s", me, airEnumStr(nrrdType, nrrd->type), airSprintSize_t(stmp, nrrd->blockSize)); return 1; @@ -757,22 +956,21 @@ _nrrdFieldCheck_block_size(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_dimension(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_dimension"; + static const char me[] = "_nrrdFieldCheck_dimension"; if (!AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX)) { - biffMaybeAddf(useBiff, NRRD, - "%s: dimension %u is outside valid range [1,%d]", - me, nrrd->dim, NRRD_DIM_MAX); + biffMaybeAddf(useBiff, NRRD, "%s: dimension %u is outside valid range [1,%d]", me, + nrrd->dim, NRRD_DIM_MAX); return 1; } return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_space(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_space"; + static const char me[] = "_nrrdFieldCheck_space"; if (_nrrdFieldCheckSpaceInfo(nrrd, useBiff)) { biffMaybeAddf(useBiff, NRRD, "%s: trouble", me); @@ -781,9 +979,9 @@ _nrrdFieldCheck_space(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_space_dimension(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_space_dimension"; + static const char me[] = "_nrrdFieldCheck_space_dimension"; if (_nrrdFieldCheckSpaceInfo(nrrd, useBiff)) { biffMaybeAddf(useBiff, NRRD, "%s: trouble", me); @@ -792,9 +990,9 @@ _nrrdFieldCheck_space_dimension(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_sizes(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_sizes"; + static const char me[] = "_nrrdFieldCheck_sizes"; size_t size[NRRD_DIM_MAX]; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoSize, size); @@ -805,17 +1003,16 @@ _nrrdFieldCheck_sizes(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_spacings(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_spacings"; + static const char me[] = "_nrrdFieldCheck_spacings"; double val[NRRD_DIM_MAX]; unsigned int ai; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoSpacing, val); - for (ai=0; aidim; ai++) { - if (!( !airIsInf_d(val[ai]) && (airIsNaN(val[ai]) || (0 != val[ai])) )) { - biffMaybeAddf(useBiff, NRRD, - "%s: axis %d spacing (%g) invalid", me, ai, val[ai]); + for (ai = 0; ai < nrrd->dim; ai++) { + if (!(!airIsInf_d(val[ai]) && (airIsNaN(val[ai]) || (0 != val[ai])))) { + biffMaybeAddf(useBiff, NRRD, "%s: axis %d spacing (%g) invalid", me, ai, val[ai]); return 1; } } @@ -826,37 +1023,37 @@ _nrrdFieldCheck_spacings(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_thicknesses(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_thicknesses"; + static const char me[] = "_nrrdFieldCheck_thicknesses"; double val[NRRD_DIM_MAX]; unsigned int ai; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoThickness, val); - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { /* note that unlike spacing, we allow zero thickness, but it makes no sense to be negative */ - if (!( !airIsInf_d(val[ai]) && (airIsNaN(val[ai]) || (0 <= val[ai])) )) { - biffMaybeAddf(useBiff, NRRD, - "%s: axis %d thickness (%g) invalid", me, ai, val[ai]); + if (!(!airIsInf_d(val[ai]) && (airIsNaN(val[ai]) || (0 <= val[ai])))) { + biffMaybeAddf(useBiff, NRRD, "%s: axis %d thickness (%g) invalid", me, ai, + val[ai]); return 1; } } return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_axis_mins(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_axis_mins"; + static const char me[] = "_nrrdFieldCheck_axis_mins"; double val[NRRD_DIM_MAX]; unsigned int ai; int ret; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoMin, val); - for (ai=0; aidim; ai++) { - if ((ret=airIsInf_d(val[ai]))) { - biffMaybeAddf(useBiff, NRRD, "%s: axis %d min %sinf invalid", - me, ai, 1==ret ? "+" : "-"); + for (ai = 0; ai < nrrd->dim; ai++) { + if ((ret = airIsInf_d(val[ai]))) { + biffMaybeAddf(useBiff, NRRD, "%s: axis %d min %sinf invalid", me, ai, + 1 == ret ? "+" : "-"); return 1; } } @@ -868,18 +1065,18 @@ _nrrdFieldCheck_axis_mins(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_axis_maxs(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_axis_maxs"; + static const char me[] = "_nrrdFieldCheck_axis_maxs"; double val[NRRD_DIM_MAX]; unsigned int ai; int ret; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoMax, val); - for (ai=0; aidim; ai++) { - if ((ret=airIsInf_d(val[ai]))) { - biffMaybeAddf(useBiff, NRRD, "%s: axis %d max %sinf invalid", - me, ai, 1==ret ? "+" : "-"); + for (ai = 0; ai < nrrd->dim; ai++) { + if ((ret = airIsInf_d(val[ai]))) { + biffMaybeAddf(useBiff, NRRD, "%s: axis %d max %sinf invalid", me, ai, + 1 == ret ? "+" : "-"); return 1; } } @@ -891,9 +1088,9 @@ _nrrdFieldCheck_axis_maxs(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_space_directions(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_space_directions"; + static const char me[] = "_nrrdFieldCheck_space_directions"; if (_nrrdFieldCheckSpaceInfo(nrrd, useBiff)) { biffMaybeAddf(useBiff, NRRD, "%s: space info problem", me); @@ -902,44 +1099,39 @@ _nrrdFieldCheck_space_directions(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_centers(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_centers"; + static const char me[] = "_nrrdFieldCheck_centers"; unsigned int ai; int val[NRRD_DIM_MAX]; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoCenter, val); - for (ai=0; aidim; ai++) { - if (!( nrrdCenterUnknown == val[ai] - || !airEnumValCheck(nrrdCenter, val[ai]) )) { - biffMaybeAddf(useBiff, NRRD, "%s: axis %d center %d invalid", - me, ai, val[ai]); + for (ai = 0; ai < nrrd->dim; ai++) { + if (!(nrrdCenterUnknown == val[ai] || !airEnumValCheck(nrrdCenter, val[ai]))) { + biffMaybeAddf(useBiff, NRRD, "%s: axis %d center %d invalid", me, ai, val[ai]); return 1; } } return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_kinds(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_kinds"; + static const char me[] = "_nrrdFieldCheck_kinds"; int val[NRRD_DIM_MAX]; unsigned int wantLen, ai; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoKind, val); - for (ai=0; aidim; ai++) { - if (!( nrrdKindUnknown == val[ai] - || !airEnumValCheck(nrrdKind, val[ai]) )) { - biffMaybeAddf(useBiff, NRRD, - "%s: axis %d kind %d invalid", me, ai, val[ai]); + for (ai = 0; ai < nrrd->dim; ai++) { + if (!(nrrdKindUnknown == val[ai] || !airEnumValCheck(nrrdKind, val[ai]))) { + biffMaybeAddf(useBiff, NRRD, "%s: axis %d kind %d invalid", me, ai, val[ai]); return 1; } wantLen = nrrdKindSize(val[ai]); if (wantLen && wantLen != nrrd->axis[ai].size) { - char stmp[AIR_STRLEN_SMALL]; - biffMaybeAddf(useBiff, NRRD, - "%s: axis %d kind %s requires size %u, but have %s", me, - ai, airEnumStr(nrrdKind, val[ai]), wantLen, + char stmp[AIR_STRLEN_SMALL + 1]; + biffMaybeAddf(useBiff, NRRD, "%s: axis %d kind %s requires size %u, but have %s", + me, ai, airEnumStr(nrrdKind, val[ai]), wantLen, airSprintSize_t(stmp, nrrd->axis[ai].size)); return 1; } @@ -947,9 +1139,11 @@ _nrrdFieldCheck_kinds(const Nrrd *nrrd, int useBiff) { return 0; } +/* (no Biff annotation because currently scan-symbols.py refrains from annotating + static functions that do NOT use biff) */ static int _nrrdFieldCheck_labels(const Nrrd *nrrd, int useBiff) { - /* char me[]="_nrrdFieldCheck_labels"; */ + /* static const char me[] = "_nrrdFieldCheck_labels"; */ AIR_UNUSED(nrrd); AIR_UNUSED(useBiff); @@ -961,9 +1155,9 @@ _nrrdFieldCheck_labels(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_units(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_units"; + static const char me[] = "_nrrdFieldCheck_units"; /* as with labels- the strings themselves don't need checking themselves */ /* but per-axis units cannot be set for axes with space directions ... */ @@ -974,28 +1168,26 @@ _nrrdFieldCheck_units(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_old_min(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_old_min"; + static const char me[] = "_nrrdFieldCheck_old_min"; int ret; - if ((ret=airIsInf_d(nrrd->oldMin))) { - biffMaybeAddf(useBiff, NRRD, - "%s: old min %sinf invalid", me, 1==ret ? "+" : "-"); + if ((ret = airIsInf_d(nrrd->oldMin))) { + biffMaybeAddf(useBiff, NRRD, "%s: old min %sinf invalid", me, 1 == ret ? "+" : "-"); return 1; } /* oldMin == oldMax is perfectly valid */ return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_old_max(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_old_max"; + static const char me[] = "_nrrdFieldCheck_old_max"; int ret; - if ((ret=airIsInf_d(nrrd->oldMax))) { - biffMaybeAddf(useBiff, NRRD, - "%s: old max %sinf invalid", me, 1==ret ? "+" : "-"); + if ((ret = airIsInf_d(nrrd->oldMax))) { + biffMaybeAddf(useBiff, NRRD, "%s: old max %sinf invalid", me, 1 == ret ? "+" : "-"); return 1; } /* oldMin == oldMax is perfectly valid */ @@ -1004,7 +1196,7 @@ _nrrdFieldCheck_old_max(const Nrrd *nrrd, int useBiff) { static int _nrrdFieldCheck_keyvalue(const Nrrd *nrrd, int useBiff) { - /* char me[]="_nrrdFieldCheck_keyvalue"; */ + /* static const char me[] = "_nrrdFieldCheck_keyvalue"; */ AIR_UNUSED(nrrd); AIR_UNUSED(useBiff); @@ -1015,9 +1207,9 @@ _nrrdFieldCheck_keyvalue(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_space_units(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_space_units"; + static const char me[] = "_nrrdFieldCheck_space_units"; /* not sure if there's anything to specifically check for the space units themselves ... */ @@ -1028,9 +1220,9 @@ _nrrdFieldCheck_space_units(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_space_origin(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_space_origin"; + static const char me[] = "_nrrdFieldCheck_space_origin"; /* pre-Fri Feb 11 04:25:36 EST 2005, I thought that the spaceOrigin must be known to describe the @@ -1043,9 +1235,9 @@ _nrrdFieldCheck_space_origin(const Nrrd *nrrd, int useBiff) { return 0; } -static int +static int /* Biff: maybe:2:1 */ _nrrdFieldCheck_measurement_frame(const Nrrd *nrrd, int useBiff) { - static const char me[]="_nrrdFieldCheck_measurement_frame"; + static const char me[] = "_nrrdFieldCheck_measurement_frame"; if (_nrrdFieldCheckSpaceInfo(nrrd, useBiff)) { biffMaybeAddf(useBiff, NRRD, "%s: space info problem", me); @@ -1054,12 +1246,11 @@ _nrrdFieldCheck_measurement_frame(const Nrrd *nrrd, int useBiff) { return 0; } -int -(*_nrrdFieldCheck[NRRD_FIELD_MAX+1])(const Nrrd *, int useBiff) = { - _nrrdFieldCheck_noop, /* nonfield */ - _nrrdFieldCheck_noop, /* comment */ - _nrrdFieldCheck_noop, /* content */ - _nrrdFieldCheck_noop, /* number */ +int (*const _nrrdFieldCheck[NRRD_FIELD_MAX + 1])(const Nrrd *, int useBiff) = { + _nrrdFieldCheck_noop, /* nonfield */ + _nrrdFieldCheck_noop, /* comment */ + _nrrdFieldCheck_noop, /* content */ + _nrrdFieldCheck_noop, /* number */ _nrrdFieldCheck_type, _nrrdFieldCheck_block_size, _nrrdFieldCheck_dimension, @@ -1075,25 +1266,25 @@ int _nrrdFieldCheck_kinds, _nrrdFieldCheck_labels, _nrrdFieldCheck_units, - _nrrdFieldCheck_noop, /* min */ - _nrrdFieldCheck_noop, /* max */ + _nrrdFieldCheck_noop, /* min */ + _nrrdFieldCheck_noop, /* max */ _nrrdFieldCheck_old_min, _nrrdFieldCheck_old_max, - _nrrdFieldCheck_noop, /* endian */ - _nrrdFieldCheck_noop, /* encoding */ - _nrrdFieldCheck_noop, /* line_skip */ - _nrrdFieldCheck_noop, /* byte_skip */ + _nrrdFieldCheck_noop, /* endian */ + _nrrdFieldCheck_noop, /* encoding */ + _nrrdFieldCheck_noop, /* line_skip */ + _nrrdFieldCheck_noop, /* byte_skip */ _nrrdFieldCheck_keyvalue, - _nrrdFieldCheck_noop, /* sample units */ + _nrrdFieldCheck_noop, /* sample units */ _nrrdFieldCheck_space_units, _nrrdFieldCheck_space_origin, _nrrdFieldCheck_measurement_frame, - _nrrdFieldCheck_noop, /* data_file */ + _nrrdFieldCheck_noop, /* data_file */ }; -int +int /* Biff: maybe:3:1 */ _nrrdCheck(const Nrrd *nrrd, int checkData, int useBiff) { - static const char me[]="_nrrdCheck"; + static const char me[] = "_nrrdCheck"; int fi; if (!nrrd) { @@ -1102,12 +1293,12 @@ _nrrdCheck(const Nrrd *nrrd, int checkData, int useBiff) { } if (checkData) { if (!(nrrd->data)) { - biffMaybeAddf(useBiff, NRRD, "%s: nrrd %p has NULL data pointer", - me, AIR_CVOIDP(nrrd)); + biffMaybeAddf(useBiff, NRRD, "%s: nrrd %p has NULL data pointer", me, + AIR_CVOIDP(nrrd)); return 1; } } - for (fi=nrrdField_unknown+1; fidim != n2->dim) { - biffMaybeAddf(useBiff, NRRD, "%s: n1->dim (%u) != n2->dim (%u)", - me, n1->dim, n2->dim); + biffMaybeAddf(useBiff, NRRD, "%s: n1->dim (%u) != n2->dim (%u)", me, n1->dim, + n2->dim); return 0; } - for (ai=0; aidim; ai++) { + for (ai = 0; ai < n1->dim; ai++) { if (n1->axis[ai].size != n2->axis[ai].size) { - biffMaybeAddf(useBiff, NRRD, "%s: n1->axis[%d].size (%s) " - "!= n2->axis[%d].size (%s)", me, ai, - airSprintSize_t(stmp[0], n1->axis[ai].size), ai, + biffMaybeAddf(useBiff, NRRD, + "%s: n1->axis[%d].size (%s) " + "!= n2->axis[%d].size (%s)", + me, ai, airSprintSize_t(stmp[0], n1->axis[ai].size), ai, airSprintSize_t(stmp[1], n2->axis[ai].size)); return 0; } @@ -1191,10 +1383,10 @@ nrrdSameSize(const Nrrd *n1, const Nrrd *n2, int useBiff) { ** Besides learning how many bytes long one element is, this function ** is useful as a way of detecting an invalid blocksize on a block nrrd. */ -size_t -nrrdElementSize (const Nrrd *nrrd) { +size_t /* Biff: nope */ +nrrdElementSize(const Nrrd *nrrd) { - if (!( nrrd && !airEnumValCheck(nrrdType, nrrd->type) )) { + if (!(nrrd && !airEnumValCheck(nrrdType, nrrd->type))) { return 0; } if (nrrdTypeBlock != nrrd->type) { @@ -1215,11 +1407,9 @@ nrrdElementSize (const Nrrd *nrrd) { ** takes the place of old "nrrd->num": the number of elements in the ** nrrd, which is just the product of the axis sizes. A return of 0 ** means there's a problem. Negative numbers are never returned. -** -** does NOT use biff */ -size_t -nrrdElementNumber (const Nrrd *nrrd) { +size_t /* Biff: nope */ +nrrdElementNumber(const Nrrd *nrrd) { size_t num, size[NRRD_DIM_MAX]; unsigned int ai; @@ -1233,7 +1423,7 @@ nrrdElementNumber (const Nrrd *nrrd) { return 0; } num = 1; - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { /* negative numbers and overflow were caught by _nrrdSizeCheck() */ num *= size[ai]; } @@ -1244,104 +1434,63 @@ nrrdElementNumber (const Nrrd *nrrd) { ** obviously, this requires that the per-axis size fields have been set */ void -_nrrdSplitSizes(size_t *pieceSize, size_t *pieceNum, Nrrd *nrrd, - unsigned int split) { +_nrrdSplitSizes(size_t *pieceSize, size_t *pieceNum, Nrrd *nrrd, unsigned int split) { unsigned int ai; size_t size[NRRD_DIM_MAX]; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoSize, size); *pieceSize = 1; - for (ai=0; aidim; ai++) { + for (ai = split; ai < nrrd->dim; ai++) { *pieceNum *= size[ai]; } return; } -/* -******** nrrdHasNonExistSet() -** -** This function will always (assuming type is valid) set the value of -** nrrd->hasNonExist to either nrrdNonExistTrue or nrrdNonExistFalse, -** and it will return that value. For lack of a more sophisticated -** policy, blocks are currently always considered to be existent -** values (because nrrdTypeIsIntegral[nrrdTypeBlock] is currently true). -** This function will ALWAYS determine the correct answer and set the -** value of nrrd->hasNonExist: it ignores the value of -** nrrd->hasNonExist on the input nrrd. Exception: if nrrd is null or -** type is bogus, no action is taken and nrrdNonExistUnknown is -** returned. -** -** Because this will return either nrrdNonExistTrue or nrrdNonExistFalse, -** and because the C boolean value of these are true and false (respectively), -** it is possible (and encouraged) to use the return of this function -** as the expression of a conditional: -** -** if (nrrdHasNonExistSet(nrrd)) { -** ... handle existance of non-existent values ... -** } -*/ -/* -int -nrrdHasNonExistSet(Nrrd *nrrd) { - size_t I, N; - float val; - - if (!( nrrd && !airEnumValCheck(nrrdType, nrrd->type) )) - return nrrdNonExistUnknown; - - if (nrrdTypeIsIntegral[nrrd->type]) { - nrrd->hasNonExist = nrrdNonExistFalse; - } else { - nrrd->hasNonExist = nrrdNonExistFalse; - N = nrrdElementNumber(nrrd); - for (I=0; Itype](nrrd->data, I); - if (!AIR_EXISTS(val)) { - nrrd->hasNonExist = nrrdNonExistTrue; - break; - } - } - } - return nrrd->hasNonExist; -} -*/ +/* TeemV2: long-commented-out nrrdHasNonExistSet() now removed */ -static int +static int /* Biff: 1 */ _nrrdCheckEnums(void) { - static const char me[]="_nrrdCheckEnums"; - char which[AIR_STRLEN_SMALL]; + static const char me[] = "_nrrdCheckEnums"; + char which[AIR_STRLEN_SMALL + 1]; - if (nrrdFormatTypeLast-1 != NRRD_FORMAT_TYPE_MAX) { - strcpy(which, "nrrdFormat"); goto err; + if (nrrdFormatTypeLast - 1 != NRRD_FORMAT_TYPE_MAX) { + strcpy(which, "nrrdFormat"); + goto err; } - if (nrrdTypeLast-1 != NRRD_TYPE_MAX) { - strcpy(which, "nrrdType"); goto err; + if (nrrdTypeLast - 1 != NRRD_TYPE_MAX) { + strcpy(which, "nrrdType"); + goto err; } - if (nrrdEncodingTypeLast-1 != NRRD_ENCODING_TYPE_MAX) { - strcpy(which, "nrrdEncodingType"); goto err; + if (nrrdEncodingTypeLast - 1 != NRRD_ENCODING_TYPE_MAX) { + strcpy(which, "nrrdEncodingType"); + goto err; } - if (nrrdCenterLast-1 != NRRD_CENTER_MAX) { - strcpy(which, "nrrdCenter"); goto err; + if (nrrdCenterLast - 1 != NRRD_CENTER_MAX) { + strcpy(which, "nrrdCenter"); + goto err; } - if (nrrdAxisInfoLast-1 != NRRD_AXIS_INFO_MAX) { - strcpy(which, "nrrdAxisInfo"); goto err; + if (nrrdAxisInfoLast - 1 != NRRD_AXIS_INFO_MAX) { + strcpy(which, "nrrdAxisInfo"); + goto err; } /* can't really check on endian enum */ - if (nrrdField_last-1 != NRRD_FIELD_MAX) { - strcpy(which, "nrrdField"); goto err; + if (nrrdField_last - 1 != NRRD_FIELD_MAX) { + strcpy(which, "nrrdField"); + goto err; } - if (nrrdHasNonExistLast-1 != NRRD_HAS_NON_EXIST_MAX) { - strcpy(which, "nrrdHasNonExist"); goto err; + if (nrrdHasNonExistLast - 1 != NRRD_HAS_NON_EXIST_MAX) { + strcpy(which, "nrrdHasNonExist"); + goto err; } /* no errors so far */ return 0; - err: +err: biffAddf(NRRD, "%s: Last vs. MAX incompatibility for %s enum", me, which); return 1; } @@ -1354,101 +1503,101 @@ _nrrdCheckEnums(void) { ** ** returns 1 if all is okay, 0 if there is a problem */ -int /*Teem: biff if (!ret) */ +int /* Biff: 0 */ nrrdSanity(void) { - static const char me[]="nrrdSanity"; + static const char me[] = "nrrdSanity"; int aret, type; size_t maxsize; airLLong tmpLLI; airULLong tmpULLI; + /* (much like with air/sane.c airSanity()) for Teem v1.13 GLK decided to remove this + optimization, which meant that this function could only run through its tests + once. Global state, especially if hidden like this, is fishy (and flagged by + teem/src/_util/scan-symbols.py). This function actually reads the values of other + global variables (like nrrdDefaultWriteEncodingType) which can absolutely change + between calls, so this also is not a valid optimization. If profiling reveals this + to be a bottleneck, we might refactor these tests into things that can and cannot + be changing at run-time. static int _nrrdSanity = 0; if (_nrrdSanity) { - /* we've been through this once before and things looked okay ... */ - /* Is this thread-safe? I think so. If we assume that any two + / * we've been through this once before and things looked okay ... * / + / * Is this thread-safe? I think so. If we assume that any two threads are going to compute the same value, isn't it the case that, at worse, both of them will go through all the tests and - then set _nrrdSanity to the same thing? */ + then set _nrrdSanity to the same thing? * / + ha ha - not if the global variables we read have changed! return 1; } + */ aret = airSanity(); if (aret != airInsane_not) { - biffAddf(NRRD, "%s: airSanity() failed: %s", me, - airInsaneErr(aret)); + biffAddf(NRRD, "%s: airSanity() failed: %s", me, airInsaneErr(aret)); return 0; } - if (airEnumValCheck(nrrdEncodingType, nrrdDefaultWriteEncodingType)) { biffAddf(NRRD, "%s: nrrdDefaultWriteEncodingType (%d) not in valid " - "range [%d,%d]", me, nrrdDefaultWriteEncodingType, - nrrdEncodingTypeUnknown+1, nrrdEncodingTypeLast-1); + "range [%d,%d]", + me, nrrdDefaultWriteEncodingType, nrrdEncodingTypeUnknown + 1, + nrrdEncodingTypeLast - 1); return 0; } if (airEnumValCheck(nrrdCenter, nrrdDefaultCenter)) { - biffAddf(NRRD, - "%s: nrrdDefaultCenter (%d) not in valid range [%d,%d]", - me, nrrdDefaultCenter, - nrrdCenterUnknown+1, nrrdCenterLast-1); + biffAddf(NRRD, "%s: nrrdDefaultCenter (%d) not in valid range [%d,%d]", me, + nrrdDefaultCenter, nrrdCenterUnknown + 1, nrrdCenterLast - 1); return 0; } - if (!( nrrdTypeSize[nrrdTypeChar] == sizeof(char) - && nrrdTypeSize[nrrdTypeUChar] == sizeof(unsigned char) - && nrrdTypeSize[nrrdTypeShort] == sizeof(short) - && nrrdTypeSize[nrrdTypeUShort] == sizeof(unsigned short) - && nrrdTypeSize[nrrdTypeInt] == sizeof(int) - && nrrdTypeSize[nrrdTypeUInt] == sizeof(unsigned int) - && nrrdTypeSize[nrrdTypeLLong] == sizeof(airLLong) - && nrrdTypeSize[nrrdTypeULLong] == sizeof(airULLong) - && nrrdTypeSize[nrrdTypeFloat] == sizeof(float) - && nrrdTypeSize[nrrdTypeDouble] == sizeof(double) )) { - biffAddf(NRRD, "%s: sizeof() for nrrd types has problem: " + if (!(nrrdTypeSize[nrrdTypeChar] == sizeof(char) + && nrrdTypeSize[nrrdTypeUChar] == sizeof(unsigned char) + && nrrdTypeSize[nrrdTypeShort] == sizeof(short) + && nrrdTypeSize[nrrdTypeUShort] == sizeof(unsigned short) + && nrrdTypeSize[nrrdTypeInt] == sizeof(int) + && nrrdTypeSize[nrrdTypeUInt] == sizeof(unsigned int) + && nrrdTypeSize[nrrdTypeLLong] == sizeof(airLLong) + && nrrdTypeSize[nrrdTypeULLong] == sizeof(airULLong) + && nrrdTypeSize[nrrdTypeFloat] == sizeof(float) + && nrrdTypeSize[nrrdTypeDouble] == sizeof(double))) { + biffAddf(NRRD, + "%s: sizeof() for nrrd types has problem: " "expected (%u,%u,%u,%u,%u,%u,%u,%u,%u,%u) " - "but got (%u,%u,%u,%u,%u,%u,%u,%u,%u,%u)", me, - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeChar]), - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeUChar]), - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeShort]), - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeUShort]), - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeInt]), - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeUInt]), - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeLLong]), - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeULLong]), - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeFloat]), - AIR_CAST(unsigned int, nrrdTypeSize[nrrdTypeDouble]), - AIR_CAST(unsigned int, sizeof(char)), - AIR_CAST(unsigned int, sizeof(unsigned char)), - AIR_CAST(unsigned int, sizeof(short)), - AIR_CAST(unsigned int, sizeof(unsigned short)), - AIR_CAST(unsigned int, sizeof(int)), - AIR_CAST(unsigned int, sizeof(unsigned int)), - AIR_CAST(unsigned int, sizeof(airLLong)), - AIR_CAST(unsigned int, sizeof(airULLong)), - AIR_CAST(unsigned int, sizeof(float)), - AIR_CAST(unsigned int, sizeof(double))); + "but got (%u,%u,%u,%u,%u,%u,%u,%u,%u,%u)", + me, AIR_UINT(nrrdTypeSize[nrrdTypeChar]), + AIR_UINT(nrrdTypeSize[nrrdTypeUChar]), + AIR_UINT(nrrdTypeSize[nrrdTypeShort]), + AIR_UINT(nrrdTypeSize[nrrdTypeUShort]), AIR_UINT(nrrdTypeSize[nrrdTypeInt]), + AIR_UINT(nrrdTypeSize[nrrdTypeUInt]), AIR_UINT(nrrdTypeSize[nrrdTypeLLong]), + AIR_UINT(nrrdTypeSize[nrrdTypeULLong]), + AIR_UINT(nrrdTypeSize[nrrdTypeFloat]), + AIR_UINT(nrrdTypeSize[nrrdTypeDouble]), AIR_UINT(sizeof(char)), + AIR_UINT(sizeof(unsigned char)), AIR_UINT(sizeof(short)), + AIR_UINT(sizeof(unsigned short)), AIR_UINT(sizeof(int)), + AIR_UINT(sizeof(unsigned int)), AIR_UINT(sizeof(airLLong)), + AIR_UINT(sizeof(airULLong)), AIR_UINT(sizeof(float)), + AIR_UINT(sizeof(double))); return 0; } /* check on NRRD_TYPE_SIZE_MAX */ maxsize = 0; - for (type=nrrdTypeUnknown+1; type<=nrrdTypeLast-2; type++) { + for (type = nrrdTypeUnknown + 1; type <= nrrdTypeLast - 2; type++) { maxsize = AIR_MAX(maxsize, nrrdTypeSize[type]); } if (maxsize != NRRD_TYPE_SIZE_MAX) { - biffAddf(NRRD, - "%s: actual max type size is %u != %u == NRRD_TYPE_SIZE_MAX", - me, AIR_CAST(unsigned int, maxsize), NRRD_TYPE_SIZE_MAX); + biffAddf(NRRD, "%s: actual max type size is %u != %u == NRRD_TYPE_SIZE_MAX", me, + AIR_UINT(maxsize), NRRD_TYPE_SIZE_MAX); return 0; } /* check on NRRD_TYPE_BIGGEST */ if (maxsize != sizeof(NRRD_TYPE_BIGGEST)) { - biffAddf(NRRD, "%s: actual max type size is %u != " + biffAddf(NRRD, + "%s: actual max type size is %u != " "%u == sizeof(NRRD_TYPE_BIGGEST)", - me, AIR_CAST(unsigned int, maxsize), - AIR_CAST(unsigned int, sizeof(NRRD_TYPE_BIGGEST))); + me, AIR_UINT(maxsize), AIR_UINT(sizeof(NRRD_TYPE_BIGGEST))); return 0; } @@ -1460,24 +1609,21 @@ nrrdSanity(void) { which we do via indirect (perhaps needlessly so) means. (h/t Sean McBride for pointing this out) */ tmpLLI = _nrrdLLongMaxHelp(_nrrdLLongMaxHelp(_NRRD_LLONG_MAX_HELP)); - if (!( tmpLLI > 0 && NRRD_LLONG_MAX == tmpLLI )) { - biffAddf(NRRD, "%s: long long int can't hold NRRD_LLONG_MAX (" - AIR_LLONG_FMT ")", me, + if (!(tmpLLI > 0 && NRRD_LLONG_MAX == tmpLLI)) { + biffAddf(NRRD, "%s: long long int can't hold NRRD_LLONG_MAX (" AIR_LLONG_FMT ")", me, NRRD_LLONG_MAX); return 0; } tmpLLI = _nrrdLLongMinHelp(_nrrdLLongMinHelp(_NRRD_LLONG_MIN_HELP)); - if (!( tmpLLI < 0 && NRRD_LLONG_MIN == tmpLLI )) { - biffAddf(NRRD, "%s: long long int can't hold NRRD_LLONG_MIN (" - AIR_LLONG_FMT ")", me, + if (!(tmpLLI < 0 && NRRD_LLONG_MIN == tmpLLI)) { + biffAddf(NRRD, "%s: long long int can't hold NRRD_LLONG_MIN (" AIR_LLONG_FMT ")", me, NRRD_LLONG_MIN); return 0; } tmpULLI = _nrrdULLongMaxHelp(NRRD_ULLONG_MAX); if (tmpULLI != 0) { - biffAddf(NRRD, - "%s: unsigned long long int max (" AIR_ULLONG_FMT - ") incorrect", me, NRRD_ULLONG_MAX); + biffAddf(NRRD, "%s: unsigned long long int max (" AIR_ULLONG_FMT ") incorrect", me, + NRRD_ULLONG_MAX); return 0; } @@ -1486,23 +1632,24 @@ nrrdSanity(void) { return 0; } - if (!( NRRD_DIM_MAX >= 3 )) { - biffAddf(NRRD, - "%s: NRRD_DIM_MAX == %u seems awfully small, doesn't it?", - me, NRRD_DIM_MAX); + if (!(NRRD_DIM_MAX >= 3)) { + biffAddf(NRRD, "%s: NRRD_DIM_MAX == %u seems awfully small, doesn't it?", me, + NRRD_DIM_MAX); return 0; } + /* this check was added in 2002 without explanation, but now (2023 pre v2 hacking) + it conflicts with a change that made that array entry 0; wackiness as yet unseen. if (!nrrdTypeIsIntegral[nrrdTypeBlock]) { biffAddf(NRRD, "%s: nrrdTypeInteger[nrrdTypeBlock] is not true, things " - "could get wacky", me); + "could get wacky", + me); return 0; - } + } */ /* HEY: any other assumptions built into Teem? */ - _nrrdSanity = 1; + /* _nrrdSanity = 1; (see above) */ return 1; } - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/string.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/string.c index dfed82dafbb..400631e2432 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/string.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/string.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -25,9 +25,11 @@ #include "NrrdIO.h" -/* this has to default to false in order for airStrtok to be a - functional substitute for strtok() */ -int airStrtokQuoting = AIR_FALSE; +/* removed for TeemV2: + * / * this has to default to false in order for airStrtok to be a + * functional substitute for strtok() * / + * int airStrtokQuoting = AIR_FALSE; + */ /* ******** airStrdup() @@ -41,9 +43,8 @@ airStrdup(const char *s) { if (!s) { ret = NULL; - } - else { - ret = (char *)malloc(strlen(s)+1); + } else { + ret = (char *)malloc(strlen(s) + 1); if (ret) { strcpy(ret, s); } @@ -62,8 +63,7 @@ airStrlen(const char *s) { if (!s) { ret = 0; - } - else { + } else { ret = strlen(s); } return ret; @@ -71,48 +71,30 @@ airStrlen(const char *s) { /* ******** airStrtok() -** -** thread-safe strtok() replacement. Use just like strtok(), but on -** each call to parse a given string, pass as the last argument the -** address of a char*, to be used for saving state while the string is -** traversed. Like strtok(), this will alter the "s" array passed to -** it on the first call, and like strtok(), this returns pointers into -** this string (rather than allocating new strings for each token). +* +* thread-safe strtok() replacement. Use just like strtok(), but on each call to parse a +* given string, pass as the last argument the address of a char*, to be used for saving +* state while the string is traversed. Like strtok(), this will alter the "s" array +* passed to it on the first call, and like strtok(), this returns pointers into this +* string (rather than allocating new strings for each token). +* +* NOTE: TeemV2 removed global airStrtokQuoting and the code in here that used it. */ char * airStrtok(char *s, const char *ct, char **last) { - char *h, *e, *q; + char *h, *e; if (!(ct && last)) { /* can't do any work, bail */ return NULL; } h = s ? s : *last; - if (!airStrlen(h)) - return NULL; + if (!airStrlen(h)) return NULL; h += strspn(h, ct); - if ('\"' == *h && airStrtokQuoting) { - /* something is trying to be quoted, and, we'll respect that */ - /* have to find the next un-escaped '\"' */ - h++; - q = h; - while (*q && !('\"' == *q && '\\' != q[-1])) { - q++; - } - if (*q) { - /* we found an unescaped '\"' */ - e = q; - } else { - /* give up; pretend we never tried to do this quoting stuff */ - e = h + strcspn(h, ct); - } - } else { - e = h + strcspn(h, ct); - } + e = h + strcspn(h, ct); if ('\0' == *e) { *last = e; - } - else { + } else { *e = '\0'; *last = e + 1; } @@ -127,7 +109,7 @@ airStrtok(char *s, const char *ct, char **last) { */ unsigned int airStrntok(const char *_s, const char *ct) { - char *s, *t, *l=NULL; + char *s, *t, *l = NULL; unsigned int n = 0; if (_s && ct) { @@ -137,7 +119,7 @@ airStrntok(const char *_s, const char *ct) { n++; t = airStrtok(NULL, ct, &l); } - airFree(s); /* no NULL assignment to s, else compile warnings */ + airFree(s); /* no NULL assignment to s, else compile warnings */ } return n; } @@ -148,7 +130,7 @@ airStrtrans(char *s, char from, char to) { if (s) { l = strlen(s); - for (i=0; i 1 AND src is a non-empy string */ - copyLen = AIR_MIN(dstSize-1, srcLen); - for (ii=0; ii= strlen(suff))) - return 0; + if (!(s && suff)) return 0; + if (!(strlen(s) >= strlen(suff))) return 0; if (!strncmp(s + strlen(s) - strlen(suff), suff, strlen(suff))) return 1; else @@ -216,28 +196,33 @@ airEndsWith(const char *s, const char *suff) { /* ******** airUnescape() ** -** unescapes \\ and \n in place in a given string. +** unescapes \\ and \n in place in a given string, which is the only form of +** escaping supported by key/value pairs in NRRD headers. ** Always returns the same pointer as given */ char * airUnescape(char *s) { size_t i, j, len; - int found=0; + int found = 0; len = airStrlen(s); - if (!len) - return s; - - for (i=1, j=0; i= 3 /* need room for a character and a Windows newline */ + if (!(size >= 3 /* need room for a character and a Windows newline */ && line && file)) { return 0; } /* c is always set at least once, but not so for any char in line[] */ - for (ii=0; - (ii <= size-2 /* room for line[ii] and \0 after that */ - && EOF != (cc=getc(file)) /* didn't hit EOF trying to read char */ - && cc != '\n' /* char isn't newline */ - && cc != '\r'); /* char isn't carriage return */ + for (ii = 0; (ii <= size - 2 /* room for line[ii] and \0 after that */ + && EOF != (cc = getc(file)) /* didn't hit EOF trying to read char */ + && cc != '\n' /* char isn't newline */ + && cc != '\r'); /* char isn't carriage return */ ++ii) { line[ii] = AIR_CAST(char, cc); } @@ -402,7 +387,7 @@ airOneLine(FILE *file, char *line, unsigned int size) { } } line[ii] = '\0'; - return ii+1; + return ii + 1; } else { /* for-loop terminated because we got to end of buffer (ii == size-1) */ cc = getc(file); @@ -415,19 +400,18 @@ airOneLine(FILE *file, char *line, unsigned int size) { ungetc(dd, file); } line[ii] = '\0'; - return ii+1; + return ii + 1; } else if ('\n' == cc) { line[ii] = '\0'; - return ii+1; + return ii + 1; } else { /* weren't about to get a line termination, we really did run out of buffer */ if (EOF != cc) { - ungetc(cc, file); /* we're allowed one ungetc on ANY stream */ + ungetc(cc, file); /* we're allowed one ungetc on ANY stream */ } - line[size-1] = '\0'; - return size+1; + line[size - 1] = '\0'; + return size + 1; } } } - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/subset.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/subset.c index 83e2474779d..0077b16386d 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/subset.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/subset.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -39,19 +39,17 @@ ** beginning it starts (offset), the length of the "on" part (length), ** the period (period), and the number of periods (numper). */ -int +int /* Biff: 1 */ nrrdSlice(Nrrd *nout, const Nrrd *cnin, unsigned int saxi, size_t pos) { - static const char me[]="nrrdSlice", func[]="slice"; - size_t - I, - rowLen, /* length of segment */ - colStep, /* distance between start of each segment */ - colLen, /* number of periods */ + static const char me[] = "nrrdSlice", func[] = "slice"; + size_t I, rowLen, /* length of segment */ + colStep, /* distance between start of each segment */ + colLen, /* number of periods */ szOut[NRRD_DIM_MAX]; unsigned int ai, outdim; int map[NRRD_DIM_MAX]; const char *src; - char *dest, stmp[2][AIR_STRLEN_SMALL]; + char *dest, stmp[2][AIR_STRLEN_SMALL + 1]; airArray *mop; Nrrd *nin; @@ -65,21 +63,20 @@ nrrdSlice(Nrrd *nout, const Nrrd *cnin, unsigned int saxi, size_t pos) { } if (1 == cnin->dim) { if (0 != saxi) { - biffAddf(NRRD, "%s: slice axis must be 0, not %u, for 1-D array", - me, saxi); + biffAddf(NRRD, "%s: slice axis must be 0, not %u, for 1-D array", me, saxi); return 1; } } else { - if (!( saxi < cnin->dim )) { - biffAddf(NRRD, "%s: slice axis %d out of bounds (0 to %d)", - me, saxi, cnin->dim-1); + if (!(saxi < cnin->dim)) { + biffAddf(NRRD, "%s: slice axis %d out of bounds (0 to %d)", me, saxi, + cnin->dim - 1); return 1; } } - if (!( pos < cnin->axis[saxi].size )) { + if (!(pos < cnin->axis[saxi].size)) { biffAddf(NRRD, "%s: position %s out of bounds (0 to %s)", me, airSprintSize_t(stmp[0], pos), - airSprintSize_t(stmp[1], cnin->axis[saxi].size-1)); + airSprintSize_t(stmp[1], cnin->axis[saxi].size - 1)); return 1; } /* this shouldn't actually be necessary .. */ @@ -100,7 +97,8 @@ nrrdSlice(Nrrd *nout, const Nrrd *cnin, unsigned int saxi, size_t pos) { airMopAdd(mop, nin, (airMopper)nrrdNuke, airMopAlways); if (nrrdAxesInsert(nin, cnin, 1)) { biffAddf(NRRD, "%s: trouble inserting axis on 1-D array", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } } else { nin = NULL; @@ -108,7 +106,7 @@ nrrdSlice(Nrrd *nout, const Nrrd *cnin, unsigned int saxi, size_t pos) { /* set up control variables */ rowLen = colLen = 1; - for (ai=0; ai<(nin ? nin : cnin)->dim; ai++) { + for (ai = 0; ai < (nin ? nin : cnin)->dim; ai++) { if (ai < saxi) { rowLen *= (nin ? nin : cnin)->axis[ai].size; } else if (ai > saxi) { @@ -116,24 +114,25 @@ nrrdSlice(Nrrd *nout, const Nrrd *cnin, unsigned int saxi, size_t pos) { } } rowLen *= nrrdElementSize(nin ? nin : cnin); - colStep = rowLen*(nin ? nin : cnin)->axis[saxi].size; + colStep = rowLen * (nin ? nin : cnin)->axis[saxi].size; - outdim = (nin ? nin : cnin)->dim-1; - for (ai=0; aidim - 1; + for (ai = 0; ai < outdim; ai++) { map[ai] = AIR_INT(ai) + (ai >= saxi); szOut[ai] = (nin ? nin : cnin)->axis[map[ai]].size; } nout->blockSize = (nin ? nin : cnin)->blockSize; if (nrrdMaybeAlloc_nva(nout, (nin ? nin : cnin)->type, outdim, szOut)) { biffAddf(NRRD, "%s: failed to create slice", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } /* the skinny */ src = AIR_CAST(const char *, (nin ? nin : cnin)->data); dest = AIR_CAST(char *, nout->data); - src += rowLen*pos; - for (I=0; Iaxis[saxi].spaceDirection[0])) { - nrrdSpaceVecScaleAdd2(nout->spaceOrigin, - 1.0, (nin ? nin : cnin)->spaceOrigin, + nrrdSpaceVecScaleAdd2(nout->spaceOrigin, 1.0, (nin ? nin : cnin)->spaceOrigin, AIR_CAST(double, pos), (nin ? nin : cnin)->axis[saxi].spaceDirection); } else { @@ -185,21 +184,19 @@ nrrdSlice(Nrrd *nout, const Nrrd *cnin, unsigned int saxi, size_t pos) { ** nrrd with the same dimensions, but with equal or smaller sizes ** along each axis. */ -int +int /* Biff: 1 */ nrrdCrop(Nrrd *nout, const Nrrd *nin, size_t *min, size_t *max) { - static const char me[]="nrrdCrop", func[] = "crop"; - char buff1[NRRD_DIM_MAX*30], buff2[AIR_STRLEN_SMALL]; + static const char me[] = "nrrdCrop", func[] = "crop"; + char buff1[NRRD_DIM_MAX * 30], buff2[AIR_STRLEN_SMALL + 1]; unsigned int ai; - size_t I, - lineSize, /* #bytes in one scanline to be copied */ - typeSize, /* size of data type */ - cIn[NRRD_DIM_MAX], /* coords for line start, in input */ - cOut[NRRD_DIM_MAX], /* coords for line start, in output */ - szIn[NRRD_DIM_MAX], - szOut[NRRD_DIM_MAX], - idxIn, idxOut, /* linear indices for input and output */ - numLines; /* number of scanlines in output nrrd */ - char *dataIn, *dataOut, stmp[3][AIR_STRLEN_SMALL]; + size_t I, lineSize, /* #bytes in one scanline to be copied */ + typeSize, /* size of data type */ + cIn[NRRD_DIM_MAX], /* coords for line start, in input */ + cOut[NRRD_DIM_MAX], /* coords for line start, in output */ + szIn[NRRD_DIM_MAX], szOut[NRRD_DIM_MAX], idxIn, + idxOut, /* linear indices for input and output */ + numLines; /* number of scanlines in output nrrd */ + char *dataIn, *dataOut, stmp[3][AIR_STRLEN_SMALL + 1]; /* errors */ if (!(nout && nin && min && max)) { @@ -210,18 +207,16 @@ nrrdCrop(Nrrd *nout, const Nrrd *nin, size_t *min, size_t *max) { biffAddf(NRRD, "%s: nout==nin disallowed", me); return 1; } - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nin->dim; ai++) { if (!(min[ai] <= max[ai])) { biffAddf(NRRD, "%s: axis %d min (%s) not <= max (%s)", me, ai, - airSprintSize_t(stmp[0], min[ai]), - airSprintSize_t(stmp[1], max[ai])); + airSprintSize_t(stmp[0], min[ai]), airSprintSize_t(stmp[1], max[ai])); return 1; } - if (!( min[ai] < nin->axis[ai].size && max[ai] < nin->axis[ai].size )) { - biffAddf(NRRD, "%s: axis %d min (%s) or max (%s) out of bounds [0,%s]", - me, ai, airSprintSize_t(stmp[0], min[ai]), - airSprintSize_t(stmp[1], max[ai]), - airSprintSize_t(stmp[2], nin->axis[ai].size-1)); + if (!(min[ai] < nin->axis[ai].size && max[ai] < nin->axis[ai].size)) { + biffAddf(NRRD, "%s: axis %d min (%s) or max (%s) out of bounds [0,%s]", me, ai, + airSprintSize_t(stmp[0], min[ai]), airSprintSize_t(stmp[1], max[ai]), + airSprintSize_t(stmp[2], nin->axis[ai].size - 1)); return 1; } } @@ -234,7 +229,7 @@ nrrdCrop(Nrrd *nout, const Nrrd *nin, size_t *min, size_t *max) { /* allocate */ nrrdAxisInfoGet_nva(nin, nrrdAxisInfoSize, szIn); numLines = 1; - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nin->dim; ai++) { szOut[ai] = max[ai] - min[ai] + 1; if (ai) { numLines *= szOut[ai]; @@ -245,13 +240,13 @@ nrrdCrop(Nrrd *nout, const Nrrd *nin, size_t *min, size_t *max) { biffAddf(NRRD, "%s:", me); return 1; } - lineSize = szOut[0]*nrrdElementSize(nin); + lineSize = szOut[0] * nrrdElementSize(nin); /* the skinny */ typeSize = nrrdElementSize(nin); dataIn = (char *)nin->data; dataOut = (char *)nout->data; - memset(cOut, 0, NRRD_DIM_MAX*sizeof(*cOut)); + memset(cOut, 0, NRRD_DIM_MAX * sizeof(*cOut)); /* printf("!%s: nin->dim = %d\n", me, nin->dim); printf("!%s: min = %d %d %d\n", me, min[0], min[1], min[2]); @@ -261,8 +256,8 @@ nrrdCrop(Nrrd *nout, const Nrrd *nin, size_t *min, size_t *max) { printf("!%s: typeSize = %d\n", me, typeSize); printf("!%s: numLines = %d\n", me, (int)numLines); */ - for (I=0; Idim; ai++) { + for (I = 0; I < numLines; I++) { + for (ai = 0; ai < nin->dim; ai++) { cIn[ai] = cOut[ai] + min[ai]; } NRRD_INDEX_GEN(idxOut, cOut, szOut, nin->dim); @@ -273,21 +268,20 @@ nrrdCrop(Nrrd *nout, const Nrrd *nin, size_t *min, size_t *max) { printf("!%s: %5d: cIn=(%3d,%3d,%3d) --> idxIn = %5d\n", me, (int)I, cIn[0], cIn[1], cIn[2], (int)idxIn); */ - memcpy(dataOut + idxOut*typeSize, dataIn + idxIn*typeSize, lineSize); + memcpy(dataOut + idxOut * typeSize, dataIn + idxIn * typeSize, lineSize); /* the lowest coordinate in cOut[] will stay zero, since we are copying one (1-D) scanline at a time */ NRRD_COORD_INCR(cOut, szOut, nin->dim, 1); } - if (nrrdAxisInfoCopy(nout, nin, NULL, (NRRD_AXIS_INFO_SIZE_BIT | - NRRD_AXIS_INFO_MIN_BIT | - NRRD_AXIS_INFO_MAX_BIT ))) { + if (nrrdAxisInfoCopy(nout, nin, NULL, + (NRRD_AXIS_INFO_SIZE_BIT | NRRD_AXIS_INFO_MIN_BIT + | NRRD_AXIS_INFO_MAX_BIT))) { biffAddf(NRRD, "%s:", me); return 1; } - for (ai=0; aidim; ai++) { - nrrdAxisInfoPosRange(&(nout->axis[ai].min), &(nout->axis[ai].max), - nin, ai, AIR_CAST(double, min[ai]), - AIR_CAST(double, max[ai])); + for (ai = 0; ai < nin->dim; ai++) { + nrrdAxisInfoPosRange(&(nout->axis[ai].min), &(nout->axis[ai].max), nin, ai, + AIR_CAST(double, min[ai]), AIR_CAST(double, max[ai])); /* do the safe thing first */ nout->axis[ai].kind = _nrrdKindAltered(nin->axis[ai].kind, AIR_FALSE); /* try cleverness */ @@ -295,43 +289,35 @@ nrrdCrop(Nrrd *nout, const Nrrd *nin, size_t *min, size_t *max) { if (nout->axis[ai].size == nin->axis[ai].size) { /* we can safely copy kind; the samples didn't change */ nout->axis[ai].kind = nin->axis[ai].kind; - } else if (nrrdKind4Color == nin->axis[ai].kind - && 3 == szOut[ai]) { + } else if (nrrdKind4Color == nin->axis[ai].kind && 3 == szOut[ai]) { nout->axis[ai].kind = nrrdKind3Color; - } else if (nrrdKind4Vector == nin->axis[ai].kind - && 3 == szOut[ai]) { + } else if (nrrdKind4Vector == nin->axis[ai].kind && 3 == szOut[ai]) { nout->axis[ai].kind = nrrdKind3Vector; } else if ((nrrdKind4Vector == nin->axis[ai].kind || nrrdKind3Vector == nin->axis[ai].kind) && 2 == szOut[ai]) { nout->axis[ai].kind = nrrdKind2Vector; - } else if (nrrdKindRGBAColor == nin->axis[ai].kind - && 0 == min[ai] + } else if (nrrdKindRGBAColor == nin->axis[ai].kind && 0 == min[ai] && 2 == max[ai]) { nout->axis[ai].kind = nrrdKindRGBColor; - } else if (nrrdKind2DMaskedSymMatrix == nin->axis[ai].kind - && 1 == min[ai] - && max[ai] == szIn[ai]-1) { + } else if (nrrdKind2DMaskedSymMatrix == nin->axis[ai].kind && 1 == min[ai] + && max[ai] == szIn[ai] - 1) { nout->axis[ai].kind = nrrdKind2DSymMatrix; - } else if (nrrdKind2DMaskedMatrix == nin->axis[ai].kind - && 1 == min[ai] - && max[ai] == szIn[ai]-1) { + } else if (nrrdKind2DMaskedMatrix == nin->axis[ai].kind && 1 == min[ai] + && max[ai] == szIn[ai] - 1) { nout->axis[ai].kind = nrrdKind2DMatrix; - } else if (nrrdKind3DMaskedSymMatrix == nin->axis[ai].kind - && 1 == min[ai] - && max[ai] == szIn[ai]-1) { + } else if (nrrdKind3DMaskedSymMatrix == nin->axis[ai].kind && 1 == min[ai] + && max[ai] == szIn[ai] - 1) { nout->axis[ai].kind = nrrdKind3DSymMatrix; - } else if (nrrdKind3DMaskedMatrix == nin->axis[ai].kind - && 1 == min[ai] - && max[ai] == szIn[ai]-1) { + } else if (nrrdKind3DMaskedMatrix == nin->axis[ai].kind && 1 == min[ai] + && max[ai] == szIn[ai] - 1) { nout->axis[ai].kind = nrrdKind3DMatrix; } } } strcpy(buff1, ""); - for (ai=0; aidim; ai++) { - sprintf(buff2, "%s[%s,%s]", (ai ? "x" : ""), - airSprintSize_t(stmp[0], min[ai]), + for (ai = 0; ai < nin->dim; ai++) { + sprintf(buff2, "%s[%s,%s]", (ai ? "x" : ""), airSprintSize_t(stmp[0], min[ai]), airSprintSize_t(stmp[1], max[ai])); strcat(buff1, buff2); } @@ -340,31 +326,25 @@ nrrdCrop(Nrrd *nout, const Nrrd *nin, size_t *min, size_t *max) { return 1; } if (nrrdBasicInfoCopy(nout, nin, - NRRD_BASIC_INFO_DATA_BIT - | NRRD_BASIC_INFO_TYPE_BIT - | NRRD_BASIC_INFO_BLOCKSIZE_BIT - | NRRD_BASIC_INFO_DIMENSION_BIT - | NRRD_BASIC_INFO_SPACEORIGIN_BIT - | NRRD_BASIC_INFO_CONTENT_BIT - | NRRD_BASIC_INFO_COMMENTS_BIT - | (nrrdStateKeyValuePairsPropagate - ? 0 - : NRRD_BASIC_INFO_KEYVALUEPAIRS_BIT))) { + NRRD_BASIC_INFO_DATA_BIT /* */ + | NRRD_BASIC_INFO_TYPE_BIT | NRRD_BASIC_INFO_BLOCKSIZE_BIT + | NRRD_BASIC_INFO_DIMENSION_BIT + | NRRD_BASIC_INFO_SPACEORIGIN_BIT | NRRD_BASIC_INFO_CONTENT_BIT + | NRRD_BASIC_INFO_COMMENTS_BIT + | (nrrdStateKeyValuePairsPropagate + ? 0 + : NRRD_BASIC_INFO_KEYVALUEPAIRS_BIT))) { biffAddf(NRRD, "%s:", me); return 1; } /* copy origin, then shift it along the spatial axes */ nrrdSpaceVecCopy(nout->spaceOrigin, nin->spaceOrigin); - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nin->dim; ai++) { if (AIR_EXISTS(nin->axis[ai].spaceDirection[0])) { - nrrdSpaceVecScaleAdd2(nout->spaceOrigin, - 1.0, nout->spaceOrigin, - AIR_CAST(double, min[ai]), - nin->axis[ai].spaceDirection); + nrrdSpaceVecScaleAdd2(nout->spaceOrigin, 1.0, nout->spaceOrigin, + AIR_CAST(double, min[ai]), nin->axis[ai].spaceDirection); } } - return 0; } - diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/tail.pl b/Modules/ThirdParty/NrrdIO/src/NrrdIO/tail.pl deleted file mode 100644 index 21f69c931eb..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/tail.pl +++ /dev/null @@ -1,36 +0,0 @@ -# -# NrrdIO: stand-alone code for basic nrrd functionality -# Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago -# Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann -# Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah -# -# This software is provided 'as-is', without any express or implied -# warranty. In no event will the authors be held liable for any -# damages arising from the use of this software. -# -# Permission is granted to anyone to use this software for any -# purpose, including commercial applications, and to alter it and -# redistribute it freely, subject to the following restrictions: -# -# 1. The origin of this software must not be misrepresented; you must -# not claim that you wrote the original software. If you use this -# software in a product, an acknowledgment in the product -# documentation would be appreciated but is not required. -# -# 2. Altered source versions must be plainly marked as such, and must -# not be misrepresented as being the original software. -# -# 3. This notice may not be removed or altered from any source distribution. -# - -# -# This simply removes the lines up to and including a line -# containing nothing but "*/", which is presumably the end -# of the comment block at the top of a Teem .c or .h file -# - -$printing = 0; -while (<>) { - print if $printing; - $printing = 1 if (m/^\*\//); -} diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/teemDio.h b/Modules/ThirdParty/NrrdIO/src/NrrdIO/teemDio.h deleted file mode 100644 index af37dff603e..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/teemDio.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. -*/ - - -/* -** the end result of this is that the source file which includes -** this can be sure that TEEM_DIO is set, and can be sure that -** it is set to either 0 or 1 -*/ - -#ifndef TEEM_DIO -# error TEEM_DIO not defined -#elif TEEM_DIO == 1 -# /* okay, its 1 */ -#elif TEEM_DIO == 0 -# /* okay, its 0 */ -#else -# error TEEM_DIO not set to 1 or 0 -#endif diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/teemPng.h b/Modules/ThirdParty/NrrdIO/src/NrrdIO/teemPng.h deleted file mode 100644 index fb9368bbd5c..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/teemPng.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. -*/ - - -/* -** the end result of this is that the source file which includes -** this can be sure that TEEM_ZLIB is set, so that the required -** compression library is always built in when PNG support is requested -*/ - -#ifdef TEEM_PNG -# ifndef TEEM_ZLIB -# error TEEM_PNG set, but TEEM_ZLIB not set -# endif -#endif - -#if TEEM_PNG && TEEM_VTK_MANGLE -#include "vtk_png_mangle.h" -#endif diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/teemQnanhibit.h b/Modules/ThirdParty/NrrdIO/src/NrrdIO/teemQnanhibit.h deleted file mode 100644 index 1f7910649b4..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/teemQnanhibit.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. -*/ - - -/* -** the end result of this is that the source file which includes -** this can be sure that TEEM_QNANHIBIT is set, and can be sure that -** it is set to either 0 or 1 -*/ - -#ifndef TEEM_QNANHIBIT -# error TEEM_QNANHIBIT not defined -#elif TEEM_QNANHIBIT == 1 -# /* okay, its 1 */ -#elif TEEM_QNANHIBIT == 0 -# /* okay, its 0 */ -#else -# error TEEM_QNANHIBIT not set to 0 or 1 -#endif diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/unteem.pl b/Modules/ThirdParty/NrrdIO/src/NrrdIO/unteem.pl deleted file mode 100644 index 277fdbcaba4..00000000000 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/unteem.pl +++ /dev/null @@ -1,69 +0,0 @@ -# -# NrrdIO: stand-alone code for basic nrrd functionality -# Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago -# Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann -# Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah -# -# This software is provided 'as-is', without any express or implied -# warranty. In no event will the authors be held liable for any -# damages arising from the use of this software. -# -# Permission is granted to anyone to use this software for any -# purpose, including commercial applications, and to alter it and -# redistribute it freely, subject to the following restrictions: -# -# 1. The origin of this software must not be misrepresented; you must -# not claim that you wrote the original software. If you use this -# software in a product, an acknowledgment in the product -# documentation would be appreciated but is not required. -# -# 2. Altered source versions must be plainly marked as such, and must -# not be misrepresented as being the original software. -# -# 3. This notice may not be removed or altered from any source distribution. -# - -# -# This helps in converting teem source files into NrrdIO source files, -# by changing the way #includes are done, and by excluding the lines -# delimited by "BEGIN non-NrrdIO" and "END non-NrrdIO", as well as doing -# some other hacks -# - -if (exists $ENV{"ITK_NRRDIO"}) { - $ITK = 1; -} else { - $ITK = 0; -} - -$printing = 1; -while (<>) { - $printing = 0 if (m/BEGIN non-NrrdIO/); - s|#include "air.h"|#include "NrrdIO.h"|g; - s|#include "biff.h"|#include "NrrdIO.h"|g; - s|#include "nrrd.h"|#include "NrrdIO.h"|g; - s|#include |#include "teem$1"|g; - if ($ITK) { - s|\/\* NrrdIO-hack-000 \*\/|\/\* THE FOLLOWING INCLUDE IS ONLY FOR THE ITK DISTRIBUTION.\n This header mangles the symbols in the NrrdIO library, preventing\n conflicts in applications linked against two versions of NrrdIO. \*\/\n#include "itk_NrrdIO_mangle.h"|g; - } else { - s|\/\* NrrdIO-hack-000 \*\/||g; - } - if ($ITK) { - s|\/\* NrrdIO-hack-001 \*\/|#cmakedefine TEEM_STATIC|g; - } else { - s|\/\* NrrdIO-hack-001 \*\/||g; - } - s|.* \/\* NrrdIO-hack-002 \*\/|#if 1|g; - s|.* \/\* NrrdIO-hack-003 \*\/|int nrrdStateVerboseIO = 0;|g; - if ($ITK) { - s|.* \/\* NrrdIO-hack-004 \*\/|#include "itk_zlib.h"|g; - } else { - s|.* \/\* NrrdIO-hack-004 \*\/|#include |g; - } - s|AIR_EXPORT|NRRDIO_EXPORT|g; - s|BIFF_EXPORT|NRRDIO_EXPORT|g; - s|NRRD_EXPORT|NRRDIO_EXPORT|g; - - print if $printing; - $printing = 1 if (m/END non-NrrdIO/); -} diff --git a/Modules/ThirdParty/NrrdIO/src/NrrdIO/write.c b/Modules/ThirdParty/NrrdIO/src/NrrdIO/write.c index 247eaf8232f..d9a6687a258 100644 --- a/Modules/ThirdParty/NrrdIO/src/NrrdIO/write.c +++ b/Modules/ThirdParty/NrrdIO/src/NrrdIO/write.c @@ -1,8 +1,8 @@ /* - NrrdIO: stand-alone code for basic nrrd functionality - Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago - Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann - Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah + NrrdIO: C library for NRRD file IO (with optional compressions) + Copyright (C) 2009--2025 University of Chicago + Copyright (C) 2005--2008 Gordon Kindlmann + Copyright (C) 1998--2004 University of Utah This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -26,22 +26,17 @@ #include "NrrdIO.h" #include "privateNrrd.h" -/* - #include - #include -*/ - -int +int /* Biff: 1 */ nrrdIoStateSet(NrrdIoState *nio, int parm, int value) { - static const char me[]="nrrdIoStateSet"; + static const char me[] = "nrrdIoStateSet"; if (!nio) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } - if (!( AIR_IN_OP(nrrdIoStateUnknown, parm, nrrdIoStateLast) )) { - biffAddf(NRRD, "%s: identifier %d not in valid range [%d,%d]", me, - parm, nrrdIoStateUnknown+1, nrrdIoStateLast-1); + if (!(AIR_IN_OP(nrrdIoStateUnknown, parm, nrrdIoStateLast))) { + biffAddf(NRRD, "%s: identifier %d not in valid range [%d,%d]", me, parm, + nrrdIoStateUnknown + 1, nrrdIoStateLast - 1); return 1; } switch (parm) { @@ -51,13 +46,16 @@ nrrdIoStateSet(NrrdIoState *nio, int parm, int value) { case nrrdIoStateBareText: nio->bareText = !!value; break; + case nrrdIoStateMoreThanFloatInText: + nio->moreThanFloatInText = !!value; + break; case nrrdIoStateCharsPerLine: if (value < 40) { biffAddf(NRRD, "%s: %d charsPerLine is awfully small", me, value); return 1; } /* cast won't lose info because "value" must be positive */ - nio->charsPerLine = AIR_CAST(unsigned int, value); + nio->charsPerLine = AIR_UINT(value); break; case nrrdIoStateValsPerLine: if (value < 4) { @@ -65,7 +63,7 @@ nrrdIoStateSet(NrrdIoState *nio, int parm, int value) { return 1; } /* cast won't lose info because "value" must be positive */ - nio->valsPerLine = AIR_CAST(unsigned int, value); + nio->valsPerLine = AIR_UINT(value); break; case nrrdIoStateSkipData: nio->skipData = !!value; @@ -74,21 +72,21 @@ nrrdIoStateSet(NrrdIoState *nio, int parm, int value) { nio->keepNrrdDataFileOpen = !!value; break; case nrrdIoStateZlibLevel: - if (!( AIR_IN_CL(-1, value, 9) )) { + if (!(AIR_IN_CL(-1, value, 9))) { biffAddf(NRRD, "%s: zlibLevel %d invalid", me, value); return 1; } nio->zlibLevel = value; break; case nrrdIoStateZlibStrategy: - if (!( AIR_IN_OP(nrrdZlibStrategyUnknown, value, nrrdZlibStrategyLast) )) { + if (!(AIR_IN_OP(nrrdZlibStrategyUnknown, value, nrrdZlibStrategyLast))) { biffAddf(NRRD, "%s: zlibStrategy %d invalid", me, value); return 1; } nio->zlibStrategy = value; break; case nrrdIoStateBzip2BlockSize: - if (!( AIR_IN_CL(-1, value, 9) )) { + if (!(AIR_IN_CL(-1, value, 9))) { biffAddf(NRRD, "%s: bzip2BlockSize %d invalid", me, value); return 1; } @@ -101,11 +99,11 @@ nrrdIoStateSet(NrrdIoState *nio, int parm, int value) { return 0; } -int +int /* Biff: 1 */ nrrdIoStateEncodingSet(NrrdIoState *nio, const NrrdEncoding *encoding) { - static const char me[]="nrrdIoStateEncodingSet"; + static const char me[] = "nrrdIoStateEncodingSet"; - if (!( nio && encoding )) { + if (!(nio && encoding)) { if (nio) { nio->encoding = nrrdEncodingUnknown; } @@ -114,19 +112,18 @@ nrrdIoStateEncodingSet(NrrdIoState *nio, const NrrdEncoding *encoding) { } if (!encoding->available()) { nio->encoding = nrrdEncodingUnknown; - biffAddf(NRRD, "%s: %s encoding isn't actually available", me, - encoding->name); + biffAddf(NRRD, "%s: %s encoding isn't actually available", me, encoding->name); return 1; } nio->encoding = encoding; return 0; } -int +int /* Biff: 1 */ nrrdIoStateFormatSet(NrrdIoState *nio, const NrrdFormat *format) { - static const char me[]="nrrdIoStateFormatSet"; + static const char me[] = "nrrdIoStateFormatSet"; - if (!( nio && format )) { + if (!(nio && format)) { if (nio) { nio->format = nrrdFormatUnknown; } @@ -135,8 +132,7 @@ nrrdIoStateFormatSet(NrrdIoState *nio, const NrrdFormat *format) { } if (!format->available()) { nio->format = nrrdFormatUnknown; - biffAddf(NRRD, "%s: %s format isn't actually available", me, - format->name); + biffAddf(NRRD, "%s: %s format isn't actually available", me, format->name); return 1; } nio->format = format; @@ -146,16 +142,16 @@ nrrdIoStateFormatSet(NrrdIoState *nio, const NrrdFormat *format) { /* ** no biff */ -int +int /* Biff: nope */ nrrdIoStateGet(NrrdIoState *nio, int parm) { - static const char me[]="nrrdIoStateGet"; + static const char me[] = "nrrdIoStateGet"; int value; if (!nio) { /* got NULL pointer */ return -1; } - if (!( AIR_IN_OP(nrrdIoStateUnknown, parm, nrrdIoStateLast) )) { + if (!(AIR_IN_OP(nrrdIoStateUnknown, parm, nrrdIoStateLast))) { /* got bogus parameter identifier */ return -1; } @@ -166,13 +162,16 @@ nrrdIoStateGet(NrrdIoState *nio, int parm) { case nrrdIoStateBareText: value = !!nio->bareText; break; + case nrrdIoStateMoreThanFloatInText: + value = !!nio->moreThanFloatInText; + break; case nrrdIoStateCharsPerLine: /* HEY: this cast is a bad because nio->charsPerLine is unsigned */ - value = AIR_CAST(int, nio->charsPerLine); + value = AIR_INT(nio->charsPerLine); break; case nrrdIoStateValsPerLine: /* HEY: this cast is a bad because nio->valsPerLine is unsigned */ - value = AIR_CAST(int, nio->valsPerLine); + value = AIR_INT(nio->valsPerLine); break; case nrrdIoStateSkipData: value = !!nio->skipData; @@ -199,7 +198,7 @@ nrrdIoStateGet(NrrdIoState *nio, int parm) { /* ** no biff */ -const NrrdEncoding * +const NrrdEncoding * /* Biff: nope */ nrrdIoStateEncodingGet(NrrdIoState *nio) { return nio ? nio->encoding : nrrdEncodingUnknown; @@ -208,25 +207,25 @@ nrrdIoStateEncodingGet(NrrdIoState *nio) { /* ** no biff */ -const NrrdFormat * +const NrrdFormat * /* Biff: nope */ nrrdIoStateFormatGet(NrrdIoState *nio) { return nio ? nio->format : nrrdFormatUnknown; } -void +static void _nrrdStrcatSpaceVector(char *str, unsigned int spaceDim, const double val[NRRD_SPACE_DIM_MAX]) { - char buff[AIR_STRLEN_MED]; /* bad Gordon */ + char buff[AIR_STRLEN_MED + 1]; /* bad Gordon */ unsigned int dd; if (AIR_EXISTS(val[0])) { strcat(str, "("); - for (dd=0; dddim, NRRD_DIM_MAX) - && nio - && nio->encoding - && AIR_IN_OP(nrrdField_unknown, field, nrrdField_last) )) { + if (!(nrrd && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) && nio && nio->encoding + && AIR_IN_OP(nrrdField_unknown, field, nrrdField_last))) { return 0; } @@ -288,22 +284,22 @@ _nrrdFieldInteresting(const Nrrd *nrrd, NrrdIoState *nio, int field) { ret = 1; break; case nrrdField_spacings: - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { ret |= AIR_EXISTS(nrrd->axis[ai].spacing); } break; case nrrdField_thicknesses: - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { ret |= AIR_EXISTS(nrrd->axis[ai].thickness); } break; case nrrdField_axis_mins: - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { ret |= AIR_EXISTS(nrrd->axis[ai].min); } break; case nrrdField_axis_maxs: - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { ret |= AIR_EXISTS(nrrd->axis[ai].max); } break; @@ -311,22 +307,22 @@ _nrrdFieldInteresting(const Nrrd *nrrd, NrrdIoState *nio, int field) { ret = nrrd->spaceDim > 0; break; case nrrdField_centers: - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { ret |= (nrrdCenterUnknown != nrrd->axis[ai].center); } break; case nrrdField_kinds: - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { ret |= (nrrdKindUnknown != nrrd->axis[ai].kind); } break; case nrrdField_labels: - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { ret |= !!(airStrlen(nrrd->axis[ai].label)); } break; case nrrdField_units: - for (ai=0; aidim; ai++) { + for (ai = 0; ai < nrrd->dim; ai++) { ret |= !!(airStrlen(nrrd->axis[ai].units)); } break; @@ -362,27 +358,23 @@ _nrrdFieldInteresting(const Nrrd *nrrd, NrrdIoState *nio, int field) { ret = !!airStrlen(nrrd->sampleUnits); break; case nrrdField_space_units: - for (ai=0; aispaceDim; ai++) { + for (ai = 0; ai < nrrd->spaceDim; ai++) { ret |= !!(airStrlen(nrrd->spaceUnits[ai])); } break; case nrrdField_space_origin: /* we're trusting other validity checks to ensure that all the coeffs exist or not, together */ - ret = (nrrd->spaceDim > 0 - && AIR_EXISTS(nrrd->spaceOrigin[0])); + ret = (nrrd->spaceDim > 0 && AIR_EXISTS(nrrd->spaceOrigin[0])); break; case nrrdField_measurement_frame: /* we're trusting other validity checks to ensure that all the coeffs exist or not, together */ - ret = (nrrd->spaceDim > 0 - && AIR_EXISTS(nrrd->measurementFrame[0][0])); + ret = (nrrd->spaceDim > 0 && AIR_EXISTS(nrrd->measurementFrame[0][0])); break; case nrrdField_data_file: /* detached header was either requested or is required */ - ret = (nio->detachedHeader - || nio->dataFNFormat - || nio->dataFNArr->len > 1); + ret = (nio->detachedHeader || nio->dataFNFormat || nio->dataFNArr->len > 1); break; } @@ -405,24 +397,18 @@ _nrrdFieldInteresting(const Nrrd *nrrd, NrrdIoState *nio, int field) { ** in formatNRRD.c */ void -_nrrdSprintFieldInfo(char **strP, const char *prefix, - const Nrrd *nrrd, NrrdIoState *nio, int field) { - static const char me[]="_nrrdSprintFieldInfo"; - char buff[AIR_STRLEN_MED], *fnb, stmp[AIR_STRLEN_SMALL], - *strtmp=NULL; +_nrrdSprintFieldInfo(char **strP, const char *prefix, const Nrrd *nrrd, NrrdIoState *nio, + int field, int dropAxis0) { + static const char me[] = "_nrrdSprintFieldInfo"; + char buff[AIR_STRLEN_MED + 1], *fnb, stmp[AIR_STRLEN_SMALL + 1], *strtmp = NULL; double colvec[NRRD_SPACE_DIM_MAX]; const char *fs; - unsigned int ii, dd, - uintStrlen = 11, - size_tStrlen = 33, - doubleStrlen = 513; + unsigned int ii, dd, uintStrlen = 11, size_tStrlen = 33, doubleStrlen = 513; size_t fslen, fdlen, maxl; int endi; - if (!( strP && prefix - && nrrd - && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) - && AIR_IN_OP(nrrdField_unknown, field, nrrdField_last) )) { + if (!(strP && prefix && nrrd && AIR_IN_CL(1, nrrd->dim, NRRD_DIM_MAX) + && AIR_IN_OP(nrrdField_unknown, field, nrrdField_last))) { return; } /* As of Sun Dec 2 01:57:48 CST 2012 (revision 5832) the only @@ -453,7 +439,8 @@ _nrrdSprintFieldInfo(char **strP, const char *prefix, strtmp = airOneLinify(airStrdup(nrrd->content)); *strP = AIR_CALLOC(fslen + strlen(strtmp), char); sprintf(*strP, "%s%s: %s", prefix, fs, strtmp); - airFree(strtmp); strtmp = NULL; + airFree(strtmp); + strtmp = NULL; break; case nrrdField_number: *strP = AIR_CALLOC(fslen + size_tStrlen, char); @@ -466,16 +453,14 @@ _nrrdSprintFieldInfo(char **strP, const char *prefix, break; case nrrdField_block_size: *strP = AIR_CALLOC(fslen + size_tStrlen, char); - sprintf(*strP, "%s%s: %s", prefix, fs, - airSprintSize_t(stmp, nrrd->blockSize)); + sprintf(*strP, "%s%s: %s", prefix, fs, airSprintSize_t(stmp, nrrd->blockSize)); break; case nrrdField_dimension: *strP = AIR_CALLOC(fslen + uintStrlen, char); sprintf(*strP, "%s%s: %d", prefix, fs, nrrd->dim); break; case nrrdField_space: - *strP = AIR_CALLOC(fslen - + strlen(airEnumStr(nrrdSpace, nrrd->space)), char); + *strP = AIR_CALLOC(fslen + strlen(airEnumStr(nrrdSpace, nrrd->space)), char); sprintf(*strP, "%s%s: %s", prefix, fs, airEnumStr(nrrdSpace, nrrd->space)); break; case nrrdField_space_dimension: @@ -484,111 +469,108 @@ _nrrdSprintFieldInfo(char **strP, const char *prefix, break; /* ---- begin per-axis fields ---- */ case nrrdField_sizes: - *strP = AIR_CALLOC(fslen + nrrd->dim*(size_tStrlen + 1), char); + *strP = AIR_CALLOC(fslen + nrrd->dim * (size_tStrlen + 1), char); sprintf(*strP, "%s%s:", prefix, fs); - for (ii=0; iidim; ii++) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { sprintf(buff, " %s", airSprintSize_t(stmp, nrrd->axis[ii].size)); strcat(*strP, buff); } break; case nrrdField_spacings: - *strP = AIR_CALLOC(fslen + nrrd->dim*(doubleStrlen + 1), char); + *strP = AIR_CALLOC(fslen + nrrd->dim * (doubleStrlen + 1), char); sprintf(*strP, "%s%s:", prefix, fs); - for (ii=0; iidim; ii++) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { airSinglePrintf(NULL, buff, " %.17g", nrrd->axis[ii].spacing); strcat(*strP, buff); } break; case nrrdField_thicknesses: - *strP = AIR_CALLOC(fslen + nrrd->dim*(doubleStrlen + 1), char); + *strP = AIR_CALLOC(fslen + nrrd->dim * (doubleStrlen + 1), char); sprintf(*strP, "%s%s:", prefix, fs); - for (ii=0; iidim; ii++) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { airSinglePrintf(NULL, buff, " %.17g", nrrd->axis[ii].thickness); strcat(*strP, buff); } break; case nrrdField_axis_mins: - *strP = AIR_CALLOC(fslen + nrrd->dim*(doubleStrlen + 1), char); + *strP = AIR_CALLOC(fslen + nrrd->dim * (doubleStrlen + 1), char); sprintf(*strP, "%s%s:", prefix, fs); - for (ii=0; iidim; ii++) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { airSinglePrintf(NULL, buff, " %.17g", nrrd->axis[ii].min); strcat(*strP, buff); } break; case nrrdField_axis_maxs: - *strP = AIR_CALLOC(fslen + nrrd->dim*(doubleStrlen + 1), char); + *strP = AIR_CALLOC(fslen + nrrd->dim * (doubleStrlen + 1), char); sprintf(*strP, "%s%s:", prefix, fs); - for (ii=0; iidim; ii++) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { airSinglePrintf(NULL, buff, " %.17g", nrrd->axis[ii].max); strcat(*strP, buff); } break; case nrrdField_space_directions: *strP = AIR_CALLOC(fslen - + nrrd->dim*nrrd->spaceDim*(doubleStrlen - + strlen("(,) ")), char); + + nrrd->dim * nrrd->spaceDim * (doubleStrlen + strlen("(,) ")), + char); sprintf(*strP, "%s%s: ", prefix, fs); - for (ii=0; iidim; ii++) { - _nrrdStrcatSpaceVector(*strP, nrrd->spaceDim, - nrrd->axis[ii].spaceDirection); - if (ii < nrrd->dim-1) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { + _nrrdStrcatSpaceVector(*strP, nrrd->spaceDim, nrrd->axis[ii].spaceDirection); + if (ii < nrrd->dim - 1) { strcat(*strP, " "); } } break; case nrrdField_centers: fdlen = 0; - for (ii=0; iidim; ii++) { - fdlen += 1 + airStrlen(nrrd->axis[ii].center - ? airEnumStr(nrrdCenter, nrrd->axis[ii].center) - : NRRD_UNKNOWN); + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { + fdlen += 1 + + airStrlen(nrrd->axis[ii].center + ? airEnumStr(nrrdCenter, nrrd->axis[ii].center) + : NRRD_UNKNOWN); } *strP = AIR_CALLOC(fslen + fdlen, char); sprintf(*strP, "%s%s:", prefix, fs); - for (ii=0; iidim; ii++) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { sprintf(buff, " %s", - (nrrd->axis[ii].center - ? airEnumStr(nrrdCenter, nrrd->axis[ii].center) - : NRRD_UNKNOWN)); + (nrrd->axis[ii].center ? airEnumStr(nrrdCenter, nrrd->axis[ii].center) + : NRRD_UNKNOWN)); strcat(*strP, buff); } break; case nrrdField_kinds: fdlen = 0; - for (ii=0; iidim; ii++) { - fdlen += 1 + airStrlen(nrrd->axis[ii].kind - ? airEnumStr(nrrdKind, nrrd->axis[ii].kind) - : NRRD_UNKNOWN); + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { + fdlen += 1 + + airStrlen(nrrd->axis[ii].kind ? airEnumStr(nrrdKind, nrrd->axis[ii].kind) + : NRRD_UNKNOWN); } *strP = AIR_CALLOC(fslen + fdlen, char); sprintf(*strP, "%s%s:", prefix, fs); - for (ii=0; iidim; ii++) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { sprintf(buff, " %s", - (nrrd->axis[ii].kind - ? airEnumStr(nrrdKind, nrrd->axis[ii].kind) - : NRRD_UNKNOWN)); + (nrrd->axis[ii].kind ? airEnumStr(nrrdKind, nrrd->axis[ii].kind) + : NRRD_UNKNOWN)); strcat(*strP, buff); } break; case nrrdField_labels: case nrrdField_units: -#define LABEL_OR_UNITS (nrrdField_labels == field \ - ? nrrd->axis[ii].label \ - : nrrd->axis[ii].units) +#define LABEL_OR_UNITS \ + (nrrdField_labels == field ? nrrd->axis[ii].label : nrrd->axis[ii].units) fdlen = 0; - for (ii=0; iidim; ii++) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { /* The "2*" is because at worst every character needs escaping. The "+ 3" for the |" "| between each part */ - fdlen += 2*airStrlen(LABEL_OR_UNITS) + 3; + fdlen += 2 * airStrlen(LABEL_OR_UNITS) + 3; } fdlen += 1; /* for '\0' */ *strP = AIR_CALLOC(fslen + fdlen, char); sprintf(*strP, "%s%s:", prefix, fs); - for (ii=0; iidim; ii++) { + for (ii = !!dropAxis0; ii < nrrd->dim; ii++) { strcat(*strP, " \""); - if (airStrlen(nrrd->axis[ii].label)) { - _nrrdWriteEscaped(NULL, *strP, LABEL_OR_UNITS, - "\"", _NRRD_WHITESPACE_NOTAB); + if (nrrdField_labels == field ? airStrlen(nrrd->axis[ii].label) + : airStrlen(nrrd->axis[ii].units)) { + _nrrdWriteEscaped(NULL, *strP, LABEL_OR_UNITS, "\"", _NRRD_WHITESPACE_NOTAB); } strcat(*strP, "\""); } @@ -644,47 +626,48 @@ _nrrdSprintFieldInfo(char **strP, const char *prefix, strtmp = airOneLinify(airStrdup(nrrd->sampleUnits)); *strP = AIR_CALLOC(fslen + strlen(strtmp), char); sprintf(*strP, "%s%s: \"%s\"", prefix, fs, strtmp); - airFree(strtmp); strtmp = NULL; + airFree(strtmp); + strtmp = NULL; break; case nrrdField_space_units: fdlen = 0; - for (ii=0; iispaceDim; ii++) { + for (ii = 0; ii < nrrd->spaceDim; ii++) { /* The "2*" is because at worst every character needs escaping. See note in formatNRRD.c about how even though its not part of the format, we have worst-case scenario of having to escape a space units which is nothing but ". The "+ 3" for the |" "| between each part */ - fdlen += 2*airStrlen(nrrd->spaceUnits[ii]) + 3; + fdlen += 2 * airStrlen(nrrd->spaceUnits[ii]) + 3; } fdlen += 1; /* for '\0' */ *strP = AIR_CALLOC(fslen + fdlen, char); sprintf(*strP, "%s%s:", prefix, fs); - for (ii=0; iispaceDim; ii++) { + for (ii = 0; ii < nrrd->spaceDim; ii++) { strcat(*strP, " \""); if (airStrlen(nrrd->spaceUnits[ii])) { - _nrrdWriteEscaped(NULL, *strP, nrrd->spaceUnits[ii], - "\"", _NRRD_WHITESPACE_NOTAB); + _nrrdWriteEscaped(NULL, *strP, nrrd->spaceUnits[ii], "\"", + _NRRD_WHITESPACE_NOTAB); } strcat(*strP, "\""); } break; case nrrdField_space_origin: - *strP = AIR_CALLOC(fslen + nrrd->spaceDim*(doubleStrlen - + strlen("(,) ")), char); + *strP = AIR_CALLOC(fslen + nrrd->spaceDim * (doubleStrlen + strlen("(,) ")), char); sprintf(*strP, "%s%s: ", prefix, fs); _nrrdStrcatSpaceVector(*strP, nrrd->spaceDim, nrrd->spaceOrigin); break; case nrrdField_measurement_frame: - *strP = AIR_CALLOC(fslen + (nrrd->spaceDim* - nrrd->spaceDim*(doubleStrlen - + strlen("(,) "))), char); + *strP = AIR_CALLOC(fslen + + (nrrd->spaceDim * nrrd->spaceDim + * (doubleStrlen + strlen("(,) "))), + char); sprintf(*strP, "%s%s: ", prefix, fs); - for (dd=0; ddspaceDim; dd++) { - for (ii=0; iispaceDim; ii++) { + for (dd = 0; dd < nrrd->spaceDim; dd++) { + for (ii = 0; ii < nrrd->spaceDim; ii++) { colvec[ii] = nrrd->measurementFrame[dd][ii]; } _nrrdStrcatSpaceVector(*strP, nrrd->spaceDim, colvec); - if (dd < nrrd->spaceDim-1) { + if (dd < nrrd->spaceDim - 1) { strcat(*strP, " "); } } @@ -696,49 +679,43 @@ _nrrdSprintFieldInfo(char **strP, const char *prefix, the filenames */ /* error checking elsewhere: assumes there is data file info */ if (nio->dataFNFormat) { - *strP = AIR_CALLOC(fslen + strlen(nio->dataFNFormat) + 4*uintStrlen, - char); - if (nio->dataFileDim == nrrd->dim-1) { + *strP = AIR_CALLOC(fslen + strlen(nio->dataFNFormat) + 4 * uintStrlen, char); + if (nio->dataFileDim == nrrd->dim - 1) { sprintf(*strP, "%s%s: %s %d %d %d", prefix, fs, nio->dataFNFormat, nio->dataFNMin, nio->dataFNMax, nio->dataFNStep); } else { sprintf(*strP, "%s%s: %s %d %d %d %u", prefix, fs, nio->dataFNFormat, - nio->dataFNMin, nio->dataFNMax, nio->dataFNStep, - nio->dataFileDim); + nio->dataFNMin, nio->dataFNMax, nio->dataFNStep, nio->dataFileDim); } } else if (nio->dataFNArr->len > 1) { maxl = 0; - for (ii=0; iidataFNArr->len; ii++) { + for (ii = 0; ii < nio->dataFNArr->len; ii++) { maxl = AIR_MAX(maxl, strlen(nio->dataFN[ii])); } - *strP = AIR_CALLOC(fslen + strlen(NRRD_LIST_FLAG) - + uintStrlen + nio->dataFNArr->len * (maxl + 1), + *strP = AIR_CALLOC(fslen + strlen(NRRD_LIST_FLAG) + uintStrlen + + nio->dataFNArr->len * (maxl + 1), char); - fnb = AIR_CALLOC(fslen + strlen(NRRD_LIST_FLAG) - + uintStrlen + maxl + 1, char); - if (nio->dataFileDim == nrrd->dim-1) { + fnb = AIR_CALLOC(fslen + strlen(NRRD_LIST_FLAG) + uintStrlen + maxl + 1, char); + if (nio->dataFileDim == nrrd->dim - 1) { sprintf(*strP, "%s%s: LIST\n", prefix, fs); } else { sprintf(*strP, "%s%s: LIST %u\n", prefix, fs, nio->dataFileDim); } - for (ii=0; iidataFNArr->len; ii++) { - sprintf(fnb, "%s%s", nio->dataFN[ii], - iidataFNArr->len-1 ? "\n" : ""); + for (ii = 0; ii < nio->dataFNArr->len; ii++) { + sprintf(fnb, "%s%s", nio->dataFN[ii], ii < nio->dataFNArr->len - 1 ? "\n" : ""); strcat(*strP, fnb); } free(fnb); } else { /* there is some ambiguity between a "LIST" of length one, and a single explicit data filename, but that's harmless */ - *strP = AIR_CALLOC(fslen + strlen("./") - + strlen(nio->dataFN[0]) + 1, char); + *strP = AIR_CALLOC(fslen + strlen("./") + strlen(nio->dataFN[0]) + 1, char); sprintf(*strP, "%s%s: %s%s", prefix, fs, /* this is a favor to older readers that can deal with this NRRD file because its being saved in a NRRD0003 (or below) version, so we don't want to confuse them by not having the old explicit header-relative flag */ - (_nrrdFormatNRRD_whichVersion(nrrd, nio) < 4 ? "./" : ""), - nio->dataFN[0]); + (_nrrdFormatNRRD_whichVersion(nrrd, nio) < 4 ? "./" : ""), nio->dataFN[0]); } break; default: @@ -757,11 +734,11 @@ _nrrdSprintFieldInfo(char **strP, const char *prefix, ** a file. Same caveats here: use _nrrdFieldInteresting */ void -_nrrdFprintFieldInfo(FILE *file, const char *prefix, - const Nrrd *nrrd, NrrdIoState *nio, int field) { - char *line=NULL; +_nrrdFprintFieldInfo(FILE *file, const char *prefix, const Nrrd *nrrd, NrrdIoState *nio, + int field, int dropAxis0) { + char *line = NULL; - _nrrdSprintFieldInfo(&line, prefix, nrrd, nio, field); + _nrrdSprintFieldInfo(&line, prefix, nrrd, nio, field, dropAxis0); if (line) { fprintf(file, "%s\n", line); free(line); @@ -769,9 +746,9 @@ _nrrdFprintFieldInfo(FILE *file, const char *prefix, return; } -int +static int /* Biff: 1 */ _nrrdEncodingMaybeSet(NrrdIoState *nio) { - static const char me[]="_nrrdEncodingMaybeSet"; + static const char me[] = "_nrrdEncodingMaybeSet"; if (!nio) { biffAddf(NRRD, "%s: got NULL pointer", me); @@ -785,8 +762,8 @@ _nrrdEncodingMaybeSet(NrrdIoState *nio) { nio->encoding = nrrdEncodingArray[nrrdDefaultWriteEncodingType]; } if (!nio->encoding->available()) { - biffAddf(NRRD, "%s: %s encoding not available in this Teem build", - me, nio->encoding->name); + biffAddf(NRRD, "%s: %s encoding not available in this Teem build", me, + nio->encoding->name); return 1; } return 0; @@ -798,11 +775,10 @@ _nrrdEncodingMaybeSet(NrrdIoState *nio) { ** ** we must set nio->format to something useful/non-trivial */ -int -_nrrdFormatMaybeGuess(const Nrrd *nrrd, NrrdIoState *nio, - const char *filename) { - static const char me[]="_nrrdFormatMaybeGuess"; - char mesg[AIR_STRLEN_MED]; +static int /* Biff: 1 */ +_nrrdFormatMaybeGuess(const Nrrd *nrrd, NrrdIoState *nio, const char *filename) { + static const char me[] = "_nrrdFormatMaybeGuess"; + char mesg[AIR_STRLEN_MED + 1]; int fi, guessed, available, fits; if (!nio->format) { @@ -810,9 +786,7 @@ _nrrdFormatMaybeGuess(const Nrrd *nrrd, NrrdIoState *nio, return 1; } if (nrrdFormatUnknown == nio->format) { - for (fi = nrrdFormatTypeUnknown+1; - fi < nrrdFormatTypeLast; - fi++) { + for (fi = nrrdFormatTypeUnknown + 1; fi < nrrdFormatTypeLast; fi++) { if (nrrdFormatArray[fi]->nameLooksLike(filename)) { nio->format = nrrdFormatArray[fi]; break; @@ -829,13 +803,11 @@ _nrrdFormatMaybeGuess(const Nrrd *nrrd, NrrdIoState *nio, available = nio->format->available(); fits = nio->format->fitsInto(nrrd, nio->encoding, AIR_FALSE); /* !available ==> !fits, by the nature of fitsInto() */ - if (!( available && fits )) { + if (!(available && fits)) { sprintf(mesg, "can not use %s format: %s", nio->format->name, - (!available - ? "not available in this Teem build" - : "array doesn\'t fit")); + (!available ? "not available in this Teem build" : "array doesn\'t fit")); if (guessed) { - if (1 <= nrrdStateVerboseIO) { + if (nio && nio->verbose >= 1) { fprintf(stderr, "(%s: %s --> saving to NRRD format)\n", me, mesg); } nio->format = nrrdFormatNRRD; @@ -849,9 +821,9 @@ _nrrdFormatMaybeGuess(const Nrrd *nrrd, NrrdIoState *nio, return 0; } -int +static int /* Biff: 1 */ _nrrdFormatMaybeSet(NrrdIoState *nio) { - static const char me[]="_nrrdFormatMaybeSet"; + static const char me[] = "_nrrdFormatMaybeSet"; if (!nio->format) { biffAddf(NRRD, "%s: invalid (NULL) format", me); @@ -861,8 +833,8 @@ _nrrdFormatMaybeSet(NrrdIoState *nio) { nio->format = nrrdFormatNRRD; } if (!nio->format->available()) { - biffAddf(NRRD, "%s: %s format not available in this Teem build", - me, nio->format->name); + biffAddf(NRRD, "%s: %s format not available in this Teem build", me, + nio->format->name); return 1; } return 0; @@ -877,9 +849,9 @@ _nrrdFormatMaybeSet(NrrdIoState *nio) { ** called, all writing parameters must be given explicitly, and their ** appropriateness is explicitly tested */ -int +static int /* Biff: 1 */ _nrrdWrite(FILE *file, char **stringP, const Nrrd *nrrd, NrrdIoState *_nio) { - static const char me[]="_nrrdWrite"; + static const char me[] = "_nrrdWrite"; NrrdIoState *nio; airArray *mop; @@ -902,52 +874,59 @@ _nrrdWrite(FILE *file, char **stringP, const Nrrd *nrrd, NrrdIoState *_nio) { nio = nrrdIoStateNew(); if (!nio) { biffAddf(NRRD, "%s: couldn't alloc local NrrdIoState", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways); } - if (_nrrdEncodingMaybeSet(nio) - || _nrrdFormatMaybeSet(nio)) { + if (_nrrdEncodingMaybeSet(nio) || _nrrdFormatMaybeSet(nio)) { biffAddf(NRRD, "%s: ", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } if (nio->byteSkip || nio->lineSkip) { /* NOTE: unu make bypasses this by calling nrrdFormatNRRD->write() directly */ biffAddf(NRRD, "%s: can't generate line or byte skips on data write", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } if (stringP) { if (nrrdFormatNRRD != nio->format) { - biffAddf(NRRD, "%s: sorry, can only write %s files to strings (not %s)", - me, nrrdFormatNRRD->name, nio->format->name); - airMopError(mop); return 1; + biffAddf(NRRD, "%s: sorry, can only write %s files to strings (not %s)", me, + nrrdFormatNRRD->name, nio->format->name); + airMopError(mop); + return 1; } /* we do this in two passes; first see how much room is needed for the header, then allocate, then write the header */ nio->learningHeaderStrlen = AIR_TRUE; if (nio->format->write(NULL, nrrd, nio)) { biffAddf(NRRD, "%s:", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } *stringP = AIR_MALLOC(nio->headerStrlen + 1, char); if (!*stringP) { - biffAddf(NRRD, "%s: couldn't allocate header string (%u len )", - me, nio->headerStrlen); - airMopError(mop); return 1; + biffAddf(NRRD, "%s: couldn't allocate header string (%u len )", me, + nio->headerStrlen); + airMopError(mop); + return 1; } nio->learningHeaderStrlen = AIR_FALSE; nio->headerStringWrite = *stringP; if (nio->format->write(NULL, nrrd, nio)) { biffAddf(NRRD, "%s:", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } } else { /* call the writer appropriate for the format */ if (nio->format->write(file, nrrd, nio)) { biffAddf(NRRD, "%s:", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } } @@ -960,9 +939,9 @@ _nrrdWrite(FILE *file, char **stringP, const Nrrd *nrrd, NrrdIoState *_nio) { ** ** wrapper around _nrrdWrite; writes to a FILE* */ -int +int /* Biff: 1 */ nrrdWrite(FILE *file, const Nrrd *nrrd, NrrdIoState *_nio) { - static const char me[]="nrrdWrite"; + static const char me[] = "nrrdWrite"; if (_nrrdWrite(file, NULL, nrrd, _nio)) { biffAddf(NRRD, "%s: trouble", me); @@ -976,9 +955,9 @@ nrrdWrite(FILE *file, const Nrrd *nrrd, NrrdIoState *_nio) { ** ** wrapper around _nrrdWrite; *allocates* and writes to a string */ -int +int /* Biff: 1 */ nrrdStringWrite(char **stringP, const Nrrd *nrrd, NrrdIoState *_nio) { - static const char me[]="nrrdStringWrite"; + static const char me[] = "nrrdStringWrite"; if (_nrrdWrite(NULL, stringP, nrrd, _nio)) { biffAddf(NRRD, "%s: trouble", me); @@ -997,9 +976,9 @@ nrrdStringWrite(char **stringP, const Nrrd *nrrd, NrrdIoState *_nio) { ** whenever the filename ends in NRRD_EXT_NHDR, and when we play this ** game, the data file is ALWAYS header relative. */ -int +int /* Biff: 1 */ nrrdSave(const char *filename, const Nrrd *nrrd, NrrdIoState *nio) { - static const char me[]="nrrdSave"; + static const char me[] = "nrrdSave"; FILE *file; airArray *mop; @@ -1016,14 +995,13 @@ nrrdSave(const char *filename, const Nrrd *nrrd, NrrdIoState *nio) { } airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways); } - if (_nrrdEncodingMaybeSet(nio) - || _nrrdFormatMaybeGuess(nrrd, nio, filename)) { + if (_nrrdEncodingMaybeSet(nio) || _nrrdFormatMaybeGuess(nrrd, nio, filename)) { biffAddf(NRRD, "%s: ", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } - if (nrrdFormatNRRD == nio->format - && airEndsWith(filename, NRRD_EXT_NHDR)) { + if (nrrdFormatNRRD == nio->format && airEndsWith(filename, NRRD_EXT_NHDR)) { nio->detachedHeader = AIR_TRUE; _nrrdSplitName(&(nio->path), &(nio->base), filename); /* nix the ".nhdr" suffix */ @@ -1033,38 +1011,42 @@ nrrdSave(const char *filename, const Nrrd *nrrd, NrrdIoState *nio) { nio->detachedHeader = AIR_FALSE; } - if (!( file = airFopen(filename, stdout, "wb") )) { - biffAddf(NRRD, "%s: couldn't fopen(\"%s\",\"wb\"): %s", - me, filename, strerror(errno)); - airMopError(mop); return 1; + if (!(file = airFopen(filename, stdout, "wb"))) { + biffAddf(NRRD, "%s: couldn't fopen(\"%s\",\"wb\"): %s", me, filename, + strerror(errno)); + airMopError(mop); + return 1; } airMopAdd(mop, file, (airMopper)airFclose, airMopAlways); if (nrrdWrite(file, nrrd, nio)) { biffAddf(NRRD, "%s:", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } airMopOkay(mop); return 0; } -int -nrrdSaveMulti(const char *fnameFormat, const Nrrd *const *nin, - unsigned int ninLen, unsigned int numStart, NrrdIoState *nio) { - static const char me[]="nrrdSaveMulti"; +int /* Biff: 1 */ +nrrdSaveMulti(const char *fnameFormat, const Nrrd *const *nin, unsigned int ninLen, + unsigned int numStart, NrrdIoState *nio) { + static const char me[] = "nrrdSaveMulti"; char *fname; airArray *mop; unsigned int nii; - if (!( fnameFormat && nin )) { + if (!(fnameFormat && nin)) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } - if (!( _nrrdContainsPercentThisAndMore(fnameFormat, 'u') )) { - biffAddf(NRRD, "%s: given format \"%s\" doesn't seem to " + if (!(nrrdContainsPercentThisAndMore(fnameFormat, 'u'))) { + biffAddf(NRRD, + "%s: given format \"%s\" doesn't seem to " "have the \"%%u\" conversion specification to sprintf " - "an unsigned int\n", me, fnameFormat); + "an unsigned int\n", + me, fnameFormat); return 1; } @@ -1073,17 +1055,19 @@ nrrdSaveMulti(const char *fnameFormat, const Nrrd *const *nin, fname = AIR_CALLOC(strlen(fnameFormat) + 128, char); if (!(fname)) { biffAddf(NRRD, "%s: couldn't allocate local fname buffer", me); - airMopError(mop); return 1; + airMopError(mop); + return 1; } airMopAdd(mop, fname, airFree, airMopAlways); - for (nii=0; nii