{"record":{"id":"4335d222c63b168b","repo":"Yalantis/uCrop","slug":"cimg-s-load-inr-big-little-endian-coding-typ","errorCode":null,"errorMessage":"CImg<%s>::load_inr(): Big/Little Endian coding type undefined in header.","messagePattern":"CImg<(.+?)>::load_inr\\(\\): Big/Little Endian coding type undefined in header\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58691,"sourceCode":"          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      }\n\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance","sourceCodeStart":58673,"sourceCodeEnd":58709,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58673-L58709","documentation":"INRIMAGE-4 headers must declare byte order via an 'Endianity' (or equivalent) field: out[7] stores the coding type (0=big endian,1=little endian conventions in this loader). If the field is absent, out[7] remains -1 and this exception is thrown because voxel data cannot be decoded correctly without knowing endianness.","triggerScenarios":"Header omits the Endianity line (e.g. 'Endianity=b' or 'l' not parsed), or the token spelling doesn't match the loader's expectations; raised from load_inr()/load() on .inr files after all other header checks pass.","commonSituations":"Files written on machines with a different convention and copied without the Endianity field; old INRIMAGE-3-style headers; manual reconstruction of headers from raw dumps missing the trailing fields.","solutions":["Add 'Endianity=b' (big endian) or 'Endianity=l' (little endian) to the header before the '##}' terminator, matching the platform that wrote the data.","Re-export with a standard INR writer which always emits the Endianity field.","If the data came from a known-endian source (e.g. SPARC=big, x86=little), set the field accordingly and verify values look sane after load.","Validate generated headers include the Endianity line before closing with '##}'.","Catch CImgIOException and guide the user to append the Endianity field."],"exampleFix":"# before (header, missing endianness)\nPIXSIZE=32\n##}\n# after\nPIXSIZE=32\nEndianity=l\n##}","handlingStrategy":"validation","validationCode":"bool inrEndianityPresent(const std::string& headerText) {\n  return headerText.find(\"Endianity=b\") != std::string::npos\n      || headerText.find(\"Endianity=l\") != std::string::npos;\n}","typeGuard":"bool endianitySpecified(int code) { return code == 0 || code == 1; }","tryCatchPattern":"try { img.load_inr(path); }\ncatch (CImgIOException& e) { fprintf(stderr, \"Endianity undefined — add Endianity=b|l before '##}'\\n\"); }","preventionTips":["Emit 'Endianity=b' or 'Endianity=l' matching the writing platform in every INR header.","Remember x86/ARM writes are little endian ('l').","Keep the Endianity line before the closing '##}' terminator.","Round-trip test generated INR files to catch missing fields."],"tags":["cimg","endianness","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"}