From fe4021dd1bfc8fedbb4a2acc29272aa966cc4457 Mon Sep 17 00:00:00 2001 From: Andras Lasso Date: Wed, 31 Jul 2024 14:57:52 +0200 Subject: [PATCH] Fix corrupted raw nrrd file output on Windows On Windows, when NRRD file was written into .nrrd format with raw pixels then the image was corrupted. The root cause was that the file was opened in text mode and therefore each 0a byte was converted to 0d0a resulting in an incorrect byte stream. --- console/nii_dicom_batch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/nii_dicom_batch.cpp b/console/nii_dicom_batch.cpp index cd65c820..cff0b91c 100644 --- a/console/nii_dicom_batch.cpp +++ b/console/nii_dicom_batch.cpp @@ -4452,7 +4452,7 @@ int nii_saveNRRD(char *niiFilename, struct nifti_1_header hdr, unsigned char *im strcat(fname, ".nhdr"); //nrrd or nhdr else strcat(fname, ".nrrd"); //nrrd or nhdr - FILE *fp = fopen(fname, "w"); + FILE *fp = fopen(fname, "wb"); fprintf(fp, "NRRD0005\n"); fprintf(fp, "# Complete NRRD file format specification at:\n"); fprintf(fp, "# http://teem.sourceforge.net/nrrd/format.html\n");