{"record":{"id":"c35caf5703783c27","repo":"Yalantis/uCrop","slug":"save-pnm-instance-is-volumetric-only-the-first","errorCode":null,"errorMessage":"save_pnm(): Instance is volumetric, only the first slice will be saved in file '%s'.","messagePattern":"save_pnm\\(\\): 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":62282,"sourceCode":"      return _save_pnm(0,filename,bytes_per_pixel);\n    }\n\n    //! Save image as a PNM file \\overloading.\n    const CImg<T>& save_pnm(std::FILE *const file, const unsigned int bytes_per_pixel=0) const {\n      return _save_pnm(file,0,bytes_per_pixel);\n    }\n\n    const CImg<T>& _save_pnm(std::FILE *const file, const char *const filename,\n                             const unsigned int bytes_per_pixel=0) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_pnm(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n\n      double stmin, stmax = (double)max_min(stmin);\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_pnm(): 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_pnm(): Instance is multispectral, only the three first channels will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n      if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)\n        cimg::warn(_cimg_instance\n                   \"save_pnm(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.\",\n                   cimg_instance,\n                   stmin,stmax,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,","sourceCodeStart":62264,"sourceCodeEnd":62300,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62264-L62300","documentation":"Warning from CImg<T>::save_pnm() when the image is volumetric (_depth>1). PNM (PBM/PGM/PPM) formats store a single 2D image, so only the first slice is written and remaining slices are dropped. The save completes without error.","triggerScenarios":"Calling save_pnm() (or save_pnm/save_ppm/save_pgm helpers) on an image whose _depth>1.","commonSituations":"Writing 3D volumes or frame stacks to PPM/PGM, common in coursework or when interoperating with tools that only read 2D PNM.","solutions":["Save each slice separately: cimg_for_z(img,z) img.get_slice(z).save_pnm(...);","Use a volume-capable format (.cimg, TIFF) instead","Take a single slice explicitly with get_slice(z) if that is intended","Ignore the warning if the first slice suffices"],"exampleFix":"// before\nvolume.save_pnm(\"out.ppm\");\n// after\ncimg_for_z(volume,z) volume.get_slice(z).save_pnm(cimg::format(\"out_%d.ppm\",z));","handlingStrategy":"validation","validationCode":"if (img.depth() > 1) { /* save slices or choose another format */ }","typeGuard":null,"tryCatchPattern":"// warning only; guard by depth check before calling save_pnm","preventionTips":["Check img.depth() before saving to PNM","PNM is 2D-only; use .cimg/TIFF for volumes"],"tags":["image-encoding","volumetric-data","pnm"],"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"}