{"record":{"id":"4bef37c189534ae3","repo":"Yalantis/uCrop","slug":"save-inr-unsupported-pixel-type-s-for-file","errorCode":null,"errorMessage":"save_inr(): Unsupported pixel type '%s' for file '%s'","messagePattern":"save_inr\\(\\): Unsupported pixel type '(.+?)' for file '(.+?)'","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63090,"sourceCode":"        inrtype = \"unsigned fixed\\nPIXSIZE=16 bits\\nSCALE=2**0\";inrpixsize = 2;\n      }\n      if (!cimg::strcasecmp(pixel_type(),\"int16\")) {\n        inrtype = \"fixed\\nPIXSIZE=16 bits\\nSCALE=2**0\"; inrpixsize = 2;\n      }\n      if (!cimg::strcasecmp(pixel_type(),\"uint32\")) {\n        inrtype = \"unsigned fixed\\nPIXSIZE=32 bits\\nSCALE=2**0\";inrpixsize = 4;\n      }\n      if (!cimg::strcasecmp(pixel_type(),\"int32\")) {\n        inrtype = \"fixed\\nPIXSIZE=32 bits\\nSCALE=2**0\"; inrpixsize = 4;\n      }\n      if (!cimg::strcasecmp(pixel_type(),\"float32\")) {\n        inrtype = \"float\\nPIXSIZE=32 bits\"; inrpixsize = 4;\n      }\n      if (!cimg::strcasecmp(pixel_type(),\"float64\")) {\n        inrtype = \"float\\nPIXSIZE=64 bits\"; inrpixsize = 8;\n      }\n      if (inrpixsize<=0)\n        throw CImgIOException(_cimg_instance\n                              \"save_inr(): Unsupported pixel type '%s' for file '%s'\",\n                              cimg_instance,\n                              pixel_type(),filename?filename:\"(FILE*)\");\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"wb\");\n      CImg<charT> header(257);\n      int err = cimg_snprintf(header,header._width,\"#INRIMAGE-4#{\\nXDIM=%u\\nYDIM=%u\\nZDIM=%u\\nVDIM=%u\\n\",\n                              _width,_height,_depth,_spectrum);\n      if (voxel_size)\n        err+=cimg_snprintf(header._data + err,128,\"VX=%g\\nVY=%g\\nVZ=%g\\n\",\n                          voxel_size[0],voxel_size[1],voxel_size[2]);\n      err+=cimg_snprintf(header._data + err,128,\"TYPE=%s\\nCPU=%s\\n\",\n                         inrtype,cimg::endianness()?\"sun\":\"decm\");\n      std::memset(header._data + err,'\\n',252 - err);\n      std::memcpy(header._data + 252,\"##}\\n\",4);\n      cimg::fwrite(header._data,256,nfile);\n      cimg_forXYZ(*this,x,y,z) cimg_forC(*this,c) cimg::fwrite(&((*this)(x,y,z,c)),1,nfile);\n      if (!file) cimg::fclose(nfile);","sourceCodeStart":63072,"sourceCodeEnd":63108,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63072-L63108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nCImg<unsigned short> depth(640,480,1,1,0);\ndepth.save_inr(\"depth.inr\"); // throws\n\n// after\nCImg<float> depthf(depth);\ndepthf.save_inr(\"depth.inr\");","handlingStrategy":"validation","validationCode":"static const char* kInrTypes[] = {\"uint8\",\"int8\",\"uint16\",\"int16\",\"float32\",\"float64\"};\nbool ok = false;\nfor (const char* t : kInrTypes)\n  if (!cimg::strcasecmp(img.pixel_type(), t)) { ok = true; break; }\nif (!ok) throw std::runtime_error(std::string(\"INR unsupported for \") + img.pixel_type());","typeGuard":"template <typename T>\nconstexpr bool inr_supported() {\n  return sizeof(T) == 1 || sizeof(T) == 2 || std::is_floating_point_v<T>;\n}","tryCatchPattern":"try {\n  img.save_inr(\"vol.inr\");\n} catch (const CImgIOException& e) {\n  std::fprintf(stderr, \"converting to float32 for INR: %s\\n\", e.what());\n  CImg<float>(img).save_inr(\"vol.inr\");\n}","preventionTips":["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"],"tags":["cimg","inr","pixel-type","datatype"],"backgroundTag":"unsupported-dtype","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}