Yalantis/uCrop · error · CImgIOException
load_parrec(): Failed to recognize valid PAR-REC data in…
Error message
load_parrec(): Failed to recognize valid PAR-REC data in file '%s'.
What it means
After parsing the PAR header and REC data, load_parrec() checks whether any image dimensions were actually set (_width). A zero width means the parser never recognized valid PAR/REC content, so CImg throws CImgIOException instead of returning an empty list.
Solutions
- Pass the .PAR header file (not the .REC binary) to load_parrec()
- Open the file in a text editor and confirm it contains Philips PAR header blocks ('# Interested Eco lane', image lines, etc.)
- Re-transfer/re-download the study - truncated files parse to zero images
- If the format is a newer Philips revision, convert to NIfTI/DICOM externally or update CImg
Example fix
// before
imgs.load_parrec("scan.rec"); // binary data, no PAR header
// after
imgs.load_parrec("scan.par"); // PAR text header (references scan.rec) Defensive patterns
Strategy: validation
Validate before calling
std::ifstream f(parPath); std::string line;
bool isPar = false;
while (std::getline(f, line)) if (line.rfind("# ", 0) == 0 && line.find("Philips") != std::string::npos) { isPar = true; break; }
if (!isPar) { /* not a PAR header - abort or convert */ } Try / catch
try { imgs.load_parrec(parPath); }
catch (CImgIOException& e) { fprintf(stderr, "not a valid PAR file: %s\n", e.what()); } Prevention
- Always pass the .par header, never the .rec binary
- Check the file's first lines look like a Philips PAR header before loading
- Verify file sizes after transfer (truncation detection)
When it happens
Trigger: load_parrec() given a file that lacks the required PAR header keywords (e.g. '# Patients', '# Recon resolution', image info lines) so no image records are parsed; passing the .REC file instead of the .PAR text header; an empty or wrong-format file.
Common situations: Mixing up the .par and .rec files (the loader wants the .par header path); loading a renamed DICOM/NIfTI file with a .par extension; truncated downloads; PAR files from scanner versions with a header layout CImg cannot parse.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- load_parrec(): Unsupported
- CImg< >::load_inr(): INRIMAGE-4 header not found.
- load_analyze(): Cannot read header (of size %u) in file
- load_analyze(): Invalid header size (%u) specified in file
- load_ascii(): Invalid ascii header in file
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/958ebde39d6ecee5.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:67124
CImg<uintT> buf(size_x,size_y);
cimg::fread(buf._data,size_x*size_y,file2);
if (cimg::endianness()) cimg::invert_endianness(buf._data,size_x*size_y);
CImg<T>& img = (*this)[imn];
cimg_forXY(img,x,y) img(x,y,sn) = (T)(( buf(x,y)*rs + ri )/(rs*ss));
} break;
default :
cimg::fclose(file);
cimg::fclose(file2);
throw CImgIOException(_cimglist_instance
"load_parrec(): Unsupported %d-bits pixel type for file '%s'.",
cimglist_instance,
pixsize,filename);
}
}
cimg::fclose(file);
cimg::fclose(file2);
if (!_width)
throw CImgIOException(_cimglist_instance
"load_parrec(): Failed to recognize valid PAR-REC data in file '%s'.",
cimglist_instance,
filename);
return *this;
}
//! Load a list from a PAR/REC (Philips) file \newinstance.
static CImgList<T> get_load_parrec(const char *const filename) {
return CImgList<T>().load_parrec(filename);
}
//! Load a list from a YUV image sequence file.
/**
\param filename Filename to read data from.
\param size_x Width of the images.
\param size_y Height of the images.
\param chroma_subsampling Type of chroma subsampling. Can be <tt>{ 420 | 422 | 444 }</tt>.
\param first_frame Index of first image frame to read.View on GitHub (pinned to f788b534b4)