{"record":{"id":"892fd9f8bb29348f","repo":"Yalantis/uCrop","slug":"save-exr-instance-is-volumetric-only-the-first","errorCode":null,"errorMessage":"save_exr(): Instance is volumetric, only the first slice will be saved in file '%s'.","messagePattern":"save_exr\\(\\): Instance is volumetric, only the first slice will be saved in file '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63124,"sourceCode":"      cimg::fwrite(header._data,256,nfile);\n      cimg_forXYZ(*this,x,y,z) cimg_forC(*this,c) cimg::fwrite(&((*this)(x,y,z,c)),1,nfile);\n      if (!file) cimg::fclose(nfile);\n      return *this;\n    }\n\n    //! Save image as an OpenEXR file.\n    /**\n       \\param filename Filename, as a C-string.\n       \\note The OpenEXR file format is <a href=\"http://en.wikipedia.org/wiki/OpenEXR\">described here</a>.\n    **/\n    const CImg<T>& save_exr(const char *const filename) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_exr(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(0,filename); return *this; }\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_exr(): Instance is volumetric, only the first slice will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename);\n\n#ifndef cimg_use_openexr\n      return save_other(filename);\n#else\n      Imf::Rgba *const ptrd0 = new Imf::Rgba[(size_t)_width*_height], *ptrd = ptrd0, rgba;\n      switch (_spectrum) {\n      case 1 : { // Grayscale image\n        for (const T *ptr_r = data(), *const ptr_e = ptr_r + (ulongT)_width*_height; ptr_r<ptr_e;) {\n          rgba.r = (half)(*(ptr_r));\n          rgba.g = (half)(*(ptr_r));\n          rgba.b = (half)(*(ptr_r++));\n          rgba.a = (half)1;\n          *(ptrd++) = rgba;\n        }\n      } break;","sourceCodeStart":63106,"sourceCodeEnd":63142,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63106-L63142","documentation":"save_exr() writes OpenEXR files which are 2D; CImg warns when _depth>1 because only the first slice (z=0) is written and the rest of the volume is silently dropped. Additionally, if CImg was not compiled with cimg_use_openexr the call falls back to save_other(). Emitted via cimg::warn(), non-fatal.","triggerScenarios":"Calling save_exr() on a volumetric image (_depth>1), e.g. a 3D scan, image stack, or an image built with wrong dimension order.","commonSituations":"HDR pipelines handling volumes; saving light-field or z-stack data; accidentally constructing a 3D image when a 2D one was intended (constructor argument mix-up).","solutions":["Save slices individually: for z in range: img.get_slice(z).save_exr(name_for_z)","Use a volumetric format (multi-page TIFF via save_tiff) or the native save_cimg() format","Fix dimension order if depth>1 is unintended: CImg(w,h,1,c) for 2D images"],"exampleFix":"// before\nvolume.save_exr(\"out.exr\");         // only slice 0\n// after\nfor (int z = 0; z < volume.depth(); ++z)\n  volume.get_slice(z).save_exr(cimg::format(\"out_%03d.exr\", z));","handlingStrategy":"validation","validationCode":"if (img.depth() > 1)\n  for (int z = 0; z < img.depth(); ++z) img.get_slice(z).save_exr(cimg::format(\"out_%03d.exr\", z));\nelse\n  img.save_exr(\"out.exr\");","typeGuard":"bool is_2d(const cimg_library::CImg<T>& img) { return img.depth() == 1; }","tryCatchPattern":"try { img.save_exr(\"out.exr\"); } catch (CImgException& e) { /* handle */ }","preventionTips":["Check depth() before EXR saves","Store volumes in TIFF or native CImg format","Verify build defines cimg_use_openexr for real EXR output"],"tags":["cimg","exr","volumetric","data-loss"],"backgroundTag":"unsupported-operation","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"}