diff --git a/nifti2/nifti_regress_test/cmake_testscripts/c22_copy_image.sh b/nifti2/nifti_regress_test/cmake_testscripts/c22_copy_image.sh index a3abddc2..18c435c9 100644 --- a/nifti2/nifti_regress_test/cmake_testscripts/c22_copy_image.sh +++ b/nifti2/nifti_regress_test/cmake_testscripts/c22_copy_image.sh @@ -11,6 +11,23 @@ DATA=$2 OUT_DATA=$(dirname ${DATA}) #Need to write to separate directory cd ${OUT_DATA} + +# Compare two NIfTI files by content rather than by compressed bytes. +# +# gzip output is not reproducible across zlib implementations: zlib-ng, +# which Arch, CachyOS and other current distributions ship as the system +# zlib, encodes the same input differently from stock zlib. Comparing +# the .gz files directly therefore fails on those systems even though the +# image data round-trips perfectly. Decompress first and compare that. +nii_cmp() { + if [ "${1##*.}" = "gz" ]; then + gzip -dc "$1" > "$1.raw" && gzip -dc "$2" > "$2.raw" || return 1 + cmp "$1.raw" "$2.raw" + return $? + fi + cmp "$1" "$2" +} + # note the main input file and prefix for all output files infile=$DATA/e4.60005.nii.gz prefix=out.c22 @@ -42,7 +59,7 @@ ${NT} -copy_image -infile ${prefix}.0.i16.nii.gz \ ${NT} -copy_image -infile ${prefix}.1.i64.nii.gz \ -prefix ${prefix}.2.0.i16.nii.gz \ -convert2dtype NIFTI_TYPE_INT16 -convert_verify -if cmp ${prefix}.0.i16.nii.gz ${prefix}.2.0.i16.nii.gz +if nii_cmp ${prefix}.0.i16.nii.gz ${prefix}.2.0.i16.nii.gz then echo "" else @@ -57,7 +74,7 @@ ${NT} -cbl -infile ${prefix}.0.i16.nii.gz \ ${NT} -copy_image -infile ${prefix}.1.f32.nii.gz \ -prefix ${prefix}.2.1.i16.nii.gz \ -convert2dtype NIFTI_TYPE_INT16 -convert_fail_choice warn -if cmp ${prefix}.0.i16.nii.gz ${prefix}.2.1.i16.nii.gz +if nii_cmp ${prefix}.0.i16.nii.gz ${prefix}.2.1.i16.nii.gz then echo "" else