{"record":{"id":"13f0eb296ad4f140","repo":"Yalantis/uCrop","slug":"cimg-s-load-inr-incomplete-pixel-type-define","errorCode":null,"errorMessage":"CImg<%s>::load_inr(): Incomplete pixel type defined in header.","messagePattern":"CImg<(.+?)>::load_inr\\(\\): Incomplete pixel type defined in header\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58685,"sourceCode":"          out[5] = cimg::strncasecmp(tmp1,\"unsigned\",8)?1:0;\n          std::strncpy(tmp1,tmp2,tmp1._width - 1); // Fallthrough\n        case 1 :\n          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          } \\","sourceCodeStart":58667,"sourceCodeEnd":58703,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58667-L58703","documentation":"The INR header must fully specify the pixel type via both TYPE (out[4]) and PIXSIZE (out[5]). If either keyword was absent/unparsed so that out[4] or out[5] remains the sentinel -1, _load_inr_header() throws this exception — the pixel encoding is incomplete, not merely invalid.","triggerScenarios":"Header omits the TYPE line entirely (out[4]==-1) or omits PIXSIZE (out[5]==-1); the TYPE line exists but no keyword matched AND the case-1 fallthrough left out[4] negative; raised from load_inr()/load() on .inr files.","commonSituations":"Hand-trimmed headers missing fields; writers that emit only PIXSIZE assuming a default TYPE; truncation of the trailing text block of the INR file where these lines live.","solutions":["Add/repair both TYPE and PIXSIZE lines in the header, e.g. TYPE=float and PIXSIZE=32.","Re-export with a standard INR writer to regenerate a complete header.","When generating headers, assert out[4]>=0 && out[5]>=0 before writing '##}'.","Inspect the text block after the magic token — ensure the file wasn't truncated before '##}'.","Catch CImgIOException and distinguish 'incomplete' vs 'invalid pixel type' to guide repair."],"exampleFix":"# before (header, TYPE line missing)\nPIXSIZE=32\n# after\nTYPE=float\nPIXSIZE=32","handlingStrategy":"validation","validationCode":"bool inrPixelSpecComplete(const std::string& headerText) {\n  return headerText.find(\"TYPE=\") != std::string::npos\n      && headerText.find(\"PIXSIZE=\") != std::string::npos;\n}","typeGuard":"bool pixelTypeSpecified(int typeCode, int pixCode) { return typeCode >= 0 && pixCode >= 0; }","tryCatchPattern":"try { img.load_inr(path); }\ncatch (CImgIOException& e) { fprintf(stderr, \"Incomplete pixel type — add TYPE and PIXSIZE lines\\n\"); }","preventionTips":["Include both TYPE and PIXSIZE in every generated INR header.","Never hand-trim header fields; edit values, not lines.","Verify the file retains its full trailing text block (through '##}').","Validate headers with a checklist at export time."],"tags":["cimg","pixel-type","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"}