{"record":{"id":"d7b287dde844c70b","repo":"Yalantis/uCrop","slug":"cimg-s-load-inr-incomplete-pixsize-field-def","errorCode":null,"errorMessage":"CImg<%s>::load_inr(): Incomplete PIXSIZE field defined in header.","messagePattern":"CImg<(.+?)>::load_inr\\(\\): Incomplete PIXSIZE field defined in header\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58688,"sourceCode":"          if (!cimg::strncasecmp(tmp1,\"int\",3) || !cimg::strncasecmp(tmp1,\"fixed\",5))  out[4] = 0;\n          if (!cimg::strncasecmp(tmp1,\"float\",5) || !cimg::strncasecmp(tmp1,\"double\",6)) out[4] = 1;\n          if (!cimg::strncasecmp(tmp1,\"packed\",6)) out[4] = 2;\n          if (out[4]>=0) break; // Fallthrough\n        default :\n          throw CImgIOException(\"CImg<%s>::load_inr(): Invalid pixel type '%s' defined in header.\",\n                                pixel_type(),\n                                tmp2._data);\n        }\n      }\n      if (out[0]<0 || out[1]<0 || out[2]<0 || out[3]<0)\n        throw CImgIOException(\"CImg<%s>::load_inr(): Invalid dimensions (%d,%d,%d,%d) defined in header.\",\n                              pixel_type(),\n                              out[0],out[1],out[2],out[3]);\n      if (out[4]<0 || out[5]<0)\n        throw CImgIOException(\"CImg<%s>::load_inr(): Incomplete pixel type defined in header.\",\n                              pixel_type());\n      if (out[6]<0)\n        throw CImgIOException(\"CImg<%s>::load_inr(): Incomplete PIXSIZE field defined in header.\",\n                              pixel_type());\n      if (out[7]<0)\n        throw CImgIOException(\"CImg<%s>::load_inr(): Big/Little Endian coding type undefined in header.\",\n                              pixel_type());\n    }\n\n    CImg<T>& _load_inr(std::FILE *const file, const char *const filename, float *const voxel_size) {\n#define _cimg_load_inr_case(Tf,sign,pixsize,Ts) \\\n     if (!loaded && fopt[6]==pixsize && fopt[4]==Tf && fopt[5]==sign) { \\\n        Ts *xval, *const val = new Ts[(size_t)fopt[0]*fopt[3]]; \\\n        cimg_forYZ(*this,y,z) { \\\n            cimg::fread(val,fopt[0]*fopt[3],nfile); \\\n            if (fopt[7]!=endian) cimg::invert_endianness(val,fopt[0]*fopt[3]); \\\n            xval = val; cimg_forX(*this,x) cimg_forC(*this,c) (*this)(x,y,z,c) = (T)*(xval++); \\\n          } \\\n        delete[] val; \\\n        loaded = true; \\\n      }","sourceCodeStart":58670,"sourceCodeEnd":58706,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58670-L58706","documentation":"Alongside TYPE, the INR header must contain a PIXSIZE field (bits per voxel: 8/16/32/64...). If the PIXSIZE line is missing or unparsable, out[6] stays -1 and this exception is thrown, separate from the TYPE checks so the user knows exactly which field is missing.","triggerScenarios":"Header lacks a 'PIXSIZE=NN' line or it doesn't match the fscanf/sscanf patterns used; raised from load_inr()/load() on an .inr file whose out[4]/out[5] passed but out[6]<0.","commonSituations":"Custom INR writers omitting PIXSIZE; header edited down to just XDIM/YDIM/ZDIM/VDIM/TYPE; corrupted token (e.g. 'PIXSIZE = thirty-two') that fails numeric parsing.","solutions":["Add a valid PIXSIZE line to the header (8, 16, 32, or 64 bits matching the data).","Re-export the file with a standard INR writer.","Validate generated headers contain all of XDIM/YDIM/ZDIM/VDIM/TYPE/PIXSIZE/Endianity before finalizing.","Check that PIXSIZE matches the actual buffer size to avoid a downstream short read.","Catch CImgIOException and instruct users which header field to add."],"exampleFix":"# before (header, PIXSIZE missing)\nTYPE=unsigned fixed\n# after\nTYPE=unsigned fixed\nPIXSIZE=16","handlingStrategy":"validation","validationCode":"bool inrPixsizeValid(const std::string& headerText) {\n  for (int bits : {8, 16, 32, 64}) {\n    if (headerText.find(\"PIXSIZE=\" + std::to_string(bits)) != std::string::npos) return true;\n  }\n  return false;\n}","typeGuard":"bool hasValidPixsize(int pixsize) { return pixsize == 8 || pixsize == 16 || pixsize == 32 || pixsize == 64; }","tryCatchPattern":"try { img.load_inr(path); }\ncatch (CImgIOException& e) { fprintf(stderr, \"PIXSIZE missing/invalid in INR header\\n\"); }","preventionTips":["Always emit a numeric PIXSIZE (8/16/32/64) in INR headers.","Match PIXSIZE to the actual voxel buffer size.","Spell the field exactly 'PIXSIZE=' with an integer value.","Round-trip test generated files by loading them immediately."],"tags":["cimg","pixsize","inrimage","header"],"backgroundTag":"missing-required-config-field","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"}