{"record":{"id":"355a0ff49d85da2b","repo":"Yalantis/uCrop","slug":"save-pfm-instance-is-volumetric-only-the-first","errorCode":null,"errorMessage":"save_pfm(): Instance is volumetric, only the first slice will be saved in file '%s'.","messagePattern":"save_pfm\\(\\): 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":62486,"sourceCode":"    const CImg<T>& save_pfm(const char *const filename) const {\n      get_mirror('y')._save_pfm(0,filename);\n      return *this;\n    }\n\n    //! Save image as a PFM file \\overloading.\n    const CImg<T>& save_pfm(std::FILE *const file) const {\n      get_mirror('y')._save_pfm(file,0);\n      return *this;\n    }\n\n    const CImg<T>& _save_pfm(std::FILE *const file, const char *const filename) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_pfm(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_pfm(): Instance is volumetric, only the first slice will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n      if (_spectrum>3)\n        cimg::warn(_cimg_instance\n                   \"save_pfm(): image instance is multispectral, only the three first channels will be saved \"\n                   \"in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"wb\");\n      const T\n        *ptr_r = data(0,0,0,0),\n        *ptr_g = (_spectrum>=2)?data(0,0,0,1):0,\n        *ptr_b = (_spectrum>=3)?data(0,0,0,2):0;\n      const unsigned int buf_size = std::min(1024*1024U,_width*_height*(_spectrum==1?1:3));\n\n      std::fprintf(nfile,\"P%c\\n%u %u\\n1.0\\n\",","sourceCodeStart":62468,"sourceCodeEnd":62504,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62468-L62504","documentation":"save_pfm() writes a 2D floating-point radiance map (Portable Float Map); CImg warns when _depth>1 because PFM has no volumetric extension and only the first z-slice (depth 0) is written. The remaining slices are silently dropped. Emitted via cimg::warn(), non-fatal.","triggerScenarios":"Calling save_pfm() on a volumetric CImg where _depth>1, e.g. after loading a multi-slice TIFF/NIfTI stack, building a 3D volume from slices, or an image accidentally constructed with depth>1.","commonSituations":"HDR pipelines handling image stacks; saving 3D medical imaging data to PFM; bugs where width/height/depth constructor arguments were passed in the wrong order producing unintended depth.","solutions":["Save each slice separately: for (int z=0; z<img.depth(); ++z) img.get_slice(z).save_pfm(name_for_z)","Use a volumetric-capable format (multi-page TIFF via save_tiff, or DICOM/NIfTI if available)","If depth>1 is a bug, fix constructor argument order: CImg(w,h,1,c) for 2D images"],"exampleFix":"// before\nvolume.save_pfm(\"out.pfm\");         // only slice 0 saved\n// after\nfor (int z = 0; z < volume.depth(); ++z)\n  volume.get_slice(z).save_pfm(cimg::format(\"out_%03d.pfm\", z));","handlingStrategy":"validation","validationCode":"if (img.depth() > 1)\n  for (int z = 0; z < img.depth(); ++z) img.get_slice(z).save_pfm(cimg::format(\"out_%03d.pfm\", z));\nelse\n  img.save_pfm(\"out.pfm\");","typeGuard":"bool is_2d(const cimg_library::CImg<T>& img) { return img.depth() == 1; }","tryCatchPattern":"try { img.save_pfm(\"out.pfm\"); } catch (CImgException& e) { /* handle */ }","preventionTips":["Check depth() before 2D-only savers","Save volumes to TIFF or native CImg format","Verify constructor argument order (w,h,d,c) for 2D images"],"tags":["cimg","pfm","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"}