Yalantis/uCrop · error · CImgIOException

CImg<%s>::load_inr(): Big/Little Endian coding type undefine

Error message

CImg<%s>::load_inr(): Big/Little Endian coding type undefined in header.

What it means

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.

Source

Thrown at ucrop/src/main/jni/CImg.h:58691

          if (out[4]>=0) break; // Fallthrough
        default :
          throw CImgIOException("CImg<%s>::load_inr(): Invalid pixel type '%s' defined in header.",
                                pixel_type(),
                                tmp2._data);
        }
      }
      if (out[0]<0 || out[1]<0 || out[2]<0 || out[3]<0)
        throw CImgIOException("CImg<%s>::load_inr(): Invalid dimensions (%d,%d,%d,%d) defined in header.",
                              pixel_type(),
                              out[0],out[1],out[2],out[3]);
      if (out[4]<0 || out[5]<0)
        throw CImgIOException("CImg<%s>::load_inr(): Incomplete pixel type defined in header.",
                              pixel_type());
      if (out[6]<0)
        throw CImgIOException("CImg<%s>::load_inr(): Incomplete PIXSIZE field defined in header.",
                              pixel_type());
      if (out[7]<0)
        throw CImgIOException("CImg<%s>::load_inr(): Big/Little Endian coding type undefined in header.",
                              pixel_type());
    }

    CImg<T>& _load_inr(std::FILE *const file, const char *const filename, float *const voxel_size) {
#define _cimg_load_inr_case(Tf,sign,pixsize,Ts) \
     if (!loaded && fopt[6]==pixsize && fopt[4]==Tf && fopt[5]==sign) { \
        Ts *xval, *const val = new Ts[(size_t)fopt[0]*fopt[3]]; \
        cimg_forYZ(*this,y,z) { \
            cimg::fread(val,fopt[0]*fopt[3],nfile); \
            if (fopt[7]!=endian) cimg::invert_endianness(val,fopt[0]*fopt[3]); \
            xval = val; cimg_forX(*this,x) cimg_forC(*this,c) (*this)(x,y,z,c) = (T)*(xval++); \
          } \
        delete[] val; \
        loaded = true; \
      }

      if (!file && !filename)
        throw CImgArgumentException(_cimg_instance

View on GitHub (pinned to f788b534b4)

Solutions

  1. Add 'Endianity=b' (big endian) or 'Endianity=l' (little endian) to the header before the '##}' terminator, matching the platform that wrote the data.
  2. Re-export with a standard INR writer which always emits the Endianity field.
  3. 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.
  4. Validate generated headers include the Endianity line before closing with '##}'.
  5. Catch CImgIOException and guide the user to append the Endianity field.

Example fix

# before (header, missing endianness)
PIXSIZE=32
##}
# after
PIXSIZE=32
Endianity=l
##}
Defensive patterns

Strategy: validation

Validate before calling

bool inrEndianityPresent(const std::string& headerText) {
  return headerText.find("Endianity=b") != std::string::npos
      || headerText.find("Endianity=l") != std::string::npos;
}

Type guard

bool endianitySpecified(int code) { return code == 0 || code == 1; }

Try / catch

try { img.load_inr(path); }
catch (CImgIOException& e) { fprintf(stderr, "Endianity undefined — add Endianity=b|l before '##}'\n"); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/4335d222c63b168b. Report an issue: GitHub.