Yalantis/uCrop · error · CImgIOException
load_analyze(): Unable to load datatype %d in file '%s'
Error message
load_analyze(): Unable to load datatype %d in file '%s'
What it means
The Analyze/NIfTI datatype field in the header maps to known storage codes (2=uint8, 4=int16, 8=int32, 16=float32, 32/64=complex, 128=RGB, 256=int8, 512=uint16, 768=uint32, 1024=float64...). If the datatype value does not match any implemented case, load_analyze() throws after closing the file. Newer NIfTI datatype codes (e.g. 2304 RGB, 256/768 in very old CImg builds, or NIfTI-2 codes) may be unsupported by the bundled CImg version.
Source
Thrown at ucrop/src/main/jni/CImg.h:58514
delete[] buffer;
} break;
case 16 : {
float *const buffer = new float[pdim];
cimg::fread(buffer,pdim,nfile);
if (endian) cimg::invert_endianness(buffer,pdim);
cimg_foroff(*this,off) _data[off] = (T)(buffer[off]*scalefactor);
delete[] buffer;
} break;
case 64 : {
double *const buffer = new double[pdim];
cimg::fread(buffer,pdim,nfile);
if (endian) cimg::invert_endianness(buffer,pdim);
cimg_foroff(*this,off) _data[off] = (T)(buffer[off]*scalefactor);
delete[] buffer;
} break;
default :
if (!file) cimg::fclose(nfile);
throw CImgIOException(_cimg_instance
"load_analyze(): Unable to load datatype %d in file '%s'",
cimg_instance,
datatype,filename?filename:"(FILE*)");
}
if (!file) cimg::fclose(nfile);
return *this;
}
//! Load image from a .cimg[z] file.
/**
\param filename Filename, as a C-string.
\param axis Appending axis, if file contains multiple images. Can be <tt>{ 'x' | 'y' | 'z' | 'c' }</tt>.
\param align Appending alignment.
**/
CImg<T>& load_cimg(const char *const filename, const char axis='z', const float align=0) {
CImgList<T> list;
list.load_cimg(filename);
if (list._width==1) return list[0].move_to(*this);View on GitHub (pinned to f788b534b4)
Solutions
- Inspect datatype in the header (offset 70 in NIfTI-1/Analyze) and convert the volume to a supported type (e.g. int16/float32) with a converter tool (fslchfiletype, nibabel).
- Update the CImg.h snapshot in ucrop/src/main/jni to a newer version supporting more datatypes.
- If datatype==0, re-export with a proper writer; the field was never set.
- Read the pixel data manually with known dims/datatype and construct the CImg yourself as a workaround.
- Catch CImgIOException in batch pipelines and quarantine unsupported volumes for conversion.
Example fix
# before: datatype 2304 (RGB) unsupported by old CImg
# after: convert to uint8/int16 first
$ fslchfiletype NIFTI_PAIR in.nii out # or with nibabel:
import nibabel as nib
img = nib.load('in.nii'); nib.save(nib.Nifti1Image(img.get_fdata().mean(-1).astype('int16'), img.affine), 'out.nii') Defensive patterns
Strategy: try-catch
Validate before calling
bool datatypeSupported(std::FILE* hdr) {
// datatype at offset 70 in NIfTI-1/Analyze header
int dt = 0; if (std::fseek(hdr, 70, SEEK_SET) != 0) return false;
if (std::fread(&dt, sizeof(int), 1, hdr) != 1) return false;
switch (dt) { case 1: case 2: case 4: case 8: case 16: case 32: case 64:
case 128: case 256: case 512: case 768: case 1024: return true; default: return false; }
} Type guard
bool isSupportedDatatype(int datatype) { return datatype != 0 && datatype <= 1024 && (datatype & (datatype - 1)) == 0 || datatype == 128; } Try / catch
try { img.load_analyze(path); }
catch (CImgIOException& e) {
fprintf(stderr, "Unsupported datatype — converting volume\n");
convertWithNibabelOrFsl(path); // external conversion fallback
} Prevention
- Pre-convert volumes to int16/float32 with dcm2niix defaults.
- Update the bundled CImg.h to a recent version.
- Reject datatype==0 headers at ingestion time.
- Test pipelines against all datatypes your scanners emit.
When it happens
Trigger: Header declares a datatype code outside the switch handled by this CImg build — e.g. datatype=2304 (NIfTI RGB24), datatype=0 (unknown), or a corrupted/zeroed datatype field; encountered via load()/load_analyze() on an .img/.hdr/.nii volume.
Common situations: Images exported by newer conversion tools (dcm2niix with RGB, INT8, or float128 outputs) fed to an old CImg snapshot; headers hand-edited or zero-filled by buggy writers; NIfTI-2 files parsed as NIfTI-1 shifting the datatype field.
Related errors
- load_analyze(): Invalid Analyze7.5 or NIFTI header in file '
- load_analyze(): Invalid header size (%u) specified in file '
- load_analyze(): Cannot read header (of size %u) in file '%s'
- _cvmat2cimg() : pixel type '%s' is not supported.
- cimg::SDL3_attr(): %s
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/03935c7814d87f39.
Report an issue: GitHub.