Yalantis/uCrop · error · CImgIOException
save_inr(): Unsupported pixel type '%s' for file '%s'
Error message
save_inr(): Unsupported pixel type '%s' for file '%s'
What it means
The INR format stores an explicit pixel type string ('unsigned fixed PIXSIZE=8 bits', 'float PIXSIZE=32/64 bits', etc.); _save_inr() selects inrtype/inrpixsize from the image's pixel_type() and throws CImgIOException when inrpixsize remains <= 0, i.e. the instance's element type has no INR representation. Unlike the null-filename check this fires after type matching, so it indicates a dtype problem, not a path problem.
Source
Thrown at ucrop/src/main/jni/CImg.h:63090
inrtype = "unsigned fixed\nPIXSIZE=16 bits\nSCALE=2**0";inrpixsize = 2;
}
if (!cimg::strcasecmp(pixel_type(),"int16")) {
inrtype = "fixed\nPIXSIZE=16 bits\nSCALE=2**0"; inrpixsize = 2;
}
if (!cimg::strcasecmp(pixel_type(),"uint32")) {
inrtype = "unsigned fixed\nPIXSIZE=32 bits\nSCALE=2**0";inrpixsize = 4;
}
if (!cimg::strcasecmp(pixel_type(),"int32")) {
inrtype = "fixed\nPIXSIZE=32 bits\nSCALE=2**0"; inrpixsize = 4;
}
if (!cimg::strcasecmp(pixel_type(),"float32")) {
inrtype = "float\nPIXSIZE=32 bits"; inrpixsize = 4;
}
if (!cimg::strcasecmp(pixel_type(),"float64")) {
inrtype = "float\nPIXSIZE=64 bits"; inrpixsize = 8;
}
if (inrpixsize<=0)
throw CImgIOException(_cimg_instance
"save_inr(): Unsupported pixel type '%s' for file '%s'",
cimg_instance,
pixel_type(),filename?filename:"(FILE*)");
std::FILE *const nfile = file?file:cimg::fopen(filename,"wb");
CImg<charT> header(257);
int err = cimg_snprintf(header,header._width,"#INRIMAGE-4#{\nXDIM=%u\nYDIM=%u\nZDIM=%u\nVDIM=%u\n",
_width,_height,_depth,_spectrum);
if (voxel_size)
err+=cimg_snprintf(header._data + err,128,"VX=%g\nVY=%g\nVZ=%g\n",
voxel_size[0],voxel_size[1],voxel_size[2]);
err+=cimg_snprintf(header._data + err,128,"TYPE=%s\nCPU=%s\n",
inrtype,cimg::endianness()?"sun":"decm");
std::memset(header._data + err,'\n',252 - err);
std::memcpy(header._data + 252,"##}\n",4);
cimg::fwrite(header._data,256,nfile);
cimg_forXYZ(*this,x,y,z) cimg_forC(*this,c) cimg::fwrite(&((*this)(x,y,z,c)),1,nfile);
if (!file) cimg::fclose(nfile);View on GitHub (pinned to f788b534b4)
Solutions
- Convert to a supported type before saving: img.get_float32().save_inr(filename) or CImg<float>(img).save_inr(...).
- Keep 8-bit data by using a format that supports unsigned char natively (PNG, BMP, PNM).
- Check pixel_type() before export and reject unsupported types with an app-level message.
- Upgrade CImg if a newer version registers additional INR pixel types.
Example fix
// before
CImg<unsigned short> depth(640,480,1,1,0);
depth.save_inr("depth.inr"); // throws
// after
CImg<float> depthf(depth);
depthf.save_inr("depth.inr"); Defensive patterns
Strategy: validation
Validate before calling
static const char* kInrTypes[] = {"uint8","int8","uint16","int16","float32","float64"};
bool ok = false;
for (const char* t : kInrTypes)
if (!cimg::strcasecmp(img.pixel_type(), t)) { ok = true; break; }
if (!ok) throw std::runtime_error(std::string("INR unsupported for ") + img.pixel_type()); Type guard
template <typename T>
constexpr bool inr_supported() {
return sizeof(T) == 1 || sizeof(T) == 2 || std::is_floating_point_v<T>;
} Try / catch
try {
img.save_inr("vol.inr");
} catch (const CImgIOException& e) {
std::fprintf(stderr, "converting to float32 for INR: %s\n", e.what());
CImg<float>(img).save_inr("vol.inr");
} Prevention
- Cast unsupported widths (e.g. bool, wide ints) before INR export
- Match PIXSIZE expectations of downstream INR readers
- Check pixel_type() once in a shared export utility
When it happens
Trigger: Calling save_inr() on CImg<unsigned short>, CImg<bool>, or any type whose pixel_type() string matches none of the handled cases (8/16-bit fixed, float32, float64); generic save("file.inr") dispatched from such an instance.
Common situations: Saving 16-bit depth maps or 8-bit masks to .inr; data pipeline switched element type without updating the export step; older CImg with fewer INR type cases.
Related errors
- save_analyze(): Unsupported pixel type '%s' for file '%s'.
- assign(): Invalid assignment request of shared instance from
- CImg<%s>::load_inr(): Invalid pixel type '%s' defined in hea
- CImg<%s>::load_inr(): Incomplete pixel type defined in heade
- load_inr(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/4bef37c189534ae3.
Report an issue: GitHub.