{"record":{"id":"59ac7eb9eb7dc67c","repo":"Yalantis/uCrop","slug":"load-jpeg-unable-to-load-data-from-file-un","errorCode":null,"errorMessage":"load_jpeg(): Unable to load data from '(FILE*)' unless libjpeg is enabled.","messagePattern":"load_jpeg\\(\\): Unable to load data from '\\(FILE\\*\\)' unless libjpeg is enabled\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57020,"sourceCode":"    typedef struct _cimg_error_mgr *_cimg_error_ptr;\n\n    METHODDEF(void) _cimg_jpeg_error_exit(j_common_ptr cinfo) {\n      _cimg_error_ptr c_err = (_cimg_error_ptr) cinfo->err; // Return control to the setjmp point\n      (*cinfo->err->format_message)(cinfo,c_err->message);\n      jpeg_destroy(cinfo); // Clean memory and temp files\n      longjmp(c_err->setjmp_buffer,1);\n    }\n#endif\n\n    CImg<T>& _load_jpeg(std::FILE *const file, const char *const filename) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_jpeg(): Specified filename is (null).\",\n                                    cimg_instance);\n\n#ifndef cimg_use_jpeg\n      if (file)\n        throw CImgIOException(_cimg_instance\n                              \"load_jpeg(): Unable to load data from '(FILE*)' unless libjpeg is enabled.\",\n                              cimg_instance);\n      else return load_other(filename);\n#else\n\n#if defined __GNUC__\n      const char *volatile nfilename = filename; // Use 'volatile' to avoid (wrong) g++ warning\n      std::FILE *volatile nfile = file?file:cimg::fopen(nfilename,\"rb\");\n#else\n      const char *nfilename = filename;\n      std::FILE *nfile = file?file:cimg::fopen(nfilename,\"rb\");\n#endif\n\n      struct jpeg_decompress_struct cinfo;\n      struct _cimg_error_mgr jerr;\n      cinfo.err = jpeg_std_error(&jerr.original);\n      jerr.original.error_exit = _cimg_jpeg_error_exit;\n      if (setjmp(jerr.setjmp_buffer)) { // JPEG error","sourceCodeStart":57002,"sourceCodeEnd":57038,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57002-L57038","documentation":"When CImg is compiled without libjpeg support (cimg_use_jpeg not defined), JPEG decoding from an already-open FILE* is impossible because the fallback path needs a filename to dispatch to another loader. CImg throws CImgIOException explaining that libjpeg must be enabled.","triggerScenarios":"Calling load_jpeg(std::FILE*) on a build where cimg_use_jpeg is not defined; in-memory streams/asset FILE* in an Android/uCrop JNI build lacking libjpeg.","commonSituations":"Build configured without cimg_use_jpeg (no cimg_jpeg flags / libjpeg-dev missing), while the app hands CImg a FILE* from Android assets.","solutions":["Rebuild with libjpeg enabled (define cimg_use_jpeg and link libjpeg/libjpeg-turbo)","Install libjpeg development headers (e.g. apt install libjpeg-dev) and recompile","Pass a filesystem path instead of a FILE* so CImg can delegate to another loader","Use a different image format (PNG) supported by the current build"],"exampleFix":"// build: -Dcimg_use_jpeg=1 -ljpeg\n// before\nimg.load_jpeg(assetFile); // FILE*, build lacks libjpeg\n// after\n// rebuild with libjpeg, or:\nimg.load_jpeg(\"/path/to/image.jpg\");","handlingStrategy":"fallback","validationCode":"#ifndef cimg_use_jpeg\n  #error \"Rebuild with cimg_use_jpeg for FILE*-based JPEG loading\"\n#endif","typeGuard":"bool canLoadJpegFromFilePtr() {\n#ifdef cimg_use_jpeg\n  return true;\n#else\n  return false;\n#endif\n}","tryCatchPattern":"try { img.load_jpeg(file, filename); }\ncatch (CImgIOException&) { img.load_jpeg(\"/sdcard/extracted.jpg\"); // path fallback\n}","preventionTips":["Ensure libjpeg is enabled and linked in the native build (cimg_use_jpeg)","Prefer filename-based loading for portability across builds","Add a build-time check that required codecs are enabled","Pin codec dependencies (libjpeg-turbo) in CI builds"],"tags":["jpeg","image-loading","build-configuration","cimg","libjpeg"],"backgroundTag":"missing-optional-dependency","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"}