{"record":{"id":"c8e89bede06cf9fb","repo":"Yalantis/uCrop","slug":"load-tiff-unable-to-load-sub-images-from-file","errorCode":null,"errorMessage":"load_tiff(): Unable to load sub-images from file '%s' unless libtiff is enabled.","messagePattern":"load_tiff\\(\\): Unable to load sub-images from file '(.+?)' unless libtiff is enabled\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":67640,"sourceCode":"        \\param first_frame Index of first image frame to read.\n        \\param last_frame Index of last image frame to read.\n        \\param step_frame Step applied between each frame.\n        \\param[out] bits_per_value Number of bits used to store a scalar value in the image file.\n        \\param[out] voxel_size Voxel size, as stored in the filename.\n        \\param[out] description Description, as stored in the filename.\n    **/\n    CImgList<T>& load_tiff(const char *const filename,\n                           const unsigned int first_frame=0, const unsigned int last_frame=~0U,\n                           const unsigned int step_frame=1, unsigned int *const bits_per_value=0,\n                           float *const voxel_size=0, CImg<charT> *const description=0) {\n      const unsigned int\n        nfirst_frame = first_frame<last_frame?first_frame:last_frame,\n        nstep_frame = step_frame?step_frame:1;\n      unsigned int nlast_frame = first_frame<last_frame?last_frame:first_frame;\n#ifndef cimg_use_tiff\n      cimg::unused(bits_per_value,voxel_size,description);\n      if (nfirst_frame || nlast_frame!=~0U || nstep_frame!=1)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_tiff(): Unable to load sub-images from file '%s' unless libtiff is enabled.\",\n                                    cimglist_instance,\n                                    filename);\n\n      return assign(CImg<T>::get_load_tiff(filename));\n#else\n#if cimg_verbosity<3\n        TIFFSetWarningHandler(0);\n        TIFFSetErrorHandler(0);\n#endif\n      TIFF *tif = TIFFOpen(filename,\"r\");\n      if (tif) {\n        unsigned int nb_images = 0;\n        do ++nb_images; while (TIFFReadDirectory(tif));\n        if (nfirst_frame>=nb_images || (nlast_frame!=~0U && nlast_frame>=nb_images))\n          cimg::warn(_cimglist_instance\n                     \"load_tiff(): Invalid specified frame range is [%u,%u] (step %u) since \"\n                     \"file '%s' contains %u image(s).\",","sourceCodeStart":67622,"sourceCodeEnd":67658,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L67622-L67658","documentation":"CImgList::load_tiff() supports loading a subrange of sub-images (frames) only when CImg is compiled with libtiff support (cimg_use_tiff defined). Without libtiff, any request with a frame range or step other than the trivial default throws CImgArgumentException. Only single-image loading via the fallback is possible.","triggerScenarios":"Calling load_tiff(filename, first_frame!=0, ...) or with last_frame/step_frame arguments while the library was built WITHOUT cimg_use_tiff; i.e. requesting multi-frame/sub-image semantics on a libtiff-less build.","commonSituations":"Prebuilt Android/JNI binaries of CImg compiled without libtiff; app code upgraded to use multi-page TIFFs while the vendored CImg build flags never enabled cimg_use_tiff.","solutions":["Rebuild CImg with cimg_use_tiff defined and link against libtiff.","If rebuilding is not possible, call load_tiff with default frame arguments (single image) and load frames one call at a time.","Decode the TIFF with an external library (e.g. libtiff directly) and populate the CImgList yourself."],"exampleFix":"// before\nlist.load_tiff(\"multi.tif\", 0, 10); // throws without libtiff\n// after\nlist.load_tiff(\"multi.tif\"); // single-frame fallback, no libtiff needed\n// or rebuild with: -Dcimg_use_tiff -ltiff","handlingStrategy":"fallback","validationCode":"// load only single-frame ranges unless libtiff support was compiled in\n#ifdef cimg_use_tiff\n  list.load_tiff(path, first, last, step);\n#else\n  list.load_tiff(path); // default single-image form\n#endif","typeGuard":null,"tryCatchPattern":"try { list.load_tiff(path, first, last); }\ncatch (CImgArgumentException &e) { list.load_tiff(path); /* single-frame fallback */ }","preventionTips":["Build CImg with cimg_use_tiff if you need multi-page TIFFs.","Keep build flags in sync with the feature usage in app code.","Document frame-range requirements for the packaging team."],"tags":["tiff","compile-time","feature-flag"],"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-17T15:17:12.973Z"}