Yalantis/uCrop · error · CImgIOException
CImg<%s>::load_inr(): Invalid pixel type '%s' defined in hea
Error message
CImg<%s>::load_inr(): Invalid pixel type '%s' defined in header.
What it means
The INR header's TYPE field (e.g. 'int', 'fixed', 'float', 'double', 'packed' combined with PIXSIZE) must map to a supported pixel class; out[4] records it (0=integer,1=float,2=packed). If TYPE/PIXSIZE combination is unrecognized, out[4] stays -1 and this exception is thrown, listing the raw TYPE/PIXSIZE string from the header.
Source
Thrown at ucrop/src/main/jni/CImg.h:58675
cimg_sscanf(item," PIXSIZE%*[^0-9]%d",out + 6);
if (voxel_size) {
cimg_sscanf(item," VX%*[^0-9.+-]%f",voxel_size);
cimg_sscanf(item," VY%*[^0-9.+-]%f",voxel_size + 1);
cimg_sscanf(item," VZ%*[^0-9.+-]%f",voxel_size + 2);
}
if (cimg_sscanf(item," CPU%*[ =]%s",tmp1._data)) out[7] = cimg::strncasecmp(tmp1,"sun",3)?0:1;
switch (cimg_sscanf(item," TYPE%*[ =]%s %s",tmp1._data,tmp2._data)) {
case 0 : break;
case 2 :
out[5] = cimg::strncasecmp(tmp1,"unsigned",8)?1:0;
std::strncpy(tmp1,tmp2,tmp1._width - 1); // Fallthrough
case 1 :
if (!cimg::strncasecmp(tmp1,"int",3) || !cimg::strncasecmp(tmp1,"fixed",5)) out[4] = 0;
if (!cimg::strncasecmp(tmp1,"float",5) || !cimg::strncasecmp(tmp1,"double",6)) out[4] = 1;
if (!cimg::strncasecmp(tmp1,"packed",6)) out[4] = 2;
if (out[4]>=0) break; // Fallthrough
default :
throw CImgIOException("CImg<%s>::load_inr(): Invalid pixel type '%s' defined in header.",
pixel_type(),
tmp2._data);
}
}
if (out[0]<0 || out[1]<0 || out[2]<0 || out[3]<0)
throw CImgIOException("CImg<%s>::load_inr(): Invalid dimensions (%d,%d,%d,%d) defined in header.",
pixel_type(),
out[0],out[1],out[2],out[3]);
if (out[4]<0 || out[5]<0)
throw CImgIOException("CImg<%s>::load_inr(): Incomplete pixel type defined in header.",
pixel_type());
if (out[6]<0)
throw CImgIOException("CImg<%s>::load_inr(): Incomplete PIXSIZE field defined in header.",
pixel_type());
if (out[7]<0)
throw CImgIOException("CImg<%s>::load_inr(): Big/Little Endian coding type undefined in header.",
pixel_type());
}View on GitHub (pinned to f788b534b4)
Solutions
- Open the header (text section at the end/after '#INRIMAGE-4#{') and set TYPE to a supported keyword: int, fixed, float, double, or packed.
- Ensure PIXSIZE (out[5]/bits) pairs correctly with TYPE (e.g. TYPE=float with PIXSIZE=32); an odd PIXSIZE can leave the case unmatched.
- Re-export the volume with standard settings (e.g. TYPE=float, PIXSIZE=32, or TYPE=unsigned fixed PIXSIZE=8/16).
- Update the bundled CImg.h — newer versions accept more TYPE/PIXSIZE combos.
- Catch CImgIOException, parse the header yourself, and convert the data to a supported type.
Example fix
# before (header) TYPE=flaot PIXSIZE=32 # after TYPE=float PIXSIZE=32
Defensive patterns
Strategy: validation
Validate before calling
bool inrTypeSupported(const std::string& headerText) {
static const char* ok[] = {"int", "fixed", "float", "double", "packed"};
for (const char* k : ok) if (headerText.find(std::string("TYPE=") + k) != std::string::npos) return true;
return false;
} Type guard
bool isKnownInrType(const std::string& t) {
return t == "int" || t == "fixed" || t == "float" || t == "double" || t == "packed";
} Try / catch
try { img.load_inr(path); }
catch (CImgIOException& e) { fprintf(stderr, "Unsupported TYPE in INR header — fix header or re-export\n"); } Prevention
- Only emit TYPE values from the supported keyword set when writing INR files.
- Keep TYPE/PIXSIZE pairs standard (e.g. float+32, unsigned fixed+8/16).
- Lint generated INR headers against a field checklist.
- Update CImg.h for newer TYPE support.
When it happens
Trigger: Header contains a TYPE value the parser doesn't recognize (e.g. TYPE=unsigned fixed, TYPE=surfel, misspelled 'flaot') or a valid TYPE reached the default branch because no known keyword matched; raised from load_inr()/load() on .inr files.
Common situations: Files produced by non-standard INR writers with exotic TYPE strings (signed, rgb packed variants); manual header edits; locale/whitespace corruption shifting the parsed token into tmp2.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- CImg<%s>::load_inr(): Incomplete pixel type defined in heade
- CImg<%s>::load_inr(): Invalid dimensions (%d,%d,%d,%d) defin
- CImg<%s>::load_inr(): Incomplete PIXSIZE field defined in he
- CImg<%s>::load_inr(): Big/Little Endian coding type undefine
- assign(): Invalid assignment request of shared instance from
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/81ec698c637edb29.
Report an issue: GitHub.